Search in sources :

Example 31 with ClientPresentationModel

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)));
}
Also used : PresentationModel(com.canoo.dp.impl.remoting.legacy.core.PresentationModel) ClientPresentationModel(com.canoo.dp.impl.client.legacy.ClientPresentationModel) ClientPresentationModel(com.canoo.dp.impl.client.legacy.ClientPresentationModel) ListReferenceModel(com.canoo.dolphin.client.util.ListReferenceModel) ClientModelStore(com.canoo.dp.impl.client.legacy.ClientModelStore) BeanManager(com.canoo.platform.remoting.BeanManager) Test(org.testng.annotations.Test) AbstractDolphinBasedTest(com.canoo.dolphin.client.util.AbstractDolphinBasedTest)

Example 32 with ClientPresentationModel

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)));
}
Also used : PresentationModel(com.canoo.dp.impl.remoting.legacy.core.PresentationModel) ClientPresentationModel(com.canoo.dp.impl.client.legacy.ClientPresentationModel) ClientPresentationModel(com.canoo.dp.impl.client.legacy.ClientPresentationModel) ListReferenceModel(com.canoo.dolphin.client.util.ListReferenceModel) ClientModelStore(com.canoo.dp.impl.client.legacy.ClientModelStore) BeanManager(com.canoo.platform.remoting.BeanManager) Test(org.testng.annotations.Test) AbstractDolphinBasedTest(com.canoo.dolphin.client.util.AbstractDolphinBasedTest)

Example 33 with ClientPresentationModel

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)));
}
Also used : PresentationModel(com.canoo.dp.impl.remoting.legacy.core.PresentationModel) ClientPresentationModel(com.canoo.dp.impl.client.legacy.ClientPresentationModel) ClientPresentationModel(com.canoo.dp.impl.client.legacy.ClientPresentationModel) ListReferenceModel(com.canoo.dolphin.client.util.ListReferenceModel) ClientModelStore(com.canoo.dp.impl.client.legacy.ClientModelStore) BeanManager(com.canoo.platform.remoting.BeanManager) Test(org.testng.annotations.Test) AbstractDolphinBasedTest(com.canoo.dolphin.client.util.AbstractDolphinBasedTest)

Example 34 with ClientPresentationModel

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);
}
Also used : PresentationModelDeletedCommand(com.canoo.dp.impl.remoting.legacy.communication.PresentationModelDeletedCommand) InterruptLongPollCommand(com.canoo.dp.impl.remoting.legacy.commands.InterruptLongPollCommand) Command(com.canoo.dp.impl.remoting.legacy.communication.Command) StartLongPollCommand(com.canoo.dp.impl.remoting.legacy.commands.StartLongPollCommand) ValueChangedCommand(com.canoo.dp.impl.remoting.legacy.communication.ValueChangedCommand) CreatePresentationModelCommand(com.canoo.dp.impl.remoting.legacy.communication.CreatePresentationModelCommand) PresentationModelDeletedCommand(com.canoo.dp.impl.remoting.legacy.communication.PresentationModelDeletedCommand) AttributeMetadataChangedCommand(com.canoo.dp.impl.remoting.legacy.communication.AttributeMetadataChangedCommand) DeletePresentationModelCommand(com.canoo.dp.impl.remoting.legacy.communication.DeletePresentationModelCommand) EmptyCommand(com.canoo.dp.impl.remoting.legacy.communication.EmptyCommand) ChangeAttributeMetadataCommand(com.canoo.dp.impl.remoting.legacy.communication.ChangeAttributeMetadataCommand) ClientPresentationModel(com.canoo.dp.impl.client.legacy.ClientPresentationModel) DeletePresentationModelCommand(com.canoo.dp.impl.remoting.legacy.communication.DeletePresentationModelCommand) Test(org.testng.annotations.Test)

Example 35 with ClientPresentationModel

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));
}
Also used : EventDispatcher(com.canoo.dp.impl.remoting.EventDispatcher) SimpleAnnotatedTestModel(com.canoo.dolphin.client.util.SimpleAnnotatedTestModel) BeanRepository(com.canoo.dp.impl.remoting.BeanRepository) SimpleTestModel(com.canoo.dolphin.client.util.SimpleTestModel) ClientPresentationModel(com.canoo.dp.impl.client.legacy.ClientPresentationModel) ClientModelStore(com.canoo.dp.impl.client.legacy.ClientModelStore) BeanManager(com.canoo.platform.remoting.BeanManager) Test(org.testng.annotations.Test) AbstractDolphinBasedTest(com.canoo.dolphin.client.util.AbstractDolphinBasedTest)

Aggregations

ClientPresentationModel (com.canoo.dp.impl.client.legacy.ClientPresentationModel)50 Test (org.testng.annotations.Test)48 AbstractDolphinBasedTest (com.canoo.dolphin.client.util.AbstractDolphinBasedTest)45 ClientModelStore (com.canoo.dp.impl.client.legacy.ClientModelStore)45 BeanManager (com.canoo.platform.remoting.BeanManager)45 PresentationModel (com.canoo.dp.impl.remoting.legacy.core.PresentationModel)39 ListReferenceModel (com.canoo.dolphin.client.util.ListReferenceModel)33 BeanRepository (com.canoo.dp.impl.remoting.BeanRepository)14 EventDispatcher (com.canoo.dp.impl.remoting.EventDispatcher)14 SimpleTestModel (com.canoo.dolphin.client.util.SimpleTestModel)10 Attribute (com.canoo.dp.impl.remoting.legacy.core.Attribute)8 SimpleAnnotatedTestModel (com.canoo.dolphin.client.util.SimpleAnnotatedTestModel)3 SingleReferenceModel (com.canoo.dolphin.client.util.SingleReferenceModel)3 ChildModel (com.canoo.dolphin.client.util.ChildModel)2 ComplexDataTypesModel (com.canoo.dolphin.client.util.ComplexDataTypesModel)1 PrimitiveDataTypesModel (com.canoo.dolphin.client.util.PrimitiveDataTypesModel)1 ClientAttribute (com.canoo.dp.impl.client.legacy.ClientAttribute)1 InterruptLongPollCommand (com.canoo.dp.impl.remoting.legacy.commands.InterruptLongPollCommand)1 StartLongPollCommand (com.canoo.dp.impl.remoting.legacy.commands.StartLongPollCommand)1 AttributeMetadataChangedCommand (com.canoo.dp.impl.remoting.legacy.communication.AttributeMetadataChangedCommand)1