BuiltIn
or
+ * com.acme.FooLibrary
. When name is used, the library is imported the same as when running the tests.
+ * Use {@link #extraPathDirectories} to set PYTHONPATH/CLASSPATH accordingly.
+ *
+ * Paths are considered relative to the location of pom.xml
and must point to a valid Python/Java
+ * source file or a resource file. For example src/main/java/com/test/ExampleLib.java
+ */
+ private String dataSourceFile;
+
+ /**
+ * Set the title of the generated documentation. Underscores in the title are converted to spaces. The default title is the name of the top level suite.
+ */
+ private String title;
+
+ /**
+ * Override the name of the top level test suite.
+ */
+ private String name;
+
+ /**
+ * Override the documentation of the top level test suite.
+ */
+ private String doc;
+}
diff --git a/src/main/java/org/robotframework/mavenplugin/TestDocMojo.java b/src/main/java/org/robotframework/mavenplugin/TestDocMojo.java
new file mode 100644
index 0000000..bd232b5
--- /dev/null
+++ b/src/main/java/org/robotframework/mavenplugin/TestDocMojo.java
@@ -0,0 +1,99 @@
+package org.robotframework.mavenplugin;
+
+/*
+ * Copyright 2011 Michael Mallete, Dietrich Schulten
+ * Copyright 2012 Nokia Siemens Networks Oyj
+ *
+ * Licensed 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.
+ */
+
+import java.io.File;
+
+import java.io.IOException;
+
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.MojoFailureException;
+import org.robotframework.RobotFramework;
+
+/**
+ * Create documentation of test libraries or resource files using the Robot Framework libdoc
tool.
+ *
+ * Uses the libdoc
bundled in Robot Framework jar distribution. For more help see
+ * libdoc documentation.
+ *
+ * @goal testdoc
+ * @requiresDependencyResolution test
+ */
+public class TestDocMojo
+ extends AbstractMojoWithLoadedClasspath {
+
+ protected void subclassExecute()
+ throws MojoExecutionException, MojoFailureException {
+ try {
+ runTestDoc();
+ } catch (IOException e) {
+ throw new MojoExecutionException("Failed to execute libdoc script: " + e.getMessage());
+ }
+ }
+
+ public void runTestDoc()
+ throws IOException {
+ testdoc.populateDefaults(this);
+ testdoc.ensureOutputDirectoryExists();
+ String[] args = testdoc.generateRunArguments();
+ getLog().debug("Run arguments -> " + args);
+ RobotFramework.run(args);
+ }
+
+ /**
+ * Test case documentation configuration.
+ *
+ * Required settings:
+ * outputFile
The name for the output file.dataSourceFile
Name or path of the documented test case(s).pom.xml
and must point to a valid test case file.
+ * For example src/main/test/ExampleTest.txt
+ * Optional settings:
+ * outputDirectory
Specifies the directory where documentation files are written.
+ * Considered to be relative to the ${basedir} of the project.
+ * Default ${project.build.directory}/robotframework/testdoctitle
Set the title of the generated documentation. Underscores in
+ * the title are converted to spaces. The default title is the
+ * name of the top level suite.name
Override the name of the top level test suite.doc
Override the name of the top level test suite.+ *+ * + * @parameter + * @required + */ + private TestDocConfiguration testdoc; + + /** + * Default output directory. Effective if outputDirectory is empty. Cannot be overridden. + * + * @parameter default-value="${project.build.directory}/robotframework/testdoc" + * @readonly + */ + File defaultTestdocOutputDirectory; +} diff --git a/src/test/java/org/robotframework/mavenplugin/AbstractRFMojoTestCase.java b/src/test/java/org/robotframework/mavenplugin/AbstractRFMojoTestCase.java new file mode 100644 index 0000000..74a184c --- /dev/null +++ b/src/test/java/org/robotframework/mavenplugin/AbstractRFMojoTestCase.java @@ -0,0 +1,32 @@ +package org.robotframework.mavenplugin; + +import java.io.File; + +import org.apache.maven.plugin.Mojo; +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugin.MojoFailureException; +import org.apache.maven.plugin.testing.AbstractMojoTestCase; + +/** + * @author g.arora@iontrading.com + * @version $Id$ + * @since 0.7.6 + */ +public abstract class AbstractRFMojoTestCase extends AbstractMojoTestCase { + + void executeLibdocWithPom(String goal, String pathToPom) throws Exception, MojoExecutionException, MojoFailureException { + File pom = getTestFile(pathToPom); + Mojo mojo = lookupMojo(goal, pom); + mojo.execute(); + } + + void deleteDocument(String documentation) throws Exception { + File document = new File(documentation); + if (document.exists()) { + boolean deleted = document.delete(); + if (!deleted) { + throw new Exception("Cannot delete existing document."); + } + } + } +} diff --git a/src/test/java/org/robotframework/mavenplugin/LibDocMojoTest.java b/src/test/java/org/robotframework/mavenplugin/LibDocMojoTest.java index 104dea7..fdf24cd 100644 --- a/src/test/java/org/robotframework/mavenplugin/LibDocMojoTest.java +++ b/src/test/java/org/robotframework/mavenplugin/LibDocMojoTest.java @@ -2,13 +2,9 @@ import java.io.File; -import org.apache.maven.plugin.MojoExecutionException; -import org.apache.maven.plugin.MojoFailureException; -import org.apache.maven.plugin.testing.AbstractMojoTestCase; - public class LibDocMojoTest - extends AbstractMojoTestCase { + extends AbstractRFMojoTestCase { private final String outputDirectory = "target/robotframework/libdoc/"; private final String htmlResourceLibDoc = outputDirectory + "html_resource.html"; @@ -29,14 +25,13 @@ protected void setUp() public void testLibDocForJavaResource() throws Exception { - executeLibdocWithPom("src/test/resources/pom-libdoc.xml"); + executeLibdocWithPom("libdoc", "src/test/resources/pom-libdoc.xml"); assertTrue(javalibLibDoc + " not found", new File(javalibLibDoc).exists()); - } public void testLibDocForTxtResource() throws Exception { - executeLibdocWithPom("src/test/resources/pom-libdoc-txtfile.xml"); + executeLibdocWithPom("libdoc", "src/test/resources/pom-libdoc-txtfile.xml"); assertTrue(htmlResourceLibDoc + " not found", new File(htmlResourceLibDoc).exists()); } @@ -44,41 +39,22 @@ public void testLibDocForTxtResource() public void testLibDocForLibraryNamePython() throws Exception { - executeLibdocWithPom("src/test/resources/pom-libdoc-libraryname-python.xml"); + executeLibdocWithPom("libdoc", "src/test/resources/pom-libdoc-libraryname-python.xml"); assertTrue(mylibLibDoc + " not found", new File(mylibLibDoc).exists()); } public void testLibDocForLibraryNamePythonWithPackage() throws Exception { - executeLibdocWithPom("src/test/resources/pom-libdoc-libraryname-python-subpackage.xml"); + executeLibdocWithPom("libdoc", "src/test/resources/pom-libdoc-libraryname-python-subpackage.xml"); assertTrue(mypackageMylibLibDoc + " not found", new File(mypackageMylibLibDoc).exists()); } public void testLibDocForLibraryNameJava() throws Exception { - executeLibdocWithPom("src/test/resources/pom-libdoc-libraryname-java.xml"); + executeLibdocWithPom("libdoc", "src/test/resources/pom-libdoc-libraryname-java.xml"); assertTrue(javalibLibDoc + " not found", new File(javalibLibDoc).exists()); } - - private void executeLibdocWithPom(String pathToPom) throws Exception, MojoExecutionException, - MojoFailureException { - File pom = getTestFile(pathToPom); - LibDocMojo mojo = (LibDocMojo) lookupMojo("libdoc", pom); - mojo.execute(); - } - - private void deleteDocument(String documentation) - throws Exception { - File document = new File(documentation); - if (document.exists()) { - boolean deleted = document.delete(); - if (!deleted) { - throw new Exception("Cannot delete existing document."); - } - } - } - } diff --git a/src/test/java/org/robotframework/mavenplugin/TestDocMojoTest.java b/src/test/java/org/robotframework/mavenplugin/TestDocMojoTest.java new file mode 100644 index 0000000..29ec48b --- /dev/null +++ b/src/test/java/org/robotframework/mavenplugin/TestDocMojoTest.java @@ -0,0 +1,56 @@ +package org.robotframework.mavenplugin; + +import java.io.File; + +import org.apache.maven.it.util.FileUtils; + +import static org.mockito.Mockito.*; + + +public class TestDocMojoTest + extends AbstractRFMojoTestCase { + + private final String outputDirectory = "target/robotframework/testdoc/"; + + protected void setUp() + throws Exception { + super.setUp(); + File outputDir = new File(outputDirectory); + outputDir.mkdirs(); + } + + public void testTestDocForTxtResource() + throws Exception { + executeLibdocWithPom("testdoc", "src/test/resources/pom-testdoc-txtfile.xml"); + String txtResourceTestDoc = outputDirectory + "invalid.html"; + assertTrue(txtResourceTestDoc + " not found", new File(txtResourceTestDoc).exists()); + } + + public void testTestDocForTxtResourceWithTitle() + throws Exception { + executeLibdocWithPom("testdoc", "src/test/resources/pom-testdoc-txtfile-title.xml"); + String txtResourceWithTitleTestDoc = outputDirectory + "invalid_login_title.html"; + assertTrue(txtResourceWithTitleTestDoc + " not found", new File(txtResourceWithTitleTestDoc).exists()); + String contents = FileUtils.fileRead(txtResourceWithTitleTestDoc); + System.out.println(contents); + assertTrue(contents.contains("\"title\":\"Custom Title\"")); + } + + public void testTestDocForTxtResourceWithName() + throws Exception { + executeLibdocWithPom("testdoc", "src/test/resources/pom-testdoc-txtfile-name.xml"); + String txtResourceWithNameTestDoc = outputDirectory + "invalid_login_name.html"; + assertTrue(txtResourceWithNameTestDoc + " not found", new File(txtResourceWithNameTestDoc).exists()); + String contents = FileUtils.fileRead(txtResourceWithNameTestDoc); + assertTrue(contents.contains("\"fullName\":\"Custom name\"")); + } + + public void testTestDocForTxtResourceWithDoc() + throws Exception { + executeLibdocWithPom("testdoc", "src/test/resources/pom-testdoc-txtfile-doc.xml"); + String txtResourceWithDocTestDoc = outputDirectory + "invalid_login_doc.html"; + assertTrue(txtResourceWithDocTestDoc + " not found", new File(txtResourceWithDocTestDoc).exists()); + String contents = FileUtils.fileRead(txtResourceWithDocTestDoc); + assertTrue(contents.contains("\"doc\":\"MyTests.html + *src/test/resources/MyTests.txt + * ]]>
Custom documentation
\"")); + } +} diff --git a/src/test/resources/pom-testdoc-txtfile-doc.xml b/src/test/resources/pom-testdoc-txtfile-doc.xml new file mode 100644 index 0000000..1144bf8 --- /dev/null +++ b/src/test/resources/pom-testdoc-txtfile-doc.xml @@ -0,0 +1,27 @@ +