Skip to content

Commit

Permalink
Moved the ant plugin over to the new Serenity namespace
Browse files Browse the repository at this point in the history
  • Loading branch information
wakaleo committed Nov 27, 2014
1 parent 61cc4d8 commit c0a1aa0
Show file tree
Hide file tree
Showing 12 changed files with 166 additions and 145 deletions.
1 change: 1 addition & 0 deletions serenity-ant-task/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ dependencies {

testCompile project(':serenity-test-utils')
testCompile "org.apache.ant:ant-testutil:1.9.3"
testCompile 'org.assertj:assertj-core:1.7.0'
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
package net.serenity_bdd.ant;

import net.serenity_bdd.ant.util.PathProcessor;
import net.thucydides.core.reports.html.HtmlAggregateStoryReporter;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Task;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;

public class SerenityReportingTask extends Task {

/**
* Aggregate reports are generated here
*/
public String outputDirectory;

/**
* Serenity test reports are read from here
*/
public String sourceDirectory;

/**
* URL of the issue tracking system to be used to generate links for issue numbers.
*/
public String issueTrackerUrl;

/**
* Base URL for JIRA, if you are using JIRA as your issue tracking system.
* If you specify this property, you don't need to specify the issueTrackerUrl.
*/
public String jiraUrl;
public String jiraUsername;
public String jiraPassword;

/**
* JIRA project key, which will be prepended to the JIRA issue numbers.
*/
public String jiraProject;

private PathProcessor pathProcessor = new PathProcessor();

public Path getSourceDirectoryFile() {
return Paths.get(pathProcessor.normalize(sourceDirectory));
}

public void setSourceDirectory(String sourceDirectory) {
this.sourceDirectory = sourceDirectory;
}

public void setOutputDirectory(String outputDirectory) {
this.outputDirectory = outputDirectory;

}

public void setIssueTrackerUrl(String issueTrackerUrl) {
this.issueTrackerUrl = issueTrackerUrl;
}

public void setJiraUrl(String jiraUrl) {
this.jiraUrl = jiraUrl;
}

public void setJiraUsername(String jiraUsername) {
this.jiraUsername = jiraUsername;
}

public void setJiraPassword(String jiraPassword) {
this.jiraPassword = jiraPassword;
}

public void setJiraProject(String jiraProject) {
this.jiraProject = jiraProject;
}

private String normalizedPath(String directoryPath) {
return pathProcessor.normalize(directoryPath);
}

public Path getOutputDirectoryFile() {
return Paths.get(normalizedPath(outputDirectory));
}



public void execute() {
log("Generating Serenity reports");


try {
prepareDirectories();

HtmlAggregateStoryReporter reporter = new HtmlAggregateStoryReporter(getProject().getName());
reporter.setSourceDirectory(getSourceDirectoryFile().toFile());
reporter.setOutputDirectory(getOutputDirectoryFile().toFile());
reporter.setIssueTrackerUrl(issueTrackerUrl);
reporter.setJiraUrl(jiraUrl);
reporter.setJiraProject(jiraProject);
reporter.setJiraUsername(jiraUsername);
reporter.setJiraPassword(jiraPassword);
reporter.generateReportsForTestResultsFrom(sourceOfTestResult().toFile());
} catch (IOException e) {
throw new BuildException(e);
}
}

private void prepareDirectories() throws IOException {
if (Files.notExists(getOutputDirectoryFile())) {
Files.createDirectories(getOutputDirectoryFile());
}

}

private Path sourceOfTestResult() {
if ((getSourceDirectoryFile() != null) && (Files.exists(getSourceDirectoryFile()))) {
return getSourceDirectoryFile();
} else {
return getOutputDirectoryFile();
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package net.thucydides.ant.util;
package net.serenity_bdd.ant.util;


import java.net.URISyntaxException;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,123 +1,17 @@
package net.thucydides.ant;

import net.thucydides.ant.util.PathProcessor;
import net.serenity_bdd.ant.SerenityReportingTask;
import net.serenity_bdd.ant.util.PathProcessor;
import net.thucydides.core.reports.html.HtmlAggregateStoryReporter;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Task;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;

public class ThucydidesReportingTask extends Task {

/**
* Aggregate reports are generated here
*/
public String outputDirectory;

/**
* Thucydides test reports are read from here
*/
public String sourceDirectory;

/**
* URL of the issue tracking system to be used to generate links for issue numbers.
*/
public String issueTrackerUrl;

/**
* Base URL for JIRA, if you are using JIRA as your issue tracking system.
* If you specify this property, you don't need to specify the issueTrackerUrl.
*/
public String jiraUrl;
public String jiraUsername;
public String jiraPassword;

/**
* JIRA project key, which will be prepended to the JIRA issue numbers.
*/
public String jiraProject;

private PathProcessor pathProcessor = new PathProcessor();

public Path getSourceDirectoryFile() {
return Paths.get(pathProcessor.normalize(sourceDirectory));
}

public void setSourceDirectory(String sourceDirectory) {
this.sourceDirectory = sourceDirectory;
}

public void setOutputDirectory(String outputDirectory) {
this.outputDirectory = outputDirectory;

}

public void setIssueTrackerUrl(String issueTrackerUrl) {
this.issueTrackerUrl = issueTrackerUrl;
}

public void setJiraUrl(String jiraUrl) {
this.jiraUrl = jiraUrl;
}

public void setJiraUsername(String jiraUsername) {
this.jiraUsername = jiraUsername;
}

public void setJiraPassword(String jiraPassword) {
this.jiraPassword = jiraPassword;
}

public void setJiraProject(String jiraProject) {
this.jiraProject = jiraProject;
}

private String normalizedPath(String directoryPath) {
return pathProcessor.normalize(directoryPath);
}

public Path getOutputDirectoryFile() {
return Paths.get(normalizedPath(outputDirectory));
}



public void execute() {
log("Generating Thucydides reports");


try {
prepareDirectories();

HtmlAggregateStoryReporter reporter = new HtmlAggregateStoryReporter(getProject().getName());
reporter.setSourceDirectory(getSourceDirectoryFile().toFile());
reporter.setOutputDirectory(getOutputDirectoryFile().toFile());
reporter.setIssueTrackerUrl(issueTrackerUrl);
reporter.setJiraUrl(jiraUrl);
reporter.setJiraProject(jiraProject);
reporter.setJiraUsername(jiraUsername);
reporter.setJiraPassword(jiraPassword);
reporter.generateReportsForTestResultsFrom(sourceOfTestResult().toFile());
} catch (IOException e) {
throw new BuildException(e);
}
}

private void prepareDirectories() throws IOException {
if (Files.notExists(getOutputDirectoryFile())) {
Files.createDirectories(getOutputDirectoryFile());
}

}

private Path sourceOfTestResult() {
if ((getSourceDirectoryFile() != null) && (Files.exists(getSourceDirectoryFile()))) {
return getSourceDirectoryFile();
} else {
return getOutputDirectoryFile();
}
}
}
/**
* Use SerenityReportingTask instead.
*/
@Deprecated
public class ThucydidesReportingTask extends SerenityReportingTask {}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package net.thucydides.ant;
package net.serenity_bdd.ant;

import org.apache.tools.ant.BuildFileTest;

Expand All @@ -12,17 +12,17 @@
import static java.lang.Thread.currentThread;
import static org.fest.assertions.Assertions.assertThat;

public abstract class ThucydidesAntTaskTestBase extends BuildFileTest {
protected void thucydidesReportsShouldAppearIn(String reportDirectory) throws URISyntaxException {
assertThat(getLog()).contains("Generating Thucydides reports");
public abstract class SerenityAntTaskTestBase extends BuildFileTest {
protected void serenityReportsShouldAppearIn(String reportDirectory) throws URISyntaxException {
assertThat(getLog()).contains("Generating Serenity reports");
String indexFilePath = reportDirectory + "/" + "index.html";
String screenshotFilePath = reportDirectory + "/" + "amazon.png";
assertThat(currentThread().getContextClassLoader().getResource(indexFilePath)).isNotNull();
assertThat(currentThread().getContextClassLoader().getResource(screenshotFilePath)).isNotNull();
}

protected void thucydidesResourcesShouldAppearIn(String reportDirectory) throws URISyntaxException {
assertThat(getLog()).contains("Generating Thucydides reports");
assertThat(getLog()).contains("Generating Serenity reports");
String cssFilePath = reportDirectory + "/css/core.css";
assertThat(currentThread().getContextClassLoader().getResource(cssFilePath)).isNotNull();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
package net.thucydides.ant;
package net.serenity_bdd.ant;

import java.net.URISyntaxException;
import java.nio.file.Paths;

import static java.lang.Thread.currentThread;

public class WhenRunningTheAntTask extends ThucydidesAntTaskTestBase {
public class WhenRunningTheAntTask extends SerenityAntTaskTestBase {
public void setUp() throws Exception {
String antFile = Paths.get(currentThread().getContextClassLoader().getResource("build.xml").toURI()).toString();//currentThread().getContextClassLoader().getResource("build.xml").getFile();
configureProject(antFile);
cleanReportsIn("test-outcomes");
}

public void testShouldExecuteTaskWithDefaultValues() throws URISyntaxException {
executeTarget("thucydides.reports");
thucydidesReportsShouldAppearIn("test-outcomes");
executeTarget("serenity.reports");
serenityReportsShouldAppearIn("test-outcomes");
thucydidesResourcesShouldAppearIn("test-outcomes");
}
}
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
package net.thucydides.ant;
package net.serenity_bdd.ant;

import java.net.URISyntaxException;

import static java.lang.Thread.currentThread;

public class WhenRunningTheAntTaskForADifferentOutputDirectory extends ThucydidesAntTaskTestBase {
public class WhenRunningTheAntTaskForADifferentOutputDirectory extends SerenityAntTaskTestBase {
public void setUp() throws Exception {
String antFile = currentThread().getContextClassLoader().getResource("build-different-output.xml").getFile();
configureProject(antFile);
cleanReportsIn("alt-test-outcomes");
}

public void testShouldExecuteTaskWithDefaultValues() throws URISyntaxException {
executeTarget("thucydides.reports");
thucydidesReportsShouldAppearIn("alt-test-outcomes");
executeTarget("serenity.reports");
serenityReportsShouldAppearIn("alt-test-outcomes");
}
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
package net.thucydides.ant;
package net.serenity_bdd.ant;

import java.net.URISyntaxException;

import static java.lang.Thread.currentThread;

public class WhenRunningTheAntTaskWithJiraConfig extends ThucydidesAntTaskTestBase {
public class WhenRunningTheAntTaskWithJiraConfig extends SerenityAntTaskTestBase {
public void setUp() {
String antFile = currentThread().getContextClassLoader().getResource("build-with-jira-authentication.xml").getFile();
configureProject(antFile);
}

public void testShouldExecuteTaskWithJIRAConfiguration() throws URISyntaxException {
executeTarget("thucydides.reports");
thucydidesReportsShouldAppearIn("test-outcomes");
executeTarget("serenity.reports");
serenityReportsShouldAppearIn("test-outcomes");
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package net.thucydides.ant.util;
package net.serenity_bdd.ant.util;

import org.junit.Test;

import static org.fest.assertions.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThat;

public class WhenPreparingResourcePaths {

Expand All @@ -13,4 +13,7 @@ public void shouldNotModifyUnprefixedPaths() {
assertThat(pathProcessor.normalize("some/path")).isEqualTo("some/path");
}




}
Loading

0 comments on commit c0a1aa0

Please sign in to comment.