use of org.kie.workbench.common.services.datamodeller.core.impl.AnnotationImpl in project kie-wb-common by kiegroup.
the class CreateAnnotationWizardTest method testAnnotationCreated.
@Test
public void testAnnotationCreated() {
// emulate the user is searching the javax.persistence.Entity annotation.
AnnotationDefinitionRequest request = new AnnotationDefinitionRequest(Entity.class.getName());
// the response has a definition
AnnotationDefinitionResponse response = new AnnotationDefinitionResponse(DriverUtils.buildAnnotationDefinition(Entity.class));
when(searchView.getClassName()).thenReturn(Entity.class.getName());
when(modelerService.resolveDefinitionRequest(request, kieModule)).thenReturn(response);
// when the search is performed the ValuePairEditor pages will be automatically created
// so we also emulate the corresponding ValuePairEditors for the given value pairs.
AnnotationValuePairDefinition valuePairDefinition = response.getAnnotationDefinition().getValuePair("name");
when(valuePairEditorProvider.getValuePairEditor(valuePairDefinition)).thenReturn(valuePairEditor);
// the wizard pages corresponding to the value pairs are also created dynamically, se we need also emulate
// the ValuePairEditorPage instantiation
when(iocManager.lookupBean(ValuePairEditorPage.class)).thenReturn(beanDef);
when(beanDef.getInstance()).thenReturn(editorPage);
// emulate the user click on the search button
searchPage.onSearchClass();
// the page should have been completed, since the modelerService returned the annotation definition as expected
WizardTestUtil.assertPageComplete(true, searchPage);
// now emulate the parameter completion in the value pair page.
// emulate a change in the internal ValuePairEditor with a valid value.
when(editorView.getValuePairEditor()).thenReturn(valuePairEditor);
when(valuePairEditor.getValue()).thenReturn("TheEntityName");
when(valuePairEditor.isValid()).thenReturn(true);
editorPage.onValueChange();
// the value pair editor page shoud have been completed.
WizardTestUtil.assertPageComplete(true, searchPage);
// emulates the user clicking on the finish button.
createAnnotationWizard.complete();
// finally if the Wizard has been completed successfuly an annotation should be created.
Annotation expectedAnnotation = new AnnotationImpl(DriverUtils.buildAnnotationDefinition(Entity.class));
expectedAnnotation.setValue("name", "TheEntityName");
assertEquals(expectedAnnotation, createdAnnotation);
}
use of org.kie.workbench.common.services.datamodeller.core.impl.AnnotationImpl in project kie-wb-common by kiegroup.
the class DataModelerEditorsTestHelper method createAnnotation.
public static Annotation createAnnotation(Class cls, Pair<String, Object>... valuePairs) {
AnnotationDefinition annotationDefinition = DriverUtils.buildAnnotationDefinition(cls);
Annotation annotation = new AnnotationImpl(annotationDefinition);
for (Pair<String, Object> valuePair : valuePairs) {
annotation.setValue(valuePair.getK1(), valuePair.getK2());
}
return annotation;
}
use of org.kie.workbench.common.services.datamodeller.core.impl.AnnotationImpl in project kie-wb-common by kiegroup.
the class DataModelerEventObserverTest method init.
@Before
public void init() {
eventObserver = createObserver();
descriptorModel = createModel();
dataObject = new DataObjectImpl("package1", "PersistableObject");
dataObject.addAnnotation(new AnnotationImpl(DriverUtils.buildAnnotationDefinition(Entity.class)));
when(descriptorPath.toURI()).thenReturn(DESCRIPTOR_PATH);
when(descriptorService.calculatePersistenceDescriptorPath(any(Module.class))).thenReturn(descriptorPath);
when(descriptorService.load(descriptorPath)).thenReturn(descriptorModel);
when(ioService.exists(any(org.uberfire.java.nio.file.Path.class))).thenReturn(true);
}
use of org.kie.workbench.common.services.datamodeller.core.impl.AnnotationImpl in project kie-wb-common by kiegroup.
the class JPADataObjectEditor method addByDefaultId.
private void addByDefaultId(DataObject dataObject) {
// add the by default id field
String idFieldName = generateIdFieldName(dataObject);
commandBuilder.buildAddPropertyCommand(getContext(), getName(), dataObject, idFieldName, null, Long.class.getName(), false).execute();
ObjectProperty idField = dataObject.getProperty(idFieldName);
commandBuilder.buildFieldAnnotationAddCommand(getContext(), getName(), dataObject, idField, JPADomainAnnotations.JAVAX_PERSISTENCE_ID_ANNOTATION).execute();
// set the by default generated value annotation.
String generatorName = dataObject.getName().toUpperCase() + "_ID_GENERATOR";
Annotation generatedValue = new AnnotationImpl(context.getAnnotationDefinition(JPADomainAnnotations.JAVAX_PERSISTENCE_GENERATED_VALUE_ANNOTATION));
generatedValue.setValue("generator", generatorName);
generatedValue.setValue("strategy", "AUTO");
commandBuilder.buildFieldAnnotationAddCommand(getContext(), getName(), dataObject, idField, generatedValue).execute();
// set by default sequence generator
String sequenceName = dataObject.getName().toUpperCase() + "_ID_SEQ";
Annotation sequenceGenerator = SequenceGeneratorValueHandler.createAnnotation(generatorName, sequenceName, context.getAnnotationDefinitions());
commandBuilder.buildFieldAnnotationAddCommand(getContext(), getName(), dataObject, idField, sequenceGenerator).execute();
}
use of org.kie.workbench.common.services.datamodeller.core.impl.AnnotationImpl in project kie-wb-common by kiegroup.
the class CreateAnnotationWizard method doComplete.
private void doComplete() {
Annotation annotation = null;
if (annotationDefinition != null) {
annotation = new AnnotationImpl(annotationDefinition);
if (!annotationDefinition.isMarker()) {
for (ValuePairEditorPage valuePairEditor : filterValuePairEditorPages()) {
if (valuePairEditor.getCurrentValue() != null) {
annotation.setValue(valuePairEditor.getValuePairDefinition().getName(), valuePairEditor.getCurrentValue());
}
}
}
}
clearCurrentValuePairEditorPages();
invokeOnCloseCallback(annotation);
}
Aggregations