use of com.canoo.impl.server.util.ChildModel 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.impl.server.util.ChildModel in project dolphin-platform by canoo.
the class TestPropertyValue method testWithInheritedModel.
@Test
public void testWithInheritedModel() {
final ServerModelStore serverModelStore = createServerModelStore();
final BeanManager manager = createBeanManager(serverModelStore);
ChildModel model = manager.create(ChildModel.class);
ServerPresentationModel dolphinModel = serverModelStore.findAllPresentationModelsByType(ChildModel.class.getName()).get(0);
Attribute childAttribute = dolphinModel.getAttribute("childProperty");
assertThat(childAttribute.getValue(), nullValue());
Attribute parentAttribute = dolphinModel.getAttribute("parentProperty");
assertThat(parentAttribute.getValue(), nullValue());
model.getChildProperty().set("Hallo Platform");
assertThat((String) childAttribute.getValue(), is("Hallo Platform"));
assertThat(model.getChildProperty().get(), is("Hallo Platform"));
assertThat(parentAttribute.getValue(), nullValue());
assertThat(model.getParentProperty().get(), nullValue());
parentAttribute.setValue("Hallo Dolphin");
assertThat((String) childAttribute.getValue(), is("Hallo Platform"));
assertThat(model.getChildProperty().get(), is("Hallo Platform"));
assertThat((String) parentAttribute.getValue(), is("Hallo Dolphin"));
assertThat(model.getParentProperty().get(), is("Hallo Dolphin"));
}
use of com.canoo.impl.server.util.ChildModel in project dolphin-platform by canoo.
the class TestModelCreation method testWithInheritedModel.
@Test
public void testWithInheritedModel() {
final ServerModelStore serverModelStore = createServerModelStore();
final EventDispatcher dispatcher = createEventDispatcher(serverModelStore);
final BeanRepository beanRepository = createBeanRepository(serverModelStore, dispatcher);
final BeanManager manager = createBeanManager(serverModelStore, beanRepository, dispatcher);
ChildModel model = manager.create(ChildModel.class);
assertThat(model, notNullValue());
assertThat(model.getParentProperty(), notNullValue());
assertThat(model.getParentProperty().get(), nullValue());
assertThat(model.getChildProperty(), notNullValue());
assertThat(model.getChildProperty().get(), nullValue());
assertThat(beanRepository.isManaged(model), is(true));
List<ServerPresentationModel> dolphinModels = serverModelStore.findAllPresentationModelsByType(ChildModel.class.getName());
assertThat(dolphinModels, hasSize(1));
ServerPresentationModel dolphinModel = dolphinModels.get(0);
List<ServerAttribute> attributes = dolphinModel.getAttributes();
assertThat(attributes, containsInAnyOrder(allOf(hasProperty("propertyName", is("childProperty")), hasProperty("value", nullValue()), hasProperty("qualifier", nullValue())), allOf(hasProperty("propertyName", is("parentProperty")), 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, hasSize(1));
assertThat(classModels, contains(hasProperty("attributes", containsInAnyOrder(allOf(hasProperty("propertyName", is(PlatformRemotingConstants.JAVA_CLASS)), hasProperty("value", is(ChildModel.class.getName())), hasProperty("qualifier", nullValue())), allOf(hasProperty("propertyName", is("childProperty")), hasProperty("value", is(StringConverterFactory.FIELD_TYPE_STRING)), hasProperty("qualifier", nullValue())), allOf(hasProperty("propertyName", is("parentProperty")), hasProperty("value", is(StringConverterFactory.FIELD_TYPE_STRING)), 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.ChildModel in project dolphin-platform by canoo.
the class TestModelDeletion method testWithInheritedModel.
@Test
public void testWithInheritedModel() {
final ServerModelStore serverModelStore = createServerModelStore();
final EventDispatcher dispatcher = createEventDispatcher(serverModelStore);
final BeanRepository beanRepository = createBeanRepository(serverModelStore, dispatcher);
final BeanManager manager = createBeanManager(serverModelStore, beanRepository, dispatcher);
ChildModel model = manager.create(ChildModel.class);
beanRepository.delete(model);
List<ServerPresentationModel> dolphinModels = serverModelStore.findAllPresentationModelsByType(ChildModel.class.getName());
assertThat(dolphinModels, empty());
Collection<ServerPresentationModel> allDolphinModels = serverModelStore.listPresentationModels();
assertThat(allDolphinModels, hasSize(1));
assertThat(beanRepository.isManaged(model), is(false));
}
Aggregations