Search in sources :

Example 1 with Dispute

use of org.drools.scenariosimulation.backend.model.Dispute in project drools by kiegroup.

the class RuleScenarioRunnerHelperTest method executeScenario.

@Test
public void executeScenario() {
    ArgumentCaptor<Object> insertCaptor = ArgumentCaptor.forClass(Object.class);
    ScenarioRunnerData scenarioRunnerData = new ScenarioRunnerData();
    scenarioRunnerData.addBackground(new InstanceGiven(personFactIdentifier, new Person()));
    scenarioRunnerData.addBackground(new InstanceGiven(disputeFactIdentifier, new Dispute()));
    scenarioRunnerData.addGiven(new InstanceGiven(personFactIdentifier, new Person()));
    FactMappingValue factMappingValue = new FactMappingValue(personFactIdentifier, firstNameExpectedExpressionIdentifier, NAME);
    scenarioRunnerData.addExpect(new ScenarioExpect(personFactIdentifier, singletonList(factMappingValue), false));
    scenarioRunnerData.addExpect(new ScenarioExpect(personFactIdentifier, singletonList(factMappingValue), true));
    int inputObjects = scenarioRunnerData.getBackgrounds().size() + scenarioRunnerData.getGivens().size();
    String ruleFlowGroup = "ruleFlowGroup";
    settings.setRuleFlowGroup(ruleFlowGroup);
    runnerHelper.executeScenario(kieContainerMock, scenarioRunnerData, expressionEvaluatorFactory, simulation.getScesimModelDescriptor(), settings);
    verify(ruleScenarioExecutableBuilderMock, times(1)).setActiveRuleFlowGroup(ruleFlowGroup);
    verify(ruleScenarioExecutableBuilderMock, times(inputObjects)).insert(insertCaptor.capture());
    for (Object value : insertCaptor.getAllValues()) {
        assertTrue(value instanceof Person || value instanceof Dispute);
    }
    verify(ruleScenarioExecutableBuilderMock, times(1)).addInternalCondition(eq(Person.class), any(), any());
    verify(ruleScenarioExecutableBuilderMock, times(1)).run();
    assertEquals(1, scenarioRunnerData.getResults().size());
    // test not rule error
    settings.setType(ScenarioSimulationModel.Type.DMN);
    assertThatThrownBy(() -> runnerHelper.executeScenario(kieContainerMock, scenarioRunnerData, expressionEvaluatorFactory, simulation.getScesimModelDescriptor(), settings)).isInstanceOf(ScenarioException.class).hasMessageStartingWith("Impossible to run");
}
Also used : ScenarioExpect(org.drools.scenariosimulation.backend.runner.model.ScenarioExpect) FactMappingValue(org.drools.scenariosimulation.api.model.FactMappingValue) InstanceGiven(org.drools.scenariosimulation.backend.runner.model.InstanceGiven) Dispute(org.drools.scenariosimulation.backend.model.Dispute) ScenarioRunnerData(org.drools.scenariosimulation.backend.runner.model.ScenarioRunnerData) Person(org.drools.scenariosimulation.backend.model.Person) AbstractRuleCoverageTest(org.drools.scenariosimulation.backend.fluent.AbstractRuleCoverageTest) Test(org.junit.Test)

Example 2 with Dispute

use of org.drools.scenariosimulation.backend.model.Dispute in project drools by kiegroup.

the class ScenarioBeanUtilTest method navigateToObjectFakeFieldTest.

@Test
public void navigateToObjectFakeFieldTest() {
    Dispute dispute = new Dispute();
    List<String> pathToProperty = singletonList("fakeField");
    String message = "Impossible to find field with name 'fakeField' in class " + Dispute.class.getCanonicalName();
    assertThatThrownBy(() -> ScenarioBeanUtil.navigateToObject(dispute, pathToProperty, true)).isInstanceOf(ScenarioException.class).hasMessage(message);
}
Also used : Dispute(org.drools.scenariosimulation.backend.model.Dispute) ScenarioException(org.drools.scenariosimulation.backend.runner.ScenarioException) EnumTest(org.drools.scenariosimulation.backend.util.model.EnumTest) Test(org.junit.Test) RuleScenarioRunnerHelperTest(org.drools.scenariosimulation.backend.runner.RuleScenarioRunnerHelperTest)

Example 3 with Dispute

use of org.drools.scenariosimulation.backend.model.Dispute in project drools by kiegroup.

