use of com.canoo.dolphin.client.util.SimpleTestModel in project dolphin-platform by canoo.
the class TestObservableListSync method deletingObjectElementAsUser_shouldDeleteElement.
@Test
public void deletingObjectElementAsUser_shouldDeleteElement(@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 SimpleTestModel object = manager.create(SimpleTestModel.class);
model.getObjectList().add(object);
deleteAllPresentationModelsOfType(clientModelStore, PlatformRemotingConstants.LIST_SPLICE);
// when :
model.getObjectList().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) "objectList")));
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.dolphin.client.util.SimpleTestModel in project dolphin-platform by canoo.
the class TestObservableListSync method replaceObjectNullWithElementAsUser_shouldReplaceElement.
@Test
public void replaceObjectNullWithElementAsUser_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 SimpleTestModel newObject = manager.create(SimpleTestModel.class);
final PresentationModel newObjectModel = clientModelStore.findAllPresentationModelsByType(SimpleTestModel.class.getName()).get(0);
model.getObjectList().add(null);
deleteAllPresentationModelsOfType(clientModelStore, PlatformRemotingConstants.LIST_SPLICE);
// when :
model.getObjectList().set(0, newObject);
// 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) "objectList")));
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) 1)));
assertThat(change.getAttribute("0").getValue(), allOf(instanceOf(String.class), is((Object) newObjectModel.getId())));
}
use of com.canoo.dolphin.client.util.SimpleTestModel in project dolphin-platform by canoo.
the class TestObservableListSync method replaceObjectElementAsUser_shouldReplaceElement.
@Test
public void replaceObjectElementAsUser_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 SimpleTestModel newObject = manager.create(SimpleTestModel.class);
final PresentationModel newObjectModel = clientModelStore.findAllPresentationModelsByType(SimpleTestModel.class.getName()).get(0);
final SimpleTestModel oldObject = manager.create(SimpleTestModel.class);
model.getObjectList().add(oldObject);
deleteAllPresentationModelsOfType(clientModelStore, PlatformRemotingConstants.LIST_SPLICE);
// when :
model.getObjectList().set(0, newObject);
// 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) "objectList")));
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) 1)));
assertThat(change.getAttribute("0").getValue(), allOf(instanceOf(String.class), is((Object) newObjectModel.getId())));
}
use of com.canoo.dolphin.client.util.SimpleTestModel in project dolphin-platform by canoo.
the class TestObservableListSync method addingObjectElementFromDolphin_shouldAddElement.
// /////////////////////////////////////////////////////////////////
// Adding, removing, and replacing all element types from dolphin
// /////////////////////////////////////////////////////////////////
@Test
public void addingObjectElementFromDolphin_shouldAddElement(@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 object = manager.create(SimpleTestModel.class);
final PresentationModel objectModel = clientModelStore.findAllPresentationModelsByType(SimpleTestModel.class.getName()).get(0);
// when :
new PresentationModelBuilder(clientModelStore, PlatformRemotingConstants.LIST_SPLICE).withAttribute("source", sourceModel.getId()).withAttribute("attribute", "objectList").withAttribute("from", 0).withAttribute("to", 0).withAttribute("count", 1).withAttribute("0", objectModel.getId()).create();
// then :
assertThat(model.getObjectList(), is(Collections.singletonList(object)));
assertThat(clientModelStore.findAllPresentationModelsByType(PlatformRemotingConstants.LIST_SPLICE), empty());
}
use of com.canoo.dolphin.client.util.SimpleTestModel in project dolphin-platform by canoo.
the class TestDeleteAll method testWithSimpleModel.
@Test
public void testWithSimpleModel(@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);
SimpleTestModel model1 = manager.create(SimpleTestModel.class);
SimpleTestModel model2 = manager.create(SimpleTestModel.class);
SimpleTestModel model3 = manager.create(SimpleTestModel.class);
SimpleAnnotatedTestModel wrongModel = manager.create(SimpleAnnotatedTestModel.class);
for (Object bean : manager.findAll(SimpleTestModel.class)) {
repository.delete(bean);
}
assertThat(repository.isManaged(model1), is(false));
assertThat(repository.isManaged(model2), is(false));
assertThat(repository.isManaged(model3), is(false));
assertThat(repository.isManaged(wrongModel), is(true));
List<ClientPresentationModel> testModels = clientModelStore.findAllPresentationModelsByType("com.canoo.dolphin.client.util.SimpleTestModel");
assertThat(testModels, hasSize(0));
}
Aggregations