use of com.canoo.impl.server.util.ComplexDataTypesModel in project dolphin-platform by canoo.
the class TestModelCreation method testWithComplexDataTypesModel.
@Test
public void testWithComplexDataTypesModel() {
final ServerModelStore serverModelStore = createServerModelStore();
final EventDispatcher dispatcher = createEventDispatcher(serverModelStore);
final BeanRepository beanRepository = createBeanRepository(serverModelStore, dispatcher);
final BeanManager manager = createBeanManager(serverModelStore, beanRepository, dispatcher);
ComplexDataTypesModel model = manager.create(ComplexDataTypesModel.class);
assertThat(model, notNullValue());
assertThat(model.getDateProperty(), notNullValue());
assertThat(model.getDateProperty().get(), nullValue());
assertThat(model.getCalendarProperty(), notNullValue());
assertThat(model.getCalendarProperty().get(), nullValue());
assertThat(model.getEnumProperty(), notNullValue());
assertThat(model.getEnumProperty().get(), nullValue());
assertThat(beanRepository.isManaged(model), is(true));
List<ServerPresentationModel> dolphinModels = serverModelStore.findAllPresentationModelsByType(ComplexDataTypesModel.class.getName());
assertThat(dolphinModels, hasSize(1));
PresentationModel dolphinModel = dolphinModels.get(0);
List<Attribute> attributes = dolphinModel.getAttributes();
assertThat(attributes, containsInAnyOrder(allOf(hasProperty("propertyName", is("dateProperty")), hasProperty("value", nullValue()), hasProperty("qualifier", nullValue())), allOf(hasProperty("propertyName", is("calendarProperty")), hasProperty("value", nullValue()), hasProperty("qualifier", nullValue())), allOf(hasProperty("propertyName", is("enumProperty")), 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(ComplexDataTypesModel.class.getName())), hasProperty("qualifier", nullValue())), allOf(hasProperty("propertyName", is("dateProperty")), hasProperty("value", is(DateConverterFactory.FIELD_TYPE_DATE)), hasProperty("qualifier", nullValue())), allOf(hasProperty("propertyName", is("calendarProperty")), hasProperty("value", is(CalendarConverterFactory.FIELD_TYPE_CALENDAR)), hasProperty("qualifier", nullValue())), allOf(hasProperty("propertyName", is("enumProperty")), hasProperty("value", is(EnumConverterFactory.FIELD_TYPE_ENUM)), 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.ComplexDataTypesModel in project dolphin-platform by canoo.
the class TestPropertyValue method testWithComplexDataTypesModel.
@Test
public void testWithComplexDataTypesModel() {
final Calendar date1 = new GregorianCalendar(2016, Calendar.MARCH, 1, 0, 1, 2);
date1.set(Calendar.MILLISECOND, 3);
date1.setTimeZone(TimeZone.getTimeZone("GMT+2:00"));
final Calendar date2 = new GregorianCalendar(2016, Calendar.FEBRUARY, 29, 0, 1, 2);
date2.set(Calendar.MILLISECOND, 3);
date2.setTimeZone(TimeZone.getTimeZone("UTC"));
final ServerModelStore serverModelStore = createServerModelStore();
final BeanManager manager = createBeanManager(serverModelStore);
ComplexDataTypesModel model = manager.create(ComplexDataTypesModel.class);
PresentationModel dolphinModel = serverModelStore.findAllPresentationModelsByType(ComplexDataTypesModel.class.getName()).get(0);
Attribute dateAttribute = dolphinModel.getAttribute("dateProperty");
assertThat(dateAttribute.getValue(), nullValue());
model.getDateProperty().set(date1.getTime());
assertThat((String) dateAttribute.getValue(), is("2016-02-29T22:01:02.003Z"));
assertThat(model.getDateProperty().get(), is(date1.getTime()));
dateAttribute.setValue("2016-02-29T00:01:02.003Z");
assertThat((String) dateAttribute.getValue(), is("2016-02-29T00:01:02.003Z"));
assertThat(model.getDateProperty().get(), is(date2.getTime()));
Attribute calendarAttribute = dolphinModel.getAttribute("calendarProperty");
assertThat(calendarAttribute.getValue(), nullValue());
model.getCalendarProperty().set(date1);
assertThat((String) calendarAttribute.getValue(), is("2016-02-29T22:01:02.003Z"));
assertThat(model.getCalendarProperty().get().getTimeInMillis(), is(date1.getTimeInMillis()));
calendarAttribute.setValue("2016-02-29T00:01:02.003Z");
assertThat((String) calendarAttribute.getValue(), is("2016-02-29T00:01:02.003Z"));
assertThat(model.getCalendarProperty().get(), is(date2));
Attribute enumAttribute = dolphinModel.getAttribute("enumProperty");
assertThat(enumAttribute.getValue(), nullValue());
model.getEnumProperty().set(VALUE_1);
assertThat((String) enumAttribute.getValue(), is("VALUE_1"));
assertThat(model.getEnumProperty().get(), is(VALUE_1));
enumAttribute.setValue("VALUE_2");
assertThat((String) enumAttribute.getValue(), is("VALUE_2"));
assertThat(model.getEnumProperty().get(), is(VALUE_2));
}
Aggregations