Skip to content

Commit

Permalink
[JENKINS-41124] Switch migration test to restartable jenkins rule
Browse files Browse the repository at this point in the history
  • Loading branch information
stephenc committed Jan 19, 2017
1 parent ec6ef00 commit 663cb3d
Showing 1 changed file with 87 additions and 38 deletions.
125 changes: 87 additions & 38 deletions src/test/java/integration/MigrationTest.java
Expand Up @@ -44,7 +44,8 @@
import org.junit.BeforeClass;
import org.junit.Rule;
import org.junit.Test;
import org.jvnet.hudson.test.JenkinsRule;
import org.junit.runners.model.Statement;
import org.jvnet.hudson.test.RestartableJenkinsRule;
import org.jvnet.hudson.test.recipes.LocalData;

import static org.hamcrest.Matchers.containsInAnyOrder;
Expand All @@ -58,7 +59,7 @@ public class MigrationTest {
private static MockSCMController c;

@Rule
public JenkinsRule j = new JenkinsRule();
public RestartableJenkinsRule r = new RestartableJenkinsRule();

@BeforeClass
public static void setupSCM() throws IOException {
Expand Down Expand Up @@ -91,8 +92,13 @@ public static void closeSCM() {
@Test
@LocalData
public void nameMangling() throws Exception {
TopLevelItem foo = j.jenkins.getItem("foo");
assertDataMigrated(foo);
r.addStep(new Statement() {
@Override
public void evaluate() throws Throwable {
TopLevelItem foo = r.j.jenkins.getItem("foo");
assertDataMigrated(foo);
}
});
}

/**
Expand All @@ -101,18 +107,29 @@ public void nameMangling() throws Exception {
@Test
@LocalData
public void nameMangling_2() throws Exception {
TopLevelItem foo = j.jenkins.getItem("foo");
assertDataMigrated(foo);
r.addStep(new Statement() {
@Override
public void evaluate() throws Throwable {
TopLevelItem foo = r.j.jenkins.getItem("foo");
assertDataMigrated(foo);
}
});
}

@Test
public void createdFromScratch() throws Exception {
OrganizationFolder foo = j.createProject(OrganizationFolder.class, "foo");
foo.getSCMNavigators().add(new MockSCMNavigator(c, true, false, false));
foo.getProjectFactories().replaceBy(Collections.singletonList(new BasicMultiBranchProjectFactory(null)));
foo.scheduleBuild2(0).getFuture().get();
j.waitUntilNoActivity();
assertDataMigrated(foo);
r.addStep(new Statement() {
@Override
public void evaluate() throws Throwable {
OrganizationFolder foo = r.j.createProject(OrganizationFolder.class, "foo");
foo.getSCMNavigators().add(new MockSCMNavigator(c, true, false, false));
foo.getProjectFactories()
.replaceBy(Collections.singletonList(new BasicMultiBranchProjectFactory(null)));
foo.scheduleBuild2(0).getFuture().get();
r.j.waitUntilNoActivity();
assertDataMigrated(foo);
}
});
}

/**
Expand All @@ -121,9 +138,14 @@ public void createdFromScratch() throws Exception {
@Test
@LocalData
public void nameMangling_full_reload() throws Exception {
TopLevelItem foo = j.jenkins.getItem("foo");
j.jenkins.reload();
assertDataMigrated(foo);
r.addStep(new Statement() {
@Override
public void evaluate() throws Throwable {
TopLevelItem foo = r.j.jenkins.getItem("foo");
r.j.jenkins.reload();
assertDataMigrated(foo);
}
});
}

/**
Expand All @@ -132,20 +154,31 @@ public void nameMangling_full_reload() throws Exception {
@Test
@LocalData
public void nameMangling_2_full_reload() throws Exception {
TopLevelItem foo = j.jenkins.getItem("foo");
j.jenkins.reload();
assertDataMigrated(foo);
r.addStep(new Statement() {
@Override
public void evaluate() throws Throwable {
TopLevelItem foo = r.j.jenkins.getItem("foo");
r.j.jenkins.reload();
assertDataMigrated(foo);
}
});
}

@Test
public void createdFromScratch_full_reload() throws Exception {
OrganizationFolder foo = j.createProject(OrganizationFolder.class, "foo");
foo.getSCMNavigators().add(new MockSCMNavigator(c, true, false, false));
foo.getProjectFactories().replaceBy(Collections.singletonList(new BasicMultiBranchProjectFactory(null)));
foo.scheduleBuild2(0).getFuture().get();
j.waitUntilNoActivity();
j.jenkins.reload();
assertDataMigrated(foo);
r.addStep(new Statement() {
@Override
public void evaluate() throws Throwable {
OrganizationFolder foo = r.j.createProject(OrganizationFolder.class, "foo");
foo.getSCMNavigators().add(new MockSCMNavigator(c, true, false, false));
foo.getProjectFactories()
.replaceBy(Collections.singletonList(new BasicMultiBranchProjectFactory(null)));
foo.scheduleBuild2(0).getFuture().get();
r.j.waitUntilNoActivity();
r.j.jenkins.reload();
assertDataMigrated(foo);
}
});
}

/**
Expand All @@ -154,9 +187,14 @@ public void createdFromScratch_full_reload() throws Exception {
@Test
@LocalData
public void nameMangling_folder_reload() throws Exception {
OrganizationFolder foo = (OrganizationFolder)j.jenkins.getItem("foo");
foo.doReload();
assertDataMigrated(foo);
r.addStep(new Statement() {
@Override
public void evaluate() throws Throwable {
OrganizationFolder foo = (OrganizationFolder) r.j.jenkins.getItem("foo");
foo.doReload();
assertDataMigrated(foo);
}
});
}

/**
Expand All @@ -165,20 +203,31 @@ public void nameMangling_folder_reload() throws Exception {
@Test
@LocalData
public void nameMangling_2_folder_reload() throws Exception {
OrganizationFolder foo = (OrganizationFolder)j.jenkins.getItem("foo");
foo.doReload();
assertDataMigrated(foo);
r.addStep(new Statement() {
@Override
public void evaluate() throws Throwable {
OrganizationFolder foo = (OrganizationFolder) r.j.jenkins.getItem("foo");
foo.doReload();
assertDataMigrated(foo);
}
});
}

@Test
public void createdFromScratch_folder_reload() throws Exception {
OrganizationFolder foo = j.createProject(OrganizationFolder.class, "foo");
foo.getSCMNavigators().add(new MockSCMNavigator(c, true, false, false));
foo.getProjectFactories().replaceBy(Collections.singletonList(new BasicMultiBranchProjectFactory(null)));
foo.scheduleBuild2(0).getFuture().get();
j.waitUntilNoActivity();
foo.doReload();
assertDataMigrated(foo);
r.addStep(new Statement() {
@Override
public void evaluate() throws Throwable {
OrganizationFolder foo = r.j.createProject(OrganizationFolder.class, "foo");
foo.getSCMNavigators().add(new MockSCMNavigator(c, true, false, false));
foo.getProjectFactories()
.replaceBy(Collections.singletonList(new BasicMultiBranchProjectFactory(null)));
foo.scheduleBuild2(0).getFuture().get();
r.j.waitUntilNoActivity();
foo.doReload();
assertDataMigrated(foo);
}
});
}

private void assertDataMigrated(TopLevelItem foo) throws Exception {
Expand Down

0 comments on commit 663cb3d

Please sign in to comment.