Search in sources :

Example 51 with JavaField

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

the class ClassValidationUtil method validateSimpleTestAddress.

public static void validateSimpleTestAddress(JavaClass c) {
    assertNotNull(c);
    assertFalse(c.isAnnonymous());
    assertFalse(c.isAnnotation());
    // assertTrue(c.getCollectionType() == null || c.getCollectionT());
    assertFalse(c.isEnumeration());
    assertFalse(c.isInterface());
    assertFalse(c.isLocalClass());
    assertFalse(c.isMemberClass());
    assertFalse(c.isPrimitive());
    assertFalse(c.isSynthetic());
    assertNotNull(c.getUri());
    assertEquals(String.format(AtlasJavaModelFactory.URI_FORMAT, c.getClassName()), c.getUri());
    assertEquals("io.atlasmap.java.test.BaseAddress", c.getClassName());
    assertEquals("io.atlasmap.java.test", c.getPackageName());
    assertNotNull(c.getJavaEnumFields());
    assertNotNull(c.getJavaEnumFields().getJavaEnumField());
    assertEquals(new Integer(0), new Integer(c.getJavaEnumFields().getJavaEnumField().size()));
    assertNotNull(c.getJavaFields());
    assertNotNull(c.getJavaFields().getJavaField());
    assertEquals(new Integer(6), new Integer(c.getJavaFields().getJavaField().size()));
    for (JavaField f : c.getJavaFields().getJavaField()) {
        switch(f.getName()) {
            case "serialVersionUID":
                validateSerialVersionUID(f);
                break;
            case "addressLine1":
                break;
            case "addressLine2":
                break;
            case "city":
                break;
            case "state":
                break;
            case "zipCode":
                break;
            default:
                fail("Unexpected field detected: " + f.getName());
        }
    }
}
Also used : JavaField(io.atlasmap.java.v2.JavaField)

Example 52 with JavaField

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

the class ComplexClassInspectTest method validateComplexClass.

public void validateComplexClass(JavaClass c) {
    assertNull(c.getAnnotations());
    assertNull(c.getArrayDimensions());
    assertNull(c.getGetMethod());
    assertNotNull(c.getJavaEnumFields());
    assertNotNull(c.getJavaEnumFields().getJavaEnumField());
    assertTrue(c.getJavaEnumFields().getJavaEnumField().size() == 0);
    assertNotNull(c.getJavaFields());
    assertNotNull(c.getJavaFields().getJavaField());
    assertNull(c.getName());
    assertEquals("io.atlasmap.java.test", c.getPackageName());
    assertNull(c.getSetMethod());
    assertNull(c.getFieldType());
    assertNotNull(c.getUri());
    assertNull(c.getValue());
    // Two serialVersionUID fields due to inheritance
    assertEquals(new Integer(6), new Integer(c.getJavaFields().getJavaField().size()));
    Integer validated = 0;
    for (JavaField f : c.getJavaFields().getJavaField()) {
        if ("io.atlasmap.java.test.BaseContact".equals(f.getClassName())) {
            if (!FieldStatus.CACHED.equals(f.getStatus())) {
                ClassValidationUtil.validateSimpleTestContact((JavaClass) f);
            }
            validated++;
        }
        if ("io.atlasmap.java.test.BaseAddress".equals(f.getClassName())) {
            if (!FieldStatus.CACHED.equals(f.getStatus())) {
                ClassValidationUtil.validateSimpleTestAddress((JavaClass) f);
            }
            validated++;
        }
        if ("long".equals(f.getClassName())) {
            ClassValidationUtil.validateSerialVersionUID(f);
            validated++;
        }
        if ("java.lang.Integer".equals(f.getClassName())) {
            ClassValidationUtil.validateOrderId(f);
            validated++;
        }
        if ("java.util.Date".equals(f.getClassName())) {
            ClassValidationUtil.validateCreated(f);
            validated++;
        }
    }
    assertEquals(validated, new Integer(c.getJavaFields().getJavaField().size()));
}
Also used : JavaField(io.atlasmap.java.v2.JavaField)

Example 53 with JavaField

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

the class ClassInspectionServiceTest method testDateTimeViaField.

