Search in sources :

Example 11 with JavaInputReader

use of com.devonfw.cobigen.javaplugin.inputreader.JavaInputReader in project cobigen by devonfw.

the class ReflectedJavaModelBuilderTest method testCorrectlyInterpretingInterfaceInheritance.

/**
 * Tests whether no {@link NullPointerException} will be thrown if an interface taken as an input extends another
 * interface. Test for issue #250.
 *
 * @throws Exception test fails
 */
@Test
public void testCorrectlyInterpretingInterfaceInheritance() throws Exception {
    JavaInputReader javaModelBuilder = new JavaInputReader();
    javaModelBuilder.createModel(TestInterfaceInheritance.class);
}
Also used : JavaInputReader(com.devonfw.cobigen.javaplugin.inputreader.JavaInputReader) Test(org.junit.Test)

Example 12 with JavaInputReader

use of com.devonfw.cobigen.javaplugin.inputreader.JavaInputReader in project cobigen by devonfw.

the class ReflectedJavaModelBuilderTest method testExtractionOfMethodAccessibleFields_inherited.

/**
 * Tests whether the input type's extracted fields are complete (including annotations and javaDoc)
 */
@Test
public void testExtractionOfMethodAccessibleFields_inherited() {
    JavaInputReader javaInputReader = new JavaInputReader();
    Map<String, Object> model = javaInputReader.createModel(TestClass.class);
    // test inherited field
    Map<String, Object> inheritedField = JavaModelUtil.getMethodAccessibleField(model, "id");
    assertThat(inheritedField).isNotNull();
    assertThat(inheritedField.get(ModelConstant.NAME)).isEqualTo("id");
    assertThat(inheritedField.get(ModelConstant.TYPE)).isEqualTo("Long");
    assertThat(inheritedField.get(ModelConstant.CANONICAL_TYPE)).isEqualTo("java.lang.Long");
    // is deprecated, so its not necessary to test here
    // assertThat(inheritedField.get("isId")).isEqualTo("false");
    // currently no javadoc provided
    // assertThat(inheritedField.get(ModelConstant.JAVADOC)).isNotNull();
    // assertThat(JavaModelUtil.getJavaDocModel(inheritedField).get("comment")).isEqualTo("Example
    // JavaDoc");
    // test annotations for attribute, getter, setter, is-method
    assertThat(inheritedField.get(ModelConstant.ANNOTATIONS)).isNotNull();
    // getter
    assertThat(JavaModelUtil.getAnnotations(inheritedField)).containsKey("com_devonfw_cobigen_javaplugin_unittest_inputreader_testdata_MySuperTypeGetterAnnotation");
    // Setter
    assertThat(JavaModelUtil.getAnnotations(inheritedField)).containsKey("com_devonfw_cobigen_javaplugin_unittest_inputreader_testdata_MySuperTypeSetterAnnotation");
    // is-method
    assertThat(JavaModelUtil.getAnnotations(inheritedField)).containsKey("com_devonfw_cobigen_javaplugin_unittest_inputreader_testdata_MySuperTypeIsAnnotation");
    // attribute
    assertThat(JavaModelUtil.getAnnotations(inheritedField)).containsKey("com_devonfw_cobigen_javaplugin_unittest_inputreader_testdata_MySuperTypeFieldAnnotation");
}
Also used : JavaInputReader(com.devonfw.cobigen.javaplugin.inputreader.JavaInputReader) Test(org.junit.Test)

Example 13 with JavaInputReader

use of com.devonfw.cobigen.javaplugin.inputreader.JavaInputReader in project cobigen by devonfw.

the class ParsedJavaModelBuilderTest method testCorrectlyExtractedImplementedTypes.

/**
 * Tests whether super types (extended Type and implemented Types) will be extracted correctly to the model
 *
 * @throws Exception test fails
 */
@Test
public void testCorrectlyExtractedImplementedTypes() throws Exception {
    File classFile = new File(testFileRootPath + "TestClass.java");
    JavaInputReader javaModelBuilder = new JavaInputReader();
    try (FileReader fileReader = new FileReader(classFile)) {
        Map<String, Object> model = javaModelBuilder.createModel(JavaParserUtil.getFirstJavaClass(fileReader));
        // check whether implemented Types (interfaces) meet expectations
        List<Map<String, Object>> interfaces = JavaModelUtil.getImplementedTypes(model);
        // interface1
        assertThat(interfaces.get(0).get(ModelConstant.NAME)).isEqualTo("TestInterface1");
        assertThat(interfaces.get(0).get(ModelConstant.CANONICAL_NAME)).isEqualTo("com.devonfw.cobigen.javaplugin.unittest.inputreader.testdata.TestInterface1");
        assertThat(interfaces.get(0).get(ModelConstant.PACKAGE)).isEqualTo("com.devonfw.cobigen.javaplugin.unittest.inputreader.testdata");
        // interface2
        assertThat(interfaces.get(1).get(ModelConstant.NAME)).isEqualTo("TestInterface2");
        assertThat(interfaces.get(1).get(ModelConstant.CANONICAL_NAME)).isEqualTo("com.devonfw.cobigen.javaplugin.unittest.inputreader.testdata.TestInterface2");
        assertThat(interfaces.get(1).get(ModelConstant.PACKAGE)).isEqualTo("com.devonfw.cobigen.javaplugin.unittest.inputreader.testdata");
    }
}
Also used : FileReader(java.io.FileReader) JavaInputReader(com.devonfw.cobigen.javaplugin.inputreader.JavaInputReader) File(java.io.File) Map(java.util.Map) Test(org.junit.Test)

