Search in sources :

Example 1 with PrimitiveDataTypesModel

use of com.canoo.dolphin.client.util.PrimitiveDataTypesModel 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 2 with PrimitiveDataTypesModel

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

the class TestPropertyValue method testWithAllPrimitiveDataTypesModel.

@Test
public void testWithAllPrimitiveDataTypesModel(@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);
    PresentationModel dolphinModel = clientModelStore.findAllPresentationModelsByType(PrimitiveDataTypesModel.class.getName()).get(0);
    Attribute textAttribute = dolphinModel.getAttribute("textProperty");
    assertThat(textAttribute.getValue(), nullValue());
    model.getTextProperty().set("Hallo Platform");
    assertThat(textAttribute.getValue(), is((Object) "Hallo Platform"));
    assertThat(model.getTextProperty().get(), is("Hallo Platform"));
    textAttribute.setValue("Hallo Dolphin");
    assertThat(textAttribute.getValue(), is((Object) "Hallo Dolphin"));
    assertThat(model.getTextProperty().get(), is("Hallo Dolphin"));
    Attribute intAttribute = dolphinModel.getAttribute("integerProperty");
    assertThat(intAttribute.getValue(), nullValue());
    model.getIntegerProperty().set(1);
    assertThat(intAttribute.getValue(), is((Object) 1));
    assertThat(model.getIntegerProperty().get(), is(1));
    intAttribute.setValue(2);
    assertThat(intAttribute.getValue(), is((Object) 2));
    assertThat(model.getIntegerProperty().get(), is(2));
    Attribute booleanAttribute = dolphinModel.getAttribute("booleanProperty");
    assertThat(booleanAttribute.getValue(), nullValue());
    model.getBooleanProperty().set(true);
    assertThat(booleanAttribute.getValue(), is((Object) true));
    assertThat(model.getBooleanProperty().get(), is(true));
    model.getBooleanProperty().set(false);
    assertThat(booleanAttribute.getValue(), is((Object) false));
    assertThat(model.getBooleanProperty().get(), is(false));
}
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) 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)2 PrimitiveDataTypesModel (com.canoo.dolphin.client.util.PrimitiveDataTypesModel)2 ClientModelStore (com.canoo.dp.impl.client.legacy.ClientModelStore)2 ClientPresentationModel (com.canoo.dp.impl.client.legacy.ClientPresentationModel)2 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)2 PresentationModel (com.canoo.dp.impl.remoting.legacy.core.PresentationModel)2 BeanManager (com.canoo.platform.remoting.BeanManager)2 Test (org.testng.annotations.Test)2