Search in sources :

Example 51 with JavaClass

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

the class ClassValidationUtil method validateFlatPrimitiveInterfaceArray.

public static void validateFlatPrimitiveInterfaceArray(ClassInspectionService classInspectionService, Class<?> clazz) {
    JavaClass flatClass = classInspectionService.inspectClass(clazz);
    validateFlatClass(flatClass);
    assertEquals(CollectionType.ARRAY, flatClass.getCollectionType());
    assertEquals(new Integer(1), flatClass.getArrayDimensions());
    assertTrue(flatClass.isInterface());
    assertEquals("io.atlasmap.java.test.FlatPrimitiveInterface", flatClass.getClassName());
    validateFlatPrimitiveFields(flatClass);
}
Also used : JavaClass(io.atlasmap.java.v2.JavaClass)

Example 52 with JavaClass

use of io.atlasmap.java.v2.JavaClass 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 JavaClass

use of io.atlasmap.java.v2.JavaClass 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 JavaClass

use of io.atlasmap.java.v2.JavaClass 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

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