use of com.canoo.dp.impl.server.legacy.ServerPresentationModel in project dolphin-platform by canoo.
the class TestObservableListSync method replacingObjectElementFromDolphin_shouldReplaceElement.
@Test
public void replacingObjectElementFromDolphin_shouldReplaceElement() {
// 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 PresentationModel classDescription = serverModelStore.findAllPresentationModelsByType(PlatformRemotingConstants.DOLPHIN_BEAN).get(0);
classDescription.getAttribute("objectList").setValue(DolphinBeanConverterFactory.FIELD_TYPE_DOLPHIN_BEAN);
final SimpleTestModel oldObject = manager.create(SimpleTestModel.class);
final PresentationModel oldObjectModel = serverModelStore.findAllPresentationModelsByType(SimpleTestModel.class.getName()).get(0);
final SimpleTestModel newObject = manager.create(SimpleTestModel.class);
final List<ServerPresentationModel> models = serverModelStore.findAllPresentationModelsByType(SimpleTestModel.class.getName());
final PresentationModel newObjectModel = oldObjectModel == models.get(1) ? models.get(0) : models.get(1);
new PresentationModelBuilder(serverModelStore, PlatformRemotingConstants.LIST_SPLICE).withAttribute("source", sourceModel.getId()).withAttribute("attribute", "objectList").withAttribute("from", 0).withAttribute("to", 0).withAttribute("count", 1).withAttribute("0", oldObjectModel.getId()).create();
assertThat(model.getObjectList(), is(Collections.singletonList(oldObject)));
// when :
new PresentationModelBuilder(serverModelStore, PlatformRemotingConstants.LIST_SPLICE).withAttribute("source", sourceModel.getId()).withAttribute("attribute", "objectList").withAttribute("pos", 0).withAttribute("from", 0).withAttribute("to", 1).withAttribute("count", 1).withAttribute("0", newObjectModel.getId()).create();
// then :
assertThat(model.getObjectList(), is(Collections.singletonList(newObject)));
assertThat(serverModelStore.findAllPresentationModelsByType(PlatformRemotingConstants.LIST_SPLICE), empty());
}
use of com.canoo.dp.impl.server.legacy.ServerPresentationModel in project dolphin-platform by canoo.
the class TestObservableListSync method addingSingleElementInBeginningAsUser_shouldAddElement.
@Test
public void addingSingleElementInBeginningAsUser_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 newElement = "42";
model.getPrimitiveList().addAll(Arrays.asList("1", "2", "3"));
removeAllPresentationModelsOfType(serverModelStore, PlatformRemotingConstants.LIST_SPLICE);
// when :
model.getPrimitiveList().add(0, newElement);
// 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(), is((Object) newElement));
}
use of com.canoo.dp.impl.server.legacy.ServerPresentationModel 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.ServerPresentationModel 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.ServerPresentationModel 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