Search in sources :

Example 1 with TestScenarioResult

use of org.drools.workbench.screens.testscenario.model.TestScenarioResult in project drools-wb by kiegroup.

the class ScenarioTestEditorServiceImpl method runScenario.

@Override
public TestScenarioResult runScenario(final String userName, final Path path, final Scenario scenario) {
    final Imports existingScenarioImports = new Imports(scenario.getImports().getImports());
    try {
        addDependentImportsToScenario(scenario, path);
        final TestScenarioResult result = scenarioRunner.run(userName, scenario, moduleService.resolveModule(path));
        return result;
    } catch (final Exception e) {
        throw ExceptionUtilities.handleException(e);
    } finally {
        scenario.setImports(existingScenarioImports);
    }
}
Also used : Imports(org.kie.soup.project.datamodel.imports.Imports) TestScenarioResult(org.drools.workbench.screens.testscenario.model.TestScenarioResult) FileAlreadyExistsException(org.uberfire.java.nio.file.FileAlreadyExistsException)

Example 2 with TestScenarioResult

use of org.drools.workbench.screens.testscenario.model.TestScenarioResult in project drools-wb by kiegroup.

the class ScenarioEditorPresenterTest method setUp.

@Before
public void setUp() throws Exception {
    final AsyncPackageDataModelOracleFactory modelOracleFactory = mock(AsyncPackageDataModelOracleFactory.class);
    fakeService = new CallerMock<>(service);
    editor = spy(new ScenarioEditorPresenter(view, user, importsWidget, fakeService, new CallerMock<>(testService), new TestScenarioResourceType(new Others()), modelOracleFactory, settingsPage, auditPage) {

        {
            kieView = ScenarioEditorPresenterTest.this.kieView;
            versionRecordManager = ScenarioEditorPresenterTest.this.versionRecordManager;
            overviewWidget = ScenarioEditorPresenterTest.this.overviewWidget;
            notification = makeNotificationEvent();
            fileMenuBuilder = ScenarioEditorPresenterTest.this.fileMenuBuilder;
            projectController = ScenarioEditorPresenterTest.this.projectController;
            workbenchContext = ScenarioEditorPresenterTest.this.workbenchContext;
            versionRecordManager = ScenarioEditorPresenterTest.this.versionRecordManager;
            alertsButtonMenuItemBuilder = ScenarioEditorPresenterTest.this.alertsButtonMenuItemBuilder;
        }

        @Override
        protected Command getSaveAndRename() {
            return mock(Command.class);
        }
    });
    scenarioRunResult = new Scenario();
    scenario = new Scenario();
    overview = new Overview();
    when(user.getIdentifier()).thenReturn("userName");
    when(workbenchContext.getActiveOrganizationalUnit()).thenReturn(Optional.empty());
    when(workbenchContext.getActiveWorkspaceProject()).thenReturn(Optional.empty());
    final TestScenarioModelContent testScenarioModelContent = new TestScenarioModelContent(scenario, overview, "org.test", new PackageDataModelOracleBaselinePayload());
    when(service.loadContent(any(Path.class))).thenReturn(testScenarioModelContent);
    final TestScenarioResult result = new TestScenarioResult(scenarioRunResult, Collections.EMPTY_SET);
    when(service.runScenario(eq("userName"), any(Path.class), eq(scenario))).thenReturn(result);
    final AsyncPackageDataModelOracle dmo = mock(AsyncPackageDataModelOracle.class);
    when(modelOracleFactory.makeAsyncPackageDataModelOracle(any(Path.class), any(HasImports.class), any(PackageDataModelOracleBaselinePayload.class))).thenReturn(dmo);
    when(alertsButtonMenuItemBuilder.build()).thenReturn(alertsButtonMenuItem);
}
Also used : ObservablePath(org.uberfire.backend.vfs.ObservablePath) Path(org.uberfire.backend.vfs.Path) AsyncPackageDataModelOracle(org.kie.workbench.common.widgets.client.datamodel.AsyncPackageDataModelOracle) Others(org.uberfire.workbench.category.Others) TestScenarioModelContent(org.drools.workbench.screens.testscenario.model.TestScenarioModelContent) TestScenarioResourceType(org.drools.workbench.screens.testscenario.client.type.TestScenarioResourceType) Overview(org.guvnor.common.services.shared.metadata.model.Overview) TestScenarioResult(org.drools.workbench.screens.testscenario.model.TestScenarioResult) Scenario(org.drools.workbench.models.testscenarios.shared.Scenario) AsyncPackageDataModelOracleFactory(org.kie.workbench.common.widgets.client.datamodel.AsyncPackageDataModelOracleFactory) PackageDataModelOracleBaselinePayload(org.kie.workbench.common.services.datamodel.model.PackageDataModelOracleBaselinePayload) HasImports(org.kie.soup.project.datamodel.imports.HasImports) Before(org.junit.Before)

Example 3 with TestScenarioResult

use of org.drools.workbench.screens.testscenario.model.TestScenarioResult in project drools-wb by kiegroup.

the class ScenarioRunnerServiceTest method testRunEmptyScenario.

