use of com.canoo.platform.remoting.BeanManager in project dolphin-platform by canoo.
the class TestObservableListSync method deletingMultipleElementAtEndAsUser_shouldAddElements.
// TODO: Enable once ObservableArrayList.sublist() was implemented completely
@Test(enabled = false)
public void deletingMultipleElementAtEndAsUser_shouldAddElements() {
// given :
final ServerModelStore serverModelStore = createServerModelStore();
final BeanManager manager = createBeanManager(serverModelStore);
final ListReferenceModel model = manager.create(ListReferenceModel.class);
final PresentationModel sourceModel = serverModelStore.findAllPresentationModelsByType(ListReferenceModel.class.getName()).get(0);
model.getPrimitiveList().addAll(Arrays.asList("1", "2", "3", "4", "5", "6"));
removeAllPresentationModelsOfType(serverModelStore, PlatformRemotingConstants.LIST_SPLICE);
// when :
model.getPrimitiveList().subList(3, 6).clear();
// then :
final List<ServerPresentationModel> changes = serverModelStore.findAllPresentationModelsByType(PlatformRemotingConstants.LIST_SPLICE);
assertThat(changes, hasSize(1));
final PresentationModel change = changes.get(0);
assertThat(change.getAttribute("source").getValue(), allOf(instanceOf(String.class), is((Object) sourceModel.getId())));
assertThat(change.getAttribute("attribute").getValue(), allOf(instanceOf(String.class), is((Object) "primitiveList")));
assertThat(change.getAttribute("from").getValue(), allOf(instanceOf(Integer.class), is((Object) 3)));
assertThat(change.getAttribute("to").getValue(), allOf(instanceOf(Integer.class), is((Object) 6)));
assertThat(change.getAttribute("count").getValue(), allOf(instanceOf(Integer.class), is((Object) 0)));
}
use of com.canoo.platform.remoting.BeanManager in project dolphin-platform by canoo.
the class TestObservableListSync method addingObjectElementAsUser_shouldAddElement.
// ////////////////////////////////////////////////////////////
// Adding, removing, and replacing all element types as user
// ////////////////////////////////////////////////////////////
@Test
public void addingObjectElementAsUser_shouldAddElement() {
// given :
final ServerModelStore serverModelStore = createServerModelStore();
final BeanManager manager = createBeanManager(serverModelStore);
final ListReferenceModel model = manager.create(ListReferenceModel.class);
final PresentationModel sourceModel = serverModelStore.findAllPresentationModelsByType(ListReferenceModel.class.getName()).get(0);
final SimpleTestModel object = manager.create(SimpleTestModel.class);
final PresentationModel objectModel = serverModelStore.findAllPresentationModelsByType(SimpleTestModel.class.getName()).get(0);
// when :
model.getObjectList().add(object);
// then :
final List<ServerPresentationModel> changes = serverModelStore.findAllPresentationModelsByType(PlatformRemotingConstants.LIST_SPLICE);
assertThat(changes, hasSize(1));
final PresentationModel change = changes.get(0);
assertThat(change.getAttribute("source").getValue(), allOf(instanceOf(String.class), is((Object) sourceModel.getId())));
assertThat(change.getAttribute("attribute").getValue(), allOf(instanceOf(String.class), is((Object) "objectList")));
assertThat(change.getAttribute("from").getValue(), allOf(instanceOf(Integer.class), is((Object) 0)));
assertThat(change.getAttribute("to").getValue(), allOf(instanceOf(Integer.class), is((Object) 0)));
assertThat(change.getAttribute("count").getValue(), allOf(instanceOf(Integer.class), is((Object) 1)));
assertThat(change.getAttribute("0").getValue(), allOf(instanceOf(String.class), is((Object) objectModel.getId())));
}
use of com.canoo.platform.remoting.BeanManager 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.BeanManager 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.BeanManager 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());
}
Aggregations