use of com.canoo.dp.impl.client.legacy.ClientPresentationModel in project dolphin-platform by canoo.
the class TestObservableListSync method deletingObjectNullAsUser_shouldDeleteElement.
@Test
public void deletingObjectNullAsUser_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);
model.getObjectList().add(null);
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.dp.impl.client.legacy.ClientPresentationModel in project dolphin-platform by canoo.
the class TestObservableListSync method replacePrimitiveNullWithElementAsUser_shouldReplaceElement.
@Test
public void replacePrimitiveNullWithElementAsUser_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 String newValue = "Goodbye World";
model.getPrimitiveList().add(null);
deleteAllPresentationModelsOfType(clientModelStore, PlatformRemotingConstants.LIST_SPLICE);
// when :
model.getPrimitiveList().set(0, newValue);
// 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) 1)));
assertThat(change.getAttribute("0").getValue(), allOf(instanceOf(String.class), is((Object) newValue)));
}
use of com.canoo.dp.impl.client.legacy.ClientPresentationModel in project dolphin-platform by canoo.
the class TestObservableListSync method replacingSingleElementInMiddleAsUser_shouldReplaceElement.
@Test
public void replacingSingleElementInMiddleAsUser_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 String newValue = "42";
model.getPrimitiveList().addAll(Arrays.asList("1", "2", "3"));
deleteAllPresentationModelsOfType(clientModelStore, PlatformRemotingConstants.LIST_SPLICE);
// when :
model.getPrimitiveList().set(1, newValue);
// 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) 1)));
assertThat(change.getAttribute("to").getValue(), allOf(instanceOf(Integer.class), is((Object) 2)));
assertThat(change.getAttribute("count").getValue(), allOf(instanceOf(Integer.class), is((Object) 1)));
assertThat(change.getAttribute("0").getValue(), allOf(instanceOf(String.class), is((Object) newValue)));
}
use of com.canoo.dp.impl.client.legacy.ClientPresentationModel in project dolphin-platform by canoo.
the class ClientConnectorTests method testHandle_DeletePresentationModel.
@Test
public void testHandle_DeletePresentationModel() {
ClientPresentationModel p1 = clientModelStore.createModel("p1", null);
p1.setClientSideOnly(true);
ClientPresentationModel p2 = clientModelStore.createModel("p2", null);
clientConnector.dispatchHandle(new DeletePresentationModelCommand(null));
ClientPresentationModel model = new ClientPresentationModel("p3", Collections.<ClientAttribute>emptyList());
clientConnector.dispatchHandle(new DeletePresentationModelCommand(model.getId()));
clientConnector.dispatchHandle(new DeletePresentationModelCommand(p1.getId()));
clientConnector.dispatchHandle(new DeletePresentationModelCommand(p2.getId()));
Assert.assertNull(clientModelStore.findPresentationModelById(p1.getId()));
Assert.assertNull(clientModelStore.findPresentationModelById(p2.getId()));
syncAndWaitUntilDone();
// 3 commands will have been transferred:
// 1: delete of p1 (causes no DeletedPresentationModelNotification since client side only)
// 2: delete of p2
// 3: DeletedPresentationModelNotification caused by delete of p2
assertCommandsTransmitted(4);
int deletedPresentationModelNotificationCount = 0;
for (Command c : clientConnector.getTransmittedCommands()) {
if (c instanceof PresentationModelDeletedCommand) {
deletedPresentationModelNotificationCount = deletedPresentationModelNotificationCount + 1;
}
}
Assert.assertEquals(1, deletedPresentationModelNotificationCount);
}
use of com.canoo.dp.impl.client.legacy.ClientPresentationModel 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