-
Notifications
You must be signed in to change notification settings - Fork 335
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make it possible to include custom columns from TestActions in case, class and package tables #503
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
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
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
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
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
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
113 changes: 113 additions & 0 deletions
113
src/test/java/hudson/tasks/junit/CustomColumnsTest.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,113 @@ | ||
package hudson.tasks.junit; | ||
|
||
import com.gargoylesoftware.htmlunit.html.HtmlPage; | ||
import com.gargoylesoftware.htmlunit.html.HtmlTable; | ||
import com.gargoylesoftware.htmlunit.html.HtmlTableCell; | ||
import hudson.Launcher; | ||
import hudson.model.AbstractBuild; | ||
import hudson.model.BuildListener; | ||
import hudson.model.FreeStyleBuild; | ||
import hudson.model.FreeStyleProject; | ||
import hudson.model.Result; | ||
import hudson.tasks.junit.rot13.Rot13Publisher; | ||
import hudson.tasks.test.helper.WebClientFactory; | ||
import org.apache.commons.lang3.tuple.Pair; | ||
import org.hamcrest.CoreMatchers; | ||
import org.junit.Before; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.jvnet.hudson.test.JenkinsRule; | ||
import org.jvnet.hudson.test.TestBuilder; | ||
|
||
import java.io.IOException; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.junit.Assert.assertEquals; | ||
|
||
/** | ||
* Verifies that TestDataPublishers can contribute custom columns to html tables in result pages. | ||
*/ | ||
public class CustomColumnsTest { | ||
|
||
@Rule | ||
public JenkinsRule jenkins = new JenkinsRule(); | ||
|
||
private FreeStyleProject project; | ||
|
||
private static final String reportFileName = "junit-report-494.xml"; | ||
|
||
@Before | ||
public void setUp() throws Exception { | ||
project = jenkins.createFreeStyleProject("customcolumns"); | ||
JUnitResultArchiver archiver = new JUnitResultArchiver("*.xml"); | ||
archiver.setTestDataPublishers(Collections.singletonList(new Rot13Publisher())); | ||
archiver.setSkipPublishingChecks(true); | ||
project.getPublishersList().add(archiver); | ||
project.getBuildersList().add(new TestBuilder() { | ||
@Override | ||
public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListener listener) | ||
throws InterruptedException, IOException { | ||
build.getWorkspace().child(reportFileName).copyFrom(getClass().getResource(reportFileName)); | ||
return true; | ||
} | ||
}); | ||
FreeStyleBuild build = project.scheduleBuild2(0).get(5, TimeUnit.MINUTES); | ||
jenkins.assertBuildStatus(Result.UNSTABLE, build); | ||
} | ||
|
||
@SafeVarargs | ||
private void verifyThatTableContainsExpectedValues(String pathToPage, String tableId, String headerName, | ||
Pair<String, String>... rowValues) throws Exception { | ||
|
||
JenkinsRule.WebClient wc = WebClientFactory.createWebClientWithDisabledJavaScript(jenkins); | ||
HtmlPage projectPage = wc.getPage(project); | ||
jenkins.assertGoodStatus(projectPage); | ||
HtmlPage classReportPage = wc.getPage(project, pathToPage); | ||
jenkins.assertGoodStatus(classReportPage); | ||
|
||
HtmlTable testResultTable = (HtmlTable) classReportPage.getFirstByXPath("//table[@id='" + tableId + "']"); | ||
List<HtmlTableCell> headerRowCells = testResultTable.getHeader().getRows().get(0).getCells(); | ||
int numberOfColumns = headerRowCells.size(); | ||
assertEquals(headerName, headerRowCells.get(numberOfColumns - 1).asNormalizedText()); | ||
|
||
for (int x = 0; x < rowValues.length; x++) { | ||
List<HtmlTableCell> bodyRowCells = testResultTable.getBodies().get(0).getRows().get(x).getCells(); | ||
assertThat(bodyRowCells.get(0).asNormalizedText(), CoreMatchers.containsString(rowValues[x].getLeft())); | ||
assertEquals(rowValues[x].getRight(), bodyRowCells.get(numberOfColumns - 1).asNormalizedText()); | ||
} | ||
} | ||
|
||
@Test | ||
public void verifyThatCustomColumnIsAddedToTheTestsTableOnTheClassResultPage() throws Exception { | ||
verifyThatTableContainsExpectedValues("/lastBuild/testReport/junit/io.jenkins.example/AnExampleTestClass/", | ||
"testresult", "ROT13 for cases on class page", Pair.of("testCaseA", "grfgPnfrN for case"), Pair.of( | ||
"testCaseZ", "grfgPnfrM for case")); | ||
} | ||
|
||
@Test | ||
public void verifyThatCustomColumnIsAddedToTheFailedTestsTableOnThePackageResultPage() throws Exception { | ||
verifyThatTableContainsExpectedValues("/lastBuild/testReport/junit/io.jenkins.example/", "failedtestresult", | ||
"ROT13 for failed cases on package page", Pair.of("testCaseA", "grfgPnfrN for case")); | ||
} | ||
|
||
@Test | ||
public void verifyThatCustomColumnIsAddedToTheClassesTableOnThePackageResultPage() throws Exception { | ||
verifyThatTableContainsExpectedValues("/lastBuild/testReport/junit/io.jenkins.example/", "testresult", | ||
"ROT13 for all classes on package page", Pair.of("AnExampleTestClass", "NaRknzcyrGrfgPynff for class")); | ||
} | ||
|
||
@Test | ||
public void verifyThatCustomColumnIsAddedToTheFailedTestsTableOnTheTestResultPage() throws Exception { | ||
verifyThatTableContainsExpectedValues("/lastBuild/testReport/", "failedtestresult", | ||
"ROT13 for failed cases on test page", Pair.of("testCaseA", "grfgPnfrN for case")); | ||
} | ||
|
||
@Test | ||
public void verifyThatCustomColumnIsAddedToTheClassesTableOnTheTestResultPage() throws Exception { | ||
verifyThatTableContainsExpectedValues("/lastBuild/testReport/", "testresult", | ||
"ROT13 for all packages on test page", Pair.of("io.jenkins.example", "vb.wraxvaf.rknzcyr for package")); | ||
} | ||
} |
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,9 @@ | ||
package hudson.tasks.junit.rot13; | ||
|
||
public class Rot13CaseAction extends Rot13CipherAction { | ||
|
||
public Rot13CaseAction(String ciphertext) { | ||
super(ciphertext); | ||
} | ||
|
||
} |
32 changes: 32 additions & 0 deletions
32
src/test/java/hudson/tasks/junit/rot13/Rot13CipherAction.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 hudson.tasks.junit.rot13; | ||
|
||
import hudson.tasks.junit.TestAction; | ||
|
||
public abstract class Rot13CipherAction extends TestAction { | ||
|
||
private final String ciphertext; | ||
|
||
public Rot13CipherAction(String ciphertext) { | ||
this.ciphertext = ciphertext; | ||
} | ||
|
||
@Override | ||
public final String getIconFileName() { | ||
return null; | ||
} | ||
|
||
@Override | ||
public final String getDisplayName() { | ||
return null; | ||
} | ||
|
||
@Override | ||
public String getUrlName() { | ||
return null; | ||
} | ||
|
||
public String getCiphertext() { | ||
return ciphertext; | ||
} | ||
|
||
} |
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,9 @@ | ||
package hudson.tasks.junit.rot13; | ||
|
||
public class Rot13ClassAction extends Rot13CipherAction { | ||
|
||
public Rot13ClassAction(String ciphertext) { | ||
super(ciphertext); | ||
} | ||
|
||
} |
9 changes: 9 additions & 0 deletions
9
src/test/java/hudson/tasks/junit/rot13/Rot13PackageAction.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,9 @@ | ||
package hudson.tasks.junit.rot13; | ||
|
||
public class Rot13PackageAction extends Rot13CipherAction { | ||
|
||
public Rot13PackageAction(String ciphertext) { | ||
super(ciphertext); | ||
} | ||
|
||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please add javadoc