Skip to content

Commit

Permalink
Merge branch 'upgrade-jenkins-version'
Browse files Browse the repository at this point in the history
  • Loading branch information
KengoTODA committed Apr 17, 2015
2 parents 8526fc2 + 7fbd711 commit 03dd171
Show file tree
Hide file tree
Showing 7 changed files with 80 additions and 17 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,12 @@ Changelog
### 1.2
- fix #5 NoSuchMethodError

### 1.3
- upgrade Jenkins to the latest LTS (1.596)

Copyright and license
---------------------
Copyright 2012 Kengo TODA (eller86)
Copyright 2015 Kengo TODA (eller86)

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

Expand Down
24 changes: 23 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>plugin</artifactId>
<version>1.436</version>
<version>1.596</version>
</parent>
<artifactId>regression-report-plugin</artifactId>
<name>Regression Report Plugin</name>
Expand Down Expand Up @@ -73,6 +73,16 @@
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>junit</artifactId>
<version>1.3</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>mailer</artifactId>
<version>1.10</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
Expand All @@ -98,4 +108,16 @@
<scope>test</scope>
</dependency>
</dependencies>
<repositories>
<repository>
<id>repo.jenkins-ci.org</id>
<url>http://repo.jenkins-ci.org/public/</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>repo.jenkins-ci.org</id>
<url>http://repo.jenkins-ci.org/public/</url>
</pluginRepository>
</pluginRepositories>
</project>
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
package jp.skypencil.jenkins.regression;

import hudson.tasks.junit.CaseResult;
import hudson.tasks.test.TestResult;

import com.google.common.base.Predicate;

class RegressionPredicate implements Predicate<CaseResult> {
class RegressionPredicate implements Predicate<TestResult> {
@Override
public boolean apply(CaseResult input) {
return input.getStatus().isRegression();
public boolean apply(TestResult input) {
if (input instanceof CaseResult) {
CaseResult caseResult = (CaseResult) input;
return caseResult.getStatus().isRegression();
}
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import hudson.tasks.Mailer;
import hudson.tasks.junit.CaseResult;
import hudson.tasks.test.AbstractTestResultAction;
import hudson.tasks.test.TestResult;

import java.io.PrintStream;
import java.util.Date;
Expand All @@ -33,6 +34,7 @@
import javax.mail.internet.MimeMessage;

import jenkins.model.Jenkins;
import jenkins.model.JenkinsLocationConfiguration;

import org.kohsuke.stapler.DataBoundConstructor;

Expand Down Expand Up @@ -103,8 +105,7 @@ public boolean perform(AbstractBuild<?, ?> build, Launcher launcher,
}

logger.println("regression reporter starts now...");
List<CaseResult> failedTest = testResultAction.getFailedTests();
List<CaseResult> regressionedTests = Lists.newArrayList(Iterables.filter(failedTest, new RegressionPredicate()));
List<CaseResult> regressionedTests = listRegressions(testResultAction);

writeToConsole(regressionedTests, listener);
try {
Expand All @@ -117,6 +118,15 @@ public boolean perform(AbstractBuild<?, ?> build, Launcher launcher,
return true;
}

private List<CaseResult> listRegressions(
AbstractTestResultAction<?> testResultAction) {
List<? extends TestResult> failedTest = testResultAction.getFailedTests();
Iterable<? extends TestResult> filtered = Iterables.filter(failedTest, new RegressionPredicate());
List<CaseResult> regressionedTests =
Lists.newArrayList(Iterables.transform(filtered, new TestResultToCaseResult()));
return regressionedTests;
}

private void writeToConsole(List<CaseResult> regressions,
BuildListener listener) {
if (regressions.isEmpty()) {
Expand Down Expand Up @@ -147,8 +157,8 @@ private void mailReport(List<CaseResult> regressions, String recipients,
if (Jenkins.getInstance() != null) {
rootUrl = Jenkins.getInstance().getRootUrl();
session = Mailer.descriptor().createSession();
adminAddress = new InternetAddress(Mailer.descriptor()
.getAdminAddress());
adminAddress = new InternetAddress(
JenkinsLocationConfiguration.get().getAdminAddress());
}
builder.append(Util.encode(rootUrl));
builder.append(Util.encode(build.getUrl()));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package jp.skypencil.jenkins.regression;

import hudson.tasks.junit.CaseResult;
import hudson.tasks.test.TestResult;

import com.google.common.base.Function;

class TestResultToCaseResult implements Function<TestResult, CaseResult> {
@Override
public CaseResult apply(TestResult input) {
return (CaseResult) input;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
public class ChangeLogSetMock extends ChangeLogSet<ChangeLogSet.Entry> {

protected ChangeLogSetMock(AbstractBuild<?, ?> build) {
super(build);
super(build, null);
}

private final Set<Entry> set = Sets.newHashSet();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,24 @@
import hudson.model.FreeStyleProject;

import java.io.IOException;
import java.util.List;

import org.junit.Ignore;
import org.junit.Rule;
import org.junit.Test;
import org.jvnet.hudson.test.HudsonTestCase;
import org.jvnet.hudson.test.JenkinsRule;
import org.xml.sax.SAXException;

import com.gargoylesoftware.htmlunit.WebClient;
import com.gargoylesoftware.htmlunit.html.HtmlButton;
import com.gargoylesoftware.htmlunit.html.HtmlElement;
import com.gargoylesoftware.htmlunit.html.HtmlForm;
import com.gargoylesoftware.htmlunit.html.HtmlInput;
import com.gargoylesoftware.htmlunit.html.HtmlPage;

public class RegressionReportConfigTest extends HudsonTestCase {
public class RegressionReportConfigTest {
@Rule
public JenkinsRule jenkins = new JenkinsRule();

private static final String NAME_CHECKBOX = "jp-skypencil-jenkins-regression-RegressionReportNotifier";
private static final String JOB_NAME = "Test";
Expand All @@ -38,17 +44,16 @@ public void testEnabledIsFalse() throws FormException, IOException,

private void testEnabled(boolean isEnabled) throws FormException,
IOException, SAXException {
FreeStyleProject project = createFreeStyleProject(JOB_NAME);
FreeStyleProject project = jenkins.createFreeStyleProject(JOB_NAME);

try {
HtmlPage configPage = new WebClient().goTo("job/" + JOB_NAME
HtmlPage configPage = new WebClient().getPage("job/" + JOB_NAME
+ "/configure");
HtmlForm form = configPage.getFormByName("config");
form.getInputByName(NAME_CHECKBOX).setChecked(isEnabled);
form.submit((HtmlButton) last(form
.getHtmlElementsByTagName("button")));
form.submit(last(form.getHtmlElementsByTagName("button")));

configPage = new WebClient().goTo("job/" + JOB_NAME + "/configure");
configPage = new WebClient().getPage("job/" + JOB_NAME + "/configure");
form = configPage.getFormByName("config");
HtmlInput checkbox = form.getInputByName(NAME_CHECKBOX);
assertThat(checkbox.isChecked(), is(isEnabled));
Expand All @@ -60,4 +65,9 @@ private void testEnabled(boolean isEnabled) throws FormException,
}
}
}

private HtmlButton last(List<HtmlElement> htmlElementsByTagName) {
HtmlElement lastElement = htmlElementsByTagName.get(htmlElementsByTagName.size() - 1);
return (HtmlButton) lastElement;
}
}

0 comments on commit 03dd171

Please sign in to comment.