Search in sources :

Example 1 with ValidationService

use of org.kie.workbench.common.services.shared.validation.ValidationService in project kie-wb-common by kiegroup.

the class GeneralSettingsPresenterTest method testExecuteValidationFailing.

@Test
public void testExecuteValidationFailing() {
    final POM pom = mock(POM.class);
    doReturn(false).when(validationService).validate(eq(pom));
    generalSettingsPresenter.executeValidation(s -> s.validate(pom), "Test message").then(valid -> {
        Assert.fail("Promise should've been resolved!");
        return promises.resolve();
    }).catch_(e -> {
        verify(validationService).validate(eq(pom));
        Assert.assertEquals(e, "Test message");
        return promises.resolve();
    });
}
Also used : GAVPreferences(org.guvnor.common.services.project.preferences.GAVPreferences) CallerMock(org.uberfire.mocks.CallerMock) Mock(org.mockito.Mock) Promises(org.uberfire.client.promise.Promises) GAV(org.guvnor.common.services.project.model.GAV) SettingsPresenter(org.kie.workbench.common.screens.library.client.settings.SettingsPresenter) RunWith(org.junit.runner.RunWith) PreferenceScopeResolutionStrategyInfo(org.uberfire.preferences.shared.impl.PreferenceScopeResolutionStrategyInfo) ProjectScopedResolutionStrategySupplier(org.guvnor.common.services.project.client.preferences.ProjectScopedResolutionStrategySupplier) Mockito.spy(org.mockito.Mockito.spy) SettingsSectionChange(org.kie.workbench.common.screens.library.client.settings.SettingsSectionChange) POM(org.guvnor.common.services.project.model.POM) Matchers.eq(org.mockito.Matchers.eq) SyncPromises(org.uberfire.promise.SyncPromises) Mockito.doReturn(org.mockito.Mockito.doReturn) Before(org.junit.Before) ValidationService(org.kie.workbench.common.services.shared.validation.ValidationService) ProjectScreenModel(org.kie.workbench.common.screens.projecteditor.model.ProjectScreenModel) Test(org.junit.Test) Mockito.verify(org.mockito.Mockito.verify) Matchers.any(org.mockito.Matchers.any) Mockito.never(org.mockito.Mockito.never) MockitoJUnitRunner(org.mockito.runners.MockitoJUnitRunner) EventSourceMock(org.uberfire.mocks.EventSourceMock) Assert(org.junit.Assert) Mockito.mock(org.mockito.Mockito.mock) POM(org.guvnor.common.services.project.model.POM) Test(org.junit.Test)

Example 2 with ValidationService

use of org.kie.workbench.common.services.shared.validation.ValidationService in project kie-wb-common by kiegroup.

the class GeneralSettingsPresenterTest method testExecuteValidation.

@Test
public void testExecuteValidation() {
    final POM pom = mock(POM.class);
    doReturn(true).when(validationService).validate(eq(pom));
    generalSettingsPresenter.executeValidation(s -> s.validate(pom), "Test message").then(valid -> {
        verify(validationService).validate(eq(pom));
        Assert.assertEquals(valid, true);
        return promises.resolve();
    }).catch_(e -> {
        Assert.fail("Promise should've been resolved!");
        return promises.resolve();
    });
}
Also used : GAVPreferences(org.guvnor.common.services.project.preferences.GAVPreferences) CallerMock(org.uberfire.mocks.CallerMock) Mock(org.mockito.Mock) Promises(org.uberfire.client.promise.Promises) GAV(org.guvnor.common.services.project.model.GAV) SettingsPresenter(org.kie.workbench.common.screens.library.client.settings.SettingsPresenter) RunWith(org.junit.runner.RunWith) PreferenceScopeResolutionStrategyInfo(org.uberfire.preferences.shared.impl.PreferenceScopeResolutionStrategyInfo) ProjectScopedResolutionStrategySupplier(org.guvnor.common.services.project.client.preferences.ProjectScopedResolutionStrategySupplier) Mockito.spy(org.mockito.Mockito.spy) SettingsSectionChange(org.kie.workbench.common.screens.library.client.settings.SettingsSectionChange) POM(org.guvnor.common.services.project.model.POM) Matchers.eq(org.mockito.Matchers.eq) SyncPromises(org.uberfire.promise.SyncPromises) Mockito.doReturn(org.mockito.Mockito.doReturn) Before(org.junit.Before) ValidationService(org.kie.workbench.common.services.shared.validation.ValidationService) ProjectScreenModel(org.kie.workbench.common.screens.projecteditor.model.ProjectScreenModel) Test(org.junit.Test) Mockito.verify(org.mockito.Mockito.verify) Matchers.any(org.mockito.Matchers.any) Mockito.never(org.mockito.Mockito.never) MockitoJUnitRunner(org.mockito.runners.MockitoJUnitRunner) EventSourceMock(org.uberfire.mocks.EventSourceMock) Assert(org.junit.Assert) Mockito.mock(org.mockito.Mockito.mock) POM(org.guvnor.common.services.project.model.POM) Test(org.junit.Test)

Example 3 with ValidationService

use of org.kie.workbench.common.services.shared.validation.ValidationService 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 4 with ValidationService

use of org.kie.workbench.common.services.shared.validation.ValidationService in project kie-wb-common by kiegroup.