the class ScenarioBeanUtilTest method fillBeanTestWithInitialInstanceTest.

@Test
public void fillBeanTestWithInitialInstanceTest() {
    Dispute dispute = new Dispute();
    Map<List<String>, Object> paramsToSet = new HashMap<>();
    paramsToSet.put(Arrays.asList("creator", "firstName"), FIRST_NAME);
    paramsToSet.put(Arrays.asList("creator", "age"), AGE);
    Object result = ScenarioBeanUtil.fillBean(of(dispute), Dispute.class.getCanonicalName(), paramsToSet, classLoader);
    assertTrue(result instanceof Dispute);
    assertSame(dispute, result);
    assertEquals(dispute.getCreator().getFirstName(), FIRST_NAME);
    assertEquals(dispute.getCreator().getAge(), AGE);
}
Also used : HashMap(java.util.HashMap) Dispute(org.drools.scenariosimulation.backend.model.Dispute) ArrayList(java.util.ArrayList) Collections.singletonList(java.util.Collections.singletonList) Collections.emptyList(java.util.Collections.emptyList) List(java.util.List) EnumTest(org.drools.scenariosimulation.backend.util.model.EnumTest) Test(org.junit.Test) RuleScenarioRunnerHelperTest(org.drools.scenariosimulation.backend.runner.RuleScenarioRunnerHelperTest)

Example 4 with Dispute

use of org.drools.scenariosimulation.backend.model.Dispute in project drools by kiegroup.

the class ScenarioBeanUtilTest method fillBeanTest.

@Test
public void fillBeanTest() {
    Map<List<String>, Object> paramsToSet = new HashMap<>();
    paramsToSet.put(Arrays.asList("creator", "firstName"), FIRST_NAME);
    paramsToSet.put(Arrays.asList("creator", "age"), AGE);
    Object result = ScenarioBeanUtil.fillBean(errorEmptyMessage(), Dispute.class.getCanonicalName(), paramsToSet, classLoader);
    assertTrue(result instanceof Dispute);
    Dispute dispute = (Dispute) result;
    assertEquals(dispute.getCreator().getFirstName(), FIRST_NAME);
    assertEquals(dispute.getCreator().getAge(), AGE);
}
Also used : HashMap(java.util.HashMap) Dispute(org.drools.scenariosimulation.backend.model.Dispute) ArrayList(java.util.ArrayList) Collections.singletonList(java.util.Collections.singletonList) Collections.emptyList(java.util.Collections.emptyList) List(java.util.List) EnumTest(org.drools.scenariosimulation.backend.util.model.EnumTest) Test(org.junit.Test) RuleScenarioRunnerHelperTest(org.drools.scenariosimulation.backend.runner.RuleScenarioRunnerHelperTest)

Example 5 with Dispute

use of org.drools.scenariosimulation.backend.model.Dispute 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)

Aggregations

Dispute (org.drools.scenariosimulation.backend.model.Dispute)8 Test (org.junit.Test)7 RuleScenarioRunnerHelperTest (org.drools.scenariosimulation.backend.runner.RuleScenarioRunnerHelperTest)5 EnumTest (org.drools.scenariosimulation.backend.util.model.EnumTest)5 Person (org.drools.scenariosimulation.backend.model.Person)3 ArrayList (java.util.ArrayList)2 Collections.emptyList (java.util.Collections.emptyList)2 Collections.singletonList (java.util.Collections.singletonList)2 HashMap (java.util.HashMap)2 List (java.util.List)2 Background (org.drools.scenariosimulation.api.model.Background)2 FactMappingValue (org.drools.scenariosimulation.api.model.FactMappingValue)2 AbstractRuleCoverageTest (org.drools.scenariosimulation.backend.fluent.AbstractRuleCoverageTest)2 ScenarioException (org.drools.scenariosimulation.backend.runner.ScenarioException)2 InstanceGiven (org.drools.scenariosimulation.backend.runner.model.InstanceGiven)2 Settings (org.drools.scenariosimulation.api.model.Settings)1 Simulation (org.drools.scenariosimulation.api.model.Simulation)1 SubPerson (org.drools.scenariosimulation.backend.model.SubPerson)1 ScenarioExpect (org.drools.scenariosimulation.backend.runner.model.ScenarioExpect)1 ScenarioRunnerData (org.drools.scenariosimulation.backend.runner.model.ScenarioRunnerData)1