use of org.kie.workbench.common.services.datamodeller.driver.model.AnnotationDefinitionRequest 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.driver.model.AnnotationDefinitionRequest 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);
}
use of org.kie.workbench.common.services.datamodeller.driver.model.AnnotationDefinitionRequest in project kie-wb-common by kiegroup.
the class SearchAnnotationPage method onSearchClass.
@Override
public void onSearchClass() {
AnnotationDefinitionRequest definitionRequest = new AnnotationDefinitionRequest(DataModelerUtils.trim(view.getClassName()));
modelerService.call(getOnSearchClassSuccessCallback(definitionRequest)).resolveDefinitionRequest(definitionRequest, project);
}
use of org.kie.workbench.common.services.datamodeller.driver.model.AnnotationDefinitionRequest 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());
}
Aggregations