use of org.drools.scenariosimulation.backend.expression.BaseExpressionEvaluator in project drools by kiegroup.
the class AbstractRunnerHelperTest method fillResult.
@Test
public void fillResult() {
FactIdentifier factIdentifier = FactIdentifier.create("MyInstance", String.class.getCanonicalName());
ExpressionIdentifier expressionIdentifier = ExpressionIdentifier.create("MyProperty", FactMappingType.GIVEN);
FactMappingValue expectedResultSpy = spy(new FactMappingValue(factIdentifier, expressionIdentifier, VALUE));
AtomicReference<ValueWrapper> resultWrapperAtomicReference = new AtomicReference<>();
Supplier<ValueWrapper<?>> resultWrapperSupplier = resultWrapperAtomicReference::get;
ExpressionEvaluator expressionEvaluator = new BaseExpressionEvaluator(AbstractRunnerHelper.class.getClassLoader());
// Success
resultWrapperAtomicReference.set(ValueWrapper.of(VALUE));
assertTrue(abstractRunnerHelper.fillResult(expectedResultSpy, resultWrapperSupplier, expressionEvaluator).getResult());
verify(expectedResultSpy, times(1)).resetStatus();
reset(expectedResultSpy);
// Fail with expected value
resultWrapperAtomicReference.set(ValueWrapper.errorWithValidValue(VALUE, "value1"));
assertFalse(abstractRunnerHelper.fillResult(expectedResultSpy, resultWrapperSupplier, expressionEvaluator).getResult());
verify(expectedResultSpy, times(1)).setErrorValue(VALUE);
reset(expectedResultSpy);
// Fail with exception while reverting actual value
resultWrapperAtomicReference.set(ValueWrapper.errorWithValidValue(VALUE, "value1"));
ExpressionEvaluator expressionEvaluatorMock = mock(ExpressionEvaluator.class);
when(expressionEvaluatorMock.fromObjectToExpression(any())).thenThrow(new IllegalArgumentException("Error"));
assertFalse(abstractRunnerHelper.fillResult(expectedResultSpy, resultWrapperSupplier, expressionEvaluatorMock).getResult());
verify(expectedResultSpy, times(1)).setExceptionMessage("Error");
reset(expectedResultSpy);
// Fail in collection case
List<String> pathToValue = Arrays.asList("field1", "fields2");
resultWrapperAtomicReference.set(ValueWrapper.errorWithCollectionPathToValue(VALUE, pathToValue));
assertFalse(abstractRunnerHelper.fillResult(expectedResultSpy, resultWrapperSupplier, expressionEvaluator).getResult());
verify(expectedResultSpy, times(1)).setCollectionPathToValue(pathToValue);
verify(expectedResultSpy, times(1)).setErrorValue(VALUE);
// Fail with exception
resultWrapperAtomicReference.set(ValueWrapper.errorWithMessage("detailedError"));
assertFalse(abstractRunnerHelper.fillResult(expectedResultSpy, resultWrapperSupplier, expressionEvaluator).getResult());
verify(expectedResultSpy, times(1)).setExceptionMessage("detailedError");
}
Aggregations