use of com.canoo.impl.server.util.SingleReferenceModel 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.impl.server.util.SingleReferenceModel in project dolphin-platform by canoo.
the class TestPropertyValue method testWithSingleReferenceModel.
@Test
public void testWithSingleReferenceModel() {
final ServerModelStore serverModelStore = createServerModelStore();
final BeanManager manager = createBeanManager(serverModelStore);
final SimpleTestModel ref1 = manager.create(SimpleTestModel.class);
ref1.getTextProperty().set("ref1_text");
final SimpleTestModel ref2 = manager.create(SimpleTestModel.class);
ref2.getTextProperty().set("ref2_text");
final List<ServerPresentationModel> refPMs = serverModelStore.findAllPresentationModelsByType(SimpleTestModel.class.getName());
final ServerPresentationModel ref1PM = "ref1_text".equals(refPMs.get(0).getAttribute("text").getValue()) ? refPMs.get(0) : refPMs.get(1);
final ServerPresentationModel ref2PM = "ref2_text".equals(refPMs.get(0).getAttribute("text").getValue()) ? refPMs.get(0) : refPMs.get(1);
final SingleReferenceModel model = manager.create(SingleReferenceModel.class);
final ServerPresentationModel dolphinModel = serverModelStore.findAllPresentationModelsByType(SingleReferenceModel.class.getName()).get(0);
final Attribute referenceAttribute = dolphinModel.getAttribute("referenceProperty");
assertThat(referenceAttribute.getValue(), nullValue());
model.getReferenceProperty().set(ref1);
assertThat((String) referenceAttribute.getValue(), is(ref1PM.getId()));
assertThat(model.getReferenceProperty().get(), is(ref1));
referenceAttribute.setValue(ref2PM.getId());
assertThat((String) referenceAttribute.getValue(), is(ref2PM.getId()));
assertThat(model.getReferenceProperty().get(), is(ref2));
}
use of com.canoo.impl.server.util.SingleReferenceModel in project dolphin-platform by canoo.
the class TestModelCreation method testWithSingleReferenceModel.
@Test
public void testWithSingleReferenceModel() {
final ServerModelStore serverModelStore = createServerModelStore();
final EventDispatcher dispatcher = createEventDispatcher(serverModelStore);
final BeanRepository beanRepository = createBeanRepository(serverModelStore, dispatcher);
final BeanManager manager = createBeanManager(serverModelStore, beanRepository, dispatcher);
SingleReferenceModel model = manager.create(SingleReferenceModel.class);
assertThat(model, notNullValue());
assertThat(model.getReferenceProperty(), notNullValue());
assertThat(model.getReferenceProperty().get(), nullValue());
assertThat(beanRepository.isManaged(model), is(true));
List<ServerPresentationModel> dolphinModels = serverModelStore.findAllPresentationModelsByType(SingleReferenceModel.class.getName());
assertThat(dolphinModels, hasSize(1));
ServerPresentationModel dolphinModel = dolphinModels.get(0);
List<ServerAttribute> attributes = dolphinModel.getAttributes();
assertThat(attributes, containsInAnyOrder(allOf(hasProperty("propertyName", is("referenceProperty")), hasProperty("value", nullValue()), hasProperty("qualifier", nullValue())), allOf(hasProperty("propertyName", is(RemotingConstants.SOURCE_SYSTEM)), hasProperty("value", is(RemotingConstants.SOURCE_SYSTEM_SERVER)), hasProperty("qualifier", nullValue()))));
List<ServerPresentationModel> classModels = serverModelStore.findAllPresentationModelsByType(PlatformRemotingConstants.DOLPHIN_BEAN);
assertThat(classModels, contains(hasProperty("attributes", containsInAnyOrder(allOf(hasProperty("propertyName", is(PlatformRemotingConstants.JAVA_CLASS)), hasProperty("value", is(SingleReferenceModel.class.getName())), hasProperty("qualifier", nullValue())), allOf(hasProperty("propertyName", is("referenceProperty")), hasProperty("value", is(DolphinBeanConverterFactory.FIELD_TYPE_DOLPHIN_BEAN)), hasProperty("qualifier", nullValue())), allOf(hasProperty("propertyName", is(RemotingConstants.SOURCE_SYSTEM)), hasProperty("value", is(RemotingConstants.SOURCE_SYSTEM_SERVER)), hasProperty("qualifier", nullValue()))))));
}
use of com.canoo.impl.server.util.SingleReferenceModel in project dolphin-platform by canoo.
the class TestModelDeletion method testWithSingleReferenceModel.
@Test
public void testWithSingleReferenceModel() {
final ServerModelStore serverModelStore = createServerModelStore();
final EventDispatcher dispatcher = createEventDispatcher(serverModelStore);
final BeanRepository beanRepository = createBeanRepository(serverModelStore, dispatcher);
final BeanManager manager = createBeanManager(serverModelStore, beanRepository, dispatcher);
SingleReferenceModel model = manager.create(SingleReferenceModel.class);
beanRepository.delete(model);
List<ServerPresentationModel> dolphinModels = serverModelStore.findAllPresentationModelsByType(SingleReferenceModel.class.getName());
assertThat(dolphinModels, empty());
Collection<ServerPresentationModel> allDolphinModels = serverModelStore.listPresentationModels();
assertThat(allDolphinModels, hasSize(1));
assertThat(beanRepository.isManaged(model), is(false));
}
Aggregations