use of com.canoo.dolphin.client.util.SimpleTestModel in project dolphin-platform by canoo.
the class TestFindAll method testWithSimpleModel.
@Test
public void testWithSimpleModel(@Mocked AbstractClientConnector connector) {
final ClientModelStore clientModelStore = createClientModelStore(connector);
final BeanManager manager = createBeanManager(clientModelStore);
SimpleTestModel model1 = manager.create(SimpleTestModel.class);
SimpleTestModel model2 = manager.create(SimpleTestModel.class);
SimpleTestModel model3 = manager.create(SimpleTestModel.class);
manager.create(SimpleAnnotatedTestModel.class);
List<SimpleTestModel> models = manager.findAll(SimpleTestModel.class);
assertThat(models, is(Arrays.asList(model1, model2, model3)));
}
use of com.canoo.dolphin.client.util.SimpleTestModel in project dolphin-platform by canoo.
the class TestModelCreation 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);
SimpleTestModel model = manager.create(SimpleTestModel.class);
assertThat(model, notNullValue());
assertThat(model.getTextProperty(), notNullValue());
assertThat(model.getTextProperty().get(), nullValue());
assertThat(repository.isManaged(model), is(true));
List<ClientPresentationModel> dolphinModels = clientModelStore.findAllPresentationModelsByType(SimpleTestModel.class.getName());
assertThat(dolphinModels, hasSize(1));
PresentationModel dolphinModel = dolphinModels.get(0);
List<Attribute> attributes = dolphinModel.getAttributes();
assertThat(attributes, containsInAnyOrder(allOf(hasProperty("propertyName", is("text")), hasProperty("value", nullValue()), hasProperty("qualifier", nullValue())), allOf(hasProperty("propertyName", is(RemotingConstants.SOURCE_SYSTEM)), hasProperty("value", is(RemotingConstants.SOURCE_SYSTEM_CLIENT)), hasProperty("qualifier", nullValue()))));
List<ClientPresentationModel> classModels = clientModelStore.findAllPresentationModelsByType(PlatformRemotingConstants.DOLPHIN_BEAN);
assertThat(classModels, contains(hasProperty("attributes", containsInAnyOrder(allOf(hasProperty("propertyName", is(PlatformRemotingConstants.JAVA_CLASS)), hasProperty("value", is(SimpleTestModel.class.getName())), hasProperty("qualifier", nullValue())), allOf(hasProperty("propertyName", is("text")), hasProperty("value", is(StringConverterFactory.FIELD_TYPE_STRING)), hasProperty("qualifier", nullValue())), allOf(hasProperty("propertyName", is(RemotingConstants.SOURCE_SYSTEM)), hasProperty("value", is(RemotingConstants.SOURCE_SYSTEM_CLIENT)), hasProperty("qualifier", nullValue()))))));
}
use of com.canoo.dolphin.client.util.SimpleTestModel in project dolphin-platform by canoo.
the class TestObservableListSync method replacingObjectElementFromDolphin_shouldReplaceElement.
@Test
public void replacingObjectElementFromDolphin_shouldReplaceElement(@Mocked AbstractClientConnector connector) {
// given :
final ClientModelStore clientModelStore = createClientModelStore(connector);
final BeanManager manager = createBeanManager(clientModelStore);
final ListReferenceModel model = manager.create(ListReferenceModel.class);
final PresentationModel sourceModel = clientModelStore.findAllPresentationModelsByType(ListReferenceModel.class.getName()).get(0);
final PresentationModel classDescription = clientModelStore.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 = clientModelStore.findAllPresentationModelsByType(SimpleTestModel.class.getName()).get(0);
final SimpleTestModel newObject = manager.create(SimpleTestModel.class);
final List<ClientPresentationModel> models = clientModelStore.findAllPresentationModelsByType(SimpleTestModel.class.getName());
final PresentationModel newObjectModel = oldObjectModel == models.get(1) ? models.get(0) : models.get(1);
new PresentationModelBuilder(clientModelStore, 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(clientModelStore, 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(clientModelStore.findAllPresentationModelsByType(PlatformRemotingConstants.LIST_SPLICE), empty());
}
use of com.canoo.dolphin.client.util.SimpleTestModel 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"));
}
use of com.canoo.dolphin.client.util.SimpleTestModel in project dolphin-platform by canoo.
the class TestPropertyChange method testWithSingleReferenceModel.
@Test
public void testWithSingleReferenceModel(@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 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>() {
@Override
public void valueChanged(ValueChangeEvent<? extends SimpleTestModel> evt) {
Assert.assertEquals(evt.getSource(), 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;
model.getReferenceProperty().set(null);
assertThat(results.listenerCalls, is(1));
assertThat(results.newValue, nullValue());
assertThat(results.oldValue, is(ref2));
results.listenerCalls = 0;
subscription.unsubscribe();
model.getReferenceProperty().set(ref3);
assertThat(results.listenerCalls, is(0));
assertThat(results.newValue, nullValue());
assertThat(results.oldValue, is(ref2));
}
Aggregations