Search in sources :

Example 36 with PresentationModel

use of com.canoo.dp.impl.remoting.legacy.core.PresentationModel in project dolphin-platform by canoo.

the class TestObservableListSync method deletingObjectNullAsUser_shouldDeleteElement.

@Test
public void deletingObjectNullAsUser_shouldDeleteElement() {
    // given :
    final ServerModelStore serverModelStore = createServerModelStore();
    final BeanManager manager = createBeanManager(serverModelStore);
    final ListReferenceModel model = manager.create(ListReferenceModel.class);
    final PresentationModel sourceModel = serverModelStore.findAllPresentationModelsByType(ListReferenceModel.class.getName()).get(0);
    model.getObjectList().add(null);
    removeAllPresentationModelsOfType(serverModelStore, PlatformRemotingConstants.LIST_SPLICE);
    // when :
    model.getObjectList().remove(0);
    // then :
    final List<ServerPresentationModel> changes = serverModelStore.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) ServerPresentationModel(com.canoo.dp.impl.server.legacy.ServerPresentationModel) ServerPresentationModel(com.canoo.dp.impl.server.legacy.ServerPresentationModel) ServerModelStore(com.canoo.dp.impl.server.legacy.ServerModelStore) ListReferenceModel(com.canoo.impl.server.util.ListReferenceModel) BeanManager(com.canoo.platform.remoting.BeanManager) Test(org.testng.annotations.Test) AbstractDolphinBasedTest(com.canoo.impl.server.util.AbstractDolphinBasedTest)

Example 37 with PresentationModel

use of com.canoo.dp.impl.remoting.legacy.core.PresentationModel in project dolphin-platform by canoo.

the class TestObservableListSync method replacingSingleElementInBeginningFromDolphin_shouldReplaceElement.

// ////////////////////////////////////////////////////////////
// Replacing elements from different positions from dolphin
// ////////////////////////////////////////////////////////////
@Test
public void replacingSingleElementInBeginningFromDolphin_shouldReplaceElement() {
    // given :
    final ServerModelStore serverModelStore = createServerModelStore();
    final BeanManager manager = createBeanManager(serverModelStore);
    final ListReferenceModel model = manager.create(ListReferenceModel.class);
    final PresentationModel sourceModel = serverModelStore.findAllPresentationModelsByType(ListReferenceModel.class.getName()).get(0);
    final String newValue = "42";
    model.getPrimitiveList().addAll(Arrays.asList("1", "2", "3"));
    removeAllPresentationModelsOfType(serverModelStore, PlatformRemotingConstants.LIST_SPLICE);
    // when :
    new PresentationModelBuilder(serverModelStore, PlatformRemotingConstants.LIST_SPLICE).withAttribute("source", sourceModel.getId()).withAttribute("attribute", "primitiveList").withAttribute("from", 0).withAttribute("to", 1).withAttribute("count", 1).withAttribute("0", newValue).create();
    assertThat(model.getPrimitiveList(), is(Arrays.asList("42", "2", "3")));
    assertThat(serverModelStore.findAllPresentationModelsByType(PlatformRemotingConstants.LIST_SPLICE), empty());
}
Also used : PresentationModel(com.canoo.dp.impl.remoting.legacy.core.PresentationModel) ServerPresentationModel(com.canoo.dp.impl.server.legacy.ServerPresentationModel) ServerModelStore(com.canoo.dp.impl.server.legacy.ServerModelStore) ListReferenceModel(com.canoo.impl.server.util.ListReferenceModel) BeanManager(com.canoo.platform.remoting.BeanManager) Test(org.testng.annotations.Test) AbstractDolphinBasedTest(com.canoo.impl.server.util.AbstractDolphinBasedTest)

Example 38 with PresentationModel

use of com.canoo.dp.impl.remoting.legacy.core.PresentationModel in project dolphin-platform by canoo.

the class ServerDolphinTest method testListPresentationModels.

@Test
public void testListPresentationModels() {
    Assert.assertTrue(dolphin.getModelStore().listPresentationModelIds().isEmpty());
    Assert.assertTrue(dolphin.getModelStore().listPresentationModels().isEmpty());
    Assert.assertTrue(dolphin.getModelStore().findAllAttributesByQualifier("no-such-qualifier").isEmpty());
    Assert.assertTrue(dolphin.getModelStore().findAllPresentationModelsByType("no-such-type").isEmpty());
    ServerPresentationModel pm1 = new ServerPresentationModel("first", new ArrayList(), dolphin.getModelStore());
    dolphin.getModelStore().add(pm1);
    Assert.assertEquals(Collections.singleton("first"), dolphin.getModelStore().listPresentationModelIds());
    Assert.assertEquals(1, dolphin.getModelStore().listPresentationModelIds().size());
    Assert.assertEquals(pm1, dolphin.getModelStore().listPresentationModels().iterator().next());
    ServerPresentationModel pm2 = new ServerPresentationModel("second", new ArrayList(), dolphin.getModelStore());
    dolphin.getModelStore().add(pm2);
    Assert.assertEquals(2, dolphin.getModelStore().listPresentationModelIds().size());
    Assert.assertEquals(2, dolphin.getModelStore().listPresentationModels().size());
    for (String id : dolphin.getModelStore().listPresentationModelIds()) {
        PresentationModel model = dolphin.getModelStore().findPresentationModelById(id);
        Assert.assertNotNull(model);
        Assert.assertTrue(dolphin.getModelStore().listPresentationModels().contains(model));
    }
}
Also used : PresentationModel(com.canoo.dp.impl.remoting.legacy.core.PresentationModel) ArrayList(java.util.ArrayList) Test(org.testng.annotations.Test)

