Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using RestartableJenkinsRule.then #2959

Merged
merged 6 commits into from
Sep 6, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion test/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ THE SOFTWARE.
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>jenkins-test-harness</artifactId>
<version>2.23</version>
<version>2.24</version>
<scope>test</scope>
<exclusions>
<exclusion>
Expand Down
2 changes: 2 additions & 0 deletions test/src/test/java/hudson/cli/CLIActionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import org.codehaus.groovy.runtime.Security218;
import static org.hamcrest.Matchers.containsString;
import static org.junit.Assert.*;
import org.junit.Ignore;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
Expand Down Expand Up @@ -255,6 +256,7 @@ public void encodingAndLocale() throws Exception {
// -ssh mode does not pass client locale or encoding
}

@Ignore("TODO JENKINS-46659 seems to be broken")
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

JENKINS-46659 appears to have been the cause of the earlier failures, as well as those in #2754.

@Issue("JENKINS-41745")
@Test
public void interleavedStdio() throws Exception {
Expand Down
65 changes: 26 additions & 39 deletions test/src/test/java/hudson/model/UserRestartTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,9 @@
import hudson.tasks.Mailer;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.not;
import org.junit.Test;
import static org.junit.Assert.*;
import org.junit.Rule;
import org.junit.runners.model.Statement;
import org.junit.Test;
import org.jvnet.hudson.test.Issue;
import org.jvnet.hudson.test.RestartableJenkinsRule;

Expand All @@ -40,51 +39,39 @@ public class UserRestartTest {
public RestartableJenkinsRule rr = new RestartableJenkinsRule();

@Test public void persistedUsers() throws Exception {
rr.addStep(new Statement() {
@Override
public void evaluate() throws Throwable {
User bob = User.getById("bob", true);
bob.setFullName("Bob");
bob.addProperty(new Mailer.UserProperty("bob@nowhere.net"));
}
rr.then(r -> {
User bob = User.getById("bob", true);
bob.setFullName("Bob");
bob.addProperty(new Mailer.UserProperty("bob@nowhere.net"));
});
rr.addStep(new Statement() {
@Override
public void evaluate() throws Throwable {
User bob = User.getById("bob", false);
assertNotNull(bob);
assertEquals("Bob", bob.getFullName());
Mailer.UserProperty email = bob.getProperty(Mailer.UserProperty.class);
assertNotNull(email);
assertEquals("bob@nowhere.net", email.getAddress());
}
rr.then(r -> {
User bob = User.getById("bob", false);
assertNotNull(bob);
assertEquals("Bob", bob.getFullName());
Mailer.UserProperty email = bob.getProperty(Mailer.UserProperty.class);
assertNotNull(email);
assertEquals("bob@nowhere.net", email.getAddress());
});
}

@Issue("JENKINS-45892")
@Test
public void badSerialization() {
rr.addStep(new Statement() {
@Override
public void evaluate() throws Throwable {
rr.j.jenkins.setSecurityRealm(rr.j.createDummySecurityRealm());
FreeStyleProject p = rr.j.createFreeStyleProject("p");
User u = User.get("pqhacker");
u.setFullName("Pat Q. Hacker");
u.save();
p.addProperty(new BadProperty(u));
String text = p.getConfigFile().asString();
assertThat(text, not(containsString("<fullName>Pat Q. Hacker</fullName>")));
assertThat(text, containsString("<id>pqhacker</id>"));
}
rr.then(r -> {
r.jenkins.setSecurityRealm(r.createDummySecurityRealm());
FreeStyleProject p = r.createFreeStyleProject("p");
User u = User.get("pqhacker");
u.setFullName("Pat Q. Hacker");
u.save();
p.addProperty(new BadProperty(u));
String text = p.getConfigFile().asString();
assertThat(text, not(containsString("<fullName>Pat Q. Hacker</fullName>")));
assertThat(text, containsString("<id>pqhacker</id>"));
});
rr.addStep(new Statement() {
@Override
public void evaluate() throws Throwable {
FreeStyleProject p = rr.j.jenkins.getItemByFullName("p", FreeStyleProject.class);
User u = p.getProperty(BadProperty.class).user; // do not inline: call User.get second
assertEquals(User.get("pqhacker"), u);
}
rr.then(r -> {
FreeStyleProject p = r.jenkins.getItemByFullName("p", FreeStyleProject.class);
User u = p.getProperty(BadProperty.class).user; // do not inline: call User.get second
assertEquals(User.get("pqhacker"), u);
});
}
static class BadProperty extends JobProperty<FreeStyleProject> {
Expand Down