Search in sources :

Example 1 with TestCases

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

the class Reporter method loadTestCases.

private static Map<String, TestCasesData> loadTestCases(Parameters params) {
    logger.info("Loading test case definitions");
    Map<String, TestCasesData> tests = new TreeMap<>();
    List<URL> testCaseURLs = getTestCaseURLs(params);
    int testCount = 0;
    for (URL url : testCaseURLs) {
        File tcFolder = null;
        try {
            tcFolder = new File(url.toURI());
        } catch (URISyntaxException e) {
            logger.error("Error loading test case " + url, e);
            System.exit(1);
        }
        final String tcName = tcFolder.getName();
        File[] tcfiles = tcFolder.listFiles(new FilenameFilter() {

            public boolean accept(File dir, String name) {
                return name.matches(tcName + "-test-\\d\\d.xml");
            }
        });
        for (File tcfile : tcfiles) {
            try {
                TestCases tcd = TckMarshallingHelper.load(new FileInputStream(tcfile));
                testCount += tcd.getTestCase().size();
                String parent = tcfile.getParent();
                String folder = parent != null ? parent.substring(parent.lastIndexOf('/', parent.lastIndexOf('/') - 1) + 1) : "<unknown>";
                String tcdname = tcfile.getName();
                tcdname = tcdname.substring(0, tcdname.lastIndexOf('.')).replaceAll("\\.", "/");
                TestCasesData tcdd = new TestCasesData(folder, tcdname, tcd);
                tests.put(createTestCaseKey(folder, tcdname), tcdd);
            } catch (FileNotFoundException e) {
                logger.error("Error loading test case " + tcfile, e);
                System.exit(1);
            } catch (JAXBException e) {
                logger.error("Error loading test case " + tcfile, e);
                System.exit(1);
            }
        }
    }
    logger.info(tests.size() + " test suites loaded, with " + testCount + " unit tests");
    return tests;
}
Also used : JAXBException(javax.xml.bind.JAXBException) URISyntaxException(java.net.URISyntaxException) URL(java.net.URL) TestCases(org.omg.dmn.tck.marshaller._20160719.TestCases)

Example 2 with TestCases

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

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

the class JDMNTckTest method createContext.

@Override
public TestSuiteContext createContext() {
    DMNReader dmnReader = new DMNReader(LOGGER, false);
    DMNWriter dmnWriter = new DMNWriter(LOGGER);
    DMNTransformer<TestCases> dmnTransformer = new ToQuotedNameTransformer(LOGGER);
    StandardDMNDialectDefinition dialectDefinition = new StandardDMNDialectDefinition();
    return new JDMNTestContext<>(dmnReader, dmnWriter, dmnTransformer, dialectDefinition);
}
Also used : DMNReader(com.gs.dmn.serialization.DMNReader) DMNWriter(com.gs.dmn.serialization.DMNWriter) StandardDMNDialectDefinition(com.gs.dmn.dialect.StandardDMNDialectDefinition) TestCases(org.omg.dmn.tck.marshaller._20160719.TestCases) ToQuotedNameTransformer(com.gs.dmn.transformation.ToQuotedNameTransformer)

Example 4 with TestCases

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

the class TckMarshallingHelper method load.

@SuppressWarnings({ "unchecked" })
public static final TestCases load(InputStream inputStream) throws JAXBException {
    JAXBContext context = JAXBContext.newInstance(TestCases.class);
    Unmarshaller um = context.createUnmarshaller();
    Object obj = um.unmarshal(inputStream);
    if (obj instanceof JAXBElement<?>) {
        return ((JAXBElement<TestCases>) obj).getValue();
    } else {
        return (TestCases) obj;
    }
}
Also used : TestCases(org.omg.dmn.tck.marshaller._20160719.TestCases) JAXBContext(javax.xml.bind.JAXBContext) JAXBElement(javax.xml.bind.JAXBElement) Unmarshaller(javax.xml.bind.Unmarshaller)

Example 5 with TestCases

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

the class TestCasesFiles method testCaseFileIsValid.

@Test
public void testCaseFileIsValid() throws Exception {
    for (File dmnFile : basedir.listFiles((dir, name) -> name.matches(".*\\.xml$"))) {
        Validator validator = testCasesSchema.newValidator();
        validator.setProperty(XMLConstants.ACCESS_EXTERNAL_DTD, "");
        validator.setProperty(XMLConstants.ACCESS_EXTERNAL_SCHEMA, "");
        validator.validate(new StreamSource(dmnFile));
        TestCases testCases = TckMarshallingHelper.load(new FileInputStream(dmnFile));
        Map<String, Long> idCounting = testCases.getTestCase().stream().map(TestCases.TestCase::getId).collect(Collectors.groupingBy(Function.identity(), Collectors.counting()));
        for (Entry<String, Long> kv : idCounting.entrySet()) {
            assertThat("The id '" + kv.getKey() + "' is occuring more than one time in the file " + dmnFile, kv.getValue(), is(1L));
        }
    }
}
Also used : TestCases(org.omg.dmn.tck.marshaller._20160719.TestCases) StreamSource(javax.xml.transform.stream.StreamSource) File(java.io.File) Validator(javax.xml.validation.Validator) FileInputStream(java.io.FileInputStream) 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