Search in sources :

Example 6 with Dispute

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

the class RuleScenarioRunnerHelperTest method extractBackgroundValues.

@Test
public void extractBackgroundValues() {
    // TEST 0 - empty background
    Background emptyBackground = new Background();
    List<InstanceGiven> emptyBackgroundGivens = runnerHelper.extractBackgroundValues(emptyBackground, classLoader, expressionEvaluatorFactory);
    assertEquals(0, emptyBackgroundGivens.size());
    emptyBackground.addData();
    emptyBackgroundGivens = runnerHelper.extractBackgroundValues(emptyBackground, classLoader, expressionEvaluatorFactory);
    assertEquals(0, emptyBackgroundGivens.size());
    // TEST 1 - background correct
    List<InstanceGiven> backgroundGivens = runnerHelper.extractBackgroundValues(this.background, classLoader, expressionEvaluatorFactory);
    assertEquals(3, backgroundGivens.size());
    for (InstanceGiven backgroundGiven : backgroundGivens) {
        if (backgroundGiven.getFactIdentifier().equals(personFactIdentifier)) {
            assertEquals(personFactIdentifier, backgroundGiven.getFactIdentifier());
            Person person = (Person) backgroundGiven.getValue();
            assertEquals(NAME, person.getFirstName());
        } else if (backgroundGiven.getFactIdentifier().equals(disputeFactIdentifier)) {
            assertEquals(disputeFactIdentifier, backgroundGiven.getFactIdentifier());
            Dispute dispute = (Dispute) backgroundGiven.getValue();
            double parsedAmount = Double.parseDouble(AMOUNT);
            assertEquals(parsedAmount, dispute.getAmount(), 0.1);
        } else {
            fail();
        }
    }
    // TEST 2 - broken background
    String notValid = "notValid";
    FactMappingValue notValid1 = backgroundData1.addOrUpdateMappingValue(disputeFactIdentifier, amountGivenExpressionIdentifier, notValid);
    FactMappingValue notValid2 = backgroundData2.addOrUpdateMappingValue(disputeFactIdentifier, amountGivenExpressionIdentifier, notValid);
    assertThatThrownBy(() -> runnerHelper.extractBackgroundValues(this.background, classLoader, expressionEvaluatorFactory)).isInstanceOf(ScenarioException.class).hasMessage("Error in BACKGROUND data");
    assertEquals(FactMappingValueStatus.FAILED_WITH_EXCEPTION, notValid1.getStatus());
    assertTrue(notValid1.getExceptionMessage().startsWith("Impossible to parse"));
    assertEquals(FactMappingValueStatus.FAILED_WITH_EXCEPTION, notValid2.getStatus());
    assertTrue(notValid2.getExceptionMessage().startsWith("Impossible to parse"));
}
Also used : Background(org.drools.scenariosimulation.api.model.Background) FactMappingValue(org.drools.scenariosimulation.api.model.FactMappingValue) InstanceGiven(org.drools.scenariosimulation.backend.runner.model.InstanceGiven) Dispute(org.drools.scenariosimulation.backend.model.Dispute) Person(org.drools.scenariosimulation.backend.model.Person) AbstractRuleCoverageTest(org.drools.scenariosimulation.backend.fluent.AbstractRuleCoverageTest) Test(org.junit.Test)

Example 7 with Dispute

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

the class ScenarioBeanUtilTest method navigateToObjectNoStepCreationTest.

@Test
public void navigateToObjectNoStepCreationTest() {
    Dispute dispute = new Dispute();
    List<String> pathToProperty = Arrays.asList("creator", "firstName");
    String message = "Impossible to reach field firstName because a step is not instantiated";
    assertThatThrownBy(() -> ScenarioBeanUtil.navigateToObject(dispute, pathToProperty, false)).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 8 with Dispute

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

the class ScenarioBeanUtilTest method navigateToObjectTest.

@Test
public void navigateToObjectTest() {
    Dispute dispute = new Dispute();
    Person creator = new Person();
    creator.setFirstName(FIRST_NAME);
    dispute.setCreator(creator);
    List<String> pathToProperty = Arrays.asList("creator", "firstName");
    ScenarioBeanWrapper<?> scenarioBeanWrapper = ScenarioBeanUtil.navigateToObject(dispute, pathToProperty, true);
    Object targetObject = scenarioBeanWrapper.getBean();
    assertEquals(targetObject, FIRST_NAME);
    assertNull(ScenarioBeanUtil.navigateToObject(null, Collections.emptyList()).getBean());
}
Also used : Dispute(org.drools.scenariosimulation.backend.model.Dispute) Person(org.drools.scenariosimulation.backend.model.Person) SubPerson(org.drools.scenariosimulation.backend.model.SubPerson) EnumTest(org.drools.scenariosimulation.backend.util.model.EnumTest) Test(org.junit.Test) RuleScenarioRunnerHelperTest(org.drools.scenariosimulation.backend.runner.RuleScenarioRunnerHelperTest)

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