use of com.devonfw.cobigen.javaplugin.inputreader.JavaInputReader in project cobigen by devonfw.
the class ParsedJavaModelBuilderTest method testCorrectlyExtractedInhertedType_extendedTypeWithoutPackageDeclaration.
/**
* Tests whether no {@link NullPointerException} will be thrown if the extended type is in the default package
*
* @throws Exception test fails
*/
@Test
public void testCorrectlyExtractedInhertedType_extendedTypeWithoutPackageDeclaration() throws Exception {
File noPackageFile = new File(testFileRootPath + "NoPackageClass.java");
JavaInputReader javaModelBuilder = new JavaInputReader();
// debug nullPointerException in case of superclass without package
try (FileReader fileReader = new FileReader(noPackageFile)) {
Map<String, Object> model = javaModelBuilder.createModel(JavaParserUtil.getFirstJavaClass(fileReader));
assertThat(JavaModelUtil.getExtendedType(model).get(ModelConstant.PACKAGE)).isEqualTo("");
}
}
use of com.devonfw.cobigen.javaplugin.inputreader.JavaInputReader in project cobigen by devonfw.
the class ParsedJavaModelBuilderTest method testCorrectlyInterpretingInterfaceInheritance.
/**
* Tests whether no {@link NullPointerException} will be thrown if an interface taken as an input extends another
* interface
*
* @Issue #250
* @throws Exception test fails
*/
@Test
public void testCorrectlyInterpretingInterfaceInheritance() throws Exception {
File noPackageFile = new File(testFileRootPath + "TestInterface.java");
JavaInputReader javaModelBuilder = new JavaInputReader();
try (FileReader fileReader = new FileReader(noPackageFile)) {
javaModelBuilder.createModel(JavaParserUtil.getFirstJavaClass(fileReader));
}
}
use of com.devonfw.cobigen.javaplugin.inputreader.JavaInputReader in project cobigen by devonfw.
the class ParsedJavaModelBuilderTest method testCorrectExtractionOfJavaDoc.
/**
* Tests the correct extraction of the JavaDoc properties.
*
* @throws Exception test fails
*/
@Test
public void testCorrectExtractionOfJavaDoc() throws Exception {
File classFile = new File(testFileRootPath + "DocumentedClass.java");
JavaInputReader javaModelBuilder = new JavaInputReader();
try (FileReader fileReader = new FileReader(classFile)) {
Map<String, Object> model = javaModelBuilder.createModel(JavaParserUtil.getFirstJavaClass(fileReader));
Map<String, Object> javaDocModel = getJavaDocModel(getRoot(model));
assertThat(javaDocModel.get(ModelConstant.COMMENT)).isEqualTo("Class Doc.");
assertThat(javaDocModel.get("author")).isEqualTo("mbrunnli (30.01.2015)");
javaDocModel = getJavaDocModel(getField(model, "field"));
assertThat(javaDocModel.get(ModelConstant.COMMENT)).isEqualTo("Field Doc.");
javaDocModel = getJavaDocModel(getMethod(model, "getField"));
assertThat(javaDocModel.get(ModelConstant.COMMENT)).isEqualTo("Returns the field 'field'.");
assertThat(javaDocModel.get("return")).isEqualTo("value of field");
assertThat(javaDocModel.get("author")).isEqualTo("mbrunnli (30.01.2015)");
javaDocModel = getJavaDocModel(getMethod(model, "setField"));
assertThat(javaDocModel.get(ModelConstant.COMMENT)).isEqualTo("Sets the field 'field'.");
Map<String, Object> params = (Map<String, Object>) javaDocModel.get("params");
assertThat(params.keySet()).hasSize(4);
assertThat(params.keySet()).containsExactly("number", "field", "arg1", "arg0");
assertThat(params.get("field")).isEqualTo("new value of field");
assertThat(params.get("number")).isEqualTo("just some number");
assertThat(javaDocModel.get("author")).isEqualTo("mbrunnli (30.01.2015)");
javaDocModel = getJavaDocModel(getMethod(model, "doSomething"));
assertThat(javaDocModel.get(ModelConstant.COMMENT)).isEqualTo("Does something");
Map<String, Object> thrown = (Map<String, Object>) javaDocModel.get("throws");
assertThat(thrown.keySet()).containsExactly("CobigenRuntimeException", "IOException");
assertThat(thrown.get("IOException")).isEqualTo("If it would throw one");
assertThat(thrown.get("CobigenRuntimeException")).isEqualTo("During generation");
assertThat(javaDocModel.get("author")).isEqualTo("mischuma (04.07.2018)");
}
}
use of com.devonfw.cobigen.javaplugin.inputreader.JavaInputReader in project cobigen by devonfw.
the class ParsedJavaModelBuilderTest method testExtractionOfMethodAccessibleFields_inheritedInherited.
/**
* Tests whether the input type's extracted fields are complete (including annotations and javaDoc)
*
* @throws Exception test fails
*/
@Test
@Ignore(value = "This test case is not successfull due to boundaries of qDox")
public void testExtractionOfMethodAccessibleFields_inheritedInherited() 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"
System.out.println(model);
Map<String, Object> inheritedField = JavaModelUtil.getMethodAccessibleField(model, "superSuperString");
assertThat(inheritedField).isNotNull();
assertThat(inheritedField.get(ModelConstant.NAME)).isEqualTo("superSuperString");
// TODO qDox library returns full qualified names for the superclass' fields
// actually the expected result of ModelConstant.Type is "String" here, but we insert this test
// case
// here with "java.lang.String" so that the test turns into red if there changes anything in qDox
assertThat(inheritedField.get(ModelConstant.TYPE)).isEqualTo("java.lang.String");
assertThat(inheritedField.get(ModelConstant.CANONICAL_TYPE)).isEqualTo("java.lang.String");
// 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("MySuperSuperTypeGetterAnnotation")); //
* Setter assertTrue(JavaModelUtil.getAnnotations
* (inheritedField).containsKey("MySuperSuperTypeSetterAnnotation")); // is-method assertTrue(JavaModelUtil
* .getAnnotations(inheritedField).containsKey("MySuperSuperTypeIsAnnotation")); // attribute assertTrue
* (JavaModelUtil.getAnnotations(inheritedField).containsKey("MySuperSuperTypeFieldAnnotation"));
*/
}
}
use of com.devonfw.cobigen.javaplugin.inputreader.JavaInputReader in project cobigen by devonfw.
the class JavaInputReaderTest method provideParsingAndReflectionModelFeatures_withAnnotationsContainingObjectArrays.
/**
* Tests whether both features can be used when providing parsed and reflected inputs for one java class, whereas the
* models are equal and an annotation contains an object array as property value
*
* @throws Exception test fails
*/
@Test
public void provideParsingAndReflectionModelFeatures_withAnnotationsContainingObjectArrays() throws Exception {
File javaSourceFile = new File(testFileRootPath + "TestClassWithAnnotationsContainingObjectArrays.java");
Class<?> javaClass = TestClassWithAnnotationsContainingObjectArrays.class;
JavaInputReader javaInputReader = new JavaInputReader();
Map<String, Object> model = javaInputReader.createModel(new Object[] { JavaParserUtil.getFirstJavaClass(new FileReader(javaSourceFile)), javaClass });
assertThat(model).as("No model has been created!").isNotNull();
}
Aggregations