Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added new content TRIGGER_NAME that will be replaced with the name of the trigger that caused the email.
- Loading branch information
Showing
2 changed files
with
87 additions
and
4 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
82 changes: 82 additions & 0 deletions
82
src/test/java/hudson/plugins/emailext/plugins/content/TriggerNameContentTest.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,82 @@ | ||
package hudson.plugins.emailext.plugins.content; | ||
|
||
import hudson.model.FreeStyleBuild; | ||
import hudson.model.FreeStyleProject; | ||
import hudson.plugins.emailext.EmailType; | ||
import hudson.plugins.emailext.ExtendedEmailPublisher; | ||
import hudson.plugins.emailext.plugins.EmailTrigger; | ||
import hudson.plugins.emailext.plugins.trigger.PreBuildTrigger; | ||
import hudson.plugins.emailext.plugins.trigger.SuccessTrigger; | ||
import javax.mail.Message; | ||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertThat; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import static org.junit.matchers.JUnitMatchers.hasItems; | ||
import org.jvnet.hudson.test.JenkinsRule; | ||
import org.jvnet.mock_javamail.Mailbox; | ||
|
||
/* | ||
* To change this license header, choose License Headers in Project Properties. | ||
* To change this template file, choose Tools | Templates | ||
* and open the template in the editor. | ||
*/ | ||
|
||
/** | ||
* | ||
* @author acearl | ||
*/ | ||
public class TriggerNameContentTest { | ||
private ExtendedEmailPublisher publisher; | ||
private FreeStyleProject project; | ||
|
||
@Rule | ||
public JenkinsRule j = new JenkinsRule() { | ||
@Override | ||
protected void before() throws Throwable { | ||
super.before(); | ||
publisher = new ExtendedEmailPublisher(); | ||
publisher.defaultSubject = "%DEFAULT_SUBJECT"; | ||
publisher.defaultContent = "%DEFAULT_CONTENT"; | ||
publisher.attachmentsPattern = ""; | ||
publisher.recipientList = "%DEFAULT_RECIPIENTS"; | ||
publisher.presendScript = ""; | ||
|
||
project = createFreeStyleProject(); | ||
project.getPublishersList().add(publisher); | ||
} | ||
|
||
@Override | ||
protected void after() { | ||
super.after(); | ||
Mailbox.clearAll(); | ||
} | ||
}; | ||
|
||
|
||
@Test | ||
public void testTriggerName() throws Exception { | ||
SuccessTrigger trigger = new SuccessTrigger(true, true, true, false, "$DEFAULT_RECIPIENTS", | ||
"$DEFAULT_REPLYTO", "$DEFAULT_SUBJECT", "${TRIGGER_NAME}", "", 0, "project"); | ||
addEmailType(trigger); | ||
publisher.getConfiguredTriggers().add(trigger); | ||
|
||
FreeStyleBuild build = project.scheduleBuild2(0).get(); | ||
j.assertBuildStatusSuccess(build); | ||
|
||
assertThat("Email should have been triggered, so we should see it in the logs.", build.getLog(100), | ||
hasItems("Email was triggered for: " + SuccessTrigger.TRIGGER_NAME)); | ||
assertEquals(1, Mailbox.get("mickey@disney.com").size()); | ||
Message message = Mailbox.get("mickey@disney.com").get(0); | ||
assertEquals("Success", message.getSubject()); | ||
} | ||
|
||
private void addEmailType(EmailTrigger trigger) { | ||
trigger.setEmail(new EmailType() { | ||
{ | ||
setRecipientList("mickey@disney.com"); | ||
setSubject("${TRIGGER_NAME}"); | ||
} | ||
}); | ||
} | ||
} |