Search in sources :

Example 1 with ChildModel

use of com.canoo.impl.server.util.ChildModel in project dolphin-platform by canoo.

the class TestPropertyChange method testWithInheritedModel.

@Test
public void testWithInheritedModel() {
    ServerModelStore serverModelStore = createServerModelStore();
    final BeanManager manager = createBeanManager(serverModelStore);
    final ChildModel model = manager.create(ChildModel.class);
    final ListerResults<String> childResults = new ListerResults<>();
    ValueChangeListener<String> childListener = new ValueChangeListener<String>() {

        @SuppressWarnings("unchecked")
        @Override
        public void valueChanged(ValueChangeEvent<? extends String> evt) {
            assertThat((Property<String>) evt.getSource(), is(model.getChildProperty()));
            childResults.newValue = evt.getNewValue();
            childResults.oldValue = evt.getOldValue();
            childResults.listenerCalls++;
        }
    };
    final ListerResults<String> parentResults = new ListerResults<>();
    ValueChangeListener<String> parentListener = new ValueChangeListener<String>() {

        @SuppressWarnings("unchecked")
        @Override
        public void valueChanged(ValueChangeEvent<? extends String> evt) {
            assertThat((Property<String>) evt.getSource(), is(model.getParentProperty()));
            parentResults.newValue = evt.getNewValue();
            parentResults.oldValue = evt.getOldValue();
            parentResults.listenerCalls++;
        }
    };
    model.getChildProperty().onChanged(childListener);
    model.getParentProperty().onChanged(parentListener);
    assertThat(childResults.listenerCalls, is(0));
    assertThat(childResults.newValue, nullValue());
    assertThat(childResults.oldValue, nullValue());
    assertThat(parentResults.listenerCalls, is(0));
    assertThat(parentResults.newValue, nullValue());
    assertThat(parentResults.oldValue, nullValue());
    model.getChildProperty().set("Hallo Property");
    assertThat(childResults.listenerCalls, is(1));
    assertThat(childResults.newValue, is("Hallo Property"));
    assertThat(childResults.oldValue, nullValue());
    assertThat(parentResults.listenerCalls, is(0));
    assertThat(parentResults.newValue, nullValue());
    assertThat(parentResults.oldValue, nullValue());
    childResults.listenerCalls = 0;
    childResults.newValue = null;
    childResults.oldValue = null;
    model.getParentProperty().set("Hallo Property2");
    assertThat(childResults.listenerCalls, is(0));
    assertThat(childResults.newValue, nullValue());
    assertThat(childResults.oldValue, nullValue());
    assertThat(parentResults.listenerCalls, is(1));
    assertThat(parentResults.newValue, is("Hallo Property2"));
    assertThat(parentResults.oldValue, nullValue());
}
Also used : ValueChangeEvent(com.canoo.platform.remoting.ValueChangeEvent) ValueChangeListener(com.canoo.platform.remoting.ValueChangeListener) ServerModelStore(com.canoo.dp.impl.server.legacy.ServerModelStore) ChildModel(com.canoo.impl.server.util.ChildModel) BeanManager(com.canoo.platform.remoting.BeanManager) Test(org.testng.annotations.Test) AbstractDolphinBasedTest(com.canoo.impl.server.util.AbstractDolphinBasedTest)

Example 2 with ChildModel

use of com.canoo.impl.server.util.ChildModel in project dolphin-platform by canoo.

the class TestPropertyValue method testWithInheritedModel.

@Test
public void testWithInheritedModel() {
    final ServerModelStore serverModelStore = createServerModelStore();
    final BeanManager manager = createBeanManager(serverModelStore);
    ChildModel model = manager.create(ChildModel.class);
    ServerPresentationModel dolphinModel = serverModelStore.findAllPresentationModelsByType(ChildModel.class.getName()).get(0);
    Attribute childAttribute = dolphinModel.getAttribute("childProperty");
    assertThat(childAttribute.getValue(), nullValue());
    Attribute parentAttribute = dolphinModel.getAttribute("parentProperty");
    assertThat(parentAttribute.getValue(), nullValue());
    model.getChildProperty().set("Hallo Platform");
    assertThat((String) childAttribute.getValue(), is("Hallo Platform"));
    assertThat(model.getChildProperty().get(), is("Hallo Platform"));
    assertThat(parentAttribute.getValue(), nullValue());
    assertThat(model.getParentProperty().get(), nullValue());
    parentAttribute.setValue("Hallo Dolphin");
    assertThat((String) childAttribute.getValue(), is("Hallo Platform"));
    assertThat(model.getChildProperty().get(), is("Hallo Platform"));
    assertThat((String) parentAttribute.getValue(), is("Hallo Dolphin"));
    assertThat(model.getParentProperty().get(), is("Hallo Dolphin"));
}
Also used : ServerPresentationModel(com.canoo.dp.impl.server.legacy.ServerPresentationModel) Attribute(com.canoo.dp.impl.remoting.legacy.core.Attribute) ServerModelStore(com.canoo.dp.impl.server.legacy.ServerModelStore) ChildModel(com.canoo.impl.server.util.ChildModel) BeanManager(com.canoo.platform.remoting.BeanManager) Test(org.testng.annotations.Test) AbstractDolphinBasedTest(com.canoo.impl.server.util.AbstractDolphinBasedTest)

Example 3 with ChildModel

use of com.canoo.impl.server.util.ChildModel in project dolphin-platform by canoo.

the class TestModelCreation method testWithInheritedModel.

