Search in sources :

Example 1 with DataModelerService

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();
}
Also used : DataModelCommandBuilder(org.kie.workbench.common.screens.datamodeller.client.command.DataModelCommandBuilder) DataModelerService(org.kie.workbench.common.screens.datamodeller.service.DataModelerService) DataModelChangeNotifier(org.kie.workbench.common.screens.datamodeller.client.command.DataModelChangeNotifier) ValidatorService(org.kie.workbench.common.screens.datamodeller.client.validation.ValidatorService) ArrayList(java.util.ArrayList) DomainHandler(org.kie.workbench.common.screens.datamodeller.client.handlers.DomainHandler) JPADomainHandler(org.kie.workbench.common.screens.datamodeller.client.handlers.jpadomain.JPADomainHandler) ValidationService(org.kie.workbench.common.services.shared.validation.ValidationService) Before(org.junit.Before)

Example 2 with DataModelerService

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);
}
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 3 with DataModelerService

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);
}
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 DataModelerService

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);
}
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 5 with DataModelerService

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());
}
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

DataModelerService (org.kie.workbench.common.screens.datamodeller.service.DataModelerService)6 Test (org.junit.Test)5 AnnotationDefinition (org.kie.workbench.common.services.datamodeller.core.AnnotationDefinition)3 AnnotationValuePairDefinition (org.kie.workbench.common.services.datamodeller.core.AnnotationValuePairDefinition)3 Entity (javax.persistence.Entity)2 AnnotationDefinitionRequest (org.kie.workbench.common.services.datamodeller.driver.model.AnnotationDefinitionRequest)2 AnnotationDefinitionResponse (org.kie.workbench.common.services.datamodeller.driver.model.AnnotationDefinitionResponse)2 WizardPageStatusChangeEvent (org.uberfire.ext.widgets.core.client.wizards.WizardPageStatusChangeEvent)2 ArrayList (java.util.ArrayList)1 Before (org.junit.Before)1 DataModelChangeNotifier (org.kie.workbench.common.screens.datamodeller.client.command.DataModelChangeNotifier)1 DataModelCommandBuilder (org.kie.workbench.common.screens.datamodeller.client.command.DataModelCommandBuilder)1 DomainHandler (org.kie.workbench.common.screens.datamodeller.client.handlers.DomainHandler)1 JPADomainHandler (org.kie.workbench.common.screens.datamodeller.client.handlers.jpadomain.JPADomainHandler)1 ValidatorService (org.kie.workbench.common.screens.datamodeller.client.validation.ValidatorService)1 ValidationService (org.kie.workbench.common.services.shared.validation.ValidationService)1