camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ningji...@apache.org
Subject [01/13] CAMEL-7220 Added Camel Schematron component with thanks to Ayache
Date Fri, 12 Sep 2014 15:40:19 GMT
Repository: camel
Updated Branches:
  refs/heads/camel-2.14.x 7bbfd3585 -> a3ab30a55


http://git-wip-us.apache.org/repos/asf/camel/blob/a07d71fe/components/camel-schematron/src/test/java/org/apache/camel/component/schematron/SchematronComponentTest.java
----------------------------------------------------------------------
diff --git a/components/camel-schematron/src/test/java/org/apache/camel/component/schematron/SchematronComponentTest.java
b/components/camel-schematron/src/test/java/org/apache/camel/component/schematron/SchematronComponentTest.java
new file mode 100644
index 0000000..70f8ac2
--- /dev/null
+++ b/components/camel-schematron/src/test/java/org/apache/camel/component/schematron/SchematronComponentTest.java
@@ -0,0 +1,85 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.schematron;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.component.schematron.constant.Constants;
+import org.apache.camel.component.schematron.util.Utils;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.apache.commons.io.IOUtils;
+import org.custommonkey.xmlunit.Diff;
+import org.custommonkey.xmlunit.DifferenceListener;
+import org.custommonkey.xmlunit.IgnoreTextAndAttributeValuesDifferenceListener;
+import org.junit.Test;
+
+import static junit.framework.Assert.assertEquals;
+
+/**
+ * Schematron Component Test.
+ */
+public class SchematronComponentTest extends CamelTestSupport {
+
+
+    /**
+     * @throws Exception
+     */
+    @Test
+    public void testSendBodyAsString() throws Exception {
+        MockEndpoint mock = getMockEndpoint("mock:result");
+        mock.expectedMinimumMessageCount(1);
+
+        String payload = IOUtils.toString(ClassLoader.getSystemResourceAsStream("xml/article-1.xml"));
+        String expected = IOUtils.toString(ClassLoader.getSystemResourceAsStream("report/article-1-report.xml"));
+        template.sendBody("direct:start", payload);
+        assertMockEndpointsSatisfied();
+        String result = mock.getExchanges().get(0).getIn().getHeader(Constants.VALIDATION_REPORT,
String.class);
+        assertEquals(0, Integer.valueOf(Utils.evaluate("count(//svrl:failed-assert)", result)).intValue());
+        assertEquals(0, Integer.valueOf(Utils.evaluate("count(//svrl:successful-report)",
result)).intValue());
+    }
+
+    /**
+     * @throws Exception
+     */
+    @Test
+    public void testSendBodyAsInputStreamInvalidXML() throws Exception {
+        MockEndpoint mock = getMockEndpoint("mock:result");
+        mock.expectedMinimumMessageCount(1);
+
+        String payload = IOUtils.toString(ClassLoader.getSystemResourceAsStream("xml/article-2.xml"));
+        template.sendBody("direct:start", payload);
+        assertMockEndpointsSatisfied();
+        String result = mock.getExchanges().get(0).getIn().getHeader(Constants.VALIDATION_REPORT,
String.class);
+
+
+        // should throw two assertions because of the missing chapters in the XML.
+        assertEquals("A chapter should have a title", Utils.evaluate("//svrl:failed-assert[1]/svrl:text",
result));
+        assertEquals("A chapter should have a title", Utils.evaluate("//svrl:failed-assert[2]/svrl:text",
result));
+
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            public void configure() {
+                from("direct:start")
+                        .to("schematron://sch/schematron-1.sch")
+                        .to("mock:result");
+            }
+        };
+    }
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/a07d71fe/components/camel-schematron/src/test/java/org/apache/camel/component/schematron/SchematronEndpointTest.java
----------------------------------------------------------------------
diff --git a/components/camel-schematron/src/test/java/org/apache/camel/component/schematron/SchematronEndpointTest.java
b/components/camel-schematron/src/test/java/org/apache/camel/component/schematron/SchematronEndpointTest.java
new file mode 100644
index 0000000..6ac1389
--- /dev/null
+++ b/components/camel-schematron/src/test/java/org/apache/camel/component/schematron/SchematronEndpointTest.java
@@ -0,0 +1,86 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.schematron;
+
+
+import org.apache.camel.Endpoint;
+import org.apache.camel.Exchange;
+import org.apache.camel.ExchangePattern;
+import org.apache.camel.Producer;
+import org.apache.camel.component.schematron.exception.SchematronValidationException;
+import org.apache.camel.component.schematron.constant.Constants;
+import org.apache.camel.impl.DefaultExchange;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.apache.commons.io.IOUtils;
+import org.junit.Test;
+
+/**
+ * Unit test for SchematronEndpoint.
+ *
+ */
+public class SchematronEndpointTest extends CamelTestSupport {
+
+
+    @Test
+    public void testSchematronFileReadFromClassPath()throws Exception {
+
+        String payload = IOUtils.toString(ClassLoader.getSystemResourceAsStream("xml/article-1.xml"));
+        Endpoint endpoint = context().getEndpoint("schematron://sch/schematron-1.sch");
+        Producer producer = endpoint.createProducer();
+        Exchange exchange = new DefaultExchange(context, ExchangePattern.InOut);
+
+        exchange.getIn().setBody(payload);
+
+        // invoke the component.
+        producer.process(exchange);
+
+        String report = exchange.getOut().getHeader(Constants.VALIDATION_REPORT, String.class);
+        assertNotNull(report);
+    }
+
+    @Test
+    public void testSchematronFileReadFromFileSystem()throws Exception {
+
+        String payload = IOUtils.toString(ClassLoader.getSystemResourceAsStream("xml/article-2.xml"));
+        String path = ClassLoader.getSystemResource("sch/schematron-1.sch").getPath();
+        Endpoint endpoint = context().getEndpoint("schematron://" + path);
+        Producer producer = endpoint.createProducer();
+        Exchange exchange = new DefaultExchange(context, ExchangePattern.InOut);
+
+        exchange.getIn().setBody(payload);
+
+        // invoke the component.
+        producer.process(exchange);
+
+        String report = exchange.getOut().getHeader(Constants.VALIDATION_REPORT, String.class);
+        assertNotNull(report);
+    }
+
+    @Test(expected = SchematronValidationException.class)
+    public void testThrowSchematronValidationException() throws Exception {
+        String payload = IOUtils.toString(ClassLoader.getSystemResourceAsStream("xml/article-2.xml"));
+        Endpoint endpoint = context().getEndpoint("schematron://sch/schematron-1.sch?abort=true");
+        Producer producer = endpoint.createProducer();
+        Exchange exchange = new DefaultExchange(context, ExchangePattern.OutIn);
+
+        exchange.getIn().setBody(payload);
+
+        // invoke the component.
+        producer.process(exchange);
+
+    }
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/a07d71fe/components/camel-schematron/src/test/java/org/apache/camel/component/schematron/SchematronProducerTest.java
----------------------------------------------------------------------
diff --git a/components/camel-schematron/src/test/java/org/apache/camel/component/schematron/SchematronProducerTest.java
b/components/camel-schematron/src/test/java/org/apache/camel/component/schematron/SchematronProducerTest.java
new file mode 100644
index 0000000..5bdf9a7
--- /dev/null
+++ b/components/camel-schematron/src/test/java/org/apache/camel/component/schematron/SchematronProducerTest.java
@@ -0,0 +1,71 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.schematron;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.ExchangePattern;
+import org.apache.camel.component.schematron.constant.Constants;
+import org.apache.camel.component.schematron.processor.TemplatesFactory;
+import org.apache.camel.impl.DefaultExchange;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import javax.xml.transform.Templates;
+
+/**
+ * Schematron Producer Unit Test.
+ * <p/>
+ */
+public class SchematronProducerTest extends CamelTestSupport {
+
+    private static SchematronProducer producer;
+
+    @BeforeClass
+    public static void setUP() {
+        SchematronEndpoint endpoint = new SchematronEndpoint();
+        Templates templates = TemplatesFactory.newInstance().newTemplates(ClassLoader.
+                getSystemResourceAsStream("sch/schematron-1.sch"));
+        endpoint.setRules(templates);
+        producer = new SchematronProducer(endpoint);
+    }
+
+    @Test
+    public void testProcessValidXML() throws Exception {
+        Exchange exc = new DefaultExchange(context, ExchangePattern.InOut);
+        exc.getIn().setBody(ClassLoader.getSystemResourceAsStream("xml/article-1.xml"));
+
+        // process xml payload
+        producer.process(exc);
+
+        // assert
+        assertTrue(exc.getOut().getHeader(Constants.VALIDATION_STATUS).equals(Constants.SUCCESS));
+    }
+
+    @Test
+    public void testProcessInValidXML() throws Exception {
+        Exchange exc = new DefaultExchange(context, ExchangePattern.InOut);
+        exc.getIn().setBody(ClassLoader.getSystemResourceAsStream("xml/article-2.xml"));
+
+        // process xml payload
+        producer.process(exc);
+
+        // assert
+        assertTrue(exc.getOut().getHeader(Constants.VALIDATION_STATUS).equals(Constants.FAILED));
+
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/a07d71fe/components/camel-schematron/src/test/java/org/apache/camel/component/schematron/processor/SchematronProcessorTest.java
----------------------------------------------------------------------
diff --git a/components/camel-schematron/src/test/java/org/apache/camel/component/schematron/processor/SchematronProcessorTest.java
b/components/camel-schematron/src/test/java/org/apache/camel/component/schematron/processor/SchematronProcessorTest.java
new file mode 100644
index 0000000..198a176
--- /dev/null
+++ b/components/camel-schematron/src/test/java/org/apache/camel/component/schematron/processor/SchematronProcessorTest.java
@@ -0,0 +1,76 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.schematron.processor;
+
+import org.apache.camel.component.schematron.util.Utils;
+import org.apache.commons.io.IOUtils;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.xml.transform.Templates;
+
+import static junit.framework.Assert.assertEquals;
+
+/**
+ * SchematronEngine Unit Test.
+ */
+public class SchematronProcessorTest {
+
+    private Logger logger = LoggerFactory.getLogger(SchematronProcessorTest.class);
+
+    @Test
+    public void testValidXML() throws Exception {
+
+        String payload = IOUtils.toString(ClassLoader.getSystemResourceAsStream("xml/article-1.xml"));
+        logger.info("Validating payload: {}", payload);
+        String expected = IOUtils.toString(ClassLoader.getSystemResourceAsStream("report/article-1-report.xml"));
+
+        // validate
+        String result = getProcessor("sch/schematron-1.sch").validate(payload);
+        logger.info("Schematron Report: {}", result);
+        assertEquals(0, Integer.valueOf(Utils.evaluate("count(//svrl:failed-assert)", result)).intValue());
+        assertEquals(0, Integer.valueOf(Utils.evaluate("count(//svrl:successful-report)",
result)).intValue());
+
+    }
+
+    @Test
+    public void testInValidXML() throws Exception {
+
+        String payload = IOUtils.toString(ClassLoader.getSystemResourceAsStream("xml/article-2.xml"));
+        logger.info("Validating payload: {}", payload);
+        // validate
+        String result = getProcessor("sch/schematron-2.sch").validate(payload);
+        logger.info("Schematron Report: {}", result);
+        // should throw two assertions because of the missing chapters in the XML.
+        assertEquals("A chapter should have a title", Utils.evaluate("//svrl:failed-assert/svrl:text",
result));
+        assertEquals("'chapter' element has more than one title present", Utils.evaluate("//svrl:successful-report/svrl:text",
result).trim());
+
+
+    }
+
+    /**
+     * Returns schematron processor
+     *
+     * @param schematron
+     * @return
+     */
+    private SchematronProcessor getProcessor(final String schematron) {
+        Templates rules = TemplatesFactory.newInstance().newTemplates(ClassLoader.getSystemResourceAsStream(schematron));
+        return SchematronProcessorFactory.newScehamtronEngine(rules);
+    }
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/a07d71fe/components/camel-schematron/src/test/java/org/apache/camel/component/schematron/processor/TemplatesFactoryTest.java
----------------------------------------------------------------------
diff --git a/components/camel-schematron/src/test/java/org/apache/camel/component/schematron/processor/TemplatesFactoryTest.java
b/components/camel-schematron/src/test/java/org/apache/camel/component/schematron/processor/TemplatesFactoryTest.java
new file mode 100644
index 0000000..5c536ee
--- /dev/null
+++ b/components/camel-schematron/src/test/java/org/apache/camel/component/schematron/processor/TemplatesFactoryTest.java
@@ -0,0 +1,42 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.schematron.processor;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import javax.xml.transform.Templates;
+
+/**
+ * TemplateFactory Unit Test.
+ *
+ */
+public class TemplatesFactoryTest {
+
+    private String rules = "sch/schematron-1.sch";
+
+    @Test
+    public void testInstantiateAnInstanceOfTemplates() throws Exception {
+
+
+        TemplatesFactory fac = TemplatesFactory.newInstance();
+        Templates templates = fac.newTemplates(ClassLoader.getSystemResourceAsStream(rules));
+        Assert.assertNotNull(templates);
+
+
+    }
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/a07d71fe/components/camel-schematron/src/test/java/org/apache/camel/component/schematron/util/Utils.java
----------------------------------------------------------------------
diff --git a/components/camel-schematron/src/test/java/org/apache/camel/component/schematron/util/Utils.java
b/components/camel-schematron/src/test/java/org/apache/camel/component/schematron/util/Utils.java
new file mode 100644
index 0000000..1754e44
--- /dev/null
+++ b/components/camel-schematron/src/test/java/org/apache/camel/component/schematron/util/Utils.java
@@ -0,0 +1,63 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.schematron.util;
+
+import org.apache.camel.RuntimeCamelException;
+import org.apache.camel.component.schematron.constant.Constants;
+import org.custommonkey.xmlunit.SimpleNamespaceContext;
+import org.custommonkey.xmlunit.XMLUnit;
+import org.custommonkey.xmlunit.XpathEngine;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * Utility Class.
+ * <p/>
+ */
+public final class Utils {
+
+    private static final Logger LOG = LoggerFactory.getLogger(Utils.class);
+
+    private Utils() {
+        throw new IllegalStateException("This is a utility class");
+    }
+
+    /**
+     * Evaluate an XPATH expression.
+     *
+     * @param xpath
+     * @param xml
+     * @return
+     */
+    public static String evaluate(final String xpath, final String xml) {
+        Map<String, Object> m = new HashMap<String, Object>();
+        m.put("svrl", Constants.HTTP_PURL_OCLC_ORG_DSDL_SVRL);
+        XpathEngine xpathEngine = XMLUnit.newXpathEngine();
+        xpathEngine.setNamespaceContext(new SimpleNamespaceContext(m));
+        try {
+            return xpathEngine.evaluate(xpath, XMLUnit.buildControlDocument(xml));
+
+        } catch (Exception e) {
+            LOG.error("Failed to apply xpath {} on xml {}", xpath, xml);
+            throw new RuntimeCamelException(e);
+        }
+    }
+
+
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/a07d71fe/components/camel-schematron/src/test/resources/log4j.properties
----------------------------------------------------------------------
diff --git a/components/camel-schematron/src/test/resources/log4j.properties b/components/camel-schematron/src/test/resources/log4j.properties
new file mode 100644
index 0000000..37c1447
--- /dev/null
+++ b/components/camel-schematron/src/test/resources/log4j.properties
@@ -0,0 +1,14 @@
+#
+# The logging properties used
+#
+log4j.rootLogger=TRACE, out
+
+# uncomment the following line to turn on Camel debugging
+#log4j.logger.org.apache.camel=DEBUG
+
+# CONSOLE appender not used by default
+log4j.appender.out=org.apache.log4j.ConsoleAppender
+log4j.appender.out.layout=org.apache.log4j.PatternLayout
+log4j.appender.out.layout.ConversionPattern=[%30.30t] %-30.30c{1} %-5p %m%n
+#log4j.appender.out.layout.ConversionPattern=%d [%-15.15t] %-5p %-30.30c{1} - %m%n
+

http://git-wip-us.apache.org/repos/asf/camel/blob/a07d71fe/components/camel-schematron/src/test/resources/report/article-1-report.xml
----------------------------------------------------------------------
diff --git a/components/camel-schematron/src/test/resources/report/article-1-report.xml b/components/camel-schematron/src/test/resources/report/article-1-report.xml
new file mode 100644
index 0000000..1f40fe8
--- /dev/null
+++ b/components/camel-schematron/src/test/resources/report/article-1-report.xml
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
+<svrl:schematron-output xmlns:svrl="http://purl.oclc.org/dsdl/svrl"
+                        xmlns:iso="http://purl.oclc.org/dsdl/schematron"
+                        xmlns:xhtml="http://www.w3.org/1999/xhtml"
+                        xmlns:p="http://www.apache.org/camel/schematron"
+                        xmlns:xsd="http://www.w3.org/2001/XMLSchema"
+                        xmlns:saxon="http://saxon.sf.net/"
+                        xmlns:xs="http://www.w3.org/2001/XMLSchema"
+                        xmlns:schold="http://www.ascc.net/xml/schematron"
+                        schemaVersion=""
+                        title="Sample Schematron using XPath 2.0"><!--   
+           
+           
+         -->
+    <svrl:ns-prefix-in-attribute-values prefix="xs" uri="http://www.w3.org/2001/XMLSchema"/>
+    <svrl:ns-prefix-in-attribute-values prefix="p" uri="http://www.apache.org/camel/schematron"/>
+    <svrl:active-pattern document=""/>
+    <svrl:fired-rule context="chapter"/>
+    <svrl:fired-rule context="chapter"/>
+    <svrl:fired-rule context="chapter"/>
+</svrl:schematron-output>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/camel/blob/a07d71fe/components/camel-schematron/src/test/resources/report/article-2-report.xml
----------------------------------------------------------------------
diff --git a/components/camel-schematron/src/test/resources/report/article-2-report.xml b/components/camel-schematron/src/test/resources/report/article-2-report.xml
new file mode 100644
index 0000000..d3069cb
--- /dev/null
+++ b/components/camel-schematron/src/test/resources/report/article-2-report.xml
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<svrl:schematron-output xmlns:svrl="http://purl.oclc.org/dsdl/svrl" xmlns:iso="http://purl.oclc.org/dsdl/schematron"
xmlns:saxon="http://saxon.sf.net/" xmlns:schold="http://www.ascc.net/xml/schematron" xmlns:xhtml="http://www.w3.org/1999/xhtml"
xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsd="http://www.w3.org/2001/XMLSchema" schemaVersion=""
title="">
+    <!--
+
+
+          -->
+    <svrl:active-pattern document="" />
+    <svrl:fired-rule context="chapter" />
+    <svrl:failed-assert test="title" location="/doc[1]/chapter[1]">
+        <svrl:text>A chapter should have a title</svrl:text>
+    </svrl:failed-assert>
+    <svrl:fired-rule context="chapter" />
+    <svrl:failed-assert test="title" location="/doc[1]/chapter[2]">
+        <svrl:text>A chapter should have a title</svrl:text>
+    </svrl:failed-assert>
+    <svrl:fired-rule context="chapter" />
+</svrl:schematron-output>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/camel/blob/a07d71fe/components/camel-schematron/src/test/resources/sch/schematron-1.sch
----------------------------------------------------------------------
diff --git a/components/camel-schematron/src/test/resources/sch/schematron-1.sch b/components/camel-schematron/src/test/resources/sch/schematron-1.sch
new file mode 100644
index 0000000..49b329c
--- /dev/null
+++ b/components/camel-schematron/src/test/resources/sch/schematron-1.sch
@@ -0,0 +1,17 @@
+<?xml version="1.0"?>
+<sch:schema xmlns:sch="http://purl.oclc.org/dsdl/schematron"
+            queryBinding="xslt2">
+
+    <sch:title>Sample Schematron using XPath 2.0</sch:title>
+    <sch:ns prefix="xs" uri="http://www.w3.org/2001/XMLSchema"/>
+    <sch:ns prefix="p" uri="http://www.apache.org/camel/schematron"/>
+
+
+    <!-- Your constraints go here -->
+    <sch:pattern>
+        <sch:rule context="chapter | p:chapter">
+            <sch:assert test="title | p:title">A chapter should have a title</sch:assert>
+        </sch:rule>
+    </sch:pattern>
+
+</sch:schema>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/camel/blob/a07d71fe/components/camel-schematron/src/test/resources/sch/schematron-2.sch
----------------------------------------------------------------------
diff --git a/components/camel-schematron/src/test/resources/sch/schematron-2.sch b/components/camel-schematron/src/test/resources/sch/schematron-2.sch
new file mode 100644
index 0000000..18f4bca
--- /dev/null
+++ b/components/camel-schematron/src/test/resources/sch/schematron-2.sch
@@ -0,0 +1,21 @@
+<?xml version="1.0"?>
+<sch:schema xmlns:sch="http://purl.oclc.org/dsdl/schematron"
+            queryBinding="xslt2">
+
+    <sch:title>Sample Schematron using XPath 2.0</sch:title>
+    <sch:ns prefix="p" uri="http://www.apache.org/camel/schematron"/>
+    <sch:ns prefix="xs" uri="http://www.w3.org/2001/XMLSchema"/>
+
+    <!-- Your constraints go here -->
+    <sch:pattern>
+
+        <sch:rule context="p:chapter">
+            <sch:let name="numOfTitles" select="count(p:title)"/>
+            <sch:assert test="p:title">A chapter should have a title</sch:assert>
+            <sch:report test="count(p:title) > 1">
+                        'chapter' element has more than one title present
+             </sch:report>
+        </sch:rule>
+    </sch:pattern>
+
+</sch:schema>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/camel/blob/a07d71fe/components/camel-schematron/src/test/resources/schema/article.xsd
----------------------------------------------------------------------
diff --git a/components/camel-schematron/src/test/resources/schema/article.xsd b/components/camel-schematron/src/test/resources/schema/article.xsd
new file mode 100644
index 0000000..8eb79b3
--- /dev/null
+++ b/components/camel-schematron/src/test/resources/schema/article.xsd
@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="utf-8"?>
+<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
+    <xs:element name="doc">
+        <xs:complexType>
+            <xs:sequence>
+                <xs:element name="chapter" maxOccurs="unbounded" minOccurs="0">
+                    <xs:complexType>
+                        <xs:sequence>
+                            <xs:element type="xs:string" name="title"/>
+                            <xs:element type="xs:string" name="para"/>
+                        </xs:sequence>
+                        <xs:attribute type="xs:string" name="id" use="optional"/>
+                    </xs:complexType>
+                </xs:element>
+            </xs:sequence>
+        </xs:complexType>
+    </xs:element>
+</xs:schema>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/camel/blob/a07d71fe/components/camel-schematron/src/test/resources/xml/article-1.xml
----------------------------------------------------------------------
diff --git a/components/camel-schematron/src/test/resources/xml/article-1.xml b/components/camel-schematron/src/test/resources/xml/article-1.xml
new file mode 100644
index 0000000..3c95d56
--- /dev/null
+++ b/components/camel-schematron/src/test/resources/xml/article-1.xml
@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="utf-8"?>
+<doc>
+    <chapter id="c1">
+        <title>chapter title</title>
+        <para>Chapter content</para>
+    </chapter>
+    <chapter id="c2">
+        <title>chapter 2 title</title>
+        <para>Content</para>
+    </chapter>
+    <chapter id="c3">
+        <title>Title</title>
+        <para>Chapter 3 content</para>
+    </chapter>
+</doc> 
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/camel/blob/a07d71fe/components/camel-schematron/src/test/resources/xml/article-2.xml
----------------------------------------------------------------------
diff --git a/components/camel-schematron/src/test/resources/xml/article-2.xml b/components/camel-schematron/src/test/resources/xml/article-2.xml
new file mode 100644
index 0000000..33698b5
--- /dev/null
+++ b/components/camel-schematron/src/test/resources/xml/article-2.xml
@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="utf-8"?>
+<p:doc xmlns:p="http://www.apache.org/camel/schematron">
+    <p:chapter id="c1">
+        <p:para>Chapter content</p:para>
+    </p:chapter>
+    <p:chapter id="c2">
+        <p:para>Content</p:para>
+    </p:chapter>
+    <p:chapter id="c3">
+        <p:title>Title</p:title>
+        <p:title>Title2</p:title>
+        <p:para>Chapter 3 content</p:para>
+    </p:chapter>
+</p:doc>
\ No newline at end of file


Mime
View raw message