Search in sources :

Example 1 with Simulation

use of org.drools.scenariosimulation.api.model.Simulation in project drools by kiegroup.

the class AbstractScenarioRunnerTest method getScenarioRunnerDTO.

private ScenarioRunnerDTO getScenarioRunnerDTO() {
    Simulation simulation = new Simulation();
    IntStream.range(0, SCENARIO_DATA).forEach(index -> {
        Scenario scenario = simulation.addData();
        scenario.setDescription("INDEX-" + index);
    });
    ScenarioSimulationModel model = new ScenarioSimulationModel();
    model.setSimulation(simulation);
    return new ScenarioRunnerDTO(model, "test.scesim");
}
Also used : Simulation(org.drools.scenariosimulation.api.model.Simulation) ScenarioRunnerDTO(org.drools.scenariosimulation.backend.runner.model.ScenarioRunnerDTO) ScenarioSimulationModel(org.drools.scenariosimulation.api.model.ScenarioSimulationModel) Scenario(org.drools.scenariosimulation.api.model.Scenario)

Example 2 with Simulation

use of org.drools.scenariosimulation.api.model.Simulation in project drools by kiegroup.

the class ScenarioJunitActivatorTest method setup.

@Before
public void setup() throws Exception {
    simulationLocal = new Simulation();
    settingsLocal = new Settings();
    settingsLocal.setSkipFromBuild(true);
    when(xmlReaderMock.unmarshal(any())).thenReturn(scenarioSimulationModelMock);
    when(scenarioSimulationModelMock.getSimulation()).thenReturn(simulationLocal);
    when(scenarioSimulationModelMock.getSettings()).thenReturn(settingsLocal);
}
Also used : Simulation(org.drools.scenariosimulation.api.model.Simulation) Settings(org.drools.scenariosimulation.api.model.Settings) Before(org.junit.Before)

Example 3 with Simulation

use of org.drools.scenariosimulation.api.model.Simulation in project drools by kiegroup.

the class RuleScenarioRunnerHelperTest method setup.

@Before
public void setup() {
    when(kieContainerMock.getClassLoader()).thenReturn(classLoader);
    simulation = new Simulation();
    background = new Background();
    settings = new Settings();
    settings.setType(ScenarioSimulationModel.Type.RULE);
    personFactIdentifier = FactIdentifier.create("Fact 1", Person.class.getCanonicalName());
    firstNameGivenExpressionIdentifier = ExpressionIdentifier.create("First Name Given", FactMappingType.GIVEN);
    firstNameGivenFactMapping = simulation.getScesimModelDescriptor().addFactMapping(personFactIdentifier, firstNameGivenExpressionIdentifier);
    firstNameGivenFactMapping.addExpressionElement("Fact 1", String.class.getCanonicalName());
    firstNameGivenFactMapping.addExpressionElement("firstName", String.class.getCanonicalName());
    disputeFactIdentifier = FactIdentifier.create("Fact 2", Dispute.class.getCanonicalName());
    amountGivenExpressionIdentifier = ExpressionIdentifier.create("Amount Given", FactMappingType.GIVEN);
    amountNameGivenFactMapping = simulation.getScesimModelDescriptor().addFactMapping(disputeFactIdentifier, amountGivenExpressionIdentifier);
    amountNameGivenFactMapping.addExpressionElement("Fact 2", Double.class.getCanonicalName());
    amountNameGivenFactMapping.addExpressionElement("amount", Double.class.getCanonicalName());
    firstNameExpectedExpressionIdentifier = ExpressionIdentifier.create("First Name Expected", FactMappingType.EXPECT);
    firstNameExpectedFactMapping = simulation.getScesimModelDescriptor().addFactMapping(personFactIdentifier, firstNameExpectedExpressionIdentifier);
    firstNameExpectedFactMapping.addExpressionElement("Fact 1", String.class.getCanonicalName());
    firstNameExpectedFactMapping.addExpressionElement("firstName", String.class.getCanonicalName());
    amountExpectedExpressionIdentifier = ExpressionIdentifier.create("Amount Expected", FactMappingType.EXPECT);
    amountNameExpectedFactMapping = simulation.getScesimModelDescriptor().addFactMapping(disputeFactIdentifier, amountExpectedExpressionIdentifier);
    amountNameExpectedFactMapping.addExpressionElement("Fact 2", Double.class.getCanonicalName());
    amountNameExpectedFactMapping.addExpressionElement("amount", Double.class.getCanonicalName());
    expressionGivenExpressionIdentifier = ExpressionIdentifier.create("directMapping", FactMappingType.GIVEN);
    disputeExpressionGivenFactMapping = simulation.getScesimModelDescriptor().addFactMapping(disputeFactIdentifier, expressionGivenExpressionIdentifier);
    disputeExpressionGivenFactMapping.setFactMappingValueType(FactMappingValueType.EXPRESSION);
    disputeExpressionGivenFactMapping.addExpressionElement("Dispute", Dispute.class.getCanonicalName());
    scenario1 = simulation.addData();
    scenario1.setDescription(TEST_DESCRIPTION);
    scenario1.addMappingValue(personFactIdentifier, firstNameGivenExpressionIdentifier, NAME);
    scenario1.addMappingValue(personFactIdentifier, firstNameExpectedExpressionIdentifier, NAME);
    scenario2 = simulation.addData();
    scenario2.setDescription(TEST_DESCRIPTION);
    scenario2.addMappingValue(personFactIdentifier, firstNameGivenExpressionIdentifier, NAME);
    scenario2.addMappingValue(personFactIdentifier, firstNameExpectedExpressionIdentifier, NAME);
    scenario2.addMappingValue(disputeFactIdentifier, amountGivenExpressionIdentifier, AMOUNT);
    amountNameExpectedFactMappingValue = scenario2.addMappingValue(disputeFactIdentifier, amountExpectedExpressionIdentifier, AMOUNT);
    backgroundFirstNameGivenFactMapping = background.getScesimModelDescriptor().addFactMapping(personFactIdentifier, firstNameGivenExpressionIdentifier);
    backgroundFirstNameGivenFactMapping.addExpressionElement("Person", String.class.getCanonicalName());
    backgroundFirstNameGivenFactMapping.addExpressionElement("firstName", String.class.getCanonicalName());
    backgroundAmountNameGivenFactMapping = background.getScesimModelDescriptor().addFactMapping(disputeFactIdentifier, amountGivenExpressionIdentifier);
    backgroundAmountNameGivenFactMapping.addExpressionElement("Dispute", Double.class.getCanonicalName());
    backgroundAmountNameGivenFactMapping.addExpressionElement("amount", Double.class.getCanonicalName());
    backgroundData1 = background.addData();
    backgroundData1.addMappingValue(personFactIdentifier, firstNameGivenExpressionIdentifier, NAME);
    backgroundData1.addMappingValue(disputeFactIdentifier, amountGivenExpressionIdentifier, AMOUNT);
    backgroundData2 = background.addData();
    backgroundData2.addMappingValue(personFactIdentifier, firstNameGivenExpressionIdentifier, NAME);
}
Also used : Simulation(org.drools.scenariosimulation.api.model.Simulation) Background(org.drools.scenariosimulation.api.model.Background) Dispute(org.drools.scenariosimulation.backend.model.Dispute) Settings(org.drools.scenariosimulation.api.model.Settings) Before(org.junit.Before)

