Skip to content
Permalink
Browse files

Reproduce JENKINS-20209 and JENKINS-21045

  • Loading branch information...
olivergondza committed Jul 16, 2014
1 parent 710d879 commit a4878c700d0fab5db68c33b93701f0658a1c54f6
@@ -98,9 +98,14 @@ public void describeMismatchSafely(PageObject po, Description d) {
* Matches if a string contains a portion that matches to the regular expression.
*/
public static Matcher<String> containsRegexp(final String regexp, int opts) {
final Pattern re = Pattern.compile(regexp, opts);
return containsRegexp(Pattern.compile(regexp, opts));
}

return new Matcher<String>("Matches regexp %s", regexp) {
/**
* Matches if a string contains a portion that matches to the regular expression.
*/
public static Matcher<String> containsRegexp(final Pattern re) {
return new Matcher<String>("Matches regexp %s", re.toString()) {
@Override
public boolean matchesSafely(String item) {
return re.matcher(item).find();
@@ -1,6 +1,7 @@
package org.jenkinsci.test.acceptance.utils.mail;

import com.google.common.base.Joiner;

import org.jenkinsci.test.acceptance.plugins.mailer.MailerGlobalConfig;
import org.jenkinsci.test.acceptance.po.CapybaraPortingLayer;
import org.jenkinsci.test.acceptance.po.CapybaraPortingLayerImpl;
@@ -9,6 +10,7 @@
import javax.mail.MessagingException;
import javax.mail.internet.MimeMessage;
import javax.mail.internet.MimeMultipart;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.List;
@@ -17,6 +19,7 @@

import static javax.mail.Message.RecipientType.*;
import static org.hamcrest.CoreMatchers.*;
import static org.jenkinsci.test.acceptance.Matchers.*;

/**
* Encapsulated the mail server to be used for test and access to emails that were sent.
@@ -73,7 +76,7 @@ public String toString() {
MimeMultipart content = (MimeMultipart) c;
c = content.getBodyPart(0).getContent();
}
assertTrue("body metches", body.matcher(c.toString()).find());
assertThat(c.toString(), containsRegexp(body));
}

/**
@@ -32,6 +32,8 @@
import org.jenkinsci.test.acceptance.junit.Bug;
import org.jenkinsci.test.acceptance.junit.Native;
import org.jenkinsci.test.acceptance.junit.Since;
import org.jenkinsci.test.acceptance.plugins.mailer.Mailer;
import org.jenkinsci.test.acceptance.plugins.mailer.MailerGlobalConfig;
import org.jenkinsci.test.acceptance.plugins.maven.MavenBuild;
import org.jenkinsci.test.acceptance.plugins.maven.MavenBuildStep;
import org.jenkinsci.test.acceptance.plugins.maven.MavenInstallation;
@@ -40,8 +42,11 @@
import org.jenkinsci.test.acceptance.po.Build;
import org.jenkinsci.test.acceptance.po.FreeStyleJob;
import org.jenkinsci.test.acceptance.po.StringParameter;
import org.jenkinsci.test.acceptance.utils.mail.MailService;
import org.junit.Test;

import com.google.inject.Inject;

import static org.hamcrest.CoreMatchers.*;
import static org.hamcrest.MatcherAssert.*;
import static org.jenkinsci.test.acceptance.Matchers.*;
@@ -51,6 +56,12 @@

private static final String GENERATE = "archetype:generate -DarchetypeGroupId=org.apache.maven.archetypes -DgroupId=com.mycompany.app -DartifactId=my-app -Dversion=1.0 -B";

@Inject
MailerGlobalConfig mailer;

@Inject
MailService mail;

@Test
public void autoinstall_maven_for_freestyle_job() {
installMaven(jenkins, "maven_3.0.4", "3.0.4");
@@ -206,6 +217,27 @@ public void build_multimodule() {
assertHasModule(job, "gid$module_b");
}

@Test @Bug({"JENKINS-20209", "JENKINS-21045"})
public void send_mail() throws Exception {
jenkins.configure();
mailer.setupDefaults();
jenkins.save();

MavenModuleSet job = jenkins.jobs.create(MavenModuleSet.class);
job.configure();
Mailer mailer = job.addBuildSettings(Mailer.class);
mailer.recipients.set("root@example.com");
job.save();

job.startBuild().shouldFail();

mail.assertMail(
Pattern.compile("Build failed in Jenkins: .* #1"),
"root@example.com",
Pattern.compile(job.name)
);
}

private void assertHasModule(MavenModuleSet job, String name) {
assertThat(job.module(name), pageObjectExists());

0 comments on commit a4878c7

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