the class POMWizardPageTest method setUp.

@Before
@SuppressWarnings("unchecked")
public void setUp() throws Exception {
    gavEditor = new GAVEditor(gavEditorView);
    pomEditor = spy(new POMEditorPanel(pomEditorView, syncBeanManager, gavPreferences, projectScopedResolutionStrategySupplier));
    // POMEditorView implementation updates a nested GAVEditor presenter. Mock the implementation to avoid use of real widgets
    doAnswer(new Answer<Void>() {

        @Override
        public Void answer(final InvocationOnMock invocation) throws Throwable {
            final String artifactId = (String) invocation.getArguments()[0];
            gavEditor.setArtifactID(artifactId);
            return null;
        }
    }).when(pomEditorView).setArtifactID(any(String.class));
    // POMEditorView implementation updates a nested GAVEditor presenter. Mock the implementation to avoid use of real widgets
    doAnswer(new Answer<Void>() {

        @Override
        public Void answer(final InvocationOnMock invocation) throws Throwable {
            final GAV gav = (GAV) invocation.getArguments()[0];
            gavEditor.setGAV(gav);
            return null;
        }
    }).when(pomEditorView).setGAV(any(GAV.class));
    // POMEditorView implementation updates a nested GAVEditor presenter. Mock the implementation to avoid use of real widgets
    doAnswer(new Answer<Void>() {

        @Override
        public Void answer(final InvocationOnMock invocation) throws Throwable {
            final ArtifactIdChangeHandler handler = (ArtifactIdChangeHandler) invocation.getArguments()[0];
            gavEditor.addArtifactIdChangeHandler(handler);
            return null;
        }
    }).when(pomEditorView).addArtifactIdChangeHandler(any(ArtifactIdChangeHandler.class));
    page = spy(new POMWizardPage(pomEditor, view, event, new CallerMock<ProjectScreenService>(projectScreenService), new CallerMock<ValidationService>(validationService)));
    page.initialise();
    doAnswer(invocationOnMock -> {
        ((ParameterizedCommand<GAVPreferences>) invocationOnMock.getArguments()[1]).execute(gavPreferences);
        return null;
    }).when(gavPreferences).load(any(PreferenceScopeResolutionStrategyInfo.class), any(ParameterizedCommand.class), any(ParameterizedCommand.class));
}
Also used : POMEditorPanel(org.guvnor.common.services.project.client.POMEditorPanel) ArtifactIdChangeHandler(org.guvnor.common.services.project.client.ArtifactIdChangeHandler) InvocationOnMock(org.mockito.invocation.InvocationOnMock) PreferenceScopeResolutionStrategyInfo(org.uberfire.preferences.shared.impl.PreferenceScopeResolutionStrategyInfo) GAVEditor(org.guvnor.common.services.project.client.GAVEditor) ValidationService(org.kie.workbench.common.services.shared.validation.ValidationService) ProjectScreenService(org.kie.workbench.common.screens.projecteditor.service.ProjectScreenService) GAV(org.guvnor.common.services.project.model.GAV) ParameterizedCommand(org.uberfire.mvp.ParameterizedCommand) Before(org.junit.Before)

Example 5 with ValidationService

use of org.kie.workbench.common.services.shared.validation.ValidationService in project kie-wb-common by kiegroup.

the class NewPackagePopupTest method initTest.

@Before
public void initTest() {
    validationServiceCallerMock = new CallerMock<ValidationService>(validationService);
    validatorService = new ValidatorService(validationServiceCallerMock);
}
Also used : ValidatorService(org.kie.workbench.common.screens.datamodeller.client.validation.ValidatorService) ValidationService(org.kie.workbench.common.services.shared.validation.ValidationService) Before(org.junit.Before)

Aggregations

Before (org.junit.Before)5 ValidationService (org.kie.workbench.common.services.shared.validation.ValidationService)5 GAV (org.guvnor.common.services.project.model.GAV)3 PreferenceScopeResolutionStrategyInfo (org.uberfire.preferences.shared.impl.PreferenceScopeResolutionStrategyInfo)3 ProjectScopedResolutionStrategySupplier (org.guvnor.common.services.project.client.preferences.ProjectScopedResolutionStrategySupplier)2 POM (org.guvnor.common.services.project.model.POM)2 GAVPreferences (org.guvnor.common.services.project.preferences.GAVPreferences)2 Assert (org.junit.Assert)2 Test (org.junit.Test)2 RunWith (org.junit.runner.RunWith)2 ValidatorService (org.kie.workbench.common.screens.datamodeller.client.validation.ValidatorService)2 SettingsPresenter (org.kie.workbench.common.screens.library.client.settings.SettingsPresenter)2 SettingsSectionChange (org.kie.workbench.common.screens.library.client.settings.SettingsSectionChange)2 ProjectScreenModel (org.kie.workbench.common.screens.projecteditor.model.ProjectScreenModel)2 Matchers.any (org.mockito.Matchers.any)2 Matchers.eq (org.mockito.Matchers.eq)2 Mock (org.mockito.Mock)2 Mockito.doReturn (org.mockito.Mockito.doReturn)2 Mockito.mock (org.mockito.Mockito.mock)2 Mockito.never (org.mockito.Mockito.never)2