Search in sources :

Example 21 with JavaField

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

Example 22 with JavaField

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

Example 23 with JavaField

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

Example 24 with JavaField

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

Example 25 with 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);
}
Also used : DefaultAtlasContextFactory(io.atlasmap.core.DefaultAtlasContextFactory) AtlasMapping(io.atlasmap.v2.AtlasMapping) JavaField(io.atlasmap.java.v2.JavaField) DateTimeClass(io.atlasmap.java.test.DateTimeClass) AtlasContext(io.atlasmap.api.AtlasContext) BaseMapping(io.atlasmap.v2.BaseMapping) Mapping(io.atlasmap.v2.Mapping) AtlasMapping(io.atlasmap.v2.AtlasMapping) AtlasSession(io.atlasmap.api.AtlasSession) BaseMapping(io.atlasmap.v2.BaseMapping)

Aggregations

JavaField (io.atlasmap.java.v2.JavaField)53 Test (org.junit.Test)19 JavaClass (io.atlasmap.java.v2.JavaClass)16 Mapping (io.atlasmap.v2.Mapping)16 AtlasMapping (io.atlasmap.v2.AtlasMapping)15 Validation (io.atlasmap.v2.Validation)8 FieldType (io.atlasmap.v2.FieldType)7 Method (java.lang.reflect.Method)7 JavaEnumField (io.atlasmap.java.v2.JavaEnumField)6 AtlasException (io.atlasmap.api.AtlasException)5 DataSource (io.atlasmap.v2.DataSource)5 Field (io.atlasmap.v2.Field)5 AtlasModuleDetail (io.atlasmap.spi.AtlasModuleDetail)4 ValidationScope (io.atlasmap.v2.ValidationScope)4 ValidationStatus (io.atlasmap.v2.ValidationStatus)4 List (java.util.List)4 Logger (org.slf4j.Logger)4 AtlasConstants (io.atlasmap.api.AtlasConstants)3 AtlasMappingUtil (io.atlasmap.core.AtlasMappingUtil)3 AtlasPath (io.atlasmap.core.AtlasPath)3