use of org.omg.dmn.tck.runner.junit4.TestResult in project tck by dmn-tck.
the class DroolsTCKTest method executeTest.
@Override
public TestResult executeTest(Description description, TestSuiteContext context, TestCases.TestCase testCase) {
DroolsContext ctx = (DroolsContext) context;
logger.info("Executing test '{} / {}'\n", description.getClassName(), description.getMethodName());
DMNContext dmnctx = ctx.runtime.newContext();
testCase.getInputNode().forEach(in -> {
InputDataNode input = ctx.dmnmodel.getInputByName(in.getName());
DecisionNode decision = ctx.dmnmodel.getDecisionByName(in.getName());
if (input != null) {
// normally data input from file, should be pointing at a InputData in the model
dmnctx.set(in.getName(), parseValue(in, input));
} else if (decision != null) {
// the test case offers a pre-evaluated Decision
dmnctx.set(in.getName(), parseValue(in, decision));
} else {
logger.warn("Override input name {} with value {}", in.getName(), in);
dmnctx.set(in.getName(), parseType(in, REGISTRY.unknown()));
}
});
DMNContext resultctx = dmnctx;
List<String> failures = new ArrayList<>();
for (TestCases.TestCase.ResultNode rn : testCase.getResultNode()) {
try {
String name = rn.getName();
DMNResult dmnResult = null;
if (testCase.getType() == TestCaseType.DECISION_SERVICE) {
dmnResult = ctx.runtime.evaluateDecisionService(ctx.dmnmodel, resultctx, testCase.getInvocableName());
} else {
dmnResult = ctx.runtime.evaluateByName(ctx.dmnmodel, resultctx, name);
}
if (!dmnResult.getMessages().isEmpty()) {
logger.info("Messages: \n-----\n{}\n-----\n", dmnResult.getMessages().stream().map(m -> m.toString()).collect(Collectors.joining("\n")));
}
resultctx = dmnResult.getContext();
Object expected = parseValue(rn, ctx.dmnmodel.getDecisionByName(name));
Object actual = resultctx.get(name);
if (rn.isErrorResult()) {
for (DMNMessage msg : dmnResult.getMessages(DMNMessage.Severity.ERROR)) {
logger.info("TEST CASE is error Result, message reported is to be expected: {}", msg);
}
} else {
if (expected == null && actual == null) {
for (DMNMessage msg : dmnResult.getMessages(DMNMessage.Severity.ERROR)) {
logger.warn("TCK value comparison is correct, but TCK test case '{}' might be missing errorResult flag?", name);
}
} else if (dmnResult.hasErrors()) {
for (DMNMessage msg : dmnResult.getMessages(DMNMessage.Severity.ERROR)) {
failures.add(msg.toString());
}
}
}
if (!isEquals(expected, actual)) {
failures.add("FAILURE: '" + name + "' expected='" + expected + "' but found='" + actual + "'");
}
} catch (Throwable t) {
failures.add("FAILURE: unnexpected exception executing test case '" + description.getClassName() + " / " + description.getMethodName() + "': " + t.getClass().getName());
logger.error("FAILURE: unnexpected exception executing test case '{} / {}'", description.getClassName(), description.getMethodName(), t);
}
}
// DMNResult dmnResult = ctx.runtime.evaluateAll( ctx.dmnmodel, dmnctx );
logger.info("Result context: {}\n", resultctx);
// if( ! dmnResult.getMessages().isEmpty() ) {
// logger.info( "Messages: \n-----\n{}-----\n", dmnResult.getMessages().stream().map( m -> m.toString() ).collect( Collectors.joining( "\n" ) ) );
// }
//
// List<String> failures = new ArrayList<>();
// if( dmnResult.hasErrors() ) {
// for( DMNMessage msg : dmnResult.getMessages( DMNMessage.Severity.ERROR ) ) {
// failures.add( msg.toString() );
// }
// }
// testCase.getResultNode().forEach( rn -> {
// try {
// String name = rn.getName();
// Object expected = parseValue( rn, ctx.dmnmodel.getDecisionByName( name ) );
// Object actual = resultctx.get( name );
// if( ! isEquals( expected, actual ) ) {
// failures.add( "FAILURE: '"+name+"' expected='"+expected+"' but found='"+actual+"'" );
// }
// } catch ( Throwable t ) {
// failures.add( "FAILURE: unnexpected exception executing test case '"+description.getClassName()+" / " +description.getMethodName()+"': "+t.getClass().getName() );
// logger.error( "FAILURE: unnexpected exception executing test case '{} / {}'", description.getClassName(), description.getMethodName(), t );
// }
// } );
TestResult.Result r = !failures.isEmpty() ? TestResult.Result.ERROR : TestResult.Result.SUCCESS;
return new TestResult(r, failures.stream().collect(Collectors.joining("\n")));
}
use of org.omg.dmn.tck.runner.junit4.TestResult in project tck by dmn-tck.
the class JDMNTckTest method executeTest.
@Override
public TestResult executeTest(Description description, TestSuiteContext context, TestCase testCase) {
List<String> failures = new ArrayList<>();
List<String> exceptions = new ArrayList<>();
try {
JDMNTestContext gsContext = (JDMNTestContext) context;
BasicDMNToJavaTransformer basicTransformer = gsContext.getBasicToJavaTransformer();
StandardFEELLib lib = gsContext.getLib();
DMNInterpreter interpreter = gsContext.getInterpreter();
TCKUtil tckUtil = new TCKUtil(basicTransformer, lib);
TestCases testCases = gsContext.getTestCases();
for (ResultNode res : testCase.getResultNode()) {
String testLocation = String.format("Unexpected result in test for model '%s', TestCase.id='%s', ResultNode.name='%s'.", testCases.getModelName(), testCase.getId(), res.getName());
Object expectedValue = null;
Result actualResult = null;
Object actualValue = null;
try {
expectedValue = tckUtil.expectedValue(testCases, testCase, res);
actualResult = tckUtil.evaluate(interpreter, testCases, testCase, res);
actualValue = Result.value(actualResult);
if (!isEquals(expectedValue, actualValue)) {
String errorMessage = String.format("%s ResultNode '%s' output mismatch, expected '%s' actual '%s'", testLocation, res.getName(), expectedValue, actualValue);
failures.add(errorMessage);
}
if (!IGNORE_ERROR_FLAG) {
String errorFlagMessage = String.format("%s ResultNode '%s' error flag mismatch", testLocation, res.getName());
if (!isEquals(res.isErrorResult(), actualResult.hasErrors())) {
failures.add(errorFlagMessage);
}
}
} catch (Throwable e) {
String stackTrace = ExceptionUtils.getStackTrace(e);
LOGGER.error(stackTrace);
String errorMessage = String.format("%s ResultNode '%s' output mismatch, expected '%s' actual '%s'", testLocation, res.getName(), expectedValue, actualValue);
exceptions.add(errorMessage + ". Exception thrown while testing");
}
}
} catch (Throwable e) {
exceptions.add(e.getMessage());
}
TestResult.Result r = TestResult.Result.SUCCESS;
String message = "";
if (!failures.isEmpty()) {
r = TestResult.Result.ERROR;
message = String.join("\n", failures);
}
if (!exceptions.isEmpty()) {
r = TestResult.Result.ERROR;
message = String.join("\n", exceptions);
}
return new TestResult(r, message);
}
Aggregations