Skip to content
Permalink
Browse files

Add test for JENKINS-22610

  • Loading branch information...
slide committed Apr 18, 2014
1 parent f4bb5be commit eb140463bb9fc0166caf3a5c0dc2f692b8010c6b
@@ -1,3 +1,3 @@
ExtEmailTemplateManagement.DisplayName=Editable Email Notification Templates
ExtEmailTemplateManagement.Description=Configure global templates for Editable Email Notification Plugin
ExtendedEmailTemplatePublisher.TemplateRemoved=Template with ID ''{0}'' has been removed, please check your settings.
ExtendedEmailTemplatePublisher.TemplateRemoved=Template with ID ''{0}'' has is not available, perhaps it was removed?
@@ -0,0 +1,60 @@
package org.jeninsci.plugins.emailext_plugin;

import hudson.model.AbstractBuild;
import hudson.model.AbstractProject;
import hudson.model.Cause;
import hudson.plugins.emailext.ExtendedEmailPublisher;
import hudson.plugins.emailext.MatrixTriggerMode;
import hudson.plugins.emailext.plugins.EmailTrigger;
import hudson.plugins.emailext.plugins.trigger.AlwaysTrigger;
import org.jenkinsci.plugins.emailext_template.ExtendedEmailPublisherTemplate;
import org.jenkinsci.plugins.emailext_template.ExtendedEmailTemplatePublisher;
import org.jenkinsci.plugins.emailext_template.Messages;
import org.jenkinsci.plugins.emailext_template.TemplateId;
import org.junit.Rule;
import org.junit.Test;
import org.jvnet.hudson.test.Bug;
import org.jvnet.hudson.test.JenkinsRule;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import static org.junit.Assert.assertTrue;

/**
* Created by acearl on 4/16/2014.
*/
public class ExtendedEmailTemplatePublisherTest {

@Rule
public JenkinsRule j = new JenkinsRule();

@Test
@Bug(22610)
public void testRemovedTemplate() throws Exception {
ExtendedEmailTemplatePublisher.DescriptorImpl descriptor = (ExtendedEmailTemplatePublisher.DescriptorImpl)j.jenkins.getDescriptor(ExtendedEmailTemplatePublisher.class);
List<EmailTrigger> triggers = new ArrayList<EmailTrigger>();
triggers.add(new AlwaysTrigger(true, false, false, false, "mickeymouse@gmail.com", "", "Test Email", "Howdy!", "", 0, "project"));

ExtendedEmailPublisher publisher = new ExtendedEmailPublisher("$DEFAULT_RECIPIENTS", "html", "$DEFAULT_SUBJECT", "$DEFAULT_CONTENT", "", "", 0, "$DEFAULT_REPLYTO", false, triggers, MatrixTriggerMode.ONLY_PARENT);

ExtendedEmailPublisherTemplate template = new ExtendedEmailPublisherTemplate("template1", "Test Template", "Simple test template", publisher);
descriptor.addTemplate(template);
ExtendedEmailTemplatePublisher templatePublisher = new ExtendedEmailTemplatePublisher(Collections.singletonList(new TemplateId(template.getId())));

AbstractProject p = j.createFreeStyleProject("Test");
p.getPublishersList().add(templatePublisher);

AbstractBuild b = (AbstractBuild)p.scheduleBuild2(0, new Cause.UserCause()).get();
assertTrue("Template should exist, so we shouldn't get the message",
!b.getLog(100).contains(Messages.ExtendedEmailTemplatePublisher_TemplateRemoved(template.getId())));

descriptor.removeTemplateById(template.getId());

b = (AbstractBuild)p.scheduleBuild2(0, new Cause.UserCause()).get();
assertTrue("Template was removed, so we should get the message",
b.getLog(100).contains(Messages.ExtendedEmailTemplatePublisher_TemplateRemoved(template.getId())));
}

}

0 comments on commit eb14046

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