Search in sources :

Example 26 with JavaClass

use of io.atlasmap.java.v2.JavaClass 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);
        }
    }
}
Also used : JavaField(io.atlasmap.java.v2.JavaField) JavaClass(io.atlasmap.java.v2.JavaClass) Test(org.junit.Test)

Example 27 with JavaClass

use of io.atlasmap.java.v2.JavaClass 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());
        }
    }
}
Also used : JavaField(io.atlasmap.java.v2.JavaField)

Example 28 with JavaClass

use of io.atlasmap.java.v2.JavaClass 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;
}
Also used : JavaField(io.atlasmap.java.v2.JavaField) JavaClass(io.atlasmap.java.v2.JavaClass)

Example 29 with JavaClass

use of io.atlasmap.java.v2.JavaClass in project atlasmap by atlasmap.

the class ClassInspectionServiceITest method testInspectClassClassNameClassPath45.

@Test
public void testInspectClassClassNameClassPath45() throws InspectionException {
    JavaClass javaClazz = classInspectionService.inspectClass("io.syndesis.connector.salesforce.Contact", "target/reference-jars/salesforce-upsert-contact-connector-0.4.5.jar:target/reference-jars/camel-salesforce-2.19.0.jar");
    assertNotNull(javaClazz);
}
Also used : JavaClass(io.atlasmap.java.v2.JavaClass) Test(org.junit.Test)

Example 30 with JavaClass

use of io.atlasmap.java.v2.JavaClass in project atlasmap by atlasmap.

the class ClassInspectionServiceITest method testInspectClassClassNameClassPath.

@Test
public void testInspectClassClassNameClassPath() throws InspectionException {
    JavaClass javaClazz = classInspectionService.inspectClass("io.atlasmap.java.test.v2.FlatPrimitiveClass", "target/reference-jars/atlas-java-test-model-1.16.0-SNAPSHOT.jar");
    assertNotNull(javaClazz);
}
Also used : JavaClass(io.atlasmap.java.v2.JavaClass) Test(org.junit.Test)

Aggregations

JavaClass (io.atlasmap.java.v2.JavaClass)47 JavaField (io.atlasmap.java.v2.JavaField)21 Test (org.junit.Test)18 ClassInspectionService (io.atlasmap.java.inspect.ClassInspectionService)4 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)3 IOException (java.io.IOException)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 TargetAddress (io.atlasmap.java.test.TargetAddress)2 TargetOrder (io.atlasmap.java.test.TargetOrder)2 JavaEnumField (io.atlasmap.java.v2.JavaEnumField)2 ModifierList (io.atlasmap.java.v2.ModifierList)2 BaseMapping (io.atlasmap.v2.BaseMapping)2 Field (io.atlasmap.v2.Field)2 Method (java.lang.reflect.Method)2 ApplicationPath (javax.ws.rs.ApplicationPath)2 Path (javax.ws.rs.Path)2 Produces (javax.ws.rs.Produces)2 AtlasException (io.atlasmap.api.AtlasException)1 AtlasValidationException (io.atlasmap.api.AtlasValidationException)1 DocumentJavaFieldWriter (io.atlasmap.java.core.DocumentJavaFieldWriter)1