Search in sources :

Example 1 with AnnotationValuePairDefinition

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;
}
Also used : GenerationTools(org.kie.workbench.common.services.datamodeller.codegen.GenerationTools) AnnotationDefinition(org.kie.workbench.common.services.datamodeller.core.AnnotationDefinition) AnnotationValuePairDefinition(org.kie.workbench.common.services.datamodeller.core.AnnotationValuePairDefinition) AnnotationSource(org.jboss.forge.roaster.model.source.AnnotationSource) DataObject(org.kie.workbench.common.services.datamodeller.core.DataObject)

Example 2 with AnnotationValuePairDefinition

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);
}
Also used : Entity(javax.persistence.Entity) AnnotationDefinitionRequest(org.kie.workbench.common.services.datamodeller.driver.model.AnnotationDefinitionRequest) AnnotationDefinitionResponse(org.kie.workbench.common.services.datamodeller.driver.model.AnnotationDefinitionResponse) AnnotationImpl(org.kie.workbench.common.services.datamodeller.core.impl.AnnotationImpl) Annotation(org.kie.workbench.common.services.datamodeller.core.Annotation) AnnotationValuePairDefinition(org.kie.workbench.common.services.datamodeller.core.AnnotationValuePairDefinition) Test(org.junit.Test)

Example 3 with AnnotationValuePairDefinition

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);
}
Also used : AnnotationDefinition(org.kie.workbench.common.services.datamodeller.core.AnnotationDefinition) DataModelerService(org.kie.workbench.common.screens.datamodeller.service.DataModelerService) AnnotationValuePairDefinition(org.kie.workbench.common.services.datamodeller.core.AnnotationValuePairDefinition) Test(org.junit.Test)

Example 4 with AnnotationValuePairDefinition

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);
}
Also used : AnnotationDefinition(org.kie.workbench.common.services.datamodeller.core.AnnotationDefinition) DataModelerService(org.kie.workbench.common.screens.datamodeller.service.DataModelerService) AnnotationValuePairDefinition(org.kie.workbench.common.services.datamodeller.core.AnnotationValuePairDefinition) Test(org.junit.Test)

Example 5 with AnnotationValuePairDefinition

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);
}
Also used : AnnotationValuePairDefinition(org.kie.workbench.common.services.datamodeller.core.AnnotationValuePairDefinition) Test(org.junit.Test)

Aggregations

AnnotationValuePairDefinition (org.kie.workbench.common.services.datamodeller.core.AnnotationValuePairDefinition)33 Test (org.junit.Test)22 ArrayList (java.util.ArrayList)8 AnnotationDefinition (org.kie.workbench.common.services.datamodeller.core.AnnotationDefinition)8 DataObject (org.kie.workbench.common.services.datamodeller.core.DataObject)4 AnnotationImpl (org.kie.workbench.common.services.datamodeller.core.impl.AnnotationImpl)4 AnnotationSource (org.jboss.forge.roaster.model.source.AnnotationSource)3 DataModelerService (org.kie.workbench.common.screens.datamodeller.service.DataModelerService)3 Annotation (org.kie.workbench.common.services.datamodeller.core.Annotation)3 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Entity (javax.persistence.Entity)1 ValuePair (org.jboss.forge.roaster.model.ValuePair)1 AdvancedAnnotationListEditorView (org.kie.workbench.common.screens.datamodeller.client.widgets.advanceddomain.annotationlisteditor.AdvancedAnnotationListEditorView)1 GenerationTools (org.kie.workbench.common.services.datamodeller.codegen.GenerationTools)1 AnnotationDefinitionRequest (org.kie.workbench.common.services.datamodeller.driver.model.AnnotationDefinitionRequest)1 AnnotationDefinitionResponse (org.kie.workbench.common.services.datamodeller.driver.model.AnnotationDefinitionResponse)1 AnnotationDescr (org.kie.workbench.common.services.datamodeller.parser.descr.AnnotationDescr)1 ElementValueDescr (org.kie.workbench.common.services.datamodeller.parser.descr.ElementValueDescr)1 ElementValuePairDescr (org.kie.workbench.common.services.datamodeller.parser.descr.ElementValuePairDescr)1