Example 14 with JavaInputReader

use of com.devonfw.cobigen.javaplugin.inputreader.JavaInputReader in project cobigen by devonfw.

the class ParsedJavaModelBuilderTest method testExtractionOfMethodAccessibleFields_inherited.

/**
 * Tests whether the input type's extracted fields are complete (including annotations and javaDoc)
 *
 * @throws Exception test fails
 */
@Test
@Ignore("see com.devonfw.cobigen.javaplugin.inputreader.ParsedJavaModelBuilder.extractMethodAccessibleFields#L115")
public void testExtractionOfMethodAccessibleFields_inherited() throws Exception {
    File file = new File(testFileRootPath + "TestClass.java");
    JavaInputReader javaModelBuilder = new JavaInputReader();
    try (FileReader fileReader = new FileReader(file)) {
        Map<String, Object> model = javaModelBuilder.createModel(JavaParserUtil.getFirstJavaClass(fileReader));
        // test inherited field of direct superclass named "id"
        Map<String, Object> inheritedField = JavaModelUtil.getMethodAccessibleField(model, "id");
        assertThat(inheritedField).isNotNull();
        assertThat(inheritedField.get(ModelConstant.NAME)).isEqualTo("id");
        assertThat(inheritedField.get(ModelConstant.TYPE)).isEqualTo("Long");
        assertThat(inheritedField.get(ModelConstant.CANONICAL_TYPE)).isEqualTo("java.lang.Long");
    }
// is deprecated, so its not necessary to test here
// assertThat(inheritedField.get("isId")).isEqualTo("false");
// currently no javadoc provided
// assertThat(inheritedField.get(ModelConstant.JAVADOC)).isNotNull();
// assertThat(JavaModelUtil.getJavaDocModel(inheritedField).get("comment")).isEqualTo("Example
// JavaDoc");
// TODO Currently qDox library does not return the superclass' annotations
/*
     * // test annotations for attribute, getter, setter, is-method
     * assertThat(inheritedField.get(ModelConstant.ANNOTATIONS)).isNotNull(); // getter
     * assertTrue(JavaModelUtil.getAnnotations (inheritedField).containsKey("MySuperTypeGetterAnnotation")); // Setter
     * assertTrue(JavaModelUtil.getAnnotations (inheritedField).containsKey("MySuperTypeSetterAnnotation")); //
     * is-method assertThat(JavaModelUtil.getAnnotations(inheritedField).containsKey("MySuperTypeIsAnnotation")).
     * isTrue(); // attribute
     * assertThat(JavaModelUtil.getAnnotations(inheritedField).containsKey("MySuperTypeFieldAnnotation")). isTrue();
     */
}
Also used : FileReader(java.io.FileReader) JavaInputReader(com.devonfw.cobigen.javaplugin.inputreader.JavaInputReader) File(java.io.File) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 15 with JavaInputReader

use of com.devonfw.cobigen.javaplugin.inputreader.JavaInputReader in project cobigen by devonfw.

the class ParsedJavaModelBuilderTest method testCorrectlyExtractedInheritedType.

/**
 * Tests whether the inherited type will be correctly extracted and put into the model
 *
 * @throws Exception test fails
 */
@Test
public void testCorrectlyExtractedInheritedType() throws Exception {
    File classFile = new File(testFileRootPath + "TestClass.java");
    JavaInputReader javaModelBuilder = new JavaInputReader();
    try (FileReader fileReader = new FileReader(classFile)) {
        Map<String, Object> model = javaModelBuilder.createModel(JavaParserUtil.getFirstJavaClass(fileReader));
        Assert.assertEquals("AbstractTestClass", JavaModelUtil.getExtendedType(model).get(ModelConstant.NAME));
        assertThat(JavaModelUtil.getExtendedType(model).get(ModelConstant.CANONICAL_NAME)).isEqualTo("com.devonfw.cobigen.javaplugin.unittest.inputreader.testdata.AbstractTestClass");
        assertThat(JavaModelUtil.getExtendedType(model).get(ModelConstant.PACKAGE)).isEqualTo("com.devonfw.cobigen.javaplugin.unittest.inputreader.testdata");
    }
}
Also used : FileReader(java.io.FileReader) JavaInputReader(com.devonfw.cobigen.javaplugin.inputreader.JavaInputReader) File(java.io.File) Test(org.junit.Test)

Aggregations

JavaInputReader (com.devonfw.cobigen.javaplugin.inputreader.JavaInputReader)30 Test (org.junit.Test)30 File (java.io.File)19 FileReader (java.io.FileReader)17 Map (java.util.Map)7 TestClass (com.devonfw.cobigen.javaplugin.unittest.inputreader.testdata.TestClass)3 Ignore (org.junit.Ignore)3 PackageFolder (com.devonfw.cobigen.javaplugin.inputreader.to.PackageFolder)2 JavaClass (com.thoughtworks.qdox.model.JavaClass)2 RootClass (com.devonfw.cobigen.javaplugin.unittest.inputreader.testdata.RootClass)1 TestClassWithAnnotations (com.devonfw.cobigen.javaplugin.unittest.inputreader.testdata.TestClassWithAnnotations)1 TestClassWithAnnotationsContainingObjectArrays (com.devonfw.cobigen.javaplugin.unittest.inputreader.testdata.TestClassWithAnnotationsContainingObjectArrays)1 TestClassWithRecursiveAnnotations (com.devonfw.cobigen.javaplugin.unittest.inputreader.testdata.TestClassWithRecursiveAnnotations)1