camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject [2/4] camel git commit: Tests added.
Date Sun, 15 Mar 2015 06:39:39 GMT
Tests added.


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/e2968394
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/e2968394
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/e2968394

Branch: refs/heads/master
Commit: e2968394b61b3b4132327548b6c2ca6367f4c7ad
Parents: c87732d
Author: nkukhar <kukhar.n@gmail.com>
Authored: Sat Mar 14 01:07:20 2015 -0700
Committer: Claus Ibsen <davsclaus@apache.org>
Committed: Sun Mar 15 07:38:49 2015 +0100

----------------------------------------------------------------------
 .../pom.xml                                     |  13 ++
 .../camel/maven/CamelSpringNamespaceTest.java   |  55 +++++++
 .../org/apache/camel/maven/DomFinderTest.java   |  72 +++++++++
 .../maven/EipDocumentationEnricherMojoTest.java | 147 +++++++++++++++++++
 .../apache/camel/maven/PackageHelperTest.java   |   4 +-
 .../org/apache/camel/maven/ResourceUtils.java   |  28 ++++
 .../org/apache/camel/maven/XmlHelperTest.java   |  51 +++++++
 .../integration/EIPDocumentationMojoTest.java   | 113 ++++++++++++++
 .../test/resources/integration/camel-spring.xsd | 114 ++++++++++++++
 .../src/test/resources/json/aop.json            |  21 +++
 .../src/test/resources/xmls/3_elements.xml      |   6 +
 .../src/test/resources/xmls/aop.xml             |   4 +
 .../src/test/resources/xmls/complex_type.xml    |   9 ++
 .../resources/xmls/complex_type_w_parent.xml    |  19 +++
 .../test/resources/xmls/element_doc_enrich.xml  |   0
 .../src/test/resources/xmls/empty.xml           |   2 +
 16 files changed, 656 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/e2968394/tooling/maven/camel-eip-documentation-enricher-maven-plugin/pom.xml
----------------------------------------------------------------------
diff --git a/tooling/maven/camel-eip-documentation-enricher-maven-plugin/pom.xml b/tooling/maven/camel-eip-documentation-enricher-maven-plugin/pom.xml
index 177c5dc..370f2eb 100644
--- a/tooling/maven/camel-eip-documentation-enricher-maven-plugin/pom.xml
+++ b/tooling/maven/camel-eip-documentation-enricher-maven-plugin/pom.xml
@@ -100,6 +100,19 @@
       <artifactId>junit</artifactId>
       <scope>test</scope>
     </dependency>
+
+    <dependency>
+      <groupId>org.hamcrest</groupId>
+      <artifactId>hamcrest-core</artifactId>
+      <version>${hamcrest-version}</version>
+      <scope>test</scope>
+    </dependency>
+
+    <dependency>
+      <groupId>org.mockito</groupId>
+      <artifactId>mockito-core</artifactId>
+      <scope>test</scope>
+    </dependency>
     <!-- Camel annotations in provided scope to avoid compile errors in IDEs -->
     <dependency>
       <groupId>org.apache.camel</groupId>

