Skip to content
Permalink
Browse files

Fixes JENKINS-20319 for email-ext plugin

  • Loading branch information...
mkutter committed Feb 12, 2015
1 parent 49f3ca7 commit 2097bff8152a1753b0ba5c7835a0d0a81159d2e4
@@ -6,12 +6,15 @@
import hudson.model.Hudson;
import hudson.plugins.emailext.EmailType;
import hudson.plugins.emailext.ExtendedEmailPublisher;
import hudson.plugins.emailext.plugins.EmailTrigger;
import hudson.plugins.emailext.plugins.EmailTriggerDescriptor;
import hudson.plugins.emailext.plugins.trigger.FailureTrigger;
import hudson.tasks.Publisher;
import hudson.util.DescribableList;

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

import org.apache.commons.lang.StringUtils;
@@ -109,8 +112,18 @@ public boolean removeMailer(AbstractProject project) throws IOException {
/**
* not yet implemented for ExtendedEmailPublisher
*/
public boolean sendToIndividuals(AbstractProject project) {
return false;
public boolean sendToIndividuals(AbstractProject project) {
boolean result = false;
ExtendedEmailPublisher mailer = getMailer(project);
if (mailer != null) {
for (EmailTrigger trigger : mailer.getConfiguredTriggers()) {
if (trigger.getEmail().getSendToDevelopers()) {
result = true;
break;
}
}
}
return result;
}
}

@@ -7,6 +7,9 @@
import hudson.model.AbstractProject;
import hudson.model.Descriptor;
import hudson.model.FreeStyleProject;
import hudson.plugins.emailext.EmailType;
import hudson.plugins.emailext.ExtendedEmailPublisher;
import hudson.plugins.emailext.plugins.trigger.FailureTrigger;
import hudson.tasks.Publisher;
import hudson.tasks.Mailer;
import hudson.util.DescribableList;
@@ -33,7 +36,7 @@
* <li>return the set list of recipients (like "john@doe.com sue@gov.com") otherwise</li>
* @throws Exception
*/
public void testSendToIndividualsWithCoreMailer() throws Exception {
public void testSendToIndividuals() throws Exception {
assertEquals("Setting empty recipients with sendToIndividuals enabled", null, setAndGetCoreValues(createMavenProjectWithSendToIndividualsAndEmptyRecipients(), null));
assertEquals("Setting >(disabled)< with sendToIndividuals enabled", "(Disabled)", setAndGetCoreValues(createMavenProjectWithSendToIndividualsAndEmptyRecipients(), "(disabled)"));
assertEquals("Setting >(DISABLED)< with sendToIndividuals enabled", "(Disabled)", setAndGetCoreValues(createMavenProjectWithSendToIndividualsAndEmptyRecipients(), "(DISABLED)"));
@@ -43,6 +46,9 @@ public void testSendToIndividualsWithCoreMailer() throws Exception {
assertEquals("Setting >(disabled)< with sendToIndividuals enabled", "(Disabled)", setAndGetCoreValues(createFreestyleProjectWithSendToIndividualsAndEmptyRecipients(), "(disabled)"));
assertEquals("Setting >(DISABLED)< with sendToIndividuals enabled", "(Disabled)", setAndGetCoreValues(createFreestyleProjectWithSendToIndividualsAndEmptyRecipients(), "(DISABLED)"));
assertEquals("Setting recipients with sendToIndividuals enabled", "john@doe.com sue@gov.com", setAndGetCoreValues(createFreestyleProjectWithSendToIndividualsAndEmptyRecipients(), "john@doe.com sue@gov.com"));

assertEquals("Setting empty recipients with ext mailer", null, setAndGetExtValues(createFreestyleProjectWithExtMailer(), null));
assertEquals("Setting >(disabled)< with ext mailer", "(Disabled)", setAndGetExtValues(createFreestyleProjectWithExtMailer(), "(disabled)"));
}

public void testNormalize() {
@@ -56,9 +62,7 @@ private void doTestNormalize(String email, String expect) {
assertEquals(expect, normalized);
}

public void testSetValues() throws Exception {
doTestSetValues("(Disabled)", "");
doTestSetValues("(Disabled)", " \b\t ");
public void testSetValues() throws Exception {
doTestSetValues("(Disabled)", "(Disabled)");
doTestSetValues("caps@gov email@gov.com", "email@gov.com, CAPS@gov");
}
@@ -124,6 +128,18 @@ private String setAndGetCoreValues(AbstractProject<?,?> project, String valuesSt
return got;
}

private String setAndGetExtValues(AbstractProject<?,?> project, String valuesString) {
ExtEmailSliceSpec spec = new ExtEmailSliceSpec();

List<String> values = new ArrayList<String>();
values.add(valuesString);
spec.setValues(project, values);

List<String> gotList = spec.getValues(project);
String got = spec.join(gotList);
return got;
}

private MavenModuleSet createMavenProjectWithSendToIndividualsAndEmptyRecipients()
throws IOException {
MavenModuleSet mavenProject = createMavenProject();
@@ -143,4 +159,23 @@ private MavenModuleSet createMavenProjectWithSendToIndividualsAndEmptyRecipients
publishers.add(mailer);
return project;
}

private AbstractProject<?,?> createFreestyleProjectWithExtMailer() throws IOException {
FreeStyleProject project = createFreeStyleProject();
DescribableList<Publisher,Descriptor<Publisher>> publishers = project.getPublishersList();
ExtendedEmailPublisher publisher = new ExtendedEmailPublisher();
FailureTrigger trigger = new FailureTrigger();
EmailType email = new EmailType();
email.setSendToDevelopers(true);
email.setSendToRecipientList(true);
trigger.setEmail(email);
publisher.getConfiguredTriggers().add(trigger);

// there is no way to get this text from the plugin itself
publisher.defaultContent = "$DEFAULT_CONTENT";
publisher.defaultSubject = "$DEFAULT_SUBJECT";

publishers.add(publisher);
return project;
}
}

0 comments on commit 2097bff

Please sign in to comment.
You can’t perform that action at this time.