use of com.devonfw.cobigen.javaplugin.inputreader.JavaInputReader in project cobigen by devonfw.
the class ReflectedJavaModelBuilderTest method testAnnotationExtractionOfSuperSuperTypes.
/**
* Tests whether the annotation of super super types are available
*/
@Test
public void testAnnotationExtractionOfSuperSuperTypes() {
JavaInputReader javaInputReader = new JavaInputReader();
Map<String, Object> model = javaInputReader.createModel(TestClass.class);
Map<String, Object> classField = JavaModelUtil.getMethodAccessibleField(model, "superSuperString");
assertThat(classField).isNotNull();
// test annotations for attribute, getter, setter, is-method
assertThat(classField.get(ModelConstant.ANNOTATIONS)).isNotNull();
// getter
assertThat(JavaModelUtil.getAnnotations(classField)).containsKey("com_devonfw_cobigen_javaplugin_unittest_inputreader_testdata_MySuperSuperTypeGetterAnnotation");
// Setter
assertThat(JavaModelUtil.getAnnotations(classField)).containsKey("com_devonfw_cobigen_javaplugin_unittest_inputreader_testdata_MySuperSuperTypeSetterAnnotation");
// is-method
assertThat(JavaModelUtil.getAnnotations(classField)).containsKey("com_devonfw_cobigen_javaplugin_unittest_inputreader_testdata_MySuperSuperTypeIsAnnotation");
// attribute
assertThat(JavaModelUtil.getAnnotations(classField)).containsKey("com_devonfw_cobigen_javaplugin_unittest_inputreader_testdata_MySuperSuperTypeFieldAnnotation");
@SuppressWarnings("unchecked") Map<String, Object> annotation = (Map<String, Object>) JavaModelUtil.getAnnotations(classField).get("com_devonfw_cobigen_javaplugin_unittest_inputreader_testdata_MySuperSuperTypeFieldAnnotation");
assertThat(annotation).isNotNull();
// currently all values are provided as Strings
assertThat(annotation.get("b")).isEqualTo("0");
assertThat(annotation.get("s")).isEqualTo("1");
assertThat(annotation.get("i")).isEqualTo("2");
assertThat(annotation.get("l")).isEqualTo("3");
assertThat(annotation.get("f")).isEqualTo("4.0");
assertThat(annotation.get("d")).isEqualTo("5.0");
assertThat(annotation.get("c")).isEqualTo("c");
assertThat(annotation.get("bool")).isEqualTo("true");
assertThat(annotation.get("str")).isEqualTo("TestString");
}
use of com.devonfw.cobigen.javaplugin.inputreader.JavaInputReader in project cobigen by devonfw.
the class ReflectedJavaModelBuilderTest method testCorrectlyExtractedAttributeTypes.
/**
* Tests whether parametric attribute types will be extracted correctly to the model
*/
@Test
@SuppressWarnings("null")
public void testCorrectlyExtractedAttributeTypes() {
JavaInputReader javaModelBuilder = new JavaInputReader();
Map<String, Object> model = javaModelBuilder.createModel(getClass());
Map<String, Object> pojoMap = JavaModelUtil.getRoot(model);
assertThat(pojoMap).as(ModelConstant.MODEL_ROOT + " is not accessible in model").isNotNull();
List<Map<String, Object>> attributes = JavaModelUtil.getFields(model);
assertThat(attributes).as(ModelConstant.FIELDS + " is not accessible in model").isNotNull();
Map<String, Object> parametricTestAttributeModel = null;
for (Map<String, Object> attr : attributes) {
if ("parametricTestAttribute".equals(attr.get(ModelConstant.NAME))) {
parametricTestAttributeModel = attr;
break;
}
}
assertThat(parametricTestAttributeModel).as("There is no field with name 'parametricTestAttribute' in the model").isNotNull();
// "List<String>" is not possible to retrieve using reflection due to type erasure
assertThat(parametricTestAttributeModel.get(ModelConstant.TYPE)).isEqualTo("List<?>");
}
use of com.devonfw.cobigen.javaplugin.inputreader.JavaInputReader in project cobigen by devonfw.
the class ReflectedJavaModelBuilderTest method testExtractionOfMethodAccessibleFields_local.
/**
* Tests whether the input type's extracted fields are complete (including annotations and javaDoc)
*/
@Test
public void testExtractionOfMethodAccessibleFields_local() {
JavaInputReader javaInputReader = new JavaInputReader();
Map<String, Object> model = javaInputReader.createModel(TestClass.class);
// test local field
Map<String, Object> classField = JavaModelUtil.getMethodAccessibleField(model, "customList");
assertThat(classField).isNotNull();
assertThat(classField.get(ModelConstant.NAME)).isEqualTo("customList");
assertThat(classField.get(ModelConstant.TYPE)).isEqualTo("List<?>");
assertThat(classField.get(ModelConstant.CANONICAL_TYPE)).isEqualTo("java.util.List");
// currently no javadoc provided
// assertThat(classField.get(ModelConstant.JAVADOC)).isNotNull();
// assertThat(JavaModelUtil.getJavaDocModel(classField).get("comment")).isEqualTo("Example JavaDoc");
assertThat(classField.get("isId")).isEqualTo("false");
// test annotations for attribute, getter, setter, is-method
assertThat(classField.get(ModelConstant.ANNOTATIONS)).isNotNull();
// getter
assertThat(JavaModelUtil.getAnnotations(classField)).containsKey("com_devonfw_cobigen_javaplugin_unittest_inputreader_testdata_MyGetterAnnotation");
// Setter
assertThat(JavaModelUtil.getAnnotations(classField)).containsKey("com_devonfw_cobigen_javaplugin_unittest_inputreader_testdata_MySetterAnnotation");
// is-method
assertThat(JavaModelUtil.getAnnotations(classField)).containsKey("com_devonfw_cobigen_javaplugin_unittest_inputreader_testdata_MyIsAnnotation");
// attribute
assertThat(JavaModelUtil.getAnnotations(classField)).containsKey("com_devonfw_cobigen_javaplugin_unittest_inputreader_testdata_MyFieldAnnotation");
}
use of com.devonfw.cobigen.javaplugin.inputreader.JavaInputReader in project cobigen by devonfw.
the class ReflectedJavaModelBuilderTest method testCorrectlyExtractingMethodsInInterfaceInheritance.
/**
* Tests whether inherited methods will be resolved as well.
*
* @throws Exception test fails
*/
@Test
public void testCorrectlyExtractingMethodsInInterfaceInheritance() throws Exception {
JavaInputReader javaModelBuilder = new JavaInputReader();
Map<String, Object> model = javaModelBuilder.createModel(TestInterfaceInheritance.class);
assertThat(JavaModelUtil.getMethods(model)).hasSize(2);
}
use of com.devonfw.cobigen.javaplugin.inputreader.JavaInputReader in project cobigen by devonfw.
the class ReflectedJavaModelBuilderTest method testCorrectlyExtractedInheritedType.
/**
* Tests whether the inherited type will be correctly extracted and put into the model
*/
@Test
public void testCorrectlyExtractedInheritedType() {
JavaInputReader javaModelBuilder = new JavaInputReader();
Map<String, Object> model = javaModelBuilder.createModel(TestClass.class);
assertThat(JavaModelUtil.getExtendedType(model).get(ModelConstant.NAME)).isEqualTo("AbstractTestClass");
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");
}
Aggregations