Example 39 with PresentationModel

use of com.canoo.dp.impl.remoting.legacy.core.PresentationModel in project dolphin-platform by canoo.

the class TestModelCreation method testWithAllPrimitiveDatatypes.

@Test
public void testWithAllPrimitiveDatatypes(@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);
    PrimitiveDataTypesModel model = manager.create(PrimitiveDataTypesModel.class);
    assertThat(model, notNullValue());
    assertThat(model.getTextProperty(), notNullValue());
    assertThat(model.getTextProperty().get(), nullValue());
    assertThat(repository.isManaged(model), is(true));
    List<ClientPresentationModel> dolphinModels = clientModelStore.findAllPresentationModelsByType(PrimitiveDataTypesModel.class.getName());
    assertThat(dolphinModels, hasSize(1));
    PresentationModel dolphinModel = dolphinModels.get(0);
    List<Attribute> attributes = dolphinModel.getAttributes();
    assertThat(attributes, hasSize(9));
    for (Attribute attribute : attributes) {
        if (RemotingConstants.SOURCE_SYSTEM.equals(attribute.getPropertyName())) {
            assertThat(attribute.getValue(), Matchers.<Object>is(RemotingConstants.SOURCE_SYSTEM_CLIENT));
        } else {
            assertThat(attribute.getValue(), nullValue());
        }
        assertThat(attribute.getQualifier(), nullValue());
    }
    final List<ClientPresentationModel> classModels = clientModelStore.findAllPresentationModelsByType(PlatformRemotingConstants.DOLPHIN_BEAN);
    assertThat(classModels, hasSize(1));
    final PresentationModel classModel = classModels.get(0);
    final List<Attribute> classAttributes = classModel.getAttributes();
    assertThat(classAttributes, hasSize(10));
    for (Attribute attribute : classAttributes) {
        if (PlatformRemotingConstants.JAVA_CLASS.equals(attribute.getPropertyName())) {
            assertThat(attribute.getValue().toString(), is(PrimitiveDataTypesModel.class.getName()));
        } else if (RemotingConstants.SOURCE_SYSTEM.equals(attribute.getPropertyName())) {
            assertThat(attribute.getValue(), Matchers.<Object>is(RemotingConstants.SOURCE_SYSTEM_CLIENT));
        } else {
            switch(attribute.getPropertyName()) {
                case "byteProperty":
                    assertThat((Integer) attribute.getValue(), is(ByteConverterFactory.FIELD_TYPE_BYTE));
                    break;
                case "shortProperty":
                    assertThat((Integer) attribute.getValue(), is(ShortConverterFactory.FIELD_TYPE_SHORT));
                    break;
                case "integerProperty":
                    assertThat((Integer) attribute.getValue(), is(IntegerConverterFactory.FIELD_TYPE_INT));
                    break;
                case "longProperty":
                    assertThat((Integer) attribute.getValue(), is(LongConverterFactory.FIELD_TYPE_LONG));
                    break;
                case "floatProperty":
                    assertThat((Integer) attribute.getValue(), is(FloatConverterFactory.FIELD_TYPE_FLOAT));
                    break;
                case "doubleProperty":
                    assertThat((Integer) attribute.getValue(), is(DoubleConverterFactory.FIELD_TYPE_DOUBLE));
                    break;
                case "booleanProperty":
                    assertThat((Integer) attribute.getValue(), is(BooleanConverterFactory.FIELD_TYPE_BOOLEAN));
                    break;
                case "textProperty":
                    assertThat((Integer) attribute.getValue(), is(StringConverterFactory.FIELD_TYPE_STRING));
                    break;
                default:
                    fail("Unknown attribute found: " + attribute);
                    break;
            }
        }
        assertThat(attribute.getQualifier(), nullValue());
    }
}
Also used : PresentationModel(com.canoo.dp.impl.remoting.legacy.core.PresentationModel) ClientPresentationModel(com.canoo.dp.impl.client.legacy.ClientPresentationModel) EventDispatcher(com.canoo.dp.impl.remoting.EventDispatcher) Attribute(com.canoo.dp.impl.remoting.legacy.core.Attribute) BeanRepository(com.canoo.dp.impl.remoting.BeanRepository) PrimitiveDataTypesModel(com.canoo.dolphin.client.util.PrimitiveDataTypesModel) 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)

