blob: 4a897d1447c9ca19be3cb12323ec728f2f50f0e7 [file] [log] [blame]
/*******************************************************************************
* Copyright (c) 2012, 2014 - Lunifera GmbH (Gross Enzersdorf, Austria), Loetz GmbH&Co.KG (69115 Heidelberg, Germany)
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributor:
* Florian Pirchner - initial implementation
*
*******************************************************************************/
package org.eclipse.osbp.runtime.web.vaadin.databinding.tests.model;
import org.eclipse.core.databinding.Binding;
import org.eclipse.core.databinding.DataBindingContext;
import org.eclipse.core.databinding.observable.value.WritableValue;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.eclipse.osbp.runtime.web.vaadin.databinding.VaadinObservables;
import com.vaadin.data.util.ObjectProperty;
import com.vaadin.ui.TextField;
public class PropertyValueTests {
@Before
public void setup() {
DefaultUI.setCurrent(new DefaultUI());
VaadinObservables.getRealm(DefaultUI.getCurrent());
}
@Test
public void test_propertyValue() {
VaadinObservables.getRealm(DefaultUI.getCurrent());
ObjectProperty<String> property = new ObjectProperty<String>("");
WritableValue value = new WritableValue();
Assert.assertNull(value.getValue());
DataBindingContext dbc = new DataBindingContext();
dbc.bindValue(value, VaadinObservables.observeValue(property));
Assert.assertEquals("", value.getValue());
property.setValue("Huhu");
Assert.assertEquals("Huhu", value.getValue());
}
@Test
public void test_propertyValue_updateFromTarget() {
VaadinObservables.getRealm(DefaultUI.getCurrent());
ObjectProperty<String> property = new ObjectProperty<String>("Huhu");
WritableValue value = new WritableValue();
DataBindingContext dbc = new DataBindingContext();
dbc.bindValue(value, VaadinObservables.observeValue(property));
Assert.assertEquals("Huhu", property.getValue());
value.setValue("Hahaha");
Assert.assertEquals("Hahaha", property.getValue());
}
@Test
public void test_propertyValue_updateModelToTarget() {
TextField text = new TextField();
WritableValue value = new WritableValue();
Assert.assertNull(value.getValue());
DataBindingContext dbc = new DataBindingContext();
Binding binding = dbc.bindValue(value, VaadinObservables.observeInputPrompt(text));
Assert.assertNull(text.getInputPrompt());
text.setInputPrompt("Huhu");
Assert.assertNull(value.getValue());
binding.updateModelToTarget();
Assert.assertEquals("Huhu", value.getValue());
}
}