Example 4 with Simulation

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

the class ScenarioSimulationBuilderTest method createSimulation.

@Test
public void createSimulation() throws Exception {
    Simulation simulationRetrieved = scenarioSimulationBuilder.createSimulation(contextMock, ScenarioSimulationModel.Type.RULE, VALUE);
    assertNotNull(simulationRetrieved);
    assertEquals(ruleSimulationMock, simulationRetrieved);
    simulationRetrieved = scenarioSimulationBuilder.createSimulation(contextMock, ScenarioSimulationModel.Type.DMN, VALUE);
    assertNotNull(simulationRetrieved);
    assertEquals(dmnSimulationMock, simulationRetrieved);
}
Also used : Simulation(org.drools.scenariosimulation.api.model.Simulation) Test(org.junit.Test)

Example 5 with Simulation

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

the class DMNSimulationSettingsCreationStrategyTest method verifySimulationCreated.

private void verifySimulationCreated(boolean hasInput, boolean hasOutput) throws Exception {
    final Path pathMock = mock(Path.class);
    final String dmnFilePath = "test";
    FactModelTuple factModelTuple = getFactModelTuple(hasInput, hasOutput);
    doReturn(factModelTuple).when(dmnSimulationCreationStrategy).getFactModelTuple(any(), any());
    Simulation simulation = dmnSimulationCreationStrategy.createSimulation(pathMock, dmnFilePath);
    assertNotNull(simulation);
    List<FactMapping> factMappings = simulation.getScesimModelDescriptor().getFactMappings();
    if (hasInput) {
        assertTrue(factMappings.stream().anyMatch(elem -> GIVEN.equals(elem.getExpressionIdentifier().getType())));
    } else {
        assertEquals(1, factMappings.stream().filter(elem -> GIVEN.equals(elem.getExpressionIdentifier().getType())).count());
    }
    if (hasOutput) {
        assertTrue(factMappings.stream().anyMatch(elem -> EXPECT.equals(elem.getExpressionIdentifier().getType())));
    } else {
        assertEquals(1, factMappings.stream().filter(elem -> EXPECT.equals(elem.getExpressionIdentifier().getType())).count());
    }
}
Also used : Path(org.uberfire.backend.vfs.Path) Arrays(java.util.Arrays) ScenarioSimulationModel(org.drools.scenariosimulation.api.model.ScenarioSimulationModel) FactModelTree(org.drools.workbench.screens.scenariosimulation.model.typedescriptor.FactModelTree) GIVEN(org.drools.scenariosimulation.api.model.FactMappingType.GIVEN) VALUE(org.drools.scenariosimulation.api.utils.ConstantsHolder.VALUE) DMNTypeService(org.drools.workbench.screens.scenariosimulation.service.DMNTypeService) Matchers.eq(org.mockito.Matchers.eq) Map(java.util.Map) ScesimModelDescriptor(org.drools.scenariosimulation.api.model.ScesimModelDescriptor) Mockito.doReturn(org.mockito.Mockito.doReturn) AbstractDMNTest(org.drools.workbench.screens.scenariosimulation.backend.server.AbstractDMNTest) Settings(org.drools.scenariosimulation.api.model.Settings) Matchers.any(org.mockito.Matchers.any) List(java.util.List) FactMapping(org.drools.scenariosimulation.api.model.FactMapping) Assert.assertFalse(org.junit.Assert.assertFalse) Simulation(org.drools.scenariosimulation.api.model.Simulation) InputDataNode(org.kie.dmn.api.core.ast.InputDataNode) EXPECT(org.drools.scenariosimulation.api.model.FactMappingType.EXPECT) SortedMap(java.util.SortedMap) Mockito.mock(org.mockito.Mockito.mock) DMNType(org.kie.dmn.api.core.DMNType) Mock(org.mockito.Mock) FactModelTuple(org.drools.workbench.screens.scenariosimulation.model.typedescriptor.FactModelTuple) RunWith(org.junit.runner.RunWith) FactIdentifier(org.drools.scenariosimulation.api.model.FactIdentifier) HashMap(java.util.HashMap) Mockito.spy(org.mockito.Mockito.spy) Matchers.anyString(org.mockito.Matchers.anyString) ArrayList(java.util.ArrayList) ExpressionIdentifier(org.drools.scenariosimulation.api.model.ExpressionIdentifier) DecisionNode(org.kie.dmn.api.core.ast.DecisionNode) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) DECISION(org.drools.workbench.screens.scenariosimulation.model.typedescriptor.FactModelTree.Type.DECISION) Path(org.uberfire.backend.vfs.Path) ScenarioWithIndex(org.drools.scenariosimulation.api.model.ScenarioWithIndex) Before(org.junit.Before) OTHER(org.drools.scenariosimulation.api.model.FactMappingType.OTHER) Assert.assertNotNull(org.junit.Assert.assertNotNull) Background(org.drools.scenariosimulation.api.model.Background) Assert.assertTrue(org.junit.Assert.assertTrue) IOException(java.io.IOException) Test(org.junit.Test) Mockito.times(org.mockito.Mockito.times) Mockito.when(org.mockito.Mockito.when) Mockito.verify(org.mockito.Mockito.verify) Mockito.never(org.mockito.Mockito.never) MockitoJUnitRunner(org.mockito.runners.MockitoJUnitRunner) TreeMap(java.util.TreeMap) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) FactMapping(org.drools.scenariosimulation.api.model.FactMapping) Simulation(org.drools.scenariosimulation.api.model.Simulation) FactModelTuple(org.drools.workbench.screens.scenariosimulation.model.typedescriptor.FactModelTuple) Matchers.anyString(org.mockito.Matchers.anyString)