@Test
public void testWithInheritedModel() {
    final ServerModelStore serverModelStore = createServerModelStore();
    final EventDispatcher dispatcher = createEventDispatcher(serverModelStore);
    final BeanRepository beanRepository = createBeanRepository(serverModelStore, dispatcher);
    final BeanManager manager = createBeanManager(serverModelStore, beanRepository, dispatcher);
    ChildModel model = manager.create(ChildModel.class);
    assertThat(model, notNullValue());
    assertThat(model.getParentProperty(), notNullValue());
    assertThat(model.getParentProperty().get(), nullValue());
    assertThat(model.getChildProperty(), notNullValue());
    assertThat(model.getChildProperty().get(), nullValue());
    assertThat(beanRepository.isManaged(model), is(true));
    List<ServerPresentationModel> dolphinModels = serverModelStore.findAllPresentationModelsByType(ChildModel.class.getName());
    assertThat(dolphinModels, hasSize(1));
    ServerPresentationModel dolphinModel = dolphinModels.get(0);
    List<ServerAttribute> attributes = dolphinModel.getAttributes();
    assertThat(attributes, containsInAnyOrder(allOf(hasProperty("propertyName", is("childProperty")), hasProperty("value", nullValue()), hasProperty("qualifier", nullValue())), allOf(hasProperty("propertyName", is("parentProperty")), hasProperty("value", nullValue()), hasProperty("qualifier", nullValue())), allOf(hasProperty("propertyName", is(RemotingConstants.SOURCE_SYSTEM)), hasProperty("value", is(RemotingConstants.SOURCE_SYSTEM_SERVER)), hasProperty("qualifier", nullValue()))));
    List<ServerPresentationModel> classModels = serverModelStore.findAllPresentationModelsByType(PlatformRemotingConstants.DOLPHIN_BEAN);
    assertThat(classModels, hasSize(1));
    assertThat(classModels, contains(hasProperty("attributes", containsInAnyOrder(allOf(hasProperty("propertyName", is(PlatformRemotingConstants.JAVA_CLASS)), hasProperty("value", is(ChildModel.class.getName())), hasProperty("qualifier", nullValue())), allOf(hasProperty("propertyName", is("childProperty")), hasProperty("value", is(StringConverterFactory.FIELD_TYPE_STRING)), hasProperty("qualifier", nullValue())), allOf(hasProperty("propertyName", is("parentProperty")), hasProperty("value", is(StringConverterFactory.FIELD_TYPE_STRING)), hasProperty("qualifier", nullValue())), allOf(hasProperty("propertyName", is(RemotingConstants.SOURCE_SYSTEM)), hasProperty("value", is(RemotingConstants.SOURCE_SYSTEM_SERVER)), hasProperty("qualifier", nullValue()))))));
}
Also used : ServerPresentationModel(com.canoo.dp.impl.server.legacy.ServerPresentationModel) EventDispatcher(com.canoo.dp.impl.remoting.EventDispatcher) BeanRepository(com.canoo.dp.impl.remoting.BeanRepository) ServerModelStore(com.canoo.dp.impl.server.legacy.ServerModelStore) ChildModel(com.canoo.impl.server.util.ChildModel) BeanManager(com.canoo.platform.remoting.BeanManager) ServerAttribute(com.canoo.dp.impl.server.legacy.ServerAttribute) Test(org.testng.annotations.Test) AbstractDolphinBasedTest(com.canoo.impl.server.util.AbstractDolphinBasedTest)

Example 4 with ChildModel

use of com.canoo.impl.server.util.ChildModel in project dolphin-platform by canoo.

the class TestModelDeletion method testWithInheritedModel.

@Test
public void testWithInheritedModel() {
    final ServerModelStore serverModelStore = createServerModelStore();
    final EventDispatcher dispatcher = createEventDispatcher(serverModelStore);
    final BeanRepository beanRepository = createBeanRepository(serverModelStore, dispatcher);
    final BeanManager manager = createBeanManager(serverModelStore, beanRepository, dispatcher);
    ChildModel model = manager.create(ChildModel.class);
    beanRepository.delete(model);
    List<ServerPresentationModel> dolphinModels = serverModelStore.findAllPresentationModelsByType(ChildModel.class.getName());
    assertThat(dolphinModels, empty());
    Collection<ServerPresentationModel> allDolphinModels = serverModelStore.listPresentationModels();
    assertThat(allDolphinModels, hasSize(1));
    assertThat(beanRepository.isManaged(model), is(false));
}
Also used : ServerPresentationModel(com.canoo.dp.impl.server.legacy.ServerPresentationModel) EventDispatcher(com.canoo.dp.impl.remoting.EventDispatcher) BeanRepository(com.canoo.dp.impl.remoting.BeanRepository) ServerModelStore(com.canoo.dp.impl.server.legacy.ServerModelStore) ChildModel(com.canoo.impl.server.util.ChildModel) BeanManager(com.canoo.platform.remoting.BeanManager) Test(org.testng.annotations.Test) AbstractDolphinBasedTest(com.canoo.impl.server.util.AbstractDolphinBasedTest)

Aggregations

ServerModelStore (com.canoo.dp.impl.server.legacy.ServerModelStore)4 AbstractDolphinBasedTest (com.canoo.impl.server.util.AbstractDolphinBasedTest)4 ChildModel (com.canoo.impl.server.util.ChildModel)4 BeanManager (com.canoo.platform.remoting.BeanManager)4 Test (org.testng.annotations.Test)4 ServerPresentationModel (com.canoo.dp.impl.server.legacy.ServerPresentationModel)3 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 ServerAttribute (com.canoo.dp.impl.server.legacy.ServerAttribute)1 ValueChangeEvent (com.canoo.platform.remoting.ValueChangeEvent)1 ValueChangeListener (com.canoo.platform.remoting.ValueChangeListener)1