Search in sources :

Example 1 with SimpleAnnotatedTestModel

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

the class TestPropertyChange method testWithAnnotatedSimpleModel.

@Test
public void testWithAnnotatedSimpleModel() {
    ServerModelStore serverModelStore = createServerModelStore();
    final BeanManager manager = createBeanManager(serverModelStore);
    final SimpleAnnotatedTestModel model = manager.create(SimpleAnnotatedTestModel.class);
    final ListerResults<String> results = new ListerResults<>();
    ValueChangeListener<String> myListener = new ValueChangeListener<String>() {

        @SuppressWarnings("unchecked")
        @Override
        public void valueChanged(ValueChangeEvent<? extends String> evt) {
            assertThat((Property<String>) evt.getSource(), is(model.getMyProperty()));
            results.newValue = evt.getNewValue();
            results.oldValue = evt.getOldValue();
            results.listenerCalls++;
        }
    };
    final Subscription subscription = model.getMyProperty().onChanged(myListener);
    assertThat(results.listenerCalls, is(0));
    assertThat(results.newValue, nullValue());
    assertThat(results.oldValue, nullValue());
    model.getMyProperty().set("Hallo Property");
    assertThat(results.listenerCalls, is(1));
    assertThat(results.newValue, is("Hallo Property"));
    assertThat(results.oldValue, nullValue());
    results.listenerCalls = 0;
    model.getMyProperty().set("Hallo Property2");
    assertThat(results.listenerCalls, is(1));
    assertThat(results.newValue, is("Hallo Property2"));
    assertThat(results.oldValue, is("Hallo Property"));
    results.listenerCalls = 0;
    subscription.unsubscribe();
    model.getMyProperty().set("Hallo Property3");
    assertThat(results.listenerCalls, is(0));
    assertThat(results.newValue, is("Hallo Property2"));
    assertThat(results.oldValue, is("Hallo Property"));
}
Also used : ValueChangeEvent(com.canoo.platform.remoting.ValueChangeEvent) ValueChangeListener(com.canoo.platform.remoting.ValueChangeListener) SimpleAnnotatedTestModel(com.canoo.impl.server.util.SimpleAnnotatedTestModel) ServerModelStore(com.canoo.dp.impl.server.legacy.ServerModelStore) Subscription(com.canoo.platform.core.functional.Subscription) BeanManager(com.canoo.platform.remoting.BeanManager) Test(org.testng.annotations.Test) AbstractDolphinBasedTest(com.canoo.impl.server.util.AbstractDolphinBasedTest)

Example 2 with SimpleAnnotatedTestModel

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

the class TestPropertyValue method testWithAnnotatedSimpleModel.

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

Example 3 with SimpleAnnotatedTestModel

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

the class TestDeleteAll method testWithSimpleModel.

