Search in sources :

Example 1 with SimpleAnnotatedTestModel

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

the class TestModelCreation method testWithAnnotatedSimpleModel.

@Test
public void testWithAnnotatedSimpleModel(@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);
    SimpleAnnotatedTestModel model = manager.create(SimpleAnnotatedTestModel.class);
    assertThat(model, notNullValue());
    assertThat(model.myProperty(), notNullValue());
    assertThat(model.myProperty().get(), nullValue());
    assertThat(repository.isManaged(model), is(true));
    List<ClientPresentationModel> dolphinModels = clientModelStore.findAllPresentationModelsByType(SimpleAnnotatedTestModel.class.getName());
    assertThat(dolphinModels, hasSize(1));
    PresentationModel dolphinModel = dolphinModels.get(0);
    List<Attribute> 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_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(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_CLIENT)), hasProperty("qualifier", 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) SimpleAnnotatedTestModel(com.canoo.dolphin.client.util.SimpleAnnotatedTestModel) 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)

Example 2 with SimpleAnnotatedTestModel

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

the class TestPropertyChange method testWithAnnotatedSimpleModel.

@Test
public void testWithAnnotatedSimpleModel(@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);
    final SimpleAnnotatedTestModel model = manager.create(SimpleAnnotatedTestModel.class);
    final ListerResults<String> results = new ListerResults<>();
    ValueChangeListener<String> myListener = new ValueChangeListener<String>() {

        @Override
        public void valueChanged(ValueChangeEvent<? extends String> evt) {
            Assert.assertEquals(evt.getSource(), model.myProperty());
            results.newValue = evt.getNewValue();
            results.oldValue = evt.getOldValue();
            results.listenerCalls++;
        }
    };
    final Subscription subscription = model.myProperty().onChanged(myListener);
    assertThat(results.listenerCalls, is(0));
    assertThat(results.newValue, nullValue());
    assertThat(results.oldValue, nullValue());
    model.myProperty().set("Hallo Property");
    assertThat(results.listenerCalls, is(1));
    assertThat(results.newValue, is("Hallo Property"));
    assertThat(results.oldValue, nullValue());
    results.listenerCalls = 0;
    model.myProperty().set("Hallo Property2");
    assertThat(results.listenerCalls, is(1));
    assertThat(results.newValue, is("Hallo Property2"));
    assertThat(results.oldValue, is("Hallo Property"));
    results.listenerCalls = 0;
    model.myProperty().set(null);
    assertThat(results.listenerCalls, is(1));
    assertThat(results.newValue, nullValue());
    assertThat(results.oldValue, is("Hallo Property2"));
    results.listenerCalls = 0;
    subscription.unsubscribe();
    model.myProperty().set("Hallo Property3");
    assertThat(results.listenerCalls, is(0));
    assertThat(results.newValue, nullValue());
    assertThat(results.oldValue, is("Hallo Property2"));
}
Also used : ValueChangeEvent(com.canoo.platform.remoting.ValueChangeEvent) EventDispatcher(com.canoo.dp.impl.remoting.EventDispatcher) ValueChangeListener(com.canoo.platform.remoting.ValueChangeListener) SimpleAnnotatedTestModel(com.canoo.dolphin.client.util.SimpleAnnotatedTestModel) BeanRepository(com.canoo.dp.impl.remoting.BeanRepository) Subscription(com.canoo.platform.core.functional.Subscription) 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 3 with SimpleAnnotatedTestModel

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

the class TestDeleteAll method testWithSimpleModel.

@Test
public void testWithSimpleModel(@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);
    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 (Object bean : manager.findAll(SimpleTestModel.class)) {
        repository.delete(bean);
    }
    assertThat(repository.isManaged(model1), is(false));
    assertThat(repository.isManaged(model2), is(false));
    assertThat(repository.isManaged(model3), is(false));
    assertThat(repository.isManaged(wrongModel), is(true));
    List<ClientPresentationModel> testModels = clientModelStore.findAllPresentationModelsByType("com.canoo.dolphin.client.util.SimpleTestModel");
    assertThat(testModels, hasSize(0));
}
Also used : EventDispatcher(com.canoo.dp.impl.remoting.EventDispatcher) SimpleAnnotatedTestModel(com.canoo.dolphin.client.util.SimpleAnnotatedTestModel) BeanRepository(com.canoo.dp.impl.remoting.BeanRepository) SimpleTestModel(com.canoo.dolphin.client.util.SimpleTestModel) 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 4 with SimpleAnnotatedTestModel

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

the class TestModelDeletion method testWithAnnotatedSimpleModel.

@Test
public void testWithAnnotatedSimpleModel(@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);
    SimpleAnnotatedTestModel model = manager.create(SimpleAnnotatedTestModel.class);
    repository.delete(model);
    List<ClientPresentationModel> dolphinModels = clientModelStore.findAllPresentationModelsByType("simple_test_model");
    assertThat(dolphinModels, empty());
    Collection<ClientPresentationModel> allDolphinModels = clientModelStore.listPresentationModels();
    assertThat(allDolphinModels, hasSize(1));
    assertThat(repository.isManaged(model), is(false));
}
Also used : EventDispatcher(com.canoo.dp.impl.remoting.EventDispatcher) SimpleAnnotatedTestModel(com.canoo.dolphin.client.util.SimpleAnnotatedTestModel) 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)

Example 5 with SimpleAnnotatedTestModel

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

the class TestPropertyValue method testWithAnnotatedSimpleModel.

@Test
public void testWithAnnotatedSimpleModel(@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);
    SimpleAnnotatedTestModel model = manager.create(SimpleAnnotatedTestModel.class);
    PresentationModel dolphinModel = clientModelStore.findAllPresentationModelsByType(SimpleAnnotatedTestModel.class.getName()).get(0);
    Attribute textAttribute = dolphinModel.getAttribute("myProperty");
    assertThat(textAttribute.getValue(), nullValue());
    model.myProperty().set("Hallo Platform");
    assertThat(textAttribute.getValue(), is((Object) "Hallo Platform"));
    assertThat(model.myProperty().get(), is("Hallo Platform"));
    textAttribute.setValue("Hallo Dolphin");
    assertThat(textAttribute.getValue(), is((Object) "Hallo Dolphin"));
    assertThat(model.myProperty().get(), is("Hallo Dolphin"));
}
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) SimpleAnnotatedTestModel(com.canoo.dolphin.client.util.SimpleAnnotatedTestModel) Attribute(com.canoo.dp.impl.remoting.legacy.core.Attribute) BeanRepository(com.canoo.dp.impl.remoting.BeanRepository) 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)5 SimpleAnnotatedTestModel (com.canoo.dolphin.client.util.SimpleAnnotatedTestModel)5 ClientModelStore (com.canoo.dp.impl.client.legacy.ClientModelStore)5 BeanRepository (com.canoo.dp.impl.remoting.BeanRepository)5 EventDispatcher (com.canoo.dp.impl.remoting.EventDispatcher)5 BeanManager (com.canoo.platform.remoting.BeanManager)5 Test (org.testng.annotations.Test)5 ClientPresentationModel (com.canoo.dp.impl.client.legacy.ClientPresentationModel)4 Attribute (com.canoo.dp.impl.remoting.legacy.core.Attribute)2 PresentationModel (com.canoo.dp.impl.remoting.legacy.core.PresentationModel)2 SimpleTestModel (com.canoo.dolphin.client.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