forked from jenkinsci/regression-report-plugin
-
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.
implemented "send to culprit" feature. refs jenkinsci#1
- Loading branch information
Showing
7 changed files
with
205 additions
and
16 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
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
1 change: 1 addition & 0 deletions
1
...main/resources/jp/skypencil/jenkins/regression/RegressionReportNotifier/config.properties
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 |
---|---|---|
@@ -1 +1,2 @@ | ||
Recipients=Recipients | ||
SentToCulprits=Send mail to who might make regression |
1 change: 1 addition & 0 deletions
1
...n/resources/jp/skypencil/jenkins/regression/RegressionReportNotifier/config_ja.properties
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 |
---|---|---|
@@ -1 +1,2 @@ | ||
Recipients=\u5b9b\u5148 | ||
SentToCulprits=\u30D3\u30EB\u30C9\u3092\u58CA\u3057\u305F\u304B\u3082\u3057\u308C\u306A\u3044\u30E6\u30FC\u30B6\u306B\u3082\u30E1\u30FC\u30EB\u3059\u308B |
51 changes: 51 additions & 0 deletions
51
src/test/java/jp/skypencil/jenkins/regression/ChangeLogSetMock.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,51 @@ | ||
package jp.skypencil.jenkins.regression; | ||
|
||
import java.util.Collection; | ||
import java.util.Collections; | ||
import java.util.Iterator; | ||
import java.util.Set; | ||
|
||
import com.google.common.collect.Sets; | ||
|
||
import hudson.model.AbstractBuild; | ||
import hudson.model.User; | ||
import hudson.scm.ChangeLogSet; | ||
|
||
public class ChangeLogSetMock extends ChangeLogSet<ChangeLogSet.Entry> { | ||
|
||
protected ChangeLogSetMock(AbstractBuild<?, ?> build) { | ||
super(build); | ||
} | ||
|
||
private final Set<Entry> set = Sets.newHashSet(); | ||
|
||
ChangeLogSetMock withChangeBy(final User user) { | ||
ChangeLogSet.Entry change = new ChangeLogSet.Entry() { | ||
@Override | ||
public String getMsg() { | ||
return ""; | ||
} | ||
@Override | ||
public User getAuthor() { | ||
return user; | ||
} | ||
@Override | ||
public Collection<String> getAffectedPaths() { | ||
return Collections.emptyList(); | ||
} | ||
}; | ||
set.add(change); | ||
return this; | ||
} | ||
|
||
@Override | ||
public Iterator<Entry> iterator() { | ||
return set.iterator(); | ||
} | ||
|
||
@Override | ||
public boolean isEmptySet() { | ||
return set.isEmpty(); | ||
} | ||
|
||
} |
87 changes: 83 additions & 4 deletions
87
src/test/java/jp/skypencil/jenkins/regression/RegressionReportNotifierTest.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 |
---|---|---|
@@ -1,38 +1,117 @@ | ||
package jp.skypencil.jenkins.regression; | ||
|
||
import static org.hamcrest.CoreMatchers.equalTo; | ||
import static org.hamcrest.CoreMatchers.is; | ||
import static org.mockito.Mockito.*; | ||
import static org.hamcrest.CoreMatchers.notNullValue; | ||
import static org.junit.Assert.assertThat; | ||
import static org.powermock.api.mockito.PowerMockito.doReturn; | ||
import static org.powermock.api.mockito.PowerMockito.mock; | ||
import hudson.Launcher; | ||
import hudson.model.BuildListener; | ||
import hudson.model.Result; | ||
import hudson.model.AbstractBuild; | ||
import hudson.model.User; | ||
import hudson.tasks.junit.CaseResult; | ||
import hudson.tasks.junit.CaseResult.Status; | ||
import hudson.tasks.test.AbstractTestResultAction; | ||
|
||
import java.io.IOException; | ||
import java.io.PrintStream; | ||
import java.util.List; | ||
|
||
import javax.mail.Address; | ||
import javax.mail.Message.RecipientType; | ||
import javax.mail.MessagingException; | ||
import javax.mail.internet.MimeMessage; | ||
|
||
import org.junit.Before; | ||
import org.junit.Test; | ||
import static org.junit.Assert.*; | ||
import org.junit.runner.RunWith; | ||
import org.powermock.core.classloader.annotations.PrepareForTest; | ||
import org.powermock.modules.junit4.PowerMockRunner; | ||
|
||
import com.google.common.collect.Lists; | ||
|
||
@RunWith(PowerMockRunner.class) | ||
@PrepareForTest(CaseResult.class) | ||
public class RegressionReportNotifierTest { | ||
private BuildListener listener; | ||
private Launcher launcher; | ||
private AbstractBuild<?, ?> build; | ||
|
||
@Before | ||
public void setUp() { | ||
public void setUp() throws Exception { | ||
listener = mock(BuildListener.class); | ||
launcher = mock(Launcher.class); | ||
build = mock(AbstractBuild.class); | ||
PrintStream logger = mock(PrintStream.class); | ||
doReturn("").when(build).getUrl(); | ||
doReturn(logger).when(listener).getLogger(); | ||
} | ||
|
||
@Test | ||
public void testCompileErrorOccured() throws InterruptedException, IOException { | ||
doReturn(null).when(build).getTestResultAction(); | ||
RegressionReportNotifier notifier = new RegressionReportNotifier(""); | ||
RegressionReportNotifier notifier = new RegressionReportNotifier("", false); | ||
|
||
assertThat(notifier.perform(build, launcher, listener), is(true)); | ||
} | ||
|
||
@Test | ||
public void testSend() throws InterruptedException, MessagingException { | ||
makeRegression(); | ||
|
||
RegressionReportNotifier notifier = new RegressionReportNotifier("author@mail.com", false); | ||
MockedMailSender mailSender = new MockedMailSender(); | ||
notifier.setMailSender(mailSender); | ||
|
||
assertThat(notifier.perform(build, launcher, listener), is(true)); | ||
assertThat(mailSender.getSentMessage(), is(notNullValue())); | ||
Address[] to = mailSender.getSentMessage().getRecipients(RecipientType.TO); | ||
assertThat(to.length, is(1)); | ||
assertThat(to[0].toString(), is(equalTo("author@mail.com"))); | ||
} | ||
|
||
@Test | ||
public void testSendToCulprits() throws InterruptedException, MessagingException { | ||
makeRegression(); | ||
|
||
RegressionReportNotifier notifier = new RegressionReportNotifier("author@mail.com", true); | ||
MockedMailSender mailSender = new MockedMailSender(); | ||
notifier.setMailSender(mailSender); | ||
|
||
assertThat(notifier.perform(build, launcher, listener), is(true)); | ||
assertThat(mailSender.getSentMessage(), is(notNullValue())); | ||
Address[] to = mailSender.getSentMessage().getRecipients(RecipientType.TO); | ||
assertThat(to.length, is(2)); | ||
assertThat(to[0].toString(), is(equalTo("author@mail.com"))); | ||
assertThat(to[1].toString(), is(equalTo("culprit@mail.com"))); | ||
} | ||
|
||
private void makeRegression() { | ||
AbstractTestResultAction<?> result = mock(AbstractTestResultAction.class); | ||
doReturn(result).when(build).getTestResultAction(); | ||
doReturn(Result.FAILURE).when(build).getResult(); | ||
User culprit = mock(User.class); | ||
doReturn("culprit").when(culprit).getId(); | ||
doReturn(new ChangeLogSetMock(build).withChangeBy(culprit)).when(build).getChangeSet(); | ||
|
||
CaseResult failedTest = mock(CaseResult.class); | ||
doReturn(Status.REGRESSION).when(failedTest).getStatus(); | ||
List<CaseResult> failedTests = Lists.newArrayList(failedTest); | ||
doReturn(failedTests).when(result).getFailedTests(); | ||
} | ||
|
||
private static final class MockedMailSender implements RegressionReportNotifier.MailSender { | ||
private MimeMessage sentMessage; | ||
|
||
@Override | ||
public void send(MimeMessage message) throws MessagingException { | ||
sentMessage = message; | ||
} | ||
|
||
public MimeMessage getSentMessage() { | ||
return sentMessage; | ||
} | ||
} | ||
} |