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