use of org.kie.workbench.common.services.datamodeller.core.impl.AnnotationImpl in project kie-wb-common by kiegroup.
the class GenerationEngineTest method testEqualsStringGeneration.
@Test
public void testEqualsStringGeneration() {
DataModel dataModel = dataModelOracleDriver.createModel();
DataObject object1 = dataModel.addDataObject("com.test.Object1");
DataObject object2 = dataModel.addDataObject("com.test.sub.Object2");
ObjectPropertyImpl prop1 = (ObjectPropertyImpl) object1.addProperty("attribute1", "java.lang.String");
prop1.setFileOrder(0);
ObjectPropertyImpl prop2 = (ObjectPropertyImpl) object1.addProperty("attribute2", "java.lang.Boolean");
prop2.setFileOrder(1);
ObjectPropertyImpl prop3 = (ObjectPropertyImpl) object1.addProperty("attribute3", object2.getClassName());
prop3.setFileOrder(2);
ObjectPropertyImpl prop4 = (ObjectPropertyImpl) object1.addProperty("attribute4", "long");
prop4.setFileOrder(3);
Annotation key = new AnnotationImpl(annotationDefinitions.get(org.kie.api.definition.type.Key.class.getName()));
Annotation position = new AnnotationImpl(annotationDefinitions.get(org.kie.api.definition.type.Position.class.getName()));
position.setValue("value", "0");
prop4.addAnnotation(key);
prop4.addAnnotation(position);
position = new AnnotationImpl(annotationDefinitions.get(org.kie.api.definition.type.Position.class.getName()));
position.setValue("value", "1");
prop1.addAnnotation(key);
prop1.addAnnotation(position);
position = new AnnotationImpl(annotationDefinitions.get(org.kie.api.definition.type.Position.class.getName()));
position.setValue("value", "2");
prop2.addAnnotation(key);
prop2.addAnnotation(position);
position = new AnnotationImpl(annotationDefinitions.get(org.kie.api.definition.type.Position.class.getName()));
position.setValue("value", "3");
prop3.addAnnotation(position);
GenerationContext generationContext = new GenerationContext(dataModel);
try {
String result = engine.generateEqualsString(generationContext, object1);
assertEquals(results.getProperty("testEqualsStringGeneration"), result);
} catch (Exception e) {
e.printStackTrace();
}
}
use of org.kie.workbench.common.services.datamodeller.core.impl.AnnotationImpl in project kie-wb-common by kiegroup.
the class GenerationEngineTest method testCompleteFieldStringGeneration.
@Test
public // Return field definition + annotations
void testCompleteFieldStringGeneration() {
DataModel dataModel = dataModelOracleDriver.createModel();
DataObject object1 = dataModel.addDataObject("com.test.Object1");
ObjectProperty prop1 = object1.addProperty("attribute1", "java.lang.String");
Annotation label = new AnnotationImpl(annotationDefinitions.get(org.kie.api.definition.type.Label.class.getName()));
label.setValue("value", "Attribute 1");
Annotation desc = new AnnotationImpl(annotationDefinitions.get(org.kie.api.definition.type.Description.class.getName()));
desc.setValue("value", "Description for Attribute 1");
Annotation key = new AnnotationImpl(annotationDefinitions.get(org.kie.api.definition.type.Key.class.getName()));
Annotation position = new AnnotationImpl(annotationDefinitions.get(org.kie.api.definition.type.Position.class.getName()));
position.setValue("value", "0");
prop1.addAnnotation(label);
prop1.addAnnotation(desc);
prop1.addAnnotation(key);
prop1.addAnnotation(position);
GenerationContext generationContext = new GenerationContext(dataModelOracleDriver.createModel());
try {
String result = engine.generateCompleteFieldString(generationContext, prop1);
assertEquals(results.getProperty("testCompleteFieldStringGeneration"), result);
} catch (Exception e) {
e.printStackTrace();
}
}
use of org.kie.workbench.common.services.datamodeller.core.impl.AnnotationImpl in project kie-wb-common by kiegroup.
the class GenerationEngineTest method testHashCodeStringGeneration.
@Test
public void testHashCodeStringGeneration() {
DataModel dataModel = dataModelOracleDriver.createModel();
DataObject object1 = dataModel.addDataObject("com.test.Object1");
DataObject object2 = dataModel.addDataObject("com.test.sub.Object2");
ObjectProperty prop1 = object1.addProperty("attribute1", "java.lang.String");
((ObjectPropertyImpl) prop1).setFileOrder(0);
ObjectProperty prop2 = object1.addProperty("attribute2", "java.lang.Boolean");
((ObjectPropertyImpl) prop2).setFileOrder(1);
ObjectProperty prop3 = object1.addProperty("attribute3", object2.getClassName());
((ObjectPropertyImpl) prop3).setFileOrder(2);
ObjectProperty prop4 = object1.addProperty("attribute4", "long");
((ObjectPropertyImpl) prop4).setFileOrder(3);
Annotation key = new AnnotationImpl(annotationDefinitions.get(org.kie.api.definition.type.Key.class.getName()));
Annotation position = new AnnotationImpl(annotationDefinitions.get(org.kie.api.definition.type.Position.class.getName()));
position.setValue("value", "0");
prop4.addAnnotation(key);
prop4.addAnnotation(position);
position = new AnnotationImpl(annotationDefinitions.get(org.kie.api.definition.type.Position.class.getName()));
position.setValue("value", "1");
prop1.addAnnotation(key);
prop1.addAnnotation(position);
position = new AnnotationImpl(annotationDefinitions.get(org.kie.api.definition.type.Position.class.getName()));
position.setValue("value", "2");
prop2.addAnnotation(key);
prop2.addAnnotation(position);
position = new AnnotationImpl(annotationDefinitions.get(org.kie.api.definition.type.Position.class.getName()));
position.setValue("value", "3");
prop3.addAnnotation(position);
GenerationContext generationContext = new GenerationContext(dataModel);
try {
String result = engine.generateHashCodeString(generationContext, object1);
assertEquals(results.getProperty("testHashCodeStringGeneration"), result);
} catch (Exception e) {
e.printStackTrace();
}
}
use of org.kie.workbench.common.services.datamodeller.core.impl.AnnotationImpl in project drools-wb by kiegroup.
the class DecisionTableXLSToDecisionTableGuidedConverter method addAnnotations.
private void addAnnotations(final DataObject dataObject, final List<AnnotationMetaModel> annotationMetaModelList) {
for (AnnotationMetaModel annotationMetaModel : annotationMetaModelList) {
final String name = annotationMetaModel.getName();
final Map<String, String> values = annotationMetaModel.getValues();
Annotation annotation;
String key = DroolsDomainAnnotations.VALUE_PARAM;
String value = "";
if (values.size() > 0) {
key = values.keySet().iterator().next();
value = values.values().iterator().next();
}
if ("Role".equals(name)) {
annotation = new AnnotationImpl(annotationDefinitions.get(DroolsDomainAnnotations.ROLE_ANNOTATION));
annotation.setValue(key, value);
dataObject.addAnnotation(annotation);
} else if ("Position".equals(name)) {
annotation = new AnnotationImpl(annotationDefinitions.get(DroolsDomainAnnotations.POSITION_ANNOTATION));
annotation.setValue(key, value);
dataObject.addAnnotation(annotation);
} else if ("Equals".equals(name)) {
annotation = new AnnotationImpl(annotationDefinitions.get(DroolsDomainAnnotations.KEY_ANNOTATION));
annotation.setValue(key, value);
dataObject.addAnnotation(annotation);
}
}
}
use of org.kie.workbench.common.services.datamodeller.core.impl.AnnotationImpl in project kie-wb-common by kiegroup.
the class AbstractDataObjectFinderTest method init.
@Before
public void init() {
dataObject = dataModel.addDataObject(PACKAGE, DATA_OBJECT_NAME);
addProperty(dataObject, DataObjectFormModelHandler.SERIAL_VERSION_UID, Long.class.getName(), false, false);
ObjectProperty property = addProperty(dataObject, PERSISTENCE_ID_PROPERTY, Long.class.getName(), false, false);
property.addAnnotation(new AnnotationImpl(new AnnotationDefinitionImpl(DataObjectFormModelHandler.PERSISTENCE_ANNOTATION)));
addProperty(dataObject, NAME_PROPERTY, String.class.getName(), false, true);
addProperty(dataObject, LAST_NAME_PROPERTY, String.class.getName(), false, true);
addProperty(dataObject, AGE_PROPERTY, Integer.class.getName(), false, true);
addProperty(dataObject, BIRTHDATE_PROPERTY, Date.class.getName(), false, true);
addProperty(dataObject, MARRIED_PROPERTY, Boolean.class.getName(), false, true);
when(dataModelerService.loadModel(any())).thenReturn(dataModel);
service = new DataObjectFinderServiceImpl(moduleService, dataModelerService);
}
Aggregations