use of org.kie.workbench.common.services.datamodeller.core.DataObject in project kie-wb-common by kiegroup.
the class DataModelerEditorsTestHelper method createTestObject1.
public static DataObject createTestObject1() {
// set general properties and annotations.
DataObject dataObject = new DataObjectImpl("org.test", "TestObject1");
dataObject.setSuperClassName("java.lang.Object");
dataObject.addAnnotation(createAnnotation(Label.class, new Pair<String, Object>("value", "TestObject1Label")));
dataObject.addAnnotation(createAnnotation(Description.class, new Pair<String, Object>("value", "TestObject1Description")));
// set annotations for drools & jbpm domain tests.
dataObject.addAnnotation(createAnnotation(TypeSafe.class, new Pair<String, Object>("value", true)));
dataObject.addAnnotation(createAnnotation(PropertyReactive.class));
dataObject.addAnnotation(createAnnotation(Role.class, new Pair<String, Object>("value", Role.Type.EVENT.name())));
dataObject.addAnnotation(createAnnotation(Timestamp.class, new Pair<String, Object>("value", "field2")));
dataObject.addAnnotation(createAnnotation(Duration.class, new Pair<String, Object>("value", "field3")));
dataObject.addAnnotation(createAnnotation(Expires.class, new Pair<String, Object>("value", "1h")));
dataObject.addAnnotation(createAnnotation(XmlRootElement.class));
// add fields
ObjectProperty field1 = dataObject.addProperty("field1", Integer.class.getName());
field1.addAnnotation(createAnnotation(Label.class, new Pair<String, Object>("value", "Field1Label")));
field1.addAnnotation(createAnnotation(Description.class, new Pair<String, Object>("value", "Field1Description")));
// set annotations for drools & jbpm domain tests
field1.addAnnotation(createAnnotation(Position.class, new Pair<String, Object>("value", 0)));
field1.addAnnotation(createAnnotation(Key.class));
ObjectProperty field2 = dataObject.addProperty("field2", Integer.class.getName());
field2.addAnnotation(createAnnotation(Label.class, new Pair<String, Object>("value", "Field2Label")));
field2.addAnnotation(createAnnotation(Description.class, new Pair<String, Object>("value", "Field2Description")));
ObjectProperty field3 = dataObject.addProperty("field3", Long.class.getName());
field1.addAnnotation(createAnnotation(Label.class, new Pair<String, Object>("value", "Field3Label")));
field1.addAnnotation(createAnnotation(Description.class, new Pair<String, Object>("value", "Field3Description")));
return dataObject;
}
use of org.kie.workbench.common.services.datamodeller.core.DataObject in project kie-wb-common by kiegroup.
the class DomainEditorBaseTest method createContext.
protected DataModelerContext createContext() {
context = DataModelerEditorsTestHelper.createTestContext();
DataObject dataObject = createTestObject1();
context.setDataObject(dataObject);
return context;
}
use of org.kie.workbench.common.services.datamodeller.core.DataObject in project kie-wb-common by kiegroup.
the class JavaRoasterModelDriverTest method updateAnnotationsTest.
@Test
public void updateAnnotationsTest() {
try {
// First read the AnnotationsUpdateTest
Path annotationsUpdateTestFilePath = rootPath.resolve("package3").resolve("AnnotationsUpdateTest.java");
String source = ioService.readAllString(annotationsUpdateTestFilePath);
JavaClassSource annotationsUpdateTestJavaClassSource = (JavaClassSource) Roaster.parse(source);
ClassLoader classLoader = getClass().getClassLoader();
ClassTypeResolver classTypeResolver = DriverUtils.createClassTypeResolver(annotationsUpdateTestJavaClassSource, classLoader);
final SourceFilter pojo1Filter = javaType -> false;
final NestedClassFilter nestedClassFilter = javaType -> javaType.isClass() && javaType.getAnnotation(Generated.class) != null;
final MethodFilter methodFilter = method -> !method.isConstructor() && method.getAnnotation(Generated.class) != null;
FilterHolder filterHolder = mock(FilterHolder.class);
when(filterHolder.getSourceFilters()).thenReturn(Collections.singleton(pojo1Filter));
when(filterHolder.getNestedClassFilters()).thenReturn(Collections.singleton(nestedClassFilter));
when(filterHolder.getMethodFilters()).thenReturn(Collections.singleton(methodFilter));
JavaRoasterModelDriver javaRoasterModelDriver = new JavaRoasterModelDriver(ioService, rootPath, classLoader, filterHolder);
ModelDriverResult result = javaRoasterModelDriver.loadDataObject(source, annotationsUpdateTestFilePath);
// 1) read the AnnotationsUpdateTest
DataObject annotationsUpdateTest = result.getDataModel().getDataObject("org.kie.workbench.common.services.datamodeller.driver.package3.AnnotationsUpdateTest");
// 2) modify the AnnotationsUpdateTest according to the expected result, basically updating all the needed annotations.
// update the AnnotationValuesAnnotation
Annotation annotationValuesAnnotation = annotationsUpdateTest.getAnnotation(AnnotationValuesAnnotation.class.getName());
// annotation.setValue( "primitivesParam", @PrimitivesAnnotation(stringParam="\"line1\" \n line2 \\ \n line3") );
Annotation primitivesParamValue = createAnnotation(PrimitivesAnnotation.class);
// construct the value -> "\"line1\" \n line2 \\ \n line3"
StringBuilder stringParamBuilder = new StringBuilder();
stringParamBuilder.append('"').append("line1").append('"').append(" ").append('\n');
stringParamBuilder.append(" line2 ").append('\\').append(" ").append('\n');
stringParamBuilder.append(" line3");
primitivesParamValue.setValue("stringParam", stringParamBuilder.toString());
annotationValuesAnnotation.setValue("primitivesParam", primitivesParamValue);
// @PrimitivesAnnotation(intParam=1)
Annotation primitiveValue1 = createAnnotation(PrimitivesAnnotation.class);
primitiveValue1.setValue("intParam", 2);
// @PrimitivesAnnotation(intParam=3)
Annotation primitiveValue2 = createAnnotation(PrimitivesAnnotation.class);
primitiveValue2.setValue("intParam", 3);
List<Annotation> primitivesArrayParamValue = new ArrayList<Annotation>();
primitivesArrayParamValue.add(primitiveValue1);
primitivesArrayParamValue.add(primitiveValue2);
// annotation.setValue( "primitivesArrayParam", "{@PrimitivesAnnotation(intParam=2),@PrimitivesAnnotation(intParam=3)}" );
annotationValuesAnnotation.setValue("primitivesArrayParam", primitivesArrayParamValue);
// annotation.setValue( "enumsParam", "@EnumsAnnotation(enum1Param=TestEnums.ENUM1.VALUE2)" );
Annotation enumsParamValue = createAnnotation(EnumsAnnotation.class);
enumsParamValue.setValue("enum1Param", TestEnums.ENUM1.VALUE2.toString());
annotationValuesAnnotation.setValue("enumsParam", enumsParamValue);
// annotation.setValue( "enumsArrayParam", "{@EnumsAnnotation(enum1Param=TestEnums.ENUM1.VALUE2),@EnumsAnnotation(enum1Param=TestEnums.ENUM1.VALUE3)}" );
Annotation enumArrayParam1 = createAnnotation(EnumsAnnotation.class);
enumArrayParam1.setValue("enum1Param", TestEnums.ENUM1.VALUE2.toString());
Annotation enumArrayParam2 = createAnnotation(EnumsAnnotation.class);
enumArrayParam2.setValue("enum1Param", TestEnums.ENUM1.VALUE3.toString());
List<Annotation> enumVarrayValues = new ArrayList<Annotation>();
enumVarrayValues.add(enumArrayParam1);
enumVarrayValues.add(enumArrayParam2);
annotationValuesAnnotation.setValue("enumsArrayParam", enumVarrayValues);
// annotation.setValue( "classAnnotationParam", "@ClassAnnotation(classParam=Set.class)" );
Annotation classAnnotationParamValue = createAnnotation(ClassAnnotation.class);
classAnnotationParamValue.setValue("classParam", "Set.class");
annotationValuesAnnotation.setValue("classAnnotationParam", classAnnotationParamValue);
// annotation.setValue( "classAnnotationArrayParam", "{@ClassAnnotation(classParam=Set.class),@ClassAnnotation(classParam=Set.class)}" );
Annotation classAnnotationArrayParamValue1 = createAnnotation(ClassAnnotation.class);
classAnnotationArrayParamValue1.setValue("classParam", "Set.class");
Annotation classAnnotationArrayParamValue2 = createAnnotation(ClassAnnotation.class);
classAnnotationArrayParamValue2.setValue("classParam", "Set.class");
List<Annotation> classAnnotationArrayParamValue = new ArrayList<Annotation>();
classAnnotationArrayParamValue.add(classAnnotationArrayParamValue1);
classAnnotationArrayParamValue.add(classAnnotationArrayParamValue2);
annotationValuesAnnotation.setValue("classAnnotationArrayParam", classAnnotationArrayParamValue);
// update the ClassAnnotation
Annotation classAnnotation = createAnnotation(ClassAnnotation.class);
classAnnotation.setValue("classParam", "java.util.Collection.class");
classAnnotation.setValue("classArrayParam", createArrayParam("List.class"));
annotationsUpdateTest.addAnnotation(classAnnotation);
// update the EnumsAnnotation
Annotation enumsAnnotation = createAnnotation(EnumsAnnotation.class);
enumsAnnotation.setValue("enum1Param", TestEnums.ENUM1.VALUE2.toString());
// enumsAnnotation.setValue( "enum1ArrayParam", "{TestEnums.ENUM1.VALUE3}" );
enumsAnnotation.setValue("enum1ArrayParam", createEnumArrayParam(TestEnums.ENUM1.VALUE3));
enumsAnnotation.setValue("enum2Param", TestEnums.ENUM2.VALUE2.toString());
// enumsAnnotation.setValue( "enum2ArrayParam", "{TestEnums.ENUM2.VALUE3}" );
enumsAnnotation.setValue("enum2ArrayParam", createEnumArrayParam(TestEnums.ENUM2.VALUE3));
annotationsUpdateTest.addAnnotation(enumsAnnotation);
// update the PrimitivesAnnotation
Annotation primitivesAnnotation = createAnnotation(PrimitivesAnnotation.class);
primitivesAnnotation.setValue("byteParam", new Byte("2"));
// primitivesAnnotation.setValue( "byteArrayParam", "{3,4}" );
primitivesAnnotation.setValue("byteArrayParam", createArrayParam((byte) 3, (byte) 4));
primitivesAnnotation.setValue("shortParam", new Short("2"));
// primitivesAnnotation.setValue( "shortArrayParam", "{3,4}" );
primitivesAnnotation.setValue("shortArrayParam", createArrayParam((short) 3, (short) 4));
primitivesAnnotation.setValue("stringParam", "2");
primitivesAnnotation.setValue("stringArrayParam", createArrayParam("3", "4"));
annotationsUpdateTest.addAnnotation(primitivesAnnotation);
// add the MarkerAnnotation
annotationsUpdateTest.addAnnotation(createMarkerAnnotation());
annotationsUpdateTest.setName("AnnotationsUpdateTestResult");
// 3) compare the modified data object with the expected data object.
Path expectedFilePath = rootPath.resolve("package3").resolve("AnnotationsUpdateTestResult.java");
String expectedSource = ioService.readAllString(expectedFilePath);
JavaClassSource expectedJavaClassSource = (JavaClassSource) Roaster.parse(expectedSource);
ModelDriverResult expectedResult = javaRoasterModelDriver.loadDataObject(expectedSource, expectedFilePath);
DataObject annotationsUpdateTestResult = expectedResult.getDataModel().getDataObject("org.kie.workbench.common.services.datamodeller.driver.package3.AnnotationsUpdateTestResult");
// First check, the modified data object in memory should be the same as the readed from the model.
DataModelerAssert.assertEqualsDataObject(annotationsUpdateTestResult, annotationsUpdateTest);
// Second check, update the JavaClassSource corresponding to the AnnotationsUpdateTest
javaRoasterModelDriver.updateSource(annotationsUpdateTestJavaClassSource, annotationsUpdateTest, new UpdateInfo(), classTypeResolver);
ModelDriverResult updatedResult = javaRoasterModelDriver.loadDataObject(annotationsUpdateTestJavaClassSource.toString(), annotationsUpdateTestFilePath);
// and now compare the updatedResult with the expected value.
DataModelerAssert.assertEqualsDataObject(annotationsUpdateTestResult, updatedResult.getDataModel().getDataObject("org.kie.workbench.common.services.datamodeller.driver.package3.AnnotationsUpdateTestResult"));
logger.debug(annotationsUpdateTestJavaClassSource.toString());
} catch (Exception e) {
e.printStackTrace();
fail("Test failed: " + e.getMessage());
}
}
use of org.kie.workbench.common.services.datamodeller.core.DataObject in project kie-wb-common by kiegroup.
the class JavaRoasterModelDriverTest method createAnnotationValuesAnnotationTest.
private DataObject createAnnotationValuesAnnotationTest() {
DataObject dataObject = createDataObject("org.kie.workbench.common.services.datamodeller.driver.package3", "AnnotationValuesAnnotationTest", null);
ObjectProperty field1 = dataObject.addProperty("field1", String.class.getName());
Annotation annotation = createAnnotationValuesAnnotation();
dataObject.addAnnotation(annotation);
field1.addAnnotation(annotation);
return dataObject;
}
use of org.kie.workbench.common.services.datamodeller.core.DataObject in project kie-wb-common by kiegroup.
the class JavaRoasterModelDriverTest method modelVetoingTest.
@Test
public void modelVetoingTest() throws Exception {
try {
final SourceFilter pojo1Filter = javaType -> javaType.getName().equals("Pojo1");
final NestedClassFilter nestedClassFilter = javaType -> javaType.isClass() && javaType.getAnnotation(Generated.class) != null;
final MethodFilter methodFilter = method -> !method.isConstructor() && method.getAnnotation(Generated.class) != null;
FilterHolder filterHolder = mock(FilterHolder.class);
when(filterHolder.getSourceFilters()).thenReturn(Collections.singleton(pojo1Filter));
when(filterHolder.getNestedClassFilters()).thenReturn(Collections.singleton(nestedClassFilter));
when(filterHolder.getMethodFilters()).thenReturn(Collections.singleton(methodFilter));
final JavaRoasterModelDriver javaRoasterModelDriver = new JavaRoasterModelDriver(ioService, rootPath, getClass().getClassLoader(), filterHolder);
ModelDriverResult modelDriverResult = javaRoasterModelDriver.loadModel();
DataModel dataModelOriginal = createModel();
assertNotNull(modelDriverResult);
assertNotNull(modelDriverResult.getDataModel());
assertEquals(dataModelOriginal.getDataObjects().size() - 1, modelDriverResult.getDataModel().getDataObjects().size());
for (DataObject dataObject : modelDriverResult.getDataModel().getDataObjects()) {
if (!dataObject.getClassName().endsWith("Pojo1")) {
DataModelerAssert.assertEqualsDataObject(dataObject, modelDriverResult.getDataModel().getDataObject(dataObject.getClassName()));
} else {
fail("Pojo1 should have been vetoed.");
}
}
} catch (Exception e) {
e.printStackTrace();
fail("Test failed: " + e.getMessage());
}
}
Aggregations