use of org.kie.workbench.common.services.datamodeller.core.AnnotationValuePairDefinition in project kie-wb-common by kiegroup.
the class JavaRoasterModelDriver method resolveAnnotationSource.
public org.kie.workbench.common.services.datamodeller.driver.model.AnnotationSource resolveAnnotationSource(Annotation annotation) {
org.kie.workbench.common.services.datamodeller.driver.model.AnnotationSource annotationSource = new org.kie.workbench.common.services.datamodeller.driver.model.AnnotationSource();
// TODO this method can be optimized and likely migrated to Roaster. Should be reviewed when we evaluate
// the removal of Velocity.
GenerationTools generationTools = new GenerationTools();
AnnotationDefinition annotationDefinition;
StringBuilder annotationCode = new StringBuilder();
annotationCode.append("@");
annotationCode.append(annotation.getClassName());
if ((annotationDefinition = annotation.getAnnotationDefinition()) != null) {
if (!annotationDefinition.isMarker()) {
annotationCode.append(generationTools.resolveAnnotationType(annotation));
}
if (annotationDefinition.getValuePairs() != null) {
Object value;
String valuePairCode;
for (AnnotationValuePairDefinition valuePairDefinition : annotationDefinition.getValuePairs()) {
if ((value = annotation.getValue(valuePairDefinition.getName())) != null) {
valuePairCode = generationTools.resolveMemberTypeExpression(valuePairDefinition, value);
} else {
valuePairCode = null;
}
annotationSource.withValuePairSource(valuePairDefinition.getName(), valuePairCode);
}
}
}
annotationSource.withSource(annotationCode.toString());
return annotationSource;
}
use of org.kie.workbench.common.services.datamodeller.core.AnnotationValuePairDefinition 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.AnnotationValuePairDefinition in project kie-wb-common by kiegroup.
the class ValuePairEditorPageTest method testValidValueChange.
@Test
public void testValidValueChange() {
modelerServiceCaller = new CallerMock<DataModelerService>(modelerService);
ValuePairEditorPage editorPage = new ValuePairEditorPage(view, valuePairEditorProvider, modelerServiceCaller, wizardPageStatusChangeEvent);
editorPage.prepareView();
AnnotationDefinition annotationDefinition = DriverUtils.buildAnnotationDefinition(Entity.class);
AnnotationValuePairDefinition valuePairDefinition = annotationDefinition.getValuePair("name");
when(valuePairEditorProvider.getValuePairEditor(valuePairDefinition)).thenReturn(valuePairEditor);
editorPage.init(annotationDefinition, valuePairDefinition, ElementType.FIELD, kieModule);
// emulate a change in the internal ValuePairEditor with a valid value.
when(view.getValuePairEditor()).thenReturn(valuePairEditor);
when(valuePairEditor.getValue()).thenReturn("TheEntityName");
when(valuePairEditor.isValid()).thenReturn(true);
editorPage.onValueChange();
// the view should be properly initialized with the corresponding editor.
verify(view, times(1)).setValuePairEditor(valuePairEditor);
verify(valuePairEditor, times(1)).getValue();
verify(valuePairEditor, times(1)).isValid();
assertEquals("TheEntityName", editorPage.getCurrentValue());
WizardTestUtil.assertPageComplete(true, editorPage);
}
use of org.kie.workbench.common.services.datamodeller.core.AnnotationValuePairDefinition in project kie-wb-common by kiegroup.
the class ValuePairEditorPageTest method testInvalidValueChange.
@Test
public void testInvalidValueChange() {
modelerServiceCaller = new CallerMock<DataModelerService>(modelerService);
ValuePairEditorPage editorPage = new ValuePairEditorPage(view, valuePairEditorProvider, modelerServiceCaller, wizardPageStatusChangeEvent);
editorPage.prepareView();
AnnotationDefinition annotationDefinition = DriverUtils.buildAnnotationDefinition(Entity.class);
AnnotationValuePairDefinition valuePairDefinition = annotationDefinition.getValuePair("name");
when(valuePairEditorProvider.getValuePairEditor(valuePairDefinition)).thenReturn(valuePairEditor);
editorPage.init(annotationDefinition, valuePairDefinition, ElementType.FIELD, kieModule);
// emulate a change in the internal ValuePairEditor with a valid value.
when(view.getValuePairEditor()).thenReturn(valuePairEditor);
when(valuePairEditor.getValue()).thenReturn(null);
when(valuePairEditor.isValid()).thenReturn(false);
editorPage.onValueChange();
// the view should be properly initialized with the corresponding editor.
verify(view, times(1)).setValuePairEditor(valuePairEditor);
verify(valuePairEditor, times(1)).getValue();
verify(valuePairEditor, times(1)).isValid();
WizardTestUtil.assertPageComplete(false, editorPage);
}
use of org.kie.workbench.common.services.datamodeller.core.AnnotationValuePairDefinition in project kie-wb-common by kiegroup.
the class BooleanValuePairEditorTest method testEditorLoad.
@Test
public void testEditorLoad() {
BooleanValuePairEditor booleanEditor = new BooleanValuePairEditor(view);
AnnotationValuePairDefinition valuePairDefinition = annotationDefinition.getValuePair("booleanParam1");
booleanEditor.init(valuePairDefinition);
verify(view, times(1)).initOptions(options);
verify(view, times(1)).setValuePairLabel(valuePairDefinition.getName());
verify(view, times(1)).showValuePairRequiredIndicator(false);
}
Aggregations