use of com.canoo.dp.impl.server.legacy.ServerModelStore in project dolphin-platform by canoo.
the class TestObservableListSync method addingPrimitiveElementAsUser_shouldAddElement.
@Test
public void addingPrimitiveElementAsUser_shouldAddElement() {
// given :
final ServerModelStore serverModelStore = createServerModelStore();
final BeanManager manager = createBeanManager(serverModelStore);
final ListReferenceModel model = manager.create(ListReferenceModel.class);
final PresentationModel sourceModel = serverModelStore.findAllPresentationModelsByType(ListReferenceModel.class.getName()).get(0);
final String value = "Hello";
// when :
model.getPrimitiveList().add(value);
// then :
final List<ServerPresentationModel> changes = serverModelStore.findAllPresentationModelsByType(PlatformRemotingConstants.LIST_SPLICE);
assertThat(changes, hasSize(1));
final PresentationModel change = changes.get(0);
assertThat(change.getAttribute("source").getValue(), allOf(instanceOf(String.class), is((Object) sourceModel.getId())));
assertThat(change.getAttribute("attribute").getValue(), allOf(instanceOf(String.class), is((Object) "primitiveList")));
assertThat(change.getAttribute("from").getValue(), allOf(instanceOf(Integer.class), is((Object) 0)));
assertThat(change.getAttribute("to").getValue(), allOf(instanceOf(Integer.class), is((Object) 0)));
assertThat(change.getAttribute("count").getValue(), allOf(instanceOf(Integer.class), is((Object) 1)));
assertThat(change.getAttribute("0").getValue(), allOf(instanceOf(String.class), is((Object) value)));
}
use of com.canoo.dp.impl.server.legacy.ServerModelStore in project dolphin-platform by canoo.
the class TestPropertyChange method testWithSimpleModel.
@Test
public void testWithSimpleModel() {
ServerModelStore serverModelStore = createServerModelStore();
final BeanManager manager = createBeanManager(serverModelStore);
final SimpleTestModel model = manager.create(SimpleTestModel.class);
final ListerResults<String> results = new ListerResults<>();
ValueChangeListener<String> myListener = new ValueChangeListener<String>() {
@SuppressWarnings("unchecked")
@Override
public void valueChanged(ValueChangeEvent<? extends String> evt) {
assertThat((Property<String>) evt.getSource(), is(model.getTextProperty()));
results.newValue = evt.getNewValue();
results.oldValue = evt.getOldValue();
results.listenerCalls++;
}
};
final Subscription subscription = model.getTextProperty().onChanged(myListener);
assertThat(results.listenerCalls, is(0));
assertThat(results.newValue, nullValue());
assertThat(results.oldValue, nullValue());
model.getTextProperty().set("Hallo Property");
assertThat(results.listenerCalls, is(1));
assertThat(results.newValue, is("Hallo Property"));
assertThat(results.oldValue, nullValue());
results.listenerCalls = 0;
model.getTextProperty().set("Hallo Property2");
assertThat(results.listenerCalls, is(1));
assertThat(results.newValue, is("Hallo Property2"));
assertThat(results.oldValue, is("Hallo Property"));
results.listenerCalls = 0;
subscription.unsubscribe();
model.getTextProperty().set("Hallo Property3");
assertThat(results.listenerCalls, is(0));
assertThat(results.newValue, is("Hallo Property2"));
assertThat(results.oldValue, is("Hallo Property"));
}
use of com.canoo.dp.impl.server.legacy.ServerModelStore in project dolphin-platform by canoo.
the class TestPropertyValue method testWithAllPrimitiveDataTypesModel.
@Test
public void testWithAllPrimitiveDataTypesModel() {
final ServerModelStore serverModelStore = createServerModelStore();
final BeanManager manager = createBeanManager(serverModelStore);
PrimitiveDataTypesModel model = manager.create(PrimitiveDataTypesModel.class);
ServerPresentationModel dolphinModel = serverModelStore.findAllPresentationModelsByType(PrimitiveDataTypesModel.class.getName()).get(0);
Attribute textAttribute = dolphinModel.getAttribute("textProperty");
assertThat(textAttribute.getValue(), nullValue());
model.getTextProperty().set("Hallo Platform");
assertThat((String) textAttribute.getValue(), is("Hallo Platform"));
assertThat(model.getTextProperty().get(), is("Hallo Platform"));
textAttribute.setValue("Hallo Dolphin");
assertThat((String) textAttribute.getValue(), is("Hallo Dolphin"));
assertThat(model.getTextProperty().get(), is("Hallo Dolphin"));
Attribute intAttribute = dolphinModel.getAttribute("integerProperty");
assertThat(intAttribute.getValue(), nullValue());
model.getIntegerProperty().set(1);
assertThat((Integer) intAttribute.getValue(), is(1));
assertThat(model.getIntegerProperty().get(), is(1));
intAttribute.setValue(2);
assertThat((Integer) intAttribute.getValue(), is(2));
assertThat(model.getIntegerProperty().get(), is(2));
Attribute booleanAttribute = dolphinModel.getAttribute("booleanProperty");
assertThat(booleanAttribute.getValue(), nullValue());
model.getBooleanProperty().set(true);
assertThat((Boolean) booleanAttribute.getValue(), is(true));
assertThat(model.getBooleanProperty().get(), is(true));
model.getBooleanProperty().set(false);
assertThat((Boolean) booleanAttribute.getValue(), is(false));
assertThat(model.getBooleanProperty().get(), is(false));
}
use of com.canoo.dp.impl.server.legacy.ServerModelStore in project dolphin-platform by canoo.
the class TestPropertyValue method testWithComplexDataTypesModel.
@Test
public void testWithComplexDataTypesModel() {
final Calendar date1 = new GregorianCalendar(2016, Calendar.MARCH, 1, 0, 1, 2);
date1.set(Calendar.MILLISECOND, 3);
date1.setTimeZone(TimeZone.getTimeZone("GMT+2:00"));
final Calendar date2 = new GregorianCalendar(2016, Calendar.FEBRUARY, 29, 0, 1, 2);
date2.set(Calendar.MILLISECOND, 3);
date2.setTimeZone(TimeZone.getTimeZone("UTC"));
final ServerModelStore serverModelStore = createServerModelStore();
final BeanManager manager = createBeanManager(serverModelStore);
ComplexDataTypesModel model = manager.create(ComplexDataTypesModel.class);
PresentationModel dolphinModel = serverModelStore.findAllPresentationModelsByType(ComplexDataTypesModel.class.getName()).get(0);
Attribute dateAttribute = dolphinModel.getAttribute("dateProperty");
assertThat(dateAttribute.getValue(), nullValue());
model.getDateProperty().set(date1.getTime());
assertThat((String) dateAttribute.getValue(), is("2016-02-29T22:01:02.003Z"));
assertThat(model.getDateProperty().get(), is(date1.getTime()));
dateAttribute.setValue("2016-02-29T00:01:02.003Z");
assertThat((String) dateAttribute.getValue(), is("2016-02-29T00:01:02.003Z"));
assertThat(model.getDateProperty().get(), is(date2.getTime()));
Attribute calendarAttribute = dolphinModel.getAttribute("calendarProperty");
assertThat(calendarAttribute.getValue(), nullValue());
model.getCalendarProperty().set(date1);
assertThat((String) calendarAttribute.getValue(), is("2016-02-29T22:01:02.003Z"));
assertThat(model.getCalendarProperty().get().getTimeInMillis(), is(date1.getTimeInMillis()));
calendarAttribute.setValue("2016-02-29T00:01:02.003Z");
assertThat((String) calendarAttribute.getValue(), is("2016-02-29T00:01:02.003Z"));
assertThat(model.getCalendarProperty().get(), is(date2));
Attribute enumAttribute = dolphinModel.getAttribute("enumProperty");
assertThat(enumAttribute.getValue(), nullValue());
model.getEnumProperty().set(VALUE_1);
assertThat((String) enumAttribute.getValue(), is("VALUE_1"));
assertThat(model.getEnumProperty().get(), is(VALUE_1));
enumAttribute.setValue("VALUE_2");
assertThat((String) enumAttribute.getValue(), is("VALUE_2"));
assertThat(model.getEnumProperty().get(), is(VALUE_2));
}
use of com.canoo.dp.impl.server.legacy.ServerModelStore in project dolphin-platform by canoo.
the class TestPropertyValue method testWithSimpleModel.
@Test
public void testWithSimpleModel() {
final ServerModelStore serverModelStore = createServerModelStore();
final BeanManager manager = createBeanManager(serverModelStore);
SimpleTestModel model = manager.create(SimpleTestModel.class);
ServerPresentationModel dolphinModel = serverModelStore.findAllPresentationModelsByType(SimpleTestModel.class.getName()).get(0);
Attribute textAttribute = dolphinModel.getAttribute("text");
assertThat(textAttribute.getValue(), nullValue());
model.getTextProperty().set("Hallo Platform");
assertThat((String) textAttribute.getValue(), is("Hallo Platform"));
assertThat(model.getTextProperty().get(), is("Hallo Platform"));
textAttribute.setValue("Hallo Dolphin");
assertThat((String) textAttribute.getValue(), is("Hallo Dolphin"));
assertThat(model.getTextProperty().get(), is("Hallo Dolphin"));
}
Aggregations