Skip to content
Permalink
Browse files

[JENKINS-41124] Lots of data migration tests

Need the restart tests also, but this at least calms my fears
  • Loading branch information...
stephenc committed Jan 18, 2017
1 parent 61e5af5 commit ec6ef005c4b525665163d39336483d240800e869
@@ -93,7 +93,7 @@
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>cloudbees-folder</artifactId>
<version>5.17-20170118.164532-2</version>
<version>5.17-20170118.174857-4</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
@@ -25,18 +25,20 @@

package integration;

import hudson.Util;
import com.cloudbees.hudson.plugins.folder.ChildNameGenerator;
import hudson.model.Job;
import hudson.model.TopLevelItem;
import integration.harness.BasicMultiBranchProjectFactory;
import java.io.File;
import java.io.IOException;
import java.nio.file.Paths;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import jenkins.branch.MultiBranchProject;
import jenkins.branch.OrganizationFolder;
import jenkins.model.Jenkins;
import jenkins.scm.impl.mock.MockSCMController;
import org.apache.commons.io.FilenameUtils;
import jenkins.scm.impl.mock.MockSCMNavigator;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import org.junit.AfterClass;
import org.junit.BeforeClass;
@@ -47,6 +49,7 @@

import static org.hamcrest.Matchers.containsInAnyOrder;
import static org.hamcrest.Matchers.instanceOf;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.notNullValue;
import static org.junit.Assert.assertThat;

@@ -82,10 +85,103 @@ public static void closeSCM() {
c = null;
}

/**
* Checks that data is migrated correctly from 1.x to current version.
*/
@Test
@LocalData
public void nameMangling() throws IOException {
public void nameMangling() throws Exception {
TopLevelItem foo = j.jenkins.getItem("foo");
assertDataMigrated(foo);
}

/**
* Checks that data migrated from 1.x to 2.0.0 name mangling is still valid when re-migrated to 2.0.2 name mangling
*/
@Test
@LocalData
public void nameMangling_2() throws Exception {
TopLevelItem foo = 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);
}

/**
* Checks that data is migrated correctly from 1.x to current version.
*/
@Test
@LocalData
public void nameMangling_full_reload() throws Exception {
TopLevelItem foo = j.jenkins.getItem("foo");
j.jenkins.reload();
assertDataMigrated(foo);
}

/**
* Checks that data migrated from 1.x to 2.0.0 name mangling is still valid when re-migrated to 2.0.2 name mangling
*/
@Test
@LocalData
public void nameMangling_2_full_reload() throws Exception {
TopLevelItem foo = j.jenkins.getItem("foo");
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);
}

/**
* Checks that data is migrated correctly from 1.x to current version.
*/
@Test
@LocalData
public void nameMangling_folder_reload() throws Exception {
OrganizationFolder foo = (OrganizationFolder)j.jenkins.getItem("foo");
foo.doReload();
assertDataMigrated(foo);
}

/**
* Checks that data migrated from 1.x to 2.0.0 name mangling is still valid when re-migrated to 2.0.2 name mangling
*/
@Test
@LocalData
public void nameMangling_2_folder_reload() throws Exception {
OrganizationFolder foo = (OrganizationFolder)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);
}

private void assertDataMigrated(TopLevelItem foo) throws Exception {
assertThat(foo, instanceOf(OrganizationFolder.class));
OrganizationFolder prj = (OrganizationFolder) foo;
Map<String, MultiBranchProject> byName = new HashMap<>();
@@ -138,7 +234,13 @@ public void nameMangling() throws IOException {
jobByName.put(j.getFullName(), j);
jobByDirName.put(jobDirName, j);
jobByDisplayName.put(j.getFullDisplayName(), j);
File nameFile = new File(j.getRootDir(), ChildNameGenerator.CHILD_NAME_FILE);
assertThat("Exists: " + nameFile, nameFile.isFile(), is(true));
assertThat("Contents: " + nameFile, FileUtils.readFileToString(nameFile), is(j.getName()));
}
File nameFile = new File(p.getRootDir(), ChildNameGenerator.CHILD_NAME_FILE);
assertThat("Exists: " + nameFile, nameFile.isFile(), is(true));
assertThat("Contents: " + nameFile, FileUtils.readFileToString(nameFile), is(p.getName()));
}
assertThat("Display Names are repo names", byDisplayName.keySet(), containsInAnyOrder(
"test.example.com",
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 comments on commit ec6ef00

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