Aggregations

Simulation (org.drools.scenariosimulation.api.model.Simulation)30 Settings (org.drools.scenariosimulation.api.model.Settings)13 Test (org.junit.Test)13 FactMapping (org.drools.scenariosimulation.api.model.FactMapping)12 Background (org.drools.scenariosimulation.api.model.Background)11 ScesimModelDescriptor (org.drools.scenariosimulation.api.model.ScesimModelDescriptor)11 ScenarioSimulationModel (org.drools.scenariosimulation.api.model.ScenarioSimulationModel)9 Path (org.uberfire.backend.vfs.Path)9 List (java.util.List)8 Before (org.junit.Before)7 Scenario (org.drools.scenariosimulation.api.model.Scenario)6 ScenarioWithIndex (org.drools.scenariosimulation.api.model.ScenarioWithIndex)6 ExpressionIdentifier (org.drools.scenariosimulation.api.model.ExpressionIdentifier)5 ArrayList (java.util.ArrayList)4 Map (java.util.Map)4 AbstractScesimModel (org.drools.scenariosimulation.api.model.AbstractScesimModel)4 FactIdentifier (org.drools.scenariosimulation.api.model.FactIdentifier)4 Inject (javax.inject.Inject)3 FactModelTuple (org.drools.workbench.screens.scenariosimulation.model.typedescriptor.FactModelTuple)3 Matchers.anyString (org.mockito.Matchers.anyString)3