Return-Path: X-Original-To: apmail-camel-commits-archive@www.apache.org Delivered-To: apmail-camel-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 0E26E1008E for ; Sun, 15 Mar 2015 06:39:39 +0000 (UTC) Received: (qmail 10884 invoked by uid 500); 15 Mar 2015 06:39:39 -0000 Delivered-To: apmail-camel-commits-archive@camel.apache.org Received: (qmail 10750 invoked by uid 500); 15 Mar 2015 06:39:38 -0000 Mailing-List: contact commits-help@camel.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@camel.apache.org Delivered-To: mailing list commits@camel.apache.org Received: (qmail 10645 invoked by uid 99); 15 Mar 2015 06:39:38 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 15 Mar 2015 06:39:38 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 6A860E1072; Sun, 15 Mar 2015 06:39:38 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: davsclaus@apache.org To: commits@camel.apache.org Date: Sun, 15 Mar 2015 06:39:39 -0000 Message-Id: <17690eca0cf7459abecd3ce49f122923@git.apache.org> In-Reply-To: <9dc63faedc11416e990f2e71c0273346@git.apache.org> References: <9dc63faedc11416e990f2e71c0273346@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [2/4] camel git commit: Tests added. 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 Authored: Sat Mar 14 01:07:20 2015 -0700 Committer: Claus Ibsen 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 @@ junit test + + + org.hamcrest + hamcrest-core + ${hamcrest-version} + test + + + + org.mockito + mockito-core + test + org.apache.camel 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 jsonFiles = PackageHelper.findJsonFiles(new File(this.getClass().getClassLoader().getResource("json").getFile())); + Map 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 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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>", "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 @@ + + + + + + \ 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 @@ + + + + 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 @@ + + + + + + + + + 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 @@ + + + + + + + + + + + + + + + + + + + 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 @@ + + \ No newline at end of file