Search in sources :

Example 61 with ListReferenceModel

use of com.canoo.dolphin.client.util.ListReferenceModel in project dolphin-platform by canoo.

the class TestObservableListSync method replacingSingleElementAtEndAsUser_shouldReplaceElement.

@Test
public void replacingSingleElementAtEndAsUser_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(2, 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) 2)));
    assertThat(change.getAttribute("to").getValue(), allOf(instanceOf(Integer.class), is((Object) 3)));
    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 62 with ListReferenceModel

use of com.canoo.dolphin.client.util.ListReferenceModel in project dolphin-platform by canoo.

the class TestObservableListSync method replacingPrimitiveElementWithNullFromDolphin_shouldReplaceElement.

@Test
public void replacingPrimitiveElementWithNullFromDolphin_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 oldValue = "Hello";
    new PresentationModelBuilder(clientModelStore, PlatformRemotingConstants.LIST_SPLICE).withAttribute("source", sourceModel.getId()).withAttribute("attribute", "primitiveList").withAttribute("from", 0).withAttribute("to", 0).withAttribute("count", 1).withAttribute("0", oldValue).create();
    assertThat(model.getPrimitiveList(), is(Collections.singletonList(oldValue)));
    // when :
    new PresentationModelBuilder(clientModelStore, PlatformRemotingConstants.LIST_SPLICE).withAttribute("source", sourceModel.getId()).withAttribute("attribute", "primitiveList").withAttribute("from", 0).withAttribute("to", 1).withAttribute("count", 1).withAttribute("0", null).create();
    // then :
    assertThat(model.getPrimitiveList(), is(Collections.singletonList((String) null)));
    assertThat(clientModelStore.findAllPresentationModelsByType(PlatformRemotingConstants.LIST_SPLICE), empty());
}
Also used : PresentationModel(com.canoo.dp.impl.remoting.legacy.core.PresentationModel) 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 63 with ListReferenceModel

use of com.canoo.dolphin.client.util.ListReferenceModel in project dolphin-platform by canoo.

the class TestObservableListSync method deletingPrimitiveElementFromDolphin_shouldDeleteElement.

@Test
public void deletingPrimitiveElementFromDolphin_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 String value = "Hello";
    new PresentationModelBuilder(clientModelStore, PlatformRemotingConstants.LIST_SPLICE).withAttribute("source", sourceModel.getId()).withAttribute("attribute", "primitiveList").withAttribute("from", 0).withAttribute("to", 0).withAttribute("count", 1).withAttribute("0", value).create();
    assertThat(model.getPrimitiveList(), hasSize(1));
    // when :
    new PresentationModelBuilder(clientModelStore, PlatformRemotingConstants.LIST_SPLICE).withAttribute("source", sourceModel.getId()).withAttribute("attribute", "primitiveList").withAttribute("from", 0).withAttribute("to", 1).withAttribute("count", 0).create();
    // then :
    assertThat(model.getPrimitiveList(), empty());
    assertThat(clientModelStore.findAllPresentationModelsByType(PlatformRemotingConstants.LIST_SPLICE), empty());
}
Also used : PresentationModel(com.canoo.dp.impl.remoting.legacy.core.PresentationModel) 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 64 with ListReferenceModel

use of com.canoo.dolphin.client.util.ListReferenceModel 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)));
}
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 65 with ListReferenceModel

use of com.canoo.dolphin.client.util.ListReferenceModel 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());
}
Also used : PresentationModel(com.canoo.dp.impl.remoting.legacy.core.PresentationModel) ClientPresentationModel(com.canoo.dp.impl.client.legacy.ClientPresentationModel) SimpleTestModel(com.canoo.dolphin.client.util.SimpleTestModel) 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)

Aggregations

AbstractDolphinBasedTest (com.canoo.dolphin.client.util.AbstractDolphinBasedTest)65 ListReferenceModel (com.canoo.dolphin.client.util.ListReferenceModel)65 ClientModelStore (com.canoo.dp.impl.client.legacy.ClientModelStore)65 ClientPresentationModel (com.canoo.dp.impl.client.legacy.ClientPresentationModel)65 BeanManager (com.canoo.platform.remoting.BeanManager)65 Test (org.testng.annotations.Test)65 PresentationModel (com.canoo.dp.impl.remoting.legacy.core.PresentationModel)64 SimpleTestModel (com.canoo.dolphin.client.util.SimpleTestModel)9 BeanRepository (com.canoo.dp.impl.remoting.BeanRepository)2 EventDispatcher (com.canoo.dp.impl.remoting.EventDispatcher)2 Attribute (com.canoo.dp.impl.remoting.legacy.core.Attribute)1