Search in sources :

Example 21 with Subscription

use of com.canoo.platform.core.functional.Subscription 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)

Example 22 with Subscription

use of com.canoo.platform.core.functional.Subscription in project dolphin-platform by canoo.

the class TestObservableArrayListWriteOperations method removeListener_shouldNotFireListener.

// TODO: removeAll, retainAll
// ////////////////////////////////////////
// add(Object)
// ////////////////////////////////////////
@Test
public void removeListener_shouldNotFireListener() {
    final ObservableArrayList<String> list = new ObservableArrayList<>();
    final TestListChangeListener listener = new TestListChangeListener();
    final Subscription subscription = list.onChanged(listener);
    subscription.unsubscribe();
    list.add("42");
    assertThat(listener.calls, is(0));
}
Also used : ObservableArrayList(com.canoo.dp.impl.remoting.collections.ObservableArrayList) Subscription(com.canoo.platform.core.functional.Subscription) Test(org.testng.annotations.Test)

Example 23 with Subscription

use of com.canoo.platform.core.functional.Subscription in project dolphin-platform by canoo.

the class DefaultDolphinEventBusTest method TestRemoveSubscription.

@Test
public void TestRemoveSubscription() {
    // given
    final AtomicBoolean calledCheck = new AtomicBoolean(false);
    RemotingEventBus eventBus = create(createContext());
    Subscription subscription = eventBus.subscribe(TEST_TOPIC, new MessageListener<String>() {

        @Override
        public void onMessage(MessageEvent<String> message) {
            calledCheck.set(true);
        }
    });
    // when
    subscription.unsubscribe();
    eventBus.publish(TEST_TOPIC, "huhu");
    // then
    Assert.assertFalse(calledCheck.get());
}
Also used : RemotingEventBus(com.canoo.platform.remoting.server.event.RemotingEventBus) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Subscription(com.canoo.platform.core.functional.Subscription) Test(org.testng.annotations.Test)

Example 24 with Subscription

use of com.canoo.platform.core.functional.Subscription in project dolphin-platform by canoo.

the class AbstractEventBus method onSessionEnds.

private void onSessionEnds(final String dolphinSessionId) {
    Assert.requireNonBlank(dolphinSessionId, "dolphinSessionId");
    final List<Subscription> subscriptions = sessionStore.get(dolphinSessionId);
    if (subscriptions != null) {
        for (Subscription subscription : subscriptions) {
            subscription.unsubscribe();
        }
    }
}
Also used : Subscription(com.canoo.platform.core.functional.Subscription)

Example 25 with Subscription

use of com.canoo.platform.core.functional.Subscription in project dolphin-platform by canoo.

the class TestPropertyChange 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);
    final SimpleTestModel model = manager.create(SimpleTestModel.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.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;
    model.getTextProperty().set(null);
    assertThat(results.listenerCalls, is(1));
    assertThat(results.newValue, nullValue());
    assertThat(results.oldValue, is("Hallo Property2"));
    results.listenerCalls = 0;
    subscription.unsubscribe();
    model.getTextProperty().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) BeanRepository(com.canoo.dp.impl.remoting.BeanRepository) SimpleTestModel(com.canoo.dolphin.client.util.SimpleTestModel) 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)

Aggregations

Subscription (com.canoo.platform.core.functional.Subscription)30 Test (org.testng.annotations.Test)10 BeanManager (com.canoo.platform.remoting.BeanManager)7 ValueChangeEvent (com.canoo.platform.remoting.ValueChangeEvent)6 ValueChangeListener (com.canoo.platform.remoting.ValueChangeListener)6 TransformedPropertyImpl (com.canoo.dp.impl.reactive.TransformedPropertyImpl)4 AbstractDolphinBasedTest (com.canoo.dolphin.client.util.AbstractDolphinBasedTest)3 ClientModelStore (com.canoo.dp.impl.client.legacy.ClientModelStore)3 BeanRepository (com.canoo.dp.impl.remoting.BeanRepository)3 EventDispatcher (com.canoo.dp.impl.remoting.EventDispatcher)3 ServerModelStore (com.canoo.dp.impl.server.legacy.ServerModelStore)3 AbstractDolphinBasedTest (com.canoo.impl.server.util.AbstractDolphinBasedTest)3 Binding (com.canoo.platform.core.functional.Binding)3 SimpleTestModel (com.canoo.dolphin.client.util.SimpleTestModel)2 Assert (com.canoo.dp.impl.platform.core.Assert)2 ContextManagerImpl (com.canoo.dp.impl.platform.core.context.ContextManagerImpl)2 ObservableArrayList (com.canoo.dp.impl.remoting.collections.ObservableArrayList)2 SimpleTestModel (com.canoo.impl.server.util.SimpleTestModel)2 List (java.util.List)2 Collectors (java.util.stream.Collectors)2