Search in sources :

Example 1 with ValueChangeListener

use of com.canoo.platform.remoting.ValueChangeListener 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 ValueChangeListener

use of com.canoo.platform.remoting.ValueChangeListener in project dolphin-platform by canoo.

the class TestPropertyChange method testWithSingleReferenceModel.

@Test
public void testWithSingleReferenceModel() {
    ServerModelStore serverModelStore = createServerModelStore();
    final BeanManager manager = createBeanManager(serverModelStore);
    final SimpleTestModel ref1 = manager.create(SimpleTestModel.class);
    final SimpleTestModel ref2 = manager.create(SimpleTestModel.class);
    final SimpleTestModel ref3 = manager.create(SimpleTestModel.class);
    final SingleReferenceModel model = manager.create(SingleReferenceModel.class);
    final ListerResults<SimpleTestModel> results = new ListerResults<>();
    final ValueChangeListener<SimpleTestModel> myListener = new ValueChangeListener<SimpleTestModel>() {

        @SuppressWarnings("unchecked")
        @Override
        public void valueChanged(ValueChangeEvent<? extends SimpleTestModel> evt) {
            assertThat((Property<SimpleTestModel>) evt.getSource(), is(model.getReferenceProperty()));
            results.newValue = evt.getNewValue();
            results.oldValue = evt.getOldValue();
            results.listenerCalls++;
        }
    };
    final Subscription subscription = model.getReferenceProperty().onChanged(myListener);
    assertThat(results.listenerCalls, is(0));
    assertThat(results.newValue, nullValue());
    assertThat(results.oldValue, nullValue());
    model.getReferenceProperty().set(ref1);
    assertThat(results.listenerCalls, is(1));
    assertThat(results.newValue, is(ref1));
    assertThat(results.oldValue, nullValue());
    results.listenerCalls = 0;
    model.getReferenceProperty().set(ref2);
    assertThat(results.listenerCalls, is(1));
    assertThat(results.newValue, is(ref2));
    assertThat(results.oldValue, is(ref1));
    results.listenerCalls = 0;
    subscription.unsubscribe();
    model.getReferenceProperty().set(ref3);
    assertThat(results.listenerCalls, is(0));
    assertThat(results.newValue, is(ref2));
    assertThat(results.oldValue, is(ref1));
}
Also used : SingleReferenceModel(com.canoo.impl.server.util.SingleReferenceModel) ValueChangeEvent(com.canoo.platform.remoting.ValueChangeEvent) ValueChangeListener(com.canoo.platform.remoting.ValueChangeListener) ServerModelStore(com.canoo.dp.impl.server.legacy.ServerModelStore) SimpleTestModel(com.canoo.impl.server.util.SimpleTestModel) 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 3 with ValueChangeListener

use of com.canoo.platform.remoting.ValueChangeListener 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 4 with ValueChangeListener

use of com.canoo.platform.remoting.ValueChangeListener 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 5 with ValueChangeListener

use of com.canoo.platform.remoting.ValueChangeListener in project dolphin-platform by canoo.

the class TestPropertyChange method testWithSimpleModel.

@Test
public void testWithSimpleModel() {
    ServerModelStore serverModelStore = createServerModelStore();
    final BeanManager manager = createBeanManager(serverModelStore);
    final SimpleTestModel model = manager.create(SimpleTestModel.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.getTextProperty()));
            results.newValue = evt.getNewValue();
            results.oldValue = evt.getOldValue();
            results.listenerCalls++;
        }
    };
    final Subscription subscription = model.getTextProperty().onChanged(myListener);
    assertThat(results.listenerCalls, is(0));
    assertThat(results.newValue, nullValue());
    assertThat(results.oldValue, nullValue());
    model.getTextProperty().set("Hallo Property");
    assertThat(results.listenerCalls, is(1));
    assertThat(results.newValue, is("Hallo Property"));
    assertThat(results.oldValue, nullValue());
    results.listenerCalls = 0;
    model.getTextProperty().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.getTextProperty().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) ServerModelStore(com.canoo.dp.impl.server.legacy.ServerModelStore) SimpleTestModel(com.canoo.impl.server.util.SimpleTestModel) 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)

Aggregations

BeanManager (com.canoo.platform.remoting.BeanManager)8 ValueChangeEvent (com.canoo.platform.remoting.ValueChangeEvent)8 ValueChangeListener (com.canoo.platform.remoting.ValueChangeListener)8 Test (org.testng.annotations.Test)8 Subscription (com.canoo.platform.core.functional.Subscription)6 AbstractDolphinBasedTest (com.canoo.dolphin.client.util.AbstractDolphinBasedTest)4 ClientModelStore (com.canoo.dp.impl.client.legacy.ClientModelStore)4 BeanRepository (com.canoo.dp.impl.remoting.BeanRepository)4 EventDispatcher (com.canoo.dp.impl.remoting.EventDispatcher)4 ServerModelStore (com.canoo.dp.impl.server.legacy.ServerModelStore)4 AbstractDolphinBasedTest (com.canoo.impl.server.util.AbstractDolphinBasedTest)4 SimpleTestModel (com.canoo.dolphin.client.util.SimpleTestModel)2 SimpleTestModel (com.canoo.impl.server.util.SimpleTestModel)2 ChildModel (com.canoo.dolphin.client.util.ChildModel)1 SimpleAnnotatedTestModel (com.canoo.dolphin.client.util.SimpleAnnotatedTestModel)1 SingleReferenceModel (com.canoo.dolphin.client.util.SingleReferenceModel)1 ChildModel (com.canoo.impl.server.util.ChildModel)1 SimpleAnnotatedTestModel (com.canoo.impl.server.util.SimpleAnnotatedTestModel)1 SingleReferenceModel (com.canoo.impl.server.util.SingleReferenceModel)1