@Test
public void testWithSimpleModel() {
    final ServerModelStore serverModelStore = createServerModelStore();
    final EventDispatcher dispatcher = createEventDispatcher(serverModelStore);
    final BeanRepository beanRepository = createBeanRepository(serverModelStore, dispatcher);
    final BeanManager manager = createBeanManager(serverModelStore, beanRepository, 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 (final Object bean : manager.findAll(SimpleTestModel.class)) {
        beanRepository.delete(bean);
    }
    assertThat(beanRepository.isManaged(model1), is(false));
    assertThat(beanRepository.isManaged(model2), is(false));
    assertThat(beanRepository.isManaged(model3), is(false));
    assertThat(beanRepository.isManaged(wrongModel), is(true));
    List<ServerPresentationModel> testModels = serverModelStore.findAllPresentationModelsByType("com.canoo.dolphin.server.util.SimpleTestModel");
    assertThat(testModels, hasSize(0));
}
Also used : ServerPresentationModel(com.canoo.dp.impl.server.legacy.ServerPresentationModel) EventDispatcher(com.canoo.dp.impl.remoting.EventDispatcher) SimpleAnnotatedTestModel(com.canoo.impl.server.util.SimpleAnnotatedTestModel) BeanRepository(com.canoo.dp.impl.remoting.BeanRepository) ServerModelStore(com.canoo.dp.impl.server.legacy.ServerModelStore) SimpleTestModel(com.canoo.impl.server.util.SimpleTestModel) BeanManager(com.canoo.platform.remoting.BeanManager) Test(org.testng.annotations.Test) AbstractDolphinBasedTest(com.canoo.impl.server.util.AbstractDolphinBasedTest)

Example 4 with SimpleAnnotatedTestModel

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

the class TestModelDeletion method testWithAnnotatedSimpleModel.

@Test
public void testWithAnnotatedSimpleModel() {
    final ServerModelStore serverModelStore = createServerModelStore();
    final EventDispatcher dispatcher = createEventDispatcher(serverModelStore);
    final BeanRepository beanRepository = createBeanRepository(serverModelStore, dispatcher);
    final BeanManager manager = createBeanManager(serverModelStore, beanRepository, dispatcher);
    SimpleAnnotatedTestModel model = manager.create(SimpleAnnotatedTestModel.class);
    beanRepository.delete(model);
    List<ServerPresentationModel> dolphinModels = serverModelStore.findAllPresentationModelsByType(SimpleAnnotatedTestModel.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) SimpleAnnotatedTestModel(com.canoo.impl.server.util.SimpleAnnotatedTestModel) BeanRepository(com.canoo.dp.impl.remoting.BeanRepository) ServerModelStore(com.canoo.dp.impl.server.legacy.ServerModelStore) BeanManager(com.canoo.platform.remoting.BeanManager) Test(org.testng.annotations.Test) AbstractDolphinBasedTest(com.canoo.impl.server.util.AbstractDolphinBasedTest)

Example 5 with SimpleAnnotatedTestModel

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

the class TestModelCreation method testWithAnnotatedSimpleModel.

@Test
public void testWithAnnotatedSimpleModel() {
    final ServerModelStore serverModelStore = createServerModelStore();
    final EventDispatcher dispatcher = createEventDispatcher(serverModelStore);
    final BeanRepository beanRepository = createBeanRepository(serverModelStore, dispatcher);
    final BeanManager manager = createBeanManager(serverModelStore, beanRepository, dispatcher);
    SimpleAnnotatedTestModel model = manager.create(SimpleAnnotatedTestModel.class);
    assertThat(model, notNullValue());
    assertThat(model.getMyProperty(), notNullValue());
    assertThat(model.getMyProperty().get(), nullValue());
    assertThat(beanRepository.isManaged(model), is(true));
    List<ServerPresentationModel> dolphinModels = serverModelStore.findAllPresentationModelsByType(SimpleAnnotatedTestModel.class.getName());
    assertThat(dolphinModels, hasSize(1));
    ServerPresentationModel dolphinModel = dolphinModels.get(0);
    List<ServerAttribute> attributes = dolphinModel.getAttributes();
    assertThat(attributes, containsInAnyOrder(allOf(hasProperty("propertyName", is("myProperty")), 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, contains(hasProperty("attributes", containsInAnyOrder(allOf(hasProperty("propertyName", is(PlatformRemotingConstants.JAVA_CLASS)), hasProperty("value", is(SimpleAnnotatedTestModel.class.getName())), hasProperty("qualifier", nullValue())), allOf(hasProperty("propertyName", is("myProperty")), 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) SimpleAnnotatedTestModel(com.canoo.impl.server.util.SimpleAnnotatedTestModel) BeanRepository(com.canoo.dp.impl.remoting.BeanRepository) ServerModelStore(com.canoo.dp.impl.server.legacy.ServerModelStore) 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)

Aggregations

ServerModelStore (com.canoo.dp.impl.server.legacy.ServerModelStore)5 AbstractDolphinBasedTest (com.canoo.impl.server.util.AbstractDolphinBasedTest)5 SimpleAnnotatedTestModel (com.canoo.impl.server.util.SimpleAnnotatedTestModel)5 BeanManager (com.canoo.platform.remoting.BeanManager)5 Test (org.testng.annotations.Test)5 ServerPresentationModel (com.canoo.dp.impl.server.legacy.ServerPresentationModel)4 BeanRepository (com.canoo.dp.impl.remoting.BeanRepository)3 EventDispatcher (com.canoo.dp.impl.remoting.EventDispatcher)3 Attribute (com.canoo.dp.impl.remoting.legacy.core.Attribute)1 ServerAttribute (com.canoo.dp.impl.server.legacy.ServerAttribute)1 SimpleTestModel (com.canoo.impl.server.util.SimpleTestModel)1 Subscription (com.canoo.platform.core.functional.Subscription)1 ValueChangeEvent (com.canoo.platform.remoting.ValueChangeEvent)1 ValueChangeListener (com.canoo.platform.remoting.ValueChangeListener)1