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