Search in sources :

Example 1 with TestCase

use of org.omg.dmn.tck.marshaller._20160719.TestCases.TestCase in project tck by dmn-tck.

the class TestCasesFiles method data.

@Parameters(name = "TestCase {0}")
public static Iterable<Object[]> data() {
    List<Object[]> testCases = new ArrayList<>();
    File cl2parent = new File("../../TestCases/compliance-level-2");
    FileFilter filenameFilter = pathname -> pathname.isDirectory();
    for (File file : cl2parent.listFiles(filenameFilter)) {
        testCases.add(new Object[] { file.getName(), file });
    }
    File cl3parent = new File("../../TestCases/compliance-level-3");
    for (File file : cl3parent.listFiles(filenameFilter)) {
        testCases.add(new Object[] { file.getName(), file });
    }
    return testCases;
}
Also used : CoreMatchers.is(org.hamcrest.CoreMatchers.is) Arrays(java.util.Arrays) XPath(javax.xml.xpath.XPath) XPathConstants(javax.xml.xpath.XPathConstants) StreamSource(javax.xml.transform.stream.StreamSource) RunWith(org.junit.runner.RunWith) Parameters(org.junit.runners.Parameterized.Parameters) HashMap(java.util.HashMap) Source(javax.xml.transform.Source) XPathExpression(javax.xml.xpath.XPathExpression) Function(java.util.function.Function) Schema(javax.xml.validation.Schema) ArrayList(java.util.ArrayList) Document(org.w3c.dom.Document) Map(java.util.Map) Node(org.w3c.dom.Node) NamedNodeMap(org.w3c.dom.NamedNodeMap) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) XMLConstants(javax.xml.XMLConstants) TckMarshallingHelper(org.omg.dmn.tck.marshaller.TckMarshallingHelper) Parameterized(org.junit.runners.Parameterized) SchemaFactory(javax.xml.validation.SchemaFactory) NodeList(org.w3c.dom.NodeList) Validator(javax.xml.validation.Validator) Test(org.junit.Test) FileInputStream(java.io.FileInputStream) Collectors(java.util.stream.Collectors) File(java.io.File) XPathFactory(javax.xml.xpath.XPathFactory) List(java.util.List) FileFilter(java.io.FileFilter) Element(org.w3c.dom.Element) DocumentBuilder(javax.xml.parsers.DocumentBuilder) SAXException(org.xml.sax.SAXException) Entry(java.util.Map.Entry) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) TestCases(org.omg.dmn.tck.marshaller._20160719.TestCases) ArrayList(java.util.ArrayList) FileFilter(java.io.FileFilter) File(java.io.File) Parameters(org.junit.runners.Parameterized.Parameters)

Example 2 with TestCase

use of org.omg.dmn.tck.marshaller._20160719.TestCases.TestCase 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)

Example 3 with TestCase

use of org.omg.dmn.tck.marshaller._20160719.TestCases.TestCase in project tck by dmn-tck.

the class TestCasesTest method testRead0001.

@Test
public void testRead0001() throws Exception {
    InputStream is = null;
    try {
        is = getClass().getResourceAsStream("/compliance-level-2/0001-input-data-string/0001-input-data-string-test-01.xml");
        TestCases testCases = load(is);
        assertNotNull(testCases);
        assertEquals(2, testCases.getTestCase().size());
        for (TestCase testCase : testCases.getTestCase()) {
            for (InputNode inputNode : testCase.getInputNode()) {
                if (inputNode.getValue() != null) {
                    System.out.println("inputNode is simple type with content: " + ((Element) inputNode.getValue().getValue()).getTextContent());
                } else {
                    System.out.println("inputNode is complex: " + inputNode.getComponent());
                }
            }
        }
        String json = objectMapper.writeValueAsString(testCases);
        // assertions on JSON go here
        File testOutputDir = new File(baseOutputDir, "0001-input-data-string");
        testOutputDir.mkdirs();
        File jsonFile = new File(testOutputDir, "0001-input-data-string-test-01.json");
        System.out.println("Writing JSON output to: " + jsonFile.getAbsolutePath());
        objectMapper.writerWithDefaultPrettyPrinter().writeValue(jsonFile, testCases);
    } finally {
        try {
            is.close();
        } catch (Exception e) {
            ;
        }
    }
}
Also used : InputNode(org.omg.dmn.tck.marshaller._20160719.TestCases.TestCase.InputNode) TestCase(org.omg.dmn.tck.marshaller._20160719.TestCases.TestCase) InputStream(java.io.InputStream) JAXBElement(javax.xml.bind.JAXBElement) Element(org.w3c.dom.Element) File(java.io.File) JAXBException(javax.xml.bind.JAXBException) Test(org.junit.Test)

Aggregations

File (java.io.File)2 ArrayList (java.util.ArrayList)2 Test (org.junit.Test)2 TestCases (org.omg.dmn.tck.marshaller._20160719.TestCases)2 Element (org.w3c.dom.Element)2 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 FileFilter (java.io.FileFilter)1 FileInputStream (java.io.FileInputStream)1 InputStream (java.io.InputStream)1 Arrays (java.util.Arrays)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Entry (java.util.Map.Entry)1 Function (java.util.function.Function)1 Collectors (java.util.stream.Collectors)1