Example 40 with PresentationModel

use of com.canoo.dp.impl.remoting.legacy.core.PresentationModel in project dolphin-platform by canoo.

the class TestModelCreation 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);
    SingleReferenceModel model = manager.create(SingleReferenceModel.class);
    assertThat(model, notNullValue());
    assertThat(model.getReferenceProperty(), notNullValue());
    assertThat(model.getReferenceProperty().get(), nullValue());
    assertThat(repository.isManaged(model), is(true));
    List<ClientPresentationModel> dolphinModels = clientModelStore.findAllPresentationModelsByType(SingleReferenceModel.class.getName());
    assertThat(dolphinModels, hasSize(1));
    PresentationModel dolphinModel = dolphinModels.get(0);
    List<Attribute> attributes = dolphinModel.getAttributes();
    assertThat(attributes, containsInAnyOrder(allOf(hasProperty("propertyName", is("referenceProperty")), hasProperty("value", nullValue()), hasProperty("qualifier", nullValue())), allOf(hasProperty("propertyName", is(RemotingConstants.SOURCE_SYSTEM)), hasProperty("value", is(RemotingConstants.SOURCE_SYSTEM_CLIENT)), hasProperty("qualifier", nullValue()))));
    List<ClientPresentationModel> classModels = clientModelStore.findAllPresentationModelsByType(PlatformRemotingConstants.DOLPHIN_BEAN);
    assertThat(classModels, contains(hasProperty("attributes", containsInAnyOrder(allOf(hasProperty("propertyName", is(PlatformRemotingConstants.JAVA_CLASS)), hasProperty("value", is(SingleReferenceModel.class.getName())), hasProperty("qualifier", nullValue())), allOf(hasProperty("propertyName", is("referenceProperty")), hasProperty("value", is(DolphinBeanConverterFactory.FIELD_TYPE_DOLPHIN_BEAN)), hasProperty("qualifier", nullValue())), allOf(hasProperty("propertyName", is(RemotingConstants.SOURCE_SYSTEM)), hasProperty("value", is(RemotingConstants.SOURCE_SYSTEM_CLIENT)), hasProperty("qualifier", nullValue()))))));
}
Also used : PresentationModel(com.canoo.dp.impl.remoting.legacy.core.PresentationModel) ClientPresentationModel(com.canoo.dp.impl.client.legacy.ClientPresentationModel) SingleReferenceModel(com.canoo.dolphin.client.util.SingleReferenceModel) EventDispatcher(com.canoo.dp.impl.remoting.EventDispatcher) Attribute(com.canoo.dp.impl.remoting.legacy.core.Attribute) BeanRepository(com.canoo.dp.impl.remoting.BeanRepository) 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

PresentationModel (com.canoo.dp.impl.remoting.legacy.core.PresentationModel)147 Test (org.testng.annotations.Test)143 BeanManager (com.canoo.platform.remoting.BeanManager)142 AbstractDolphinBasedTest (com.canoo.dolphin.client.util.AbstractDolphinBasedTest)76 ClientModelStore (com.canoo.dp.impl.client.legacy.ClientModelStore)76 ClientPresentationModel (com.canoo.dp.impl.client.legacy.ClientPresentationModel)76 ServerModelStore (com.canoo.dp.impl.server.legacy.ServerModelStore)66 ServerPresentationModel (com.canoo.dp.impl.server.legacy.ServerPresentationModel)66 AbstractDolphinBasedTest (com.canoo.impl.server.util.AbstractDolphinBasedTest)66 ListReferenceModel (com.canoo.dolphin.client.util.ListReferenceModel)64 ListReferenceModel (com.canoo.impl.server.util.ListReferenceModel)63 Attribute (com.canoo.dp.impl.remoting.legacy.core.Attribute)16 BeanRepository (com.canoo.dp.impl.remoting.BeanRepository)15 EventDispatcher (com.canoo.dp.impl.remoting.EventDispatcher)15 SimpleTestModel (com.canoo.dolphin.client.util.SimpleTestModel)12 SimpleTestModel (com.canoo.impl.server.util.SimpleTestModel)10 ChildModel (com.canoo.dolphin.client.util.ChildModel)2 ComplexDataTypesModel (com.canoo.dolphin.client.util.ComplexDataTypesModel)2 PrimitiveDataTypesModel (com.canoo.dolphin.client.util.PrimitiveDataTypesModel)2 SimpleAnnotatedTestModel (com.canoo.dolphin.client.util.SimpleAnnotatedTestModel)2