http://git-wip-us.apache.org/repos/asf/camel/blob/e2968394/tooling/maven/camel-eip-documentation-enricher-maven-plugin/src/test/java/org/apache/camel/maven/CamelSpringNamespaceTest.java
----------------------------------------------------------------------
diff --git a/tooling/maven/camel-eip-documentation-enricher-maven-plugin/src/test/java/org/apache/camel/maven/CamelSpringNamespaceTest.java
b/tooling/maven/camel-eip-documentation-enricher-maven-plugin/src/test/java/org/apache/camel/maven/CamelSpringNamespaceTest.java
new file mode 100644
index 0000000..ee19982
--- /dev/null
+++ b/tooling/maven/camel-eip-documentation-enricher-maven-plugin/src/test/java/org/apache/camel/maven/CamelSpringNamespaceTest.java
@@ -0,0 +1,55 @@
+/**
+ * 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.maven;
+
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.fail;
+
+public class CamelSpringNamespaceTest {
+
+    private CamelSpringNamespace camelSpringNamespace = new CamelSpringNamespace();
+
+    @Test
+    public void testSchemaNamespace() throws Exception {
+        assertEquals(Constants.XML_SCHEMA_NAMESPACE_URI,
+                camelSpringNamespace.getNamespaceURI(Constants.XML_SCHEMA_NAMESPACE_PREFIX));
+        assertNull(camelSpringNamespace.getNamespaceURI("unregisterdPrefix"));
+    }
+
+    @Test
+    public void testGetPrefix() throws Exception {
+        try {
+            camelSpringNamespace.getPrefix(Constants.XML_SCHEMA_NAMESPACE_URI);
+            fail("UnsupportedOperationException expected");
+        } catch (UnsupportedOperationException e) {
+            // Expected.
+        }
+    }
+
+    @Test
+    public void testGetPrefixes() throws Exception {
+        try {
+            camelSpringNamespace.getPrefixes(Constants.XML_SCHEMA_NAMESPACE_URI);
+            fail("UnsupportedOperationException expected");
+        } catch (UnsupportedOperationException e) {
+            // Expected.
+        }
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/camel/blob/e2968394/tooling/maven/camel-eip-documentation-enricher-maven-plugin/src/test/java/org/apache/camel/maven/DomFinderTest.java
----------------------------------------------------------------------
diff --git a/tooling/maven/camel-eip-documentation-enricher-maven-plugin/src/test/java/org/apache/camel/maven/DomFinderTest.java
b/tooling/maven/camel-eip-documentation-enricher-maven-plugin/src/test/java/org/apache/camel/maven/DomFinderTest.java
new file mode 100644
index 0000000..86a508f
--- /dev/null
+++ b/tooling/maven/camel-eip-documentation-enricher-maven-plugin/src/test/java/org/apache/camel/maven/DomFinderTest.java
@@ -0,0 +1,72 @@
+/**
+ * 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.maven;
+
+import javax.xml.xpath.XPath;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.NodeList;
+
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+
+public class DomFinderTest {
+    private DomFinder domFinder;
+
+    @Test
+    public void testFindElementsAndTypes() throws Exception {
+        Document document = XmlHelper.buildNamespaceAwareDocument(
+                ResourceUtils.getResourceAsFile("xmls/3_elements.xml"));
+        XPath xPath = XmlHelper.buildXPath(new CamelSpringNamespace());
+        domFinder = new DomFinder(document, xPath);
+
+        NodeList elements = domFinder.findElementsAndTypes();
+
+        assertEquals(3, elements.getLength());
+    }
+
+    @Test
+    public void testFindAttributesElements() throws Exception {
+        Document document = XmlHelper.buildNamespaceAwareDocument(
+                ResourceUtils.getResourceAsFile("xmls/complex_type.xml"));
+        XPath xPath = XmlHelper.buildXPath(new CamelSpringNamespace());
+        domFinder = new DomFinder(document, xPath);
+
+        NodeList attributesList = domFinder.findAttributesElements("interceptSendToEndpointDefinition");
+
+        assertEquals(2, attributesList.getLength());
+
+        assertEquals("uri", ((Element) attributesList.item(0)).getAttribute(Constants.NAME_ATTRIBUTE_NAME));
+        assertEquals("skipSendToOriginalEndpoint",
+                ((Element) attributesList.item(1)).getAttribute(Constants.NAME_ATTRIBUTE_NAME));
+
+    }
+
+    @Test
+    public void testFindBaseType() throws Exception {
+        Document document = XmlHelper.buildNamespaceAwareDocument(
+                ResourceUtils.getResourceAsFile("xmls/complex_type_w_parent.xml"));
+        XPath xPath = XmlHelper.buildXPath(new CamelSpringNamespace());
+        domFinder = new DomFinder(document, xPath);
+
+        String baseTypeName = domFinder.findBaseType("keyManagersParametersFactoryBean");
+
+        assertEquals("tns:abstractKeyManagersParametersFactoryBean", baseTypeName);
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/camel/blob/e2968394/tooling/maven/camel-eip-documentation-enricher-maven-plugin/src/test/java/org/apache/camel/maven/EipDocumentationEnricherMojoTest.java
----------------------------------------------------------------------
diff --git a/tooling/maven/camel-eip-documentation-enricher-maven-plugin/src/test/java/org/apache/camel/maven/EipDocumentationEnricherMojoTest.java
b/tooling/maven/camel-eip-documentation-enricher-maven-plugin/src/test/java/org/apache/camel/maven/EipDocumentationEnricherMojoTest.java
new file mode 100644
index 0000000..e9dc226
--- /dev/null
+++ b/tooling/maven/camel-eip-documentation-enricher-maven-plugin/src/test/java/org/apache/camel/maven/EipDocumentationEnricherMojoTest.java
@@ -0,0 +1,147 @@
+/**
+ * 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.maven;
+
+import java.io.File;
+
+import org.apache.maven.plugin.MojoExecutionException;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+
+import static org.junit.Assert.fail;
+import static org.mockito.Mockito.when;
+
+public class EipDocumentationEnricherMojoTest {
+    private EipDocumentationEnricherMojo eipDocumentationEnricherMojo = new EipDocumentationEnricherMojo();
+
+    @Mock
+    private File mockCamelCore;
+
+    @Mock
+    private File mockInputSchema;
+
+
+    @Before
+    public void setUp() throws Exception {
+        MockitoAnnotations.initMocks(this);
+    }
+
+    @Test
+    public void testExecuteCamelCoreDoesNotExist() throws Exception {
+        when(mockCamelCore.exists()).thenReturn(false);
+        when(mockCamelCore.isDirectory()).thenReturn(true);
+        when(mockInputSchema.exists()).thenReturn(true);
+        when(mockInputSchema.isFile()).thenReturn(true);
+
+        eipDocumentationEnricherMojo.camelCoreDir = mockCamelCore;
+        eipDocumentationEnricherMojo.inputCamelSchemaFile = mockInputSchema;
+
+        try {
+            eipDocumentationEnricherMojo.execute();
+            fail("Expected MojoExecutionException");
+        } catch (MojoExecutionException e) {
+            // Expected.
+        }
+    }
+
+    @Test
+    public void testExecuteCamelCoreIsNull() throws Exception {
+        when(mockInputSchema.exists()).thenReturn(true);
+        when(mockInputSchema.isFile()).thenReturn(true);
+
+        eipDocumentationEnricherMojo.camelCoreDir = null;
+        eipDocumentationEnricherMojo.inputCamelSchemaFile = mockInputSchema;
+        try {
+            eipDocumentationEnricherMojo.execute();
+            fail("Expected MojoExecutionException");
+        } catch (MojoExecutionException e) {
+            // Expected.
+        }
+    }
+
+    @Test
+    public void testExecuteCamelCoreIsNotADirectory() throws Exception {
+        when(mockCamelCore.exists()).thenReturn(true);
+        when(mockCamelCore.isDirectory()).thenReturn(false);
+        when(mockInputSchema.exists()).thenReturn(true);
+        when(mockInputSchema.isFile()).thenReturn(true);
+
+        eipDocumentationEnricherMojo.camelCoreDir = mockCamelCore;
+        eipDocumentationEnricherMojo.inputCamelSchemaFile = mockInputSchema;
+
+        try {
+            eipDocumentationEnricherMojo.execute();
+            fail("Expected MojoExecutionException");
+        } catch (MojoExecutionException e) {
+            // Expected.
+        }
+    }
+
+    @Test
+    public void testExecuteInputCamelSchemaDoesNotExist() throws Exception {
+        when(mockCamelCore.exists()).thenReturn(true);
+        when(mockCamelCore.isDirectory()).thenReturn(true);
+        when(mockInputSchema.exists()).thenReturn(false);
+        when(mockInputSchema.isFile()).thenReturn(true);
+
+        eipDocumentationEnricherMojo.camelCoreDir = mockCamelCore;
+        eipDocumentationEnricherMojo.inputCamelSchemaFile = mockInputSchema;
+
+        try {
+            eipDocumentationEnricherMojo.execute();
+            fail("Expected MojoExecutionException");
+        } catch (MojoExecutionException e) {
+            // Expected.
+        }
+    }
+
+    @Test
+    public void testExecuteInputCamelSchemaIsNull() throws Exception {
+        when(mockCamelCore.exists()).thenReturn(true);
+        when(mockCamelCore.isDirectory()).thenReturn(true);
+
+        eipDocumentationEnricherMojo.camelCoreDir = mockCamelCore;
+        eipDocumentationEnricherMojo.inputCamelSchemaFile = null;
+        try {
+            eipDocumentationEnricherMojo.execute();
+            fail("Expected MojoExecutionException");
+        } catch (MojoExecutionException e) {
+            // Expected.
+        }
+    }
+
+    @Test
+    public void testExecuteInputCamelSchemaIsNotAFile() throws Exception {
+        when(mockCamelCore.exists()).thenReturn(true);
+        when(mockCamelCore.isDirectory()).thenReturn(true);
+        when(mockInputSchema.exists()).thenReturn(true);
+        when(mockInputSchema.isFile()).thenReturn(false);
+
+        eipDocumentationEnricherMojo.camelCoreDir = mockCamelCore;
+        eipDocumentationEnricherMojo.inputCamelSchemaFile = mockInputSchema;
+
+        try {
+            eipDocumentationEnricherMojo.execute();
+            fail("Expected MojoExecutionException");
+        } catch (MojoExecutionException e) {
+            // Expected.
+        }
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/camel/blob/e2968394/tooling/maven/camel-eip-documentation-enricher-maven-plugin/src/test/java/org/apache/camel/maven/PackageHelperTest.java
----------------------------------------------------------------------
diff --git a/tooling/maven/camel-eip-documentation-enricher-maven-plugin/src/test/java/org/apache/camel/maven/PackageHelperTest.java
b/tooling/maven/camel-eip-documentation-enricher-maven-plugin/src/test/java/org/apache/camel/maven/PackageHelperTest.java
index 0d45deb..2acdb20 100644
--- a/tooling/maven/camel-eip-documentation-enricher-maven-plugin/src/test/java/org/apache/camel/maven/PackageHelperTest.java
+++ b/tooling/maven/camel-eip-documentation-enricher-maven-plugin/src/test/java/org/apache/camel/maven/PackageHelperTest.java
@@ -29,12 +29,12 @@ public class PackageHelperTest {
 
     @Test
     public void testFileToString() throws Exception {
-        assertEquals("dk19i21)@+#(OR", PackageHelper.fileToString(new File(this.getClass().getClassLoader().getResource("filecontent/a.txt").getFile())));
+        assertEquals("dk19i21)@+#(OR", PackageHelper.fileToString(ResourceUtils.getResourceAsFile("filecontent/a.txt")));
     }
 
     @Test
     public void testFindJsonFiles() throws Exception {
-        Map<String, File> jsonFiles = PackageHelper.findJsonFiles(new File(this.getClass().getClassLoader().getResource("json").getFile()));
+        Map<String, File> jsonFiles = PackageHelper.findJsonFiles(ResourceUtils.getResourceAsFile("json"));
 
         assertTrue("Files a.json must be found", jsonFiles.containsKey("a"));
         assertTrue("Files b.json must be found", jsonFiles.containsKey("b"));

http://git-wip-us.apache.org/repos/asf/camel/blob/e2968394/tooling/maven/camel-eip-documentation-enricher-maven-plugin/src/test/java/org/apache/camel/maven/ResourceUtils.java
----------------------------------------------------------------------
diff --git a/tooling/maven/camel-eip-documentation-enricher-maven-plugin/src/test/java/org/apache/camel/maven/ResourceUtils.java
b/tooling/maven/camel-eip-documentation-enricher-maven-plugin/src/test/java/org/apache/camel/maven/ResourceUtils.java
new file mode 100644
index 0000000..2da69fa
--- /dev/null
+++ b/tooling/maven/camel-eip-documentation-enricher-maven-plugin/src/test/java/org/apache/camel/maven/ResourceUtils.java
@@ -0,0 +1,28 @@
+/**
+ * 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.maven;
+
+import java.io.File;
+
+public class ResourceUtils {
+    private ResourceUtils() { }
+
+    public static File getResourceAsFile(String pathToFile) throws Exception {
+        return new File(ResourceUtils.class.getClassLoader().getResource(pathToFile).getFile());
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/e2968394/tooling/maven/camel-eip-documentation-enricher-maven-plugin/src/test/java/org/apache/camel/maven/XmlHelperTest.java
----------------------------------------------------------------------
diff --git a/tooling/maven/camel-eip-documentation-enricher-maven-plugin/src/test/java/org/apache/camel/maven/XmlHelperTest.java
b/tooling/maven/camel-eip-documentation-enricher-maven-plugin/src/test/java/org/apache/camel/maven/XmlHelperTest.java
new file mode 100644
index 0000000..b2e3ed5
--- /dev/null
+++ b/tooling/maven/camel-eip-documentation-enricher-maven-plugin/src/test/java/org/apache/camel/maven/XmlHelperTest.java
@@ -0,0 +1,51 @@
+/**
+ * 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.maven;
+
+import org.junit.Test;
+
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.fail;
+
+public class XmlHelperTest {
+
+    @Test
+    public void testBuildNamespaceAwareDocument() throws Exception {
+        assertNotNull(XmlHelper.buildNamespaceAwareDocument(ResourceUtils.getResourceAsFile("xmls/empty.xml")));
+    }
+
+    @Test
+    public void testBuildTransformer() throws Exception {
+        assertNotNull(XmlHelper.buildTransformer());
+    }
+
+    @Test
+    public void testBuildXPath() throws Exception {
+        assertNotNull(XmlHelper.buildXPath(new CamelSpringNamespace()));
+    }
+
+    @Test
+    public void testBuildXPathNullPointerExpected() throws Exception {
+        try {
+            XmlHelper.buildXPath(null);
+            fail("NullPointerException expected");
+        } catch (NullPointerException e) {
+            // Expected.
+        }
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/camel/blob/e2968394/tooling/maven/camel-eip-documentation-enricher-maven-plugin/src/test/java/org/apache/camel/maven/integration/EIPDocumentationMojoTest.java
----------------------------------------------------------------------
diff --git a/tooling/maven/camel-eip-documentation-enricher-maven-plugin/src/test/java/org/apache/camel/maven/integration/EIPDocumentationMojoTest.java
b/tooling/maven/camel-eip-documentation-enricher-maven-plugin/src/test/java/org/apache/camel/maven/integration/EIPDocumentationMojoTest.java
new file mode 100644
index 0000000..5dc7887
--- /dev/null
+++ b/tooling/maven/camel-eip-documentation-enricher-maven-plugin/src/test/java/org/apache/camel/maven/integration/EIPDocumentationMojoTest.java
@@ -0,0 +1,113 @@
+/**
+ * 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.maven.integration;
+
+import java.io.File;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.xpath.XPath;
+import javax.xml.xpath.XPathConstants;
+import javax.xml.xpath.XPathFactory;
+
+import org.w3c.dom.CharacterData;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
+import org.apache.camel.maven.CamelSpringNamespace;
+import org.apache.camel.maven.Constants;
+import org.apache.camel.maven.EipDocumentationEnricherMojo;
+import org.apache.camel.maven.ResourceUtils;
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.hamcrest.CoreMatchers.containsString;
+import static org.hamcrest.CoreMatchers.instanceOf;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertThat;
+
+public class EIPDocumentationMojoTest {
+    EipDocumentationEnricherMojo eipDocumentationEnricherMojo = new EipDocumentationEnricherMojo();
+    XPath xPath = XPathFactory.newInstance().newXPath();
+    File tempFile;
+
+    @Before
+    public void setUp() throws Exception {
+        eipDocumentationEnricherMojo.camelCoreDir = ResourceUtils.getResourceAsFile("integration/camel-core-integration");
+        eipDocumentationEnricherMojo.inputCamelSchemaFile = ResourceUtils.getResourceAsFile("integration/camel-spring.xsd");
+        xPath.setNamespaceContext(new CamelSpringNamespace());
+        tempFile = File.createTempFile("outputXml", ".xml");
+        tempFile.deleteOnExit();
+        eipDocumentationEnricherMojo.outputCamelSchemaFile = tempFile;
+    }
+
+    @Test
+    public void testExecuteMojo() throws Exception {
+        eipDocumentationEnricherMojo.execute();
+        DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
+        documentBuilderFactory.setNamespaceAware(true);
+        DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
+        Document doc = documentBuilder.parse(tempFile);
+        validateElement(doc);
+        validateAttributes(doc);
+        validateParentAttribute(doc);
+    }
+
+    private void validateParentAttribute(Document doc) throws Exception {
+        Element e = (Element) xPath.compile("//xs:attribute[@name='id']").evaluate(doc, XPathConstants.NODE);
+
+        assertEquals("id", e.getAttribute(Constants.NAME_ATTRIBUTE_NAME));
+
+        validateDocumentation(e, "id documentation");
+    }
+
+    private void validateAttributes(Document doc) throws Exception {
+        Element e = (Element) xPath.compile("//xs:attribute[@name='beforeUri']").evaluate(doc,
XPathConstants.NODE);
+
+        assertEquals("beforeUri", e.getAttribute(Constants.NAME_ATTRIBUTE_NAME));
+
+        validateDocumentation(e, "beforeUri documentation");
+
+    }
+
+    private void validateElement(Document doc) {
+        NodeList element = doc.getElementsByTagName("xs:element");
+        Element e = ((Element) element.item(0));
+
+        assertEquals("aop", e.getAttribute(Constants.NAME_ATTRIBUTE_NAME));
+
+        validateDocumentation(e, "element documentation");
+    }
+
+    private void validateDocumentation(Element element, String expectedText) {
+        Element annotation = getFirsElement(element.getChildNodes());
+        Element documentation = getFirsElement(annotation.getChildNodes());
+
+        assertEquals("xs:annotation", annotation.getTagName());
+        assertEquals("xs:documentation", documentation.getTagName());
+
+        Node cdata = documentation.getFirstChild();
+        assertThat(cdata, instanceOf(CharacterData.class));
+
+        assertThat(cdata.getTextContent(), containsString(expectedText));
+    }
+
+    private Element getFirsElement(NodeList nodeList) {
+        return (Element) nodeList.item(1);
+    }
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/e2968394/tooling/maven/camel-eip-documentation-enricher-maven-plugin/src/test/resources/integration/camel-spring.xsd
----------------------------------------------------------------------
diff --git a/tooling/maven/camel-eip-documentation-enricher-maven-plugin/src/test/resources/integration/camel-spring.xsd
b/tooling/maven/camel-eip-documentation-enricher-maven-plugin/src/test/resources/integration/camel-spring.xsd
new file mode 100644
index 0000000..6fa9e39
--- /dev/null
+++ b/tooling/maven/camel-eip-documentation-enricher-maven-plugin/src/test/resources/integration/camel-spring.xsd
@@ -0,0 +1,114 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:tns="http://camel.apache.org/schema/spring"
elementFormDefault="qualified" targetNamespace="http://camel.apache.org/schema/spring" version="1.0">
+
+  <xs:element name="aop" type="tns:aopDefinition">
+
+  </xs:element>
+
+  <xs:complexType name="aopDefinition">
+    <xs:complexContent>
+      <xs:extension base="tns:output">
+        <xs:sequence/>
+        <xs:attribute name="beforeUri" type="xs:string">
+        </xs:attribute>
+        <xs:attribute name="afterUri" type="xs:string">
+        </xs:attribute>
+        <xs:attribute name="afterFinallyUri" type="xs:string">
+        </xs:attribute>
+        <xs:anyAttribute namespace="##other" processContents="skip"/>
+      </xs:extension>
+    </xs:complexContent>
+  </xs:complexType>
+
+  <xs:complexType name="output">
+    <xs:complexContent>
+      <xs:extension base="tns:processorDefinition">
+        <xs:sequence>
+          <xs:choice maxOccurs="unbounded" minOccurs="0">
+            <xs:element ref="tns:aop"/>
+            <xs:element ref="tns:aggregate"/>
+            <xs:element ref="tns:bean"/>
+            <xs:element ref="tns:doCatch"/>
+            <xs:element ref="tns:when"/>
+            <xs:element ref="tns:choice"/>
+            <xs:element ref="tns:otherwise"/>
+            <xs:element ref="tns:convertBodyTo"/>
+            <xs:element ref="tns:delay"/>
+            <xs:element ref="tns:dynamicRouter"/>
+            <xs:element ref="tns:enrich"/>
+            <xs:element ref="tns:filter"/>
+            <xs:element ref="tns:doFinally"/>
+            <xs:element ref="tns:idempotentConsumer"/>
+            <xs:element ref="tns:inOnly"/>
+            <xs:element ref="tns:inOut"/>
+            <xs:element ref="tns:intercept"/>
+            <xs:element ref="tns:interceptFrom"/>
+            <xs:element ref="tns:interceptSendToEndpoint"/>
+            <xs:element ref="tns:loadBalance"/>
+            <xs:element ref="tns:log"/>
+            <xs:element ref="tns:loop"/>
+            <xs:element ref="tns:marshal"/>
+            <xs:element ref="tns:multicast"/>
+            <xs:element ref="tns:onCompletion"/>
+            <xs:element ref="tns:onException"/>
+            <xs:element ref="tns:pipeline"/>
+            <xs:element ref="tns:policy"/>
+            <xs:element ref="tns:pollEnrich"/>
+            <xs:element ref="tns:process"/>
+            <xs:element ref="tns:recipientList"/>
+            <xs:element ref="tns:removeHeader"/>
+            <xs:element ref="tns:removeHeaders"/>
+            <xs:element ref="tns:removeProperties"/>
+            <xs:element ref="tns:removeProperty"/>
+            <xs:element ref="tns:resequence"/>
+            <xs:element ref="tns:rollback"/>
+            <xs:element ref="tns:route"/>
+            <xs:element ref="tns:routingSlip"/>
+            <xs:element ref="tns:sample"/>
+            <xs:element ref="tns:setBody"/>
+            <xs:element ref="tns:setExchangePattern"/>
+            <xs:element ref="tns:setFaultBody"/>
+            <xs:element ref="tns:setHeader"/>
+            <xs:element ref="tns:setOutHeader"/>
+            <xs:element ref="tns:setProperty"/>
+            <xs:element ref="tns:sort"/>
+            <xs:element ref="tns:split"/>
+            <xs:element ref="tns:stop"/>
+            <xs:element ref="tns:threads"/>
+            <xs:element ref="tns:throttle"/>
+            <xs:element ref="tns:throwException"/>
+            <xs:element ref="tns:to"/>
+            <xs:element ref="tns:transacted"/>
+            <xs:element ref="tns:transform"/>
+            <xs:element ref="tns:doTry"/>
+            <xs:element ref="tns:unmarshal"/>
+            <xs:element ref="tns:validate"/>
+            <xs:element ref="tns:whenSkipSendToEndpoint"/>
+            <xs:element ref="tns:wireTap"/>
+            <xs:element ref="tns:restBinding"/>
+          </xs:choice>
+        </xs:sequence>
+        <xs:anyAttribute namespace="##other" processContents="skip"/>
+      </xs:extension>
+    </xs:complexContent>
+  </xs:complexType>
+
+  <xs:complexType abstract="true" name="processorDefinition">
+    <xs:complexContent>
+      <xs:extension base="tns:optionalIdentifiedDefinition">
+        <xs:sequence/>
+        <xs:attribute name="inheritErrorHandler" type="xs:boolean"/>
+        <xs:anyAttribute namespace="##other" processContents="skip"/>
+      </xs:extension>
+    </xs:complexContent>
+  </xs:complexType>
+
+  <xs:complexType abstract="true" name="optionalIdentifiedDefinition">
+    <xs:sequence>
+      <xs:element minOccurs="0" ref="tns:description"/>
+    </xs:sequence>
+    <xs:attribute name="customId" type="xs:boolean"/>
+    <xs:attribute name="id" type="xs:string">
+    </xs:attribute>
+  </xs:complexType>
+</xs:schema>

http://git-wip-us.apache.org/repos/asf/camel/blob/e2968394/tooling/maven/camel-eip-documentation-enricher-maven-plugin/src/test/resources/json/aop.json
----------------------------------------------------------------------
diff --git a/tooling/maven/camel-eip-documentation-enricher-maven-plugin/src/test/resources/json/aop.json
b/tooling/maven/camel-eip-documentation-enricher-maven-plugin/src/test/resources/json/aop.json
new file mode 100644
index 0000000..3d91228
--- /dev/null
+++ b/tooling/maven/camel-eip-documentation-enricher-maven-plugin/src/test/resources/json/aop.json
@@ -0,0 +1,21 @@
+{
+ "model": {
+    "kind": "model",
+    "name": "aop",
+    "title": "Aop",
+    "description": "Does processing before and/or after the route is completed",
+    "javaType": "org.apache.camel.model.AOPDefinition",
+    "label": "configuration",
+    "input": "true",
+    "output": "true"
+  },
+  "properties": {
+    "beforeUri": { "kind": "attribute", "required": "false", "type": "string", "javaType":
"java.lang.String", "deprecated": "false", "description": "Endpoint to call in AOP before."
},
+    "afterUri": { "kind": "attribute", "required": "false", "type": "string", "javaType":
"java.lang.String", "deprecated": "false", "description": "Endpoint to call in AOP after.
The difference between after and afterFinally is that afterFinally is invoked from a finally
block so it will always be invoked no matter what eg also in case of an exception occur."
},
+    "afterFinallyUri": { "kind": "attribute", "required": "false", "type": "string", "javaType":
"java.lang.String", "deprecated": "false", "description": "Endpoint to call in AOP after finally.
The difference between after and afterFinally is that afterFinally is invoked from a finally
block so it will always be invoked no matter what eg also in case of an exception occur."
},
+    "outputs": { "kind": "element", "required": "true", "type": "array", "javaType": "java.util.List<org.apache.camel.model.ProcessorDefinition<?>>",
"oneOf": [ "aggregate", "aop", "bean", "choice", "convertBodyTo", "delay", "doCatch", "doFinally",
"doTry", "dynamicRouter", "enrich", "filter", "idempotentConsumer", "inOnly", "inOut", "intercept",
"interceptFrom", "interceptSendToEndpoint", "loadBalance", "log", "loop", "marshal", "multicast",
"onCompletion", "onException", "otherwise", "pipeline", "policy", "pollEnrich", "process",
"recipientList", "removeHeader", "removeHeaders", "removeProperties", "removeProperty", "resequence",
"rollback", "routingSlip", "sample", "setBody", "setExchangePattern", "setFaultBody", "setHeader",
"setOutHeader", "setProperty", "sort", "split", "stop", "threads", "throttle", "throwException",
"to", "transacted", "transform", "unmarshal", "validate", "when", "whenSkipSendToEndpoint",
"wireTap" ], "deprecated": "false" },
+    "id": { "kind": "attribute", "required": "false", "type": "string", "javaType": "java.lang.String",
"deprecated": "false", "description": "Sets the id of this node" },
+    "description": { "kind": "element", "required": "false", "type": "object", "javaType":
"org.apache.camel.model.DescriptionDefinition", "deprecated": "false", "description": "Sets
the description of this node" }
+  }
+}
+

http://git-wip-us.apache.org/repos/asf/camel/blob/e2968394/tooling/maven/camel-eip-documentation-enricher-maven-plugin/src/test/resources/xmls/3_elements.xml
----------------------------------------------------------------------
diff --git a/tooling/maven/camel-eip-documentation-enricher-maven-plugin/src/test/resources/xmls/3_elements.xml
b/tooling/maven/camel-eip-documentation-enricher-maven-plugin/src/test/resources/xmls/3_elements.xml
new file mode 100644
index 0000000..a859838
--- /dev/null
+++ b/tooling/maven/camel-eip-documentation-enricher-maven-plugin/src/test/resources/xmls/3_elements.xml
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:tns="http://camel.apache.org/schema/spring"
elementFormDefault="qualified" targetNamespace="http://camel.apache.org/schema/spring" version="1.0">
+  <xs:element name="aop"/>
+  <xs:element name="avro"/>
+  <xs:element name="barcode"/>
+</xs:schema>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/camel/blob/e2968394/tooling/maven/camel-eip-documentation-enricher-maven-plugin/src/test/resources/xmls/aop.xml
----------------------------------------------------------------------
diff --git a/tooling/maven/camel-eip-documentation-enricher-maven-plugin/src/test/resources/xmls/aop.xml
b/tooling/maven/camel-eip-documentation-enricher-maven-plugin/src/test/resources/xmls/aop.xml
new file mode 100644
index 0000000..9c732e7
--- /dev/null
+++ b/tooling/maven/camel-eip-documentation-enricher-maven-plugin/src/test/resources/xmls/aop.xml
@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:tns="http://camel.apache.org/schema/spring"
elementFormDefault="qualified" targetNamespace="http://camel.apache.org/schema/spring" version="1.0">
+  <xs:element name="aop"/>
+</xs:schema>

http://git-wip-us.apache.org/repos/asf/camel/blob/e2968394/tooling/maven/camel-eip-documentation-enricher-maven-plugin/src/test/resources/xmls/complex_type.xml
----------------------------------------------------------------------
diff --git a/tooling/maven/camel-eip-documentation-enricher-maven-plugin/src/test/resources/xmls/complex_type.xml
b/tooling/maven/camel-eip-documentation-enricher-maven-plugin/src/test/resources/xmls/complex_type.xml
new file mode 100644
index 0000000..c0436d4
--- /dev/null
+++ b/tooling/maven/camel-eip-documentation-enricher-maven-plugin/src/test/resources/xmls/complex_type.xml
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:tns="http://camel.apache.org/schema/spring"
elementFormDefault="qualified" targetNamespace="http://camel.apache.org/schema/spring" version="1.0">
+  <xs:complexType name="interceptSendToEndpointDefinition">
+    <xs:sequence/>
+    <xs:attribute name="uri" type="xs:string" use="required"/>
+    <xs:attribute name="skipSendToOriginalEndpoint" type="xs:boolean"/>
+    <xs:anyAttribute namespace="##other" processContents="skip"/>
+  </xs:complexType>
+</xs:schema>

http://git-wip-us.apache.org/repos/asf/camel/blob/e2968394/tooling/maven/camel-eip-documentation-enricher-maven-plugin/src/test/resources/xmls/complex_type_w_parent.xml
----------------------------------------------------------------------
diff --git a/tooling/maven/camel-eip-documentation-enricher-maven-plugin/src/test/resources/xmls/complex_type_w_parent.xml
b/tooling/maven/camel-eip-documentation-enricher-maven-plugin/src/test/resources/xmls/complex_type_w_parent.xml
new file mode 100644
index 0000000..02fc6c1
--- /dev/null
+++ b/tooling/maven/camel-eip-documentation-enricher-maven-plugin/src/test/resources/xmls/complex_type_w_parent.xml
@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:tns="http://camel.apache.org/schema/spring"
elementFormDefault="qualified" targetNamespace="http://camel.apache.org/schema/spring" version="1.0">
+
+  <xs:complexType name="keyManagersParametersFactoryBean">
+    <xs:complexContent>
+      <xs:extension base="tns:abstractKeyManagersParametersFactoryBean">
+        <xs:sequence>
+        </xs:sequence>
+      </xs:extension>
+    </xs:complexContent>
+  </xs:complexType>
+
+  <xs:complexType abstract="true" name="abstractKeyManagersParametersFactoryBean">
+    <xs:sequence/>
+    <xs:attribute name="keyPassword" type="xs:string"/>
+    <xs:attribute name="provider" type="xs:string"/>
+    <xs:attribute name="algorithm" type="xs:string"/>
+  </xs:complexType>
+</xs:schema>

http://git-wip-us.apache.org/repos/asf/camel/blob/e2968394/tooling/maven/camel-eip-documentation-enricher-maven-plugin/src/test/resources/xmls/element_doc_enrich.xml
----------------------------------------------------------------------
diff --git a/tooling/maven/camel-eip-documentation-enricher-maven-plugin/src/test/resources/xmls/element_doc_enrich.xml
b/tooling/maven/camel-eip-documentation-enricher-maven-plugin/src/test/resources/xmls/element_doc_enrich.xml
new file mode 100644
index 0000000..e69de29

http://git-wip-us.apache.org/repos/asf/camel/blob/e2968394/tooling/maven/camel-eip-documentation-enricher-maven-plugin/src/test/resources/xmls/empty.xml
----------------------------------------------------------------------
diff --git a/tooling/maven/camel-eip-documentation-enricher-maven-plugin/src/test/resources/xmls/empty.xml
b/tooling/maven/camel-eip-documentation-enricher-maven-plugin/src/test/resources/xmls/empty.xml
new file mode 100644
index 0000000..1b21f5a
--- /dev/null
+++ b/tooling/maven/camel-eip-documentation-enricher-maven-plugin/src/test/resources/xmls/empty.xml
@@ -0,0 +1,2 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<void/>
\ No newline at end of file


Mime
View raw message