Search in sources :

Example 6 with TestCases

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

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

the class CommandLineRunner method main.

public static void main(String[] args) {
    AnsiConsole.systemInstall();
    Properties properties = null;
    try {
        properties = TrisotechTCKHelper.getProperties();
    } catch (IOException e) {
        AnsiConsole.err.println(e.getMessage());
        AnsiConsole.err.println();
        exitOnUsage();
    }
    File tckTestsRoot = args.length > 1 ? new File(args[1]) : new File(".");
    if (!tckTestsRoot.exists()) {
        AnsiConsole.err.println(ansi().fg(RED).a("Invalid DMN TCK test case folder: " + tckTestsRoot.getAbsolutePath() + " it does not exist").reset());
        exitOnUsage();
    }
    if (!tckTestsRoot.isDirectory()) {
        AnsiConsole.err.println(ansi().fg(RED).a("Invalid DMN TCK test case folder: " + tckTestsRoot.getAbsolutePath() + " it's not a folder").reset());
        exitOnUsage();
    }
    File testCasesFolder = new File(".").getAbsoluteFile();
    if (args.length > 0) {
        testCasesFolder = new File(args[0]).getAbsoluteFile();
    }
    if (!testCasesFolder.exists()) {
        AnsiConsole.err.println(ansi().fg(RED).a("Invalid DMN TCK test case folder: " + testCasesFolder.getAbsolutePath() + " it does not exist").reset());
        exitOnUsage();
    }
    if (!testCasesFolder.isDirectory()) {
        AnsiConsole.err.println(ansi().fg(RED).a("Invalid DMN TCK test case folder: " + testCasesFolder.getAbsolutePath() + " it's not a folder").reset());
        exitOnUsage();
    }
    // Detect all test categories
    File[] testCategoriesFolders = testCasesFolder.listFiles(new FilenameFilter() {

        @Override
        public boolean accept(File dir, String name) {
            return dir.isDirectory() && name.startsWith("compliance");
        }
    });
    if (testCategoriesFolders == null || testCategoriesFolders.length == 0) {
        AnsiConsole.err.println(ansi().fg(RED).a("Invalid DMN TCK test case folder: " + testCasesFolder.getAbsolutePath() + " it does not contain compliance sub folders").reset());
        exitOnUsage();
    }
    // Inside each category, there are a list of tests
    for (File testCategoriesFolder : testCategoriesFolders) {
        String category = testCategoriesFolder.getName();
        File[] testFolders = testCategoriesFolder.listFiles(new FileFilter() {

            @Override
            public boolean accept(File pathname) {
                return pathname.isDirectory();
            }
        });
        if (testFolders == null) {
            continue;
        }
        AnsiConsole.out.println(category);
        for (File testFolder : testFolders) {
            String testId = testFolder.getName();
            File[] testCasesFiles = testFolder.listFiles(new FilenameFilter() {

                @Override
                public boolean accept(File dir, String name) {
                    return name.startsWith(testId + "-test-") && name.endsWith(".xml");
                }
            });
            for (File testCaseFile : testCasesFiles) {
                try {
                    TestCases tcs = TckMarshallingHelper.load(new FileInputStream(testCaseFile));
                    String modelName = tcs.getModelName();
                    LinkedList<File> dmnFiles = new LinkedList<>();
                    dmnFiles.add(new File(testCaseFile.getParentFile(), modelName));
                    for (File fileInDirectory : testCaseFile.getParentFile().listFiles()) {
                        if ((fileInDirectory.getName().endsWith(".dmn")) && (!fileInDirectory.getName().equals(modelName))) {
                            dmnFiles.add(fileInDirectory);
                        }
                    }
                    AnsiConsole.out.print(testCaseFile.getName() + " ");
                    try {
                        if (TrisotechTCKHelper.pushTestCase(category, testId, properties, dmnFiles.toArray(new File[dmnFiles.size()]))) {
                            Map<String, Boolean> results = TrisotechTCKHelper.runTestCase(category, testId, testCaseFile, properties);
                            int total = 0;
                            int passed = 0;
                            for (Map.Entry<String, Boolean> result : results.entrySet()) {
                                total += 1;
                                if (result.getValue()) {
                                    passed += 1;
                                }
                            }
                            if (total == 0) {
                                AnsiConsole.out.println(ansi().a("[").fg(YELLOW).a("NO TESTS FOUND").reset().a("]"));
                            } else if (total == passed) {
                                AnsiConsole.out.println(ansi().a("[").fg(GREEN).a("PASSED " + passed + "/" + total).reset().a("]"));
                            } else {
                                AnsiConsole.out.println(ansi().a("[").fg(RED).a("FAILED " + passed + "/" + total).reset().a("]"));
                            }
                        }
                    } catch (IOException | SAXException e) {
                        AnsiConsole.out.println(ansi().a("[").fg(RED).a("ERROR").reset().a("]"));
                        e.printStackTrace();
                    }
                } catch (FileNotFoundException | JAXBException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}
Also used : JAXBException(javax.xml.bind.JAXBException) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) Properties(java.util.Properties) FileInputStream(java.io.FileInputStream) LinkedList(java.util.LinkedList) SAXException(org.xml.sax.SAXException) FilenameFilter(java.io.FilenameFilter) TestCases(org.omg.dmn.tck.marshaller._20160719.TestCases) FileFilter(java.io.FileFilter) File(java.io.File) Map(java.util.Map)

Example 8 with TestCases

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

the class DroolsTCKTest method getTestCases.

@Override
public List<URL> getTestCases() {
    List<URL> testCases = new ArrayList<>();
    File cl2parent = new File("../../TestCases/compliance-level-2");
    FilenameFilter filenameFilter = (dir, name) -> name.matches("\\d\\d\\d\\d-.*");
    // FilenameFilter filenameFilter = (dir, name) -> name.matches( "0031-.*" );
    for (File file : cl2parent.listFiles(filenameFilter)) {
        try {
            testCases.add(file.toURI().toURL());
        } catch (MalformedURLException e) {
            e.printStackTrace();
        }
    }
    File cl3parent = new File("../../TestCases/compliance-level-3");
    for (File file : cl3parent.listFiles(filenameFilter)) {
        try {
            testCases.add(file.toURI().toURL());
        } catch (MalformedURLException e) {
            e.printStackTrace();
        }
    }
    testCases.sort((x, y) -> x.toString().compareTo(y.toString()));
    return testCases;
}
Also used : Arrays(java.util.Arrays) DmnTckSuite(org.omg.dmn.tck.runner.junit4.DmnTckSuite) DMNMessage(org.kie.dmn.api.core.DMNMessage) DMNResult(org.kie.dmn.api.core.DMNResult) URL(java.net.URL) ZonedDateTime(java.time.ZonedDateTime) LoggerFactory(org.slf4j.LoggerFactory) SimpleTypeImpl(org.kie.dmn.core.impl.SimpleTypeImpl) BigDecimal(java.math.BigDecimal) Duration(javax.xml.datatype.Duration) DMNModel(org.kie.dmn.api.core.DMNModel) TestSuiteContext(org.omg.dmn.tck.runner.junit4.TestSuiteContext) Map(java.util.Map) LocalTime(java.time.LocalTime) DatatypeConstants(javax.xml.datatype.DatatypeConstants) Method(java.lang.reflect.Method) Path(java.nio.file.Path) KieHelper(org.kie.internal.utils.KieHelper) SimpleFileVisitor(java.nio.file.SimpleFileVisitor) OffsetTime(java.time.OffsetTime) Collection(java.util.Collection) BaseDMNTypeImpl(org.kie.dmn.core.impl.BaseDMNTypeImpl) BuiltInType(org.kie.dmn.feel.lang.types.BuiltInType) Description(org.junit.runner.Description) Collectors(java.util.stream.Collectors) FileNotFoundException(java.io.FileNotFoundException) UncheckedIOException(java.io.UncheckedIOException) FileVisitResult(java.nio.file.FileVisitResult) TestCaseType(org.omg.dmn.tck.marshaller._20160719.TestCaseType) TestResult(org.omg.dmn.tck.runner.junit4.TestResult) DateTimeParseException(java.time.format.DateTimeParseException) List(java.util.List) ComparablePeriod(org.kie.dmn.feel.lang.types.impl.ComparablePeriod) LocalDate(java.time.LocalDate) DMNContext(org.kie.dmn.api.core.DMNContext) InputDataNode(org.kie.dmn.api.core.ast.InputDataNode) TestCases(org.omg.dmn.tck.marshaller._20160719.TestCases) EvalHelper(org.kie.dmn.feel.util.EvalHelper) FilenameFilter(java.io.FilenameFilter) DMNType(org.kie.dmn.api.core.DMNType) DmnTckVendorTestSuite(org.omg.dmn.tck.runner.junit4.DmnTckVendorTestSuite) LocalDateTime(java.time.LocalDateTime) RunWith(org.junit.runner.RunWith) HashMap(java.util.HashMap) Definitions(org.kie.dmn.model.api.Definitions) ArrayList(java.util.ArrayList) DecisionNode(org.kie.dmn.api.core.ast.DecisionNode) DMNMarshallerFactory(org.kie.dmn.backend.marshalling.v1x.DMNMarshallerFactory) Node(org.w3c.dom.Node) KieServices(org.kie.api.KieServices) DMNRuntime(org.kie.dmn.api.core.DMNRuntime) Type(org.kie.dmn.feel.lang.Type) Properties(java.util.Properties) Logger(org.slf4j.Logger) MalformedURLException(java.net.MalformedURLException) Files(java.nio.file.Files) JAXBElement(javax.xml.bind.JAXBElement) FileOutputStream(java.io.FileOutputStream) KieContainer(org.kie.api.runtime.KieContainer) IOException(java.io.IOException) BasicFileAttributes(java.nio.file.attribute.BasicFileAttributes) XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) File(java.io.File) DMNTypeRegistryV12(org.kie.dmn.core.compiler.DMNTypeRegistryV12) Paths(java.nio.file.Paths) DateTimeFormatter(java.time.format.DateTimeFormatter) ValueType(org.omg.dmn.tck.marshaller._20160719.ValueType) FileReader(java.io.FileReader) Collections(java.util.Collections) FilenameFilter(java.io.FilenameFilter) MalformedURLException(java.net.MalformedURLException) ArrayList(java.util.ArrayList) File(java.io.File) URL(java.net.URL)

Example 9 with TestCases

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

TestCases (org.omg.dmn.tck.marshaller._20160719.TestCases)8 File (java.io.File)5 FileInputStream (java.io.FileInputStream)3 ArrayList (java.util.ArrayList)3 Map (java.util.Map)3 JAXBElement (javax.xml.bind.JAXBElement)3 JAXBException (javax.xml.bind.JAXBException)3 Test (org.junit.Test)3 FileFilter (java.io.FileFilter)2 FileNotFoundException (java.io.FileNotFoundException)2 FilenameFilter (java.io.FilenameFilter)2 IOException (java.io.IOException)2 URL (java.net.URL)2 Properties (java.util.Properties)2 TestResult (org.omg.dmn.tck.runner.junit4.TestResult)2 StandardDMNDialectDefinition (com.gs.dmn.dialect.StandardDMNDialectDefinition)1 StandardFEELLib (com.gs.dmn.feel.lib.StandardFEELLib)1 DMNInterpreter (com.gs.dmn.runtime.interpreter.DMNInterpreter)1 Result (com.gs.dmn.runtime.interpreter.Result)1 DMNReader (com.gs.dmn.serialization.DMNReader)1