Search in sources :

Example 1 with AnnotationDefinitionResponse

use of org.kie.workbench.common.services.datamodeller.driver.model.AnnotationDefinitionResponse in project kie-wb-common by kiegroup.

the class DataModelerServiceImpl method resolveDefinitionRequest.

@Override
public AnnotationDefinitionResponse resolveDefinitionRequest(AnnotationDefinitionRequest definitionRequest, KieModule kieModule) {
    JavaRoasterModelDriver modelDriver = new JavaRoasterModelDriver();
    ClassLoader classLoader = classLoaderHelper.getModuleClassLoader(kieModule);
    ClassTypeResolver classTypeResolver = DriverUtils.createClassTypeResolver(classLoader);
    AnnotationDefinitionResponse definitionResponse = new AnnotationDefinitionResponse();
    try {
        AnnotationDefinition annotationDefinition = modelDriver.buildAnnotationDefinition(definitionRequest.getClassName(), classTypeResolver);
        definitionResponse.withAnnotationDefinition(annotationDefinition);
    } catch (ModelDriverException e) {
        DriverError driverError = new DriverError(e.getMessage());
        definitionResponse.addError(driverError);
    }
    return definitionResponse;
}
Also used : AnnotationDefinition(org.kie.workbench.common.services.datamodeller.core.AnnotationDefinition) AnnotationDefinitionResponse(org.kie.workbench.common.services.datamodeller.driver.model.AnnotationDefinitionResponse) ModelDriverException(org.kie.workbench.common.services.datamodeller.driver.ModelDriverException) ClassTypeResolver(org.kie.soup.project.datamodel.commons.types.ClassTypeResolver) JavaRoasterModelDriver(org.kie.workbench.common.services.datamodeller.driver.impl.JavaRoasterModelDriver) DriverError(org.kie.workbench.common.services.datamodeller.driver.model.DriverError)

Example 2 with AnnotationDefinitionResponse

use of org.kie.workbench.common.services.datamodeller.driver.model.AnnotationDefinitionResponse 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 AnnotationDefinitionResponse

use of org.kie.workbench.common.services.datamodeller.driver.model.AnnotationDefinitionResponse in project kie-wb-common by kiegroup.

the class SearchAnnotationPageTest method testSearchAnnotationNotFound.

@Test
public void testSearchAnnotationNotFound() {
    modelerServiceCaller = new CallerMock<DataModelerService>(modelerService);
    SearchAnnotationPage searchPage = new SearchAnnotationPage(view, modelerServiceCaller, wizardPageStatusChangeEvent);
    searchPage.init(kieModule, ElementType.FIELD);
    searchPage.prepareView();
    searchPage.addSearchAnnotationHandler(searchAnnotationHandler);
    // emulates the user is typing
    searchPage.onSearchClassChanged();
    // the wizard page should be automatically invalidated since the annotation class name to search
    // has changed.
    verify(wizardPageStatusChangeEvent, times(1)).fire(any(WizardPageStatusChangeEvent.class));
    WizardTestUtil.assertPageComplete(false, searchPage);
    assertEquals(CreateAnnotationWizardPage.PageStatus.NOT_VALIDATED, searchPage.getStatus());
    // the handler should also have been invocked.
    verify(searchAnnotationHandler, times(1)).onSearchClassChanged();
    // emulate the user is searching the javax.persistence.Entity annotation.
    AnnotationDefinitionRequest request = new AnnotationDefinitionRequest(Entity.class.getName());
    // empty response was returned
    AnnotationDefinitionResponse response = new AnnotationDefinitionResponse(null);
    when(view.getClassName()).thenReturn(Entity.class.getName());
    when(modelerService.resolveDefinitionRequest(request, kieModule)).thenReturn(response);
    // emulate the user click on the search button
    searchPage.onSearchClass();
    // now the page should be completed
    WizardTestUtil.assertPageComplete(false, searchPage);
    verify(wizardPageStatusChangeEvent, times(2)).fire(any(WizardPageStatusChangeEvent.class));
    // the handler should also have been invoked with the expected annotation definition.
    verify(searchAnnotationHandler, times(1)).onAnnotationDefinitionChange(null);
}
Also used : Entity(javax.persistence.Entity) DataModelerService(org.kie.workbench.common.screens.datamodeller.service.DataModelerService) AnnotationDefinitionRequest(org.kie.workbench.common.services.datamodeller.driver.model.AnnotationDefinitionRequest) AnnotationDefinitionResponse(org.kie.workbench.common.services.datamodeller.driver.model.AnnotationDefinitionResponse) WizardPageStatusChangeEvent(org.uberfire.ext.widgets.core.client.wizards.WizardPageStatusChangeEvent) Test(org.junit.Test)

