Search in sources :

Example 21 with Settings

use of org.drools.scenariosimulation.api.model.Settings in project drools-wb by kiegroup.

the class ScenarioSimulationServiceImpl method load.

@Override
public ScenarioSimulationModel load(final Path path) {
    try {
        final String content = ioService.readAllString(Paths.convert(path));
        final ScenarioSimulationModel scenarioSimulationModel = unmarshalInternal(content);
        final Settings settings = scenarioSimulationModel.getSettings();
        if (settings != null && DMN.equals(settings.getType())) {
            try {
                dmnTypeService.initializeNameAndNamespace(settings, path, settings.getDmnFilePath());
            } catch (ImpossibleToFindDMNException e) {
                // this error is not thrown so user can fix the file path manually
                logger.error(e.getMessage(), e);
            }
        }
        return scenarioSimulationModel;
    } catch (Exception e) {
        throw ExceptionUtilities.handleException(e);
    }
}
Also used : ImpossibleToFindDMNException(org.drools.scenariosimulation.backend.util.ImpossibleToFindDMNException) ScenarioSimulationModel(org.drools.scenariosimulation.api.model.ScenarioSimulationModel) Settings(org.drools.scenariosimulation.api.model.Settings) ImpossibleToFindDMNException(org.drools.scenariosimulation.backend.util.ImpossibleToFindDMNException) IOException(java.io.IOException) FileAlreadyExistsException(org.uberfire.java.nio.file.FileAlreadyExistsException)

Example 22 with Settings

use of org.drools.scenariosimulation.api.model.Settings in project drools-wb by kiegroup.

the class ScenarioValidationServiceTest method validateSimulationStructure.

@Test
public void validateSimulationStructure() {
    Simulation simulation = new Simulation();
    Settings settings = new Settings();
    ScenarioValidationService scenarioValidationServiceSpy = spy(new ScenarioValidationService() {

        @Override
        protected List<FactMappingValidationError> validateDMN(Simulation simulation, Settings settings, KieContainer kieContainer) {
            return Collections.emptyList();
        }

        @Override
        protected List<FactMappingValidationError> validateRULE(Simulation simulation, Settings settings, KieContainer kieContainer) {
            return Collections.emptyList();
        }

        @Override
        protected KieContainer getKieContainer(Path path) {
            return kieContainerMock;
        }
    });
    settings.setType(ScenarioSimulationModel.Type.DMN);
    scenarioValidationServiceSpy.validateSimulationStructure(simulation, settings, pathMock);
    verify(scenarioValidationServiceSpy, never()).validateDMN(eq(simulation), eq(settings), eq(kieContainerMock));
    verify(scenarioValidationServiceSpy, never()).validateRULE(eq(simulation), eq(settings), eq(kieContainerMock));
    reset(scenarioValidationServiceSpy);
    FactMapping sampleFactMapping = simulation.getScesimModelDescriptor().addFactMapping(FactIdentifier.create("sample", String.class.getCanonicalName()), ExpressionIdentifier.create("sample", FactMappingType.GIVEN));
    sampleFactMapping.addExpressionElement("sample", String.class.getCanonicalName());
    settings.setType(ScenarioSimulationModel.Type.DMN);
    scenarioValidationServiceSpy.validateSimulationStructure(simulation, settings, pathMock);
    verify(scenarioValidationServiceSpy, timeout(1)).validateDMN(eq(simulation), eq(settings), eq(kieContainerMock));
    reset(scenarioValidationServiceSpy);
    settings.setType(ScenarioSimulationModel.Type.RULE);
    scenarioValidationServiceSpy.validateSimulationStructure(simulation, settings, pathMock);
    verify(scenarioValidationServiceSpy, timeout(1)).validateRULE(eq(simulation), eq(settings), eq(kieContainerMock));
    settings.setType(null);
    assertThatThrownBy(() -> scenarioValidationServiceSpy.validateSimulationStructure(simulation, settings, pathMock)).isInstanceOf(IllegalArgumentException.class);
}
Also used : Path(org.uberfire.backend.vfs.Path) FactMapping(org.drools.scenariosimulation.api.model.FactMapping) Simulation(org.drools.scenariosimulation.api.model.Simulation) List(java.util.List) Settings(org.drools.scenariosimulation.api.model.Settings) KieContainer(org.kie.api.runtime.KieContainer) Test(org.junit.Test)

Example 23 with Settings

use of org.drools.scenariosimulation.api.model.Settings in project drools-wb by kiegroup.

the class DMNScenarioValidationTest method init.

@Before
public void init() {
    settingsLocal = new Settings();
    settingsLocal.setType(ScenarioSimulationModel.Type.DMN);
    when(dmnModelMock.getDecisionByName(anyString())).thenAnswer(invocation -> mapOfMockDecisions.get(invocation.getArguments()[0]));
}
Also used : Settings(org.drools.scenariosimulation.api.model.Settings) Before(org.junit.Before)

Example 24 with Settings

use of org.drools.scenariosimulation.api.model.Settings in project drools-wb by kiegroup.

the class RULESimulationSettingsCreationStrategy method createSettings.

@Override
public Settings createSettings(Path context, String dmoSession) {
    Settings toReturn = new Settings();
    toReturn.setType(ScenarioSimulationModel.Type.RULE);
    toReturn.setDmoSession(dmoSession);
    return toReturn;
}
Also used : Settings(org.drools.scenariosimulation.api.model.Settings)

Example 25 with Settings

use of org.drools.scenariosimulation.api.model.Settings in project drools-wb by kiegroup.

the class DMNTypeServiceImplTest method initializeNameAndNamespace.

@Test
public void initializeNameAndNamespace() {
    Settings settings = new Settings();
    dmnTypeServiceImpl.initializeNameAndNamespace(settings, mock(Path.class), "");
    assertEquals(NAMESPACE, settings.getDmnNamespace());
    assertEquals(MODEL_NAME, settings.getDmnName());
}
Also used : Path(org.uberfire.backend.vfs.Path) Settings(org.drools.scenariosimulation.api.model.Settings) Test(org.junit.Test)

Aggregations

Settings (org.drools.scenariosimulation.api.model.Settings)29 Test (org.junit.Test)11 Before (org.junit.Before)10 Simulation (org.drools.scenariosimulation.api.model.Simulation)9 Background (org.drools.scenariosimulation.api.model.Background)7 Path (org.uberfire.backend.vfs.Path)6 AbstractScenarioSimulationTest (org.drools.workbench.screens.scenariosimulation.client.AbstractScenarioSimulationTest)4 ScenarioSimulationModel (org.drools.scenariosimulation.api.model.ScenarioSimulationModel)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Map (java.util.Map)2 ExpressionIdentifier (org.drools.scenariosimulation.api.model.ExpressionIdentifier)2 FactMapping (org.drools.scenariosimulation.api.model.FactMapping)2 Scenario (org.drools.scenariosimulation.api.model.Scenario)2 ScenarioWithIndex (org.drools.scenariosimulation.api.model.ScenarioWithIndex)2 ScenarioRunnerData (org.drools.scenariosimulation.backend.runner.model.ScenarioRunnerData)2 ScenarioSimulationViolation (org.drools.workbench.screens.scenariosimulation.client.commands.ScenarioSimulationViolation)2 UpdateSettingsDataCommand (org.drools.workbench.screens.scenariosimulation.client.commands.actualcommands.UpdateSettingsDataCommand)2 UpdateSettingsDataEvent (org.drools.workbench.screens.scenariosimulation.client.events.UpdateSettingsDataEvent)2 TestResultMessage (org.guvnor.common.services.shared.test.TestResultMessage)2