@Test
public void testDateTimeViaField() {
    JavaClass javaClass = classInspectionService.inspectClass(DateTimeField.class);
    assertEquals(14, javaClass.getJavaFields().getJavaField().size());
    assertFalse(javaClass.getModifiers().getModifier().contains(Modifier.PRIVATE));
    assertFalse(javaClass.getModifiers().getModifier().contains(Modifier.PROTECTED));
    assertFalse(javaClass.getModifiers().getModifier().contains(Modifier.PUBLIC));
    assertTrue(javaClass.getModifiers().getModifier().contains(Modifier.PACKAGE_PRIVATE));
    for (JavaField field : javaClass.getJavaFields().getJavaField()) {
        if ("year".equals(field.getName())) {
            assertEquals("java.time.Year", field.getClassName());
            assertEquals(FieldType.DATE, field.getFieldType());
            assertFalse(field.getModifiers().getModifier().contains(Modifier.PRIVATE));
            assertFalse(field.getModifiers().getModifier().contains(Modifier.PROTECTED));
            assertFalse(field.getModifiers().getModifier().contains(Modifier.PUBLIC));
            assertTrue(field.getModifiers().getModifier().contains(Modifier.PACKAGE_PRIVATE));
        } else if ("month".equals(field.getName())) {
            assertEquals("java.time.Month", field.getClassName());
            assertEquals(FieldType.DATE, field.getFieldType());
            assertFalse(field.getModifiers().getModifier().contains(Modifier.PRIVATE));
            assertFalse(field.getModifiers().getModifier().contains(Modifier.PROTECTED));
            assertFalse(field.getModifiers().getModifier().contains(Modifier.PUBLIC));
            assertTrue(field.getModifiers().getModifier().contains(Modifier.PACKAGE_PRIVATE));
        } else if ("yearMonth".equals(field.getName())) {
            assertEquals("java.time.YearMonth", field.getClassName());
            assertEquals(FieldType.DATE, field.getFieldType());
            assertFalse(field.getModifiers().getModifier().contains(Modifier.PRIVATE));
            assertFalse(field.getModifiers().getModifier().contains(Modifier.PROTECTED));
            assertFalse(field.getModifiers().getModifier().contains(Modifier.PUBLIC));
            assertTrue(field.getModifiers().getModifier().contains(Modifier.PACKAGE_PRIVATE));
        } else if ("monthDay".equals(field.getName())) {
            assertEquals("java.time.MonthDay", field.getClassName());
            assertEquals(FieldType.DATE, field.getFieldType());
            assertFalse(field.getModifiers().getModifier().contains(Modifier.PRIVATE));
            assertFalse(field.getModifiers().getModifier().contains(Modifier.PROTECTED));
            assertFalse(field.getModifiers().getModifier().contains(Modifier.PUBLIC));
            assertTrue(field.getModifiers().getModifier().contains(Modifier.PACKAGE_PRIVATE));
        } else if ("localDate".equals(field.getName())) {
            assertEquals("java.time.LocalDate", field.getClassName());
            assertEquals(FieldType.DATE, field.getFieldType());
            assertFalse(field.getModifiers().getModifier().contains(Modifier.PRIVATE));
            assertFalse(field.getModifiers().getModifier().contains(Modifier.PROTECTED));
            assertFalse(field.getModifiers().getModifier().contains(Modifier.PUBLIC));
            assertTrue(field.getModifiers().getModifier().contains(Modifier.PACKAGE_PRIVATE));
        } else if ("localTime".equals(field.getName())) {
            assertEquals("java.time.LocalTime", field.getClassName());
            assertEquals(FieldType.TIME, field.getFieldType());
            assertFalse(field.getModifiers().getModifier().contains(Modifier.PRIVATE));
            assertFalse(field.getModifiers().getModifier().contains(Modifier.PROTECTED));
            assertFalse(field.getModifiers().getModifier().contains(Modifier.PUBLIC));
            assertTrue(field.getModifiers().getModifier().contains(Modifier.PACKAGE_PRIVATE));
        } else if ("localDateTime".equals(field.getName())) {
            assertEquals("java.time.LocalDateTime", field.getClassName());
            assertEquals(FieldType.DATE_TIME, field.getFieldType());
            assertFalse(field.getModifiers().getModifier().contains(Modifier.PRIVATE));
            assertFalse(field.getModifiers().getModifier().contains(Modifier.PROTECTED));
            assertFalse(field.getModifiers().getModifier().contains(Modifier.PUBLIC));
            assertTrue(field.getModifiers().getModifier().contains(Modifier.PACKAGE_PRIVATE));
        } else if ("zonedDateTime".equals(field.getName())) {
            assertEquals("java.time.ZonedDateTime", field.getClassName());
            assertEquals(FieldType.DATE_TIME_TZ, field.getFieldType());
            assertFalse(field.getModifiers().getModifier().contains(Modifier.PRIVATE));
            assertFalse(field.getModifiers().getModifier().contains(Modifier.PROTECTED));
            assertFalse(field.getModifiers().getModifier().contains(Modifier.PUBLIC));
            assertTrue(field.getModifiers().getModifier().contains(Modifier.PACKAGE_PRIVATE));
        } else if ("calendar".equals(field.getName())) {
            assertEquals("java.util.Calendar", field.getClassName());
            assertEquals(FieldType.DATE_TIME_TZ, field.getFieldType());
            assertFalse(field.getModifiers().getModifier().contains(Modifier.PRIVATE));
            assertFalse(field.getModifiers().getModifier().contains(Modifier.PROTECTED));
            assertFalse(field.getModifiers().getModifier().contains(Modifier.PUBLIC));
            assertTrue(field.getModifiers().getModifier().contains(Modifier.PACKAGE_PRIVATE));
        } else if ("date".equals(field.getName())) {
            assertEquals("java.util.Date", field.getClassName());
            assertEquals(FieldType.DATE_TIME, field.getFieldType());
            assertFalse(field.getModifiers().getModifier().contains(Modifier.PRIVATE));
            assertFalse(field.getModifiers().getModifier().contains(Modifier.PROTECTED));
            assertFalse(field.getModifiers().getModifier().contains(Modifier.PUBLIC));
            assertTrue(field.getModifiers().getModifier().contains(Modifier.PACKAGE_PRIVATE));
        } else if ("gregorianCalendar".equals(field.getName())) {
            assertEquals("java.util.GregorianCalendar", field.getClassName());
            assertEquals(FieldType.DATE_TIME_TZ, field.getFieldType());
            assertFalse(field.getModifiers().getModifier().contains(Modifier.PRIVATE));
            assertFalse(field.getModifiers().getModifier().contains(Modifier.PROTECTED));
            assertFalse(field.getModifiers().getModifier().contains(Modifier.PUBLIC));
            assertTrue(field.getModifiers().getModifier().contains(Modifier.PACKAGE_PRIVATE));
        } else if ("sqlDate".equals(field.getName())) {
            assertEquals("java.sql.Date", field.getClassName());
            assertEquals(FieldType.DATE, field.getFieldType());
            assertFalse(field.getModifiers().getModifier().contains(Modifier.PRIVATE));
            assertFalse(field.getModifiers().getModifier().contains(Modifier.PROTECTED));
            assertFalse(field.getModifiers().getModifier().contains(Modifier.PUBLIC));
            assertTrue(field.getModifiers().getModifier().contains(Modifier.PACKAGE_PRIVATE));
        } else if ("sqlTime".equals(field.getName())) {
            assertEquals("java.sql.Time", field.getClassName());
            assertEquals(FieldType.TIME, field.getFieldType());
            assertFalse(field.getModifiers().getModifier().contains(Modifier.PRIVATE));
            assertFalse(field.getModifiers().getModifier().contains(Modifier.PROTECTED));
            assertFalse(field.getModifiers().getModifier().contains(Modifier.PUBLIC));
            assertTrue(field.getModifiers().getModifier().contains(Modifier.PACKAGE_PRIVATE));
        } else if ("sqlTimestamp".equals(field.getName())) {
            assertEquals("java.sql.Timestamp", field.getClassName());
            assertEquals(FieldType.DATE_TIME, field.getFieldType());
            assertFalse(field.getModifiers().getModifier().contains(Modifier.PRIVATE));
            assertFalse(field.getModifiers().getModifier().contains(Modifier.PROTECTED));
            assertFalse(field.getModifiers().getModifier().contains(Modifier.PUBLIC));
            assertTrue(field.getModifiers().getModifier().contains(Modifier.PACKAGE_PRIVATE));
        } 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 54 with JavaField

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

the class ClassInspectionServiceTest method testEnum.

@Test
public void testEnum() {
    JavaClass javaClass = classInspectionService.inspectClass(TestEnum.class);
    assertNotNull(javaClass.getJavaFields());
    assertEquals(2, javaClass.getJavaFields().getJavaField().size());
    for (JavaField field : javaClass.getJavaFields().getJavaField()) {
        if ("extendedStatus".equals(field.getName())) {
            assertNotNull(((JavaClass) field).getJavaEnumFields());
            assertEquals(4, ((JavaClass) field).getJavaEnumFields().getJavaEnumField().size());
        } else if ("status".equals(field.getName())) {
            assertNotNull(field.getGetMethod());
            assertNotNull(field.getSetMethod());
            assertNotNull(((JavaClass) field).getJavaEnumFields());
            assertNotNull(((JavaClass) field).getJavaEnumFields());
            assertEquals(2, ((JavaClass) field).getJavaEnumFields().getJavaEnumField().size());
        }
    }
}
Also used : JavaField(io.atlasmap.java.v2.JavaField) JavaClass(io.atlasmap.java.v2.JavaClass) Test(org.junit.Test)

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