use of io.atlasmap.java.v2.JavaField in project atlasmap by atlasmap.
the class ClassInspectionServiceTest method testDateTimeViaSetter.
@Test
public void testDateTimeViaSetter() {
JavaClass javaClass = classInspectionService.inspectClass(DateTimeSetter.class);
assertEquals(14, javaClass.getJavaFields().getJavaField().size());
for (JavaField field : javaClass.getJavaFields().getJavaField()) {
if ("year".equals(field.getName())) {
assertEquals("java.time.Year", field.getClassName());
assertEquals(FieldType.DATE, field.getFieldType());
assertEquals("setYear", field.getSetMethod());
} else if ("month".equals(field.getName())) {
assertEquals("java.time.Month", field.getClassName());
assertEquals(FieldType.DATE, field.getFieldType());
assertEquals("setMonth", field.getSetMethod());
} else if ("yearMonth".equals(field.getName())) {
assertEquals("java.time.YearMonth", field.getClassName());
assertEquals(FieldType.DATE, field.getFieldType());
assertEquals("setYearMonth", field.getSetMethod());
} else if ("monthDay".equals(field.getName())) {
assertEquals("java.time.MonthDay", field.getClassName());
assertEquals(FieldType.DATE, field.getFieldType());
assertEquals("setMonthDay", field.getSetMethod());
} else if ("localDate".equals(field.getName())) {
assertEquals("java.time.LocalDate", field.getClassName());
assertEquals(FieldType.DATE, field.getFieldType());
assertEquals("setLocalDate", field.getSetMethod());
} else if ("localTime".equals(field.getName())) {
assertEquals("java.time.LocalTime", field.getClassName());
assertEquals(FieldType.TIME, field.getFieldType());
assertEquals("setLocalTime", field.getSetMethod());
} else if ("localDateTime".equals(field.getName())) {
assertEquals("java.time.LocalDateTime", field.getClassName());
assertEquals(FieldType.DATE_TIME, field.getFieldType());
assertEquals("setLocalDateTime", field.getSetMethod());
} else if ("zonedDateTime".equals(field.getName())) {
assertEquals("java.time.ZonedDateTime", field.getClassName());
assertEquals(FieldType.DATE_TIME_TZ, field.getFieldType());
assertEquals("setZonedDateTime", field.getSetMethod());
} else if ("calendar".equals(field.getName())) {
assertEquals("java.util.Calendar", field.getClassName());
assertEquals(FieldType.DATE_TIME_TZ, field.getFieldType());
assertEquals("setCalendar", field.getSetMethod());
} else if ("date".equals(field.getName())) {
assertEquals("java.util.Date", field.getClassName());
assertEquals(FieldType.DATE_TIME, field.getFieldType());
assertEquals("setDate", field.getSetMethod());
} else if ("gregorianCalendar".equals(field.getName())) {
assertEquals("java.util.GregorianCalendar", field.getClassName());
assertEquals(FieldType.DATE_TIME_TZ, field.getFieldType());
assertEquals("setGregorianCalendar", field.getSetMethod());
} else if ("sqlDate".equals(field.getName())) {
assertEquals("java.sql.Date", field.getClassName());
assertEquals(FieldType.DATE, field.getFieldType());
assertEquals("setSqlDate", field.getSetMethod());
} else if ("sqlTime".equals(field.getName())) {
assertEquals("java.sql.Time", field.getClassName());
assertEquals(FieldType.TIME, field.getFieldType());
assertEquals("setSqlTime", field.getSetMethod());
} else if ("sqlTimestamp".equals(field.getName())) {
assertEquals("java.sql.Timestamp", field.getClassName());
assertEquals(FieldType.DATE_TIME, field.getFieldType());
assertEquals("setSqlTimestamp", field.getSetMethod());
} else {
fail("Unsupported field was detected: " + field);
}
}
}
use of io.atlasmap.java.v2.JavaField in project atlasmap by atlasmap.
the class ClassValidationUtil method validateFlatPrimitiveFields.
public static void validateFlatPrimitiveFields(JavaClass flatClass) {
assertNotNull(flatClass.getPackageName());
assertEquals("io.atlasmap.java.test", flatClass.getPackageName());
assertNotNull(flatClass.getJavaFields());
assertNotNull(flatClass.getJavaFields().getJavaField());
assertFalse(flatClass.getJavaFields().getJavaField().isEmpty());
assertEquals(new Integer(34), new Integer(flatClass.getJavaFields().getJavaField().size()));
assertNotNull(flatClass.getJavaEnumFields());
assertNotNull(flatClass.getJavaEnumFields().getJavaEnumField());
assertTrue(flatClass.getJavaEnumFields().getJavaEnumField().isEmpty());
for (JavaField f : flatClass.getJavaFields().getJavaField()) {
assertNotNull(f);
JavaField j = f;
assertNotNull(j.getName());
switch(j.getFieldType()) {
case BOOLEAN:
if (CollectionType.ARRAY.equals(j.getCollectionType())) {
validatePrimitiveField("boolean", "Boolean", j, false);
} else {
validatePrimitiveField("boolean", "Boolean", j, true);
}
break;
case BYTE:
validatePrimitiveField("byte", "Byte", j);
break;
case CHAR:
validatePrimitiveField("char", "Char", j);
break;
case DOUBLE:
validatePrimitiveField("double", "Double", j);
break;
case FLOAT:
validatePrimitiveField("float", "Float", j);
break;
case INTEGER:
validatePrimitiveField("int", "Int", j);
break;
case LONG:
validatePrimitiveField("long", "Long", j);
break;
case SHORT:
validatePrimitiveField("short", "Short", j);
break;
case STRING:
validatePrimitiveField("string", "String", j);
break;
default:
fail("Extra field detected: " + j.getName());
}
}
}
use of io.atlasmap.java.v2.JavaField in project atlasmap by atlasmap.
the class JavaConstructServiceComplexListTest method generateOrderList.
protected JavaClass generateOrderList(String prefix) {
JavaClass j = classInspectionService.inspectClass("io.atlasmap.java.test." + prefix + "OrderList");
for (JavaField jf : j.getJavaFields().getJavaField()) {
if (jf.getPath().equals("orders")) {
jf.setClassName("io.atlasmap.java.test." + prefix + "Order");
jf.setCollectionClassName("java.util.ArrayList");
}
if (jf instanceof JavaClass) {
for (JavaField cjf : ((JavaClass) jf).getJavaFields().getJavaField()) {
if (cjf.getPath().equals("orders.contact")) {
cjf.setClassName("io.atlasmap.java.test." + prefix + "Contact");
}
if (cjf.getPath().equals("orders.address")) {
cjf.setClassName("io.atlasmap.java.test." + prefix + "Address");
}
}
}
}
return j;
}
use of io.atlasmap.java.v2.JavaField in project atlasmap by atlasmap.
the class JavaJavaFlatMappingTest method generateJavaField.
protected JavaField generateJavaField(String path) {
JavaField javaField = AtlasJavaModelFactory.createJavaField();
javaField.setPath(path);
javaField.setModifiers(null);
return javaField;
}
use of io.atlasmap.java.v2.JavaField in project atlasmap by atlasmap.
the class JavaJavaDateTimeMappingTest method doTest.
private void doTest(int offset) throws Exception {
AtlasMapping atlasMapping = AtlasModelFactory.createAtlasMapping();
atlasMapping.setName("JavaJavaDateTimeMapping");
addDataSource(atlasMapping, "atlas:java?className=io.atlasmap.java.test.DateTimeClass", DataSourceType.SOURCE);
addDataSource(atlasMapping, "atlas:java?className=io.atlasmap.java.test.DateTimeClass", DataSourceType.TARGET);
List<BaseMapping> mappings = atlasMapping.getMappings().getMapping();
for (int i = 0; i < DATE_TIME_FIELDS.length; i++) {
int targetIndex = offset + i < DATE_TIME_FIELDS.length ? offset + i : offset + i - DATE_TIME_FIELDS.length;
JavaField sourceField = copyJavaField(DATE_TIME_FIELDS[i]);
JavaField targetField = copyJavaField(DATE_TIME_FIELDS[targetIndex]);
if (UNSUPPORTED.containsKey(sourceField.getFieldType()) && UNSUPPORTED.get(sourceField.getFieldType()).equals(targetField.getFieldType())) {
sourceField = copyJavaField(targetField);
}
Mapping mfm = AtlasModelFactory.createMapping(MappingType.MAP);
mfm.getInputField().add(sourceField);
mfm.getOutputField().add(targetField);
mappings.add(mfm);
}
AtlasContext context = ((DefaultAtlasContextFactory) atlasContextFactory).createContext(atlasMapping);
AtlasSession session = context.createSession();
session.setDefaultSourceDocument(createSource());
context.process(session);
Object object = session.getDefaultTargetDocument();
assertNotNull(object);
assertTrue(object instanceof DateTimeClass);
validateTarget((DateTimeClass) object);
}
Aggregations