use of com.canoo.dp.impl.client.legacy.ClientPresentationModel in project dolphin-platform by canoo.
the class TestObservableListSync method deletingSingleElementInBeginningAsUser_shouldRemoveElement.
// ////////////////////////////////////////////////////////////
// Removing elements from different positions as user
// ////////////////////////////////////////////////////////////
@Test
public void deletingSingleElementInBeginningAsUser_shouldRemoveElement(@Mocked AbstractClientConnector connector) {
// given :
final ClientModelStore clientModelStore = createClientModelStore(connector);
final BeanManager manager = createBeanManager(clientModelStore);
final ListReferenceModel model = manager.create(ListReferenceModel.class);
final PresentationModel sourceModel = clientModelStore.findAllPresentationModelsByType(ListReferenceModel.class.getName()).get(0);
model.getPrimitiveList().addAll(Arrays.asList("1", "2", "3"));
deleteAllPresentationModelsOfType(clientModelStore, PlatformRemotingConstants.LIST_SPLICE);
// when :
model.getPrimitiveList().remove(0);
// then :
final List<ClientPresentationModel> changes = clientModelStore.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) 1)));
assertThat(change.getAttribute("count").getValue(), allOf(instanceOf(Integer.class), is((Object) 0)));
}
use of com.canoo.dp.impl.client.legacy.ClientPresentationModel in project dolphin-platform by canoo.
the class TestObservableListSync method replacingObjectElementFromDolphin_shouldReplaceElement.
@Test
public void replacingObjectElementFromDolphin_shouldReplaceElement(@Mocked AbstractClientConnector connector) {
// given :
final ClientModelStore clientModelStore = createClientModelStore(connector);
final BeanManager manager = createBeanManager(clientModelStore);
final ListReferenceModel model = manager.create(ListReferenceModel.class);
final PresentationModel sourceModel = clientModelStore.findAllPresentationModelsByType(ListReferenceModel.class.getName()).get(0);
final PresentationModel classDescription = clientModelStore.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 = clientModelStore.findAllPresentationModelsByType(SimpleTestModel.class.getName()).get(0);
final SimpleTestModel newObject = manager.create(SimpleTestModel.class);
final List<ClientPresentationModel> models = clientModelStore.findAllPresentationModelsByType(SimpleTestModel.class.getName());
final PresentationModel newObjectModel = oldObjectModel == models.get(1) ? models.get(0) : models.get(1);
new PresentationModelBuilder(clientModelStore, 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(clientModelStore, 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(clientModelStore.findAllPresentationModelsByType(PlatformRemotingConstants.LIST_SPLICE), empty());
}
use of com.canoo.dp.impl.client.legacy.ClientPresentationModel in project dolphin-platform by canoo.
the class TestPropertyValue method testWithSingleReferenceModel.
@Test
public void testWithSingleReferenceModel(@Mocked AbstractClientConnector connector) {
final ClientModelStore clientModelStore = createClientModelStore(connector);
final EventDispatcher dispatcher = createEventDispatcher(clientModelStore);
final BeanRepository repository = createBeanRepository(clientModelStore, dispatcher);
final BeanManager manager = createBeanManager(clientModelStore, repository, dispatcher);
final SimpleTestModel ref1 = manager.create(SimpleTestModel.class);
ref1.getTextProperty().set("ref1_text");
final SimpleTestModel ref2 = manager.create(SimpleTestModel.class);
ref2.getTextProperty().set("ref2_text");
final List<ClientPresentationModel> refPMs = clientModelStore.findAllPresentationModelsByType(SimpleTestModel.class.getName());
final PresentationModel ref1PM = "ref1_text".equals(refPMs.get(0).getAttribute("text").getValue()) ? refPMs.get(0) : refPMs.get(1);
final PresentationModel ref2PM = "ref2_text".equals(refPMs.get(0).getAttribute("text").getValue()) ? refPMs.get(0) : refPMs.get(1);
final SingleReferenceModel model = manager.create(SingleReferenceModel.class);
final PresentationModel dolphinModel = clientModelStore.findAllPresentationModelsByType(SingleReferenceModel.class.getName()).get(0);
final Attribute referenceAttribute = dolphinModel.getAttribute("referenceProperty");
assertThat(referenceAttribute.getValue(), nullValue());
model.getReferenceProperty().set(ref1);
assertThat(referenceAttribute.getValue(), is((Object) ref1PM.getId()));
assertThat(model.getReferenceProperty().get(), is(ref1));
referenceAttribute.setValue(ref2PM.getId());
assertThat(referenceAttribute.getValue(), is((Object) ref2PM.getId()));
assertThat(model.getReferenceProperty().get(), is(ref2));
}
use of com.canoo.dp.impl.client.legacy.ClientPresentationModel in project dolphin-platform by canoo.
the class ClientPresentationModelTest method testStandardCtor.
@Test
public void testStandardCtor() {
ClientPresentationModel model = new ClientPresentationModel("x", Collections.<ClientAttribute>emptyList());
Assert.assertEquals("x", model.getId());
}
use of com.canoo.dp.impl.client.legacy.ClientPresentationModel in project dolphin-platform by canoo.
the class ClientPresentationModelTest method testNullIdCtor.
@Test
public void testNullIdCtor() {
ClientPresentationModel model1 = new ClientPresentationModel(Collections.<ClientAttribute>emptyList());
ClientPresentationModel model2 = new ClientPresentationModel(Collections.<ClientAttribute>emptyList());
Assert.assertNotEquals(model1.getId(), model2.getId());
}
Aggregations