forked from robotframework/MavenPlugin
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
411845b
commit 19c5b6d
Showing
12 changed files
with
447 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,4 +7,6 @@ target | |
.DS_store | ||
src/test/projects/acceptance-and-verify/log.txt | ||
docs/_build | ||
|
||
.classpath | ||
.settings/ | ||
.project |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
112 changes: 112 additions & 0 deletions
112
src/main/java/org/robotframework/mavenplugin/TestDocConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
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.codehaus.plexus.util.StringUtils; | ||
|
||
|
||
public class TestDocConfiguration { | ||
|
||
public String[] generateRunArguments() throws IOException { | ||
Arguments generatedArguments = new Arguments(); | ||
generatedArguments.add("testdoc"); | ||
generatedArguments.addNonEmptyStringToArguments(title, "--title"); | ||
generatedArguments.addNonEmptyStringToArguments(name, "--name"); | ||
generatedArguments.addNonEmptyStringToArguments(doc, "--doc"); | ||
generatedArguments.add(getDatasourceFile()); | ||
generatedArguments.add(getOutputPath()); | ||
return generatedArguments.toArray(); | ||
} | ||
|
||
private String getDatasourceFile() throws IOException { | ||
File libOrResource = new File(dataSourceFile); | ||
if (!libOrResource.exists()) { | ||
throw new IOException("Data source file " + dataSourceFile + " does not exist"); | ||
} | ||
return libOrResource.getAbsolutePath(); | ||
} | ||
|
||
private String getOutputPath() { | ||
return outputDirectory + File.separator + outputFile.getName(); | ||
} | ||
|
||
public void ensureOutputDirectoryExists() | ||
throws IOException { | ||
if (outputDirectory == null) { | ||
String baseDir = System.getProperty("basedir"); | ||
// FIXME: this is to get around the problem that default-value does not currently work | ||
if (baseDir == null) | ||
baseDir = "."; | ||
outputDirectory = new File(joinPaths(baseDir, "target", "robotframework", "testdoc")); | ||
} | ||
if (!outputDirectory.exists() && !outputDirectory.mkdirs()) { | ||
throw new IOException("Target output directory cannot be created: " + outputDirectory.getAbsolutePath()); | ||
} | ||
} | ||
|
||
private String joinPaths(String... parts) { | ||
return StringUtils.join(parts, File.separator); | ||
} | ||
|
||
public void populateDefaults(TestDocMojo defaults) { | ||
if (this.outputDirectory == null) | ||
this.outputDirectory = defaults.defaultTestdocOutputDirectory; | ||
} | ||
|
||
/** | ||
* Specifies the directory where documentation files are written. Considered to be relative to the ${basedir} of the | ||
* project. | ||
*/ | ||
private File outputDirectory; | ||
|
||
/** | ||
* Specifies the filename of the created documentation. Considered to be relative to the {@link #outputDirectory} of | ||
* the project. | ||
*/ | ||
private File outputFile; | ||
|
||
/** | ||
* Name or path of the documented library or resource file. | ||
* <p/> | ||
* Name must be in the same format as when used in Robot Framework test data, for example <code>BuiltIn</code> or | ||
* <code>com.acme.FooLibrary</code>. When name is used, the library is imported the same as when running the tests. | ||
* Use {@link #extraPathDirectories} to set PYTHONPATH/CLASSPATH accordingly. | ||
* <p/> | ||
* Paths are considered relative to the location of <code>pom.xml</code> and must point to a valid Python/Java | ||
* source file or a resource file. For example <code>src/main/java/com/test/ExampleLib.java</code> | ||
*/ | ||
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; | ||
} |
99 changes: 99 additions & 0 deletions
99
src/main/java/org/robotframework/mavenplugin/TestDocMojo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <code>libdoc</code> tool. | ||
* <p/> | ||
* Uses the <code>libdoc</code> bundled in Robot Framework jar distribution. For more help see | ||
* <a href="http://robotframework.googlecode.com/hg/doc/userguide/RobotFrameworkUserGuide.html#library-documentation-tool-libdoc">libdoc documentation</a>. | ||
* | ||
* @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: | ||
* <ul> | ||
* <li><code>outputFile</code> The name for the output file.</li> | ||
* <li><code>dataSourceFile</code> Name or path of the documented test case(s).</li> | ||
* </ul> | ||
* <p/> | ||
* Paths are considered relative to the location of <code>pom.xml</code> and must point to a valid test case file. | ||
* For example <code>src/main/test/ExampleTest.txt</code> | ||
* Optional settings: | ||
* <ul> | ||
* <li><code>outputDirectory</code> Specifies the directory where documentation files are written. | ||
* Considered to be relative to the ${basedir} of the project. | ||
* Default ${project.build.directory}/robotframework/testdoc</li> | ||
* <li><code>title</code> 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.</li> | ||
* <li><code>name</code> Override the name of the top level test suite.</li> | ||
* <li><code>doc</code> Override the name of the top level test suite.</li> | ||
* </ul> | ||
* | ||
* Example: | ||
* <pre><![CDATA[<libdoc> | ||
* <outputFile>MyTests.html</outputFile> | ||
* <dataSourceFile>src/test/resources/MyTests.txt</dataSourceFile> | ||
* </libdoc>]]></pre> | ||
* | ||
* @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; | ||
} |
32 changes: 32 additions & 0 deletions
32
src/test/java/org/robotframework/mavenplugin/AbstractRFMojoTestCase.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 [email protected] | ||
* @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."); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
src/test/java/org/robotframework/mavenplugin/TestDocMojoTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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\":\"<p>Custom documentation</p>\"")); | ||
} | ||
} |
Oops, something went wrong.