@Test
public void testRunEmptyScenario() throws Exception {
    initKieSession();
    TestScenarioResult result = service.run("userName", makeScenario("test.scenario"), new KieModule());
    assertNotNull(result);
    ArgumentCaptor<TestResultMessage> argumentCaptor = ArgumentCaptor.forClass(TestResultMessage.class);
    verify(defaultTestResultMessageEvent).fire(argumentCaptor.capture());
    assertEquals("userName", argumentCaptor.getValue().getIdentifier());
}
Also used : TestResultMessage(org.guvnor.common.services.shared.test.TestResultMessage) TestScenarioResult(org.drools.workbench.screens.testscenario.model.TestScenarioResult) KieModule(org.kie.workbench.common.services.shared.project.KieModule) Test(org.junit.Test)

Example 4 with TestScenarioResult

use of org.drools.workbench.screens.testscenario.model.TestScenarioResult in project drools-wb by kiegroup.

the class ScenarioRunnerService method run.

public TestScenarioResult run(final String identifier, final Scenario scenario, final KieModule module) {
    try {
        final HashMap<String, KieSession> ksessions = new HashMap<String, KieSession>();
        final String ksessionName = getKSessionName(scenario.getKSessions());
        ksessions.put(ksessionName, loadKSession(module, ksessionName));
        final AuditLogger auditLogger = new AuditLogger(ksessions);
        final ScenarioRunner4JUnit scenarioRunner = new ScenarioRunner4JUnit(scenario, ksessions, getMaxRuleFirings());
        run(identifier, scenarioRunner, defaultTestResultMessageEvent);
        return new TestScenarioResult(scenario, auditLogger.getLog());
    } catch (InitializationError initializationError) {
        throw new GenericPortableException(initializationError.getMessage());
    }
}
Also used : HashMap(java.util.HashMap) InitializationError(org.junit.runners.model.InitializationError) GenericPortableException(org.guvnor.common.services.shared.exceptions.GenericPortableException) KieSession(org.kie.api.runtime.KieSession) ScenarioRunner4JUnit(org.drools.workbench.models.testscenarios.backend.ScenarioRunner4JUnit) TestScenarioResult(org.drools.workbench.screens.testscenario.model.TestScenarioResult)

Example 5 with TestScenarioResult

use of org.drools.workbench.screens.testscenario.model.TestScenarioResult in project drools-wb by kiegroup.

the class ScenarioRunnerServiceTest method testScenario.

private void testScenario(String scenarioName, boolean isExpectedSuccess) throws Exception {
    final KieModule module = mock(KieModule.class);
    final URL scenarioResource = getClass().getResource(scenarioName);
    final Path scenarioPath = PathFactory.newPath(scenarioResource.getFile(), scenarioResource.toURI().toString());
    final Scenario scenario = testEditorService.load(scenarioPath);
    assertFalse(scenario.wasSuccessful());
    final TestScenarioResult result = service.run("userName", scenario, module);
    assertEquals(isExpectedSuccess, scenario.wasSuccessful());
    assertEquals(isExpectedSuccess, result.getScenario().wasSuccessful());
    verify(defaultTestResultMessageEvent).fire(testResultMessageCaptor.capture());
    final TestResultMessage resultMessage = testResultMessageCaptor.getValue();
    assertEquals(isExpectedSuccess, resultMessage.getFailures().size() == 0);
    assertEquals(isExpectedSuccess, resultMessage.wasSuccessful());
}
Also used : Path(org.uberfire.backend.vfs.Path) TestResultMessage(org.guvnor.common.services.shared.test.TestResultMessage) TestScenarioResult(org.drools.workbench.screens.testscenario.model.TestScenarioResult) KieModule(org.kie.workbench.common.services.shared.project.KieModule) URL(java.net.URL) Scenario(org.drools.workbench.models.testscenarios.shared.Scenario)

Aggregations

TestScenarioResult (org.drools.workbench.screens.testscenario.model.TestScenarioResult)5 Scenario (org.drools.workbench.models.testscenarios.shared.Scenario)2 TestResultMessage (org.guvnor.common.services.shared.test.TestResultMessage)2 KieModule (org.kie.workbench.common.services.shared.project.KieModule)2 Path (org.uberfire.backend.vfs.Path)2 URL (java.net.URL)1 HashMap (java.util.HashMap)1 ScenarioRunner4JUnit (org.drools.workbench.models.testscenarios.backend.ScenarioRunner4JUnit)1 TestScenarioResourceType (org.drools.workbench.screens.testscenario.client.type.TestScenarioResourceType)1 TestScenarioModelContent (org.drools.workbench.screens.testscenario.model.TestScenarioModelContent)1 GenericPortableException (org.guvnor.common.services.shared.exceptions.GenericPortableException)1 Overview (org.guvnor.common.services.shared.metadata.model.Overview)1 Before (org.junit.Before)1 Test (org.junit.Test)1 InitializationError (org.junit.runners.model.InitializationError)1 KieSession (org.kie.api.runtime.KieSession)1 HasImports (org.kie.soup.project.datamodel.imports.HasImports)1 Imports (org.kie.soup.project.datamodel.imports.Imports)1 PackageDataModelOracleBaselinePayload (org.kie.workbench.common.services.datamodel.model.PackageDataModelOracleBaselinePayload)1 AsyncPackageDataModelOracle (org.kie.workbench.common.widgets.client.datamodel.AsyncPackageDataModelOracle)1