use of org.kie.workbench.common.screens.datamodeller.service.DataModelerService in project kie-wb-common by kiegroup.
the class DomainEditorBaseTest method initTest.
@Before
public void initTest() {
List<DomainHandler> domainHandlers = new ArrayList<>();
domainHandlers.add(jpaDomainHandler);
when(jpaDomainHandler.getName()).thenReturn("JPA");
when(jpaDomainHandler.isDataObjectAuditEnabled()).thenReturn(false);
when(handlerRegistry.getDomainHandlers()).thenReturn(domainHandlers);
when(handlerRegistry.getDomainHandlers(anyList())).thenReturn(domainHandlers);
when(handlerRegistry.getDomainHandlers(anyString())).thenReturn(domainHandlers);
changeNotifier = new DataModelChangeNotifier(dataModelerEvent);
commandBuilder = new DataModelCommandBuilder(changeNotifier);
modelerServiceCaller = new CallerMock<DataModelerService>(modelerService);
validationServiceCallerMock = new CallerMock<ValidationService>(validationService);
validatorService = new ValidatorService(validationServiceCallerMock);
context = createContext();
}
use of org.kie.workbench.common.screens.datamodeller.service.DataModelerService 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.screens.datamodeller.service.DataModelerService 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.screens.datamodeller.service.DataModelerService 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.screens.datamodeller.service.DataModelerService 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