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