use of org.kie.soup.project.datamodel.oracle.Annotation in project kie-wb-common by kiegroup.
the class PackageDataModelFactFieldsAnnotationsTest method testIncorrectPackageDMOZeroAnnotationAttributes.
@Test
public void testIncorrectPackageDMOZeroAnnotationAttributes() throws Exception {
// Build ModuleDMO
final ModuleDataModelOracleBuilder moduleBuilder = ModuleDataModelOracleBuilder.newModuleOracleBuilder(new RawMVELEvaluator());
final ModuleDataModelOracleImpl moduleLoader = new ModuleDataModelOracleImpl();
final ClassFactBuilder cb = new ClassFactBuilder(moduleBuilder, Product.class, false, TypeSource.JAVA_PROJECT);
cb.build(moduleLoader);
// Build PackageDMO. Defaults to defaultpkg
final PackageDataModelOracleBuilder packageBuilder = PackageDataModelOracleBuilder.newPackageOracleBuilder(new RawMVELEvaluator());
packageBuilder.setModuleOracle(moduleLoader);
final PackageDataModelOracle packageLoader = packageBuilder.build();
// Emulate server-to-client conversions
final Caller<IncrementalDataModelService> service = new MockIncrementalDataModelServiceCaller(packageLoader);
final AsyncPackageDataModelOracle oracle = new AsyncPackageDataModelOracleImpl(service, validatorInstance);
final PackageDataModelOracleBaselinePayload dataModel = new PackageDataModelOracleBaselinePayload();
dataModel.setPackageName(packageLoader.getPackageName());
dataModel.setModelFields(packageLoader.getModuleModelFields());
dataModel.setTypeAnnotations(packageLoader.getModuleTypeAnnotations());
dataModel.setTypeFieldsAnnotations(packageLoader.getModuleTypeFieldsAnnotations());
PackageDataModelOracleTestUtils.populateDataModelOracle(mock(Path.class), new MockHasImports(), oracle, dataModel);
assertEquals(0, oracle.getFactTypes().length);
oracle.getTypeFieldsAnnotations("Product", new Callback<Map<String, Set<Annotation>>>() {
@Override
public void callback(final Map<String, Set<Annotation>> fieldsAnnotations) {
assertNotNull(fieldsAnnotations);
assertEquals(0, fieldsAnnotations.size());
}
});
}
use of org.kie.soup.project.datamodel.oracle.Annotation in project kie-wb-common by kiegroup.
the class PackageDataModelFactFieldsAnnotationsTest method testCorrectPackageDMOZeroAnnotationAttributes.
@Test
public void testCorrectPackageDMOZeroAnnotationAttributes() throws Exception {
// Build ModuleDMO
final ModuleDataModelOracleBuilder moduleBuilder = ModuleDataModelOracleBuilder.newModuleOracleBuilder(new RawMVELEvaluator());
final ModuleDataModelOracleImpl moduleLoader = new ModuleDataModelOracleImpl();
final ClassFactBuilder cb = new ClassFactBuilder(moduleBuilder, Product.class, false, TypeSource.JAVA_PROJECT);
cb.build(moduleLoader);
// Build PackageDMO
final PackageDataModelOracleBuilder packageBuilder = PackageDataModelOracleBuilder.newPackageOracleBuilder(new RawMVELEvaluator(), "org.kie.workbench.common.widgets.client.datamodel.testclasses");
packageBuilder.setModuleOracle(moduleLoader);
final PackageDataModelOracle packageLoader = packageBuilder.build();
// Emulate server-to-client conversions
final Caller<IncrementalDataModelService> service = new MockIncrementalDataModelServiceCaller(packageLoader);
final AsyncPackageDataModelOracle oracle = new AsyncPackageDataModelOracleImpl(service, validatorInstance);
final PackageDataModelOracleBaselinePayload dataModel = new PackageDataModelOracleBaselinePayload();
dataModel.setPackageName(packageLoader.getPackageName());
dataModel.setModelFields(packageLoader.getModuleModelFields());
dataModel.setTypeAnnotations(packageLoader.getModuleTypeAnnotations());
dataModel.setTypeFieldsAnnotations(packageLoader.getModuleTypeFieldsAnnotations());
PackageDataModelOracleTestUtils.populateDataModelOracle(mock(Path.class), new MockHasImports(), oracle, dataModel);
assertEquals(1, oracle.getFactTypes().length);
assertEquals("Product", oracle.getFactTypes()[0]);
oracle.getTypeFieldsAnnotations("Product", new Callback<Map<String, Set<Annotation>>>() {
@Override
public void callback(final Map<String, Set<Annotation>> fieldsAnnotations) {
assertNotNull(fieldsAnnotations);
assertEquals(0, fieldsAnnotations.size());
}
});
}
use of org.kie.soup.project.datamodel.oracle.Annotation in project kie-wb-common by kiegroup.
the class ClassFactBuilder method loadClassFields.
private void loadClassFields(final Class<?> clazz, final Map<String, FactBuilder> discoveredFieldFactBuilders) throws IOException {
if (clazz == null) {
return;
}
final String factType = getType();
// Get all getters and setters for the class. This does not handle delegated properties
// - FIELDS need a getter ("getXXX", "isXXX") or setter ("setXXX") or are public properties
// - METHODS are any accessor that does not have a getter or setter
final ClassFieldInspector inspector = new ClassFieldInspector(clazz);
final Set<String> fieldNames = inspector.getFieldNames();
for (final String fieldName : fieldNames) {
final ClassFieldInspector.FieldInfo f = inspector.getFieldTypesFieldInfo().get(fieldName);
addParametricTypeForField(factType, fieldName, f.getGenericType());
final Class<?> returnType = f.getReturnType();
final String genericReturnType = typeSystemConverter.translateClassToGenericType(returnType);
addField(new ModelField(fieldName, returnType.getName(), ModelField.FIELD_CLASS_TYPE.REGULAR_CLASS, f.getOrigin(), f.getAccessorAndMutator(), genericReturnType));
addEnumsForField(factType, fieldName, returnType);
// To prevent recursion we keep track of all ClassFactBuilder's created and re-use where applicable
if (BlackLists.isReturnTypeBlackListed(returnType)) {
continue;
}
discoverFieldFactBuilder(genericReturnType, returnType, discoveredFieldFactBuilders);
// Check types on generic arguments
if (f.getGenericType() instanceof ParameterizedType) {
ParameterizedType parameterizedType = (ParameterizedType) f.getGenericType();
for (Type parameterType : parameterizedType.getActualTypeArguments()) {
if (discoveredFieldFactBuilders.containsKey(parameterType.getTypeName())) {
continue;
}
if (parameterType instanceof Class) {
Class<?> parameterClazz = (Class<?>) parameterType;
discoverFieldFactBuilder(parameterClazz.getName(), parameterClazz, discoveredFieldFactBuilders);
}
}
}
Set<Annotation> fieldAnnotations = f.getAnnotations();
if (fieldAnnotations != null && !fieldAnnotations.isEmpty()) {
this.fieldAnnotations.put(fieldName, f.getAnnotations());
}
}
// Methods for use in Expressions and ActionCallMethod's
ClassMethodInspector methodInspector = new ClassMethodInspector(clazz, typeSystemConverter);
final List<MethodInfo> methodInformation = methodInspector.getMethodInfos();
for (final MethodInfo mi : methodInformation) {
final String genericType = mi.getParametricReturnType();
if (genericType != null) {
final String qualifiedFactFieldName = factType + "#" + mi.getNameWithParameters();
this.fieldParametersType.put(qualifiedFactFieldName, genericType);
}
}
this.methodInformation.put(factType, methodInformation);
}
use of org.kie.soup.project.datamodel.oracle.Annotation in project kie-wb-common by kiegroup.
the class ModuleDataModelFactAnnotationsTest method testModuleDMOZeroAnnotationAttributes.
@Test
public void testModuleDMOZeroAnnotationAttributes() throws Exception {
final ModuleDataModelOracleBuilder builder = ModuleDataModelOracleBuilder.newModuleOracleBuilder(new RawMVELEvaluator());
final ModuleDataModelOracleImpl oracle = new ModuleDataModelOracleImpl();
final ClassFactBuilder cb = new ClassFactBuilder(builder, Product.class, false, TypeSource.JAVA_PROJECT);
cb.build(oracle);
assertEquals(1, oracle.getModuleModelFields().size());
assertContains("org.kie.workbench.common.services.datamodel.backend.server.testclasses.Product", oracle.getModuleModelFields().keySet());
final Set<Annotation> annotations = oracle.getModuleTypeAnnotations().get("org.kie.workbench.common.services.datamodel.backend.server.testclasses.Product");
assertNotNull(annotations);
assertEquals(0, annotations.size());
}
use of org.kie.soup.project.datamodel.oracle.Annotation in project kie-wb-common by kiegroup.
the class ModuleDataModelFactAnnotationsTest method annotationsWithMemberOfTypeClass.
@Test
public void annotationsWithMemberOfTypeClass() throws Exception {
final ModuleDataModelOracleBuilder builder = ModuleDataModelOracleBuilder.newModuleOracleBuilder(new RawMVELEvaluator());
final ModuleDataModelOracleImpl oracle = new ModuleDataModelOracleImpl();
final ClassFactBuilder cb = new ClassFactBuilder(builder, JAXBSmurf.class, false, TypeSource.JAVA_PROJECT);
cb.build(oracle);
assertEquals(1, oracle.getModuleModelFields().size());
assertContains("org.kie.workbench.common.services.datamodel.backend.server.testclasses.annotations.JAXBSmurf", oracle.getModuleModelFields().keySet());
final Set<Annotation> annotations = oracle.getModuleTypeAnnotations().get("org.kie.workbench.common.services.datamodel.backend.server.testclasses.annotations.JAXBSmurf");
assertNotNull(annotations);
assertEquals(1, annotations.size());
final Annotation annotation = annotations.iterator().next();
assertEquals("javax.xml.bind.annotation.XmlType", annotation.getQualifiedTypeName());
assertEquals(5, annotation.getParameters().size());
assertEquals("smurf-namespace", annotation.getParameters().get("namespace"));
assertEquals("smurf-xsd", annotation.getParameters().get("name"));
assertArraysEqual(new String[] { "name", "colour" }, (String[]) annotation.getParameters().get("propOrder"));
assertTrue(annotation.getParameters().get("factoryClass").toString().contains("org.kie.workbench.common.services.datamodel.backend.server.testclasses.annotations.JAXBSmurfFactory"));
}
Aggregations