Search in sources :

Example 1 with DMNInterpreter

use of com.gs.dmn.runtime.interpreter.DMNInterpreter 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);
}
Also used : BasicDMNToJavaTransformer(com.gs.dmn.transformation.basic.BasicDMNToJavaTransformer) ResultNode(org.omg.dmn.tck.marshaller._20160719.TestCases.TestCase.ResultNode) ArrayList(java.util.ArrayList) TestResult(org.omg.dmn.tck.runner.junit4.TestResult) Result(com.gs.dmn.runtime.interpreter.Result) TestResult(org.omg.dmn.tck.runner.junit4.TestResult) TestCases(org.omg.dmn.tck.marshaller._20160719.TestCases) TCKUtil(com.gs.dmn.tck.TCKUtil) DMNInterpreter(com.gs.dmn.runtime.interpreter.DMNInterpreter) StandardFEELLib(com.gs.dmn.feel.lib.StandardFEELLib)

Aggregations

StandardFEELLib (com.gs.dmn.feel.lib.StandardFEELLib)1 DMNInterpreter (com.gs.dmn.runtime.interpreter.DMNInterpreter)1 Result (com.gs.dmn.runtime.interpreter.Result)1 TCKUtil (com.gs.dmn.tck.TCKUtil)1 BasicDMNToJavaTransformer (com.gs.dmn.transformation.basic.BasicDMNToJavaTransformer)1 ArrayList (java.util.ArrayList)1 TestCases (org.omg.dmn.tck.marshaller._20160719.TestCases)1 ResultNode (org.omg.dmn.tck.marshaller._20160719.TestCases.TestCase.ResultNode)1 TestResult (org.omg.dmn.tck.runner.junit4.TestResult)1