use of com.canoo.impl.server.util.SimpleTestModel in project dolphin-platform by canoo.
the class TestObservableListSync method replaceObjectNullWithElementAsUser_shouldReplaceElement.
@Test
public void replaceObjectNullWithElementAsUser_shouldReplaceElement() {
// 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 newObject = manager.create(SimpleTestModel.class);
final PresentationModel newObjectModel = serverModelStore.findAllPresentationModelsByType(SimpleTestModel.class.getName()).get(0);
model.getObjectList().add(null);
removeAllPresentationModelsOfType(serverModelStore, PlatformRemotingConstants.LIST_SPLICE);
// when :
model.getObjectList().set(0, newObject);
// 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) 1)));
assertThat(change.getAttribute("count").getValue(), allOf(instanceOf(Integer.class), is((Object) 1)));
assertThat(change.getAttribute("0").getValue(), allOf(instanceOf(String.class), is((Object) newObjectModel.getId())));
}
use of com.canoo.impl.server.util.SimpleTestModel in project dolphin-platform by canoo.
the class TestDeleteAll method testWithSimpleModel.
@Test
public void testWithSimpleModel() {
final ServerModelStore serverModelStore = createServerModelStore();
final EventDispatcher dispatcher = createEventDispatcher(serverModelStore);
final BeanRepository beanRepository = createBeanRepository(serverModelStore, dispatcher);
final BeanManager manager = createBeanManager(serverModelStore, beanRepository, 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 (final Object bean : manager.findAll(SimpleTestModel.class)) {
beanRepository.delete(bean);
}
assertThat(beanRepository.isManaged(model1), is(false));
assertThat(beanRepository.isManaged(model2), is(false));
assertThat(beanRepository.isManaged(model3), is(false));
assertThat(beanRepository.isManaged(wrongModel), is(true));
List<ServerPresentationModel> testModels = serverModelStore.findAllPresentationModelsByType("com.canoo.dolphin.server.util.SimpleTestModel");
assertThat(testModels, hasSize(0));
}
use of com.canoo.impl.server.util.SimpleTestModel in project dolphin-platform by canoo.
the class TestObservableListSync method replaceObjectElementWithNullAsUser_shouldReplaceElement.
@Test
public void replaceObjectElementWithNullAsUser_shouldReplaceElement() {
// 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 oldObject = manager.create(SimpleTestModel.class);
model.getObjectList().add(oldObject);
removeAllPresentationModelsOfType(serverModelStore, PlatformRemotingConstants.LIST_SPLICE);
// when :
model.getObjectList().set(0, null);
// 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) 1)));
assertThat(change.getAttribute("count").getValue(), allOf(instanceOf(Integer.class), is((Object) 1)));
assertThat(change.getAttribute("0").getValue(), nullValue());
}
use of com.canoo.impl.server.util.SimpleTestModel in project dolphin-platform by canoo.
the class TestObservableListSync method replacingObjectElementFromDolphin_shouldReplaceElement.
@Test
public void replacingObjectElementFromDolphin_shouldReplaceElement() {
// 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 PresentationModel classDescription = serverModelStore.findAllPresentationModelsByType(PlatformRemotingConstants.DOLPHIN_BEAN).get(0);
classDescription.getAttribute("objectList").setValue(DolphinBeanConverterFactory.FIELD_TYPE_DOLPHIN_BEAN);
final SimpleTestModel oldObject = manager.create(SimpleTestModel.class);
final PresentationModel oldObjectModel = serverModelStore.findAllPresentationModelsByType(SimpleTestModel.class.getName()).get(0);
final SimpleTestModel newObject = manager.create(SimpleTestModel.class);
final List<ServerPresentationModel> models = serverModelStore.findAllPresentationModelsByType(SimpleTestModel.class.getName());
final PresentationModel newObjectModel = oldObjectModel == models.get(1) ? models.get(0) : models.get(1);
new PresentationModelBuilder(serverModelStore, PlatformRemotingConstants.LIST_SPLICE).withAttribute("source", sourceModel.getId()).withAttribute("attribute", "objectList").withAttribute("from", 0).withAttribute("to", 0).withAttribute("count", 1).withAttribute("0", oldObjectModel.getId()).create();
assertThat(model.getObjectList(), is(Collections.singletonList(oldObject)));
// when :
new PresentationModelBuilder(serverModelStore, PlatformRemotingConstants.LIST_SPLICE).withAttribute("source", sourceModel.getId()).withAttribute("attribute", "objectList").withAttribute("pos", 0).withAttribute("from", 0).withAttribute("to", 1).withAttribute("count", 1).withAttribute("0", newObjectModel.getId()).create();
// then :
assertThat(model.getObjectList(), is(Collections.singletonList(newObject)));
assertThat(serverModelStore.findAllPresentationModelsByType(PlatformRemotingConstants.LIST_SPLICE), empty());
}
use of com.canoo.impl.server.util.SimpleTestModel 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