* All property types.
*/
@Test
public void types() {
DataModelDescriptor descriptor = FieldPropertyDescriptor.extract(MockTypes.class);
MockTypes obj = (MockTypes) descriptor.createDataModelObject();
obj.booleanOption.modify(true);
obj.byteOption.modify((byte) 1);
obj.shortOption.modify((short) 2);
obj.intOption.modify(3);
obj.longOption.modify(4L);
obj.floatOption.modify(5f);
obj.doubleOption.modify(6d);
obj.dateOption.modify(new Date(2014, 6, 1));
obj.dateTimeOption.modify(new DateTime(2014, 6, 1, 2, 3, 4));
obj.stringOption.modify("Hello, world!");
obj.decimalOption.modify(new BigDecimal("7.8"));
DataModelInspector inspector = new DataModelInspector(descriptor);
assertThat(inspector.getTypeName(), is(MockTypes.class.getName()));
assertThat(inspector.getAllStructFieldRefs(), hasSize(11));
assertThat(inspector.getStructFieldsDataAsList(obj), is(Arrays.asList(new Object[] {
obj.booleanOption,
obj.byteOption,
obj.shortOption,
obj.intOption,
obj.longOption,
obj.floatOption,
obj.doubleOption,
obj.dateOption,
obj.dateTimeOption,
obj.stringOption,
obj.decimalOption,
})));
assertThat(getJavaField(inspector, obj, "booleanOption"), equalTo((Object) obj.booleanOption.get()));
assertThat(getJavaField(inspector, obj, "byteOption"), equalTo((Object) obj.byteOption.get()));
assertThat(getJavaField(inspector, obj, "shortOption"), equalTo((Object) obj.shortOption.get()));
assertThat(getJavaField(inspector, obj, "intOption"), equalTo((Object) obj.intOption.get()));
assertThat(getJavaField(inspector, obj, "longOption"), equalTo((Object) obj.longOption.get()));
assertThat(getJavaField(inspector, obj, "floatOption"), equalTo((Object) obj.floatOption.get()));
assertThat(getJavaField(inspector, obj, "doubleOption"), equalTo((Object) obj.doubleOption.get()));
Calendar calendar = Calendar.getInstance();
DateUtil.setDayToCalendar(obj.dateOption.get().getElapsedDays(), calendar);
assertThat(getJavaField(inspector, obj, "dateOption"),
equalTo((Object) new java.sql.Date(calendar.getTimeInMillis())));
DateUtil.setSecondToCalendar(obj.dateTimeOption.get().getElapsedSeconds(), calendar);
assertThat(getJavaField(inspector, obj, "dateTimeOption"),
equalTo((Object) new java.sql.Timestamp(calendar.getTimeInMillis())));
assertThat(getJavaField(inspector, obj, "stringOption"),
equalTo((Object) obj.stringOption.getAsString()));
assertThat(((HiveDecimal) getJavaField(inspector, obj, "decimalOption")),
equalTo(HiveDecimal.create(obj.decimalOption.get())));
DataModelDriver driver = new DataModelDriver(descriptor, inspector);
MockTypes copy = new MockTypes();
driver.set(copy, obj);
assertThat(copy.booleanOption, equalTo(obj.booleanOption));
assertThat(copy.byteOption, equalTo(obj.byteOption));
assertThat(copy.shortOption, equalTo(obj.shortOption));