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"));
}
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));
}
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());
}
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"));
}
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"));
}
Aggregations