Example 4 with AnnotationDefinitionResponse

use of org.kie.workbench.common.services.datamodeller.driver.model.AnnotationDefinitionResponse in project kie-wb-common by kiegroup.

the class SearchAnnotationPageTest method testSearchAnnotationFound.

@Test
public void testSearchAnnotationFound() {
    modelerServiceCaller = new CallerMock<DataModelerService>(modelerService);
    SearchAnnotationPage searchPage = new SearchAnnotationPage(view, modelerServiceCaller, wizardPageStatusChangeEvent);
    searchPage.init(kieModule, ElementType.FIELD);
    searchPage.prepareView();
    searchPage.addSearchAnnotationHandler(searchAnnotationHandler);
    // emulates the user is typing
    searchPage.onSearchClassChanged();
    // the wizard page should be automatically invalidated since the annotation class name to search
    // has changed.
    verify(wizardPageStatusChangeEvent, times(1)).fire(any(WizardPageStatusChangeEvent.class));
    WizardTestUtil.assertPageComplete(false, searchPage);
    assertEquals(CreateAnnotationWizardPage.PageStatus.NOT_VALIDATED, searchPage.getStatus());
    // the handler should also have been invocked.
    verify(searchAnnotationHandler, times(1)).onSearchClassChanged();
    // 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(view.getClassName()).thenReturn(Entity.class.getName());
    when(modelerService.resolveDefinitionRequest(request, kieModule)).thenReturn(response);
    // emulate the user click on the search button
    searchPage.onSearchClass();
    // now the page should be completed
    WizardTestUtil.assertPageComplete(true, searchPage);
    verify(wizardPageStatusChangeEvent, times(2)).fire(any(WizardPageStatusChangeEvent.class));
    // the handler should also have been invoked with the expected annotation definition.
    verify(searchAnnotationHandler, times(1)).onAnnotationDefinitionChange(response.getAnnotationDefinition());
}
Also used : Entity(javax.persistence.Entity) DataModelerService(org.kie.workbench.common.screens.datamodeller.service.DataModelerService) AnnotationDefinitionRequest(org.kie.workbench.common.services.datamodeller.driver.model.AnnotationDefinitionRequest) AnnotationDefinitionResponse(org.kie.workbench.common.services.datamodeller.driver.model.AnnotationDefinitionResponse) WizardPageStatusChangeEvent(org.uberfire.ext.widgets.core.client.wizards.WizardPageStatusChangeEvent) Test(org.junit.Test)

Aggregations

AnnotationDefinitionResponse (org.kie.workbench.common.services.datamodeller.driver.model.AnnotationDefinitionResponse)4 Entity (javax.persistence.Entity)3 Test (org.junit.Test)3 AnnotationDefinitionRequest (org.kie.workbench.common.services.datamodeller.driver.model.AnnotationDefinitionRequest)3 DataModelerService (org.kie.workbench.common.screens.datamodeller.service.DataModelerService)2 WizardPageStatusChangeEvent (org.uberfire.ext.widgets.core.client.wizards.WizardPageStatusChangeEvent)2 ClassTypeResolver (org.kie.soup.project.datamodel.commons.types.ClassTypeResolver)1 Annotation (org.kie.workbench.common.services.datamodeller.core.Annotation)1 AnnotationDefinition (org.kie.workbench.common.services.datamodeller.core.AnnotationDefinition)1 AnnotationValuePairDefinition (org.kie.workbench.common.services.datamodeller.core.AnnotationValuePairDefinition)1 AnnotationImpl (org.kie.workbench.common.services.datamodeller.core.impl.AnnotationImpl)1 ModelDriverException (org.kie.workbench.common.services.datamodeller.driver.ModelDriverException)1 JavaRoasterModelDriver (org.kie.workbench.common.services.datamodeller.driver.impl.JavaRoasterModelDriver)1 DriverError (org.kie.workbench.common.services.datamodeller.driver.model.DriverError)1