Navigation Menu

Skip to content

Commit

Permalink
JENKINS-40920
Browse files Browse the repository at this point in the history
no longer assuming just one liquibase builder per project.
Also better way of testing migration
  • Loading branch information
prospero238 committed Jan 9, 2017
1 parent a764793 commit 4073144
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 198 deletions.
@@ -1,7 +1,6 @@
package org.jenkinsci.plugins.liquibase.evaluator;

import hudson.Extension;
import hudson.model.Describable;
import hudson.model.Item;
import hudson.model.ModelObject;
import hudson.model.Project;
Expand Down Expand Up @@ -46,9 +45,9 @@ static void migrateLegacyCredentials() {
List<Project> projects = instance.getItems(Project.class);
for (Project project : projects) {
DescribableList buildersList = project.getBuildersList();
Describable describable = buildersList.get(AbstractLiquibaseBuilder.class);
if (describable != null) {
AbstractLiquibaseBuilder liquibaseBuilder = (AbstractLiquibaseBuilder) describable;
List builders = buildersList.getAll(AbstractLiquibaseBuilder.class);
for (Object builder : builders) {
AbstractLiquibaseBuilder liquibaseBuilder = (AbstractLiquibaseBuilder) builder;
migrateCredentials(project, liquibaseBuilder);
}
}
Expand Down
@@ -0,0 +1,63 @@
package org.jenkinsci.plugins.liquibase.evaluator;

import hudson.model.Project;
import jenkins.model.Jenkins;

import java.io.IOException;
import java.util.List;

import org.junit.ClassRule;
import org.junit.Test;
import org.jvnet.hudson.test.JenkinsRule;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.notNullValue;
import static org.junit.Assert.assertThat;

public class CredentialsMigratorTest {


private static final Logger LOG = LoggerFactory.getLogger(CredentialsMigratorTest.class);

@ClassRule
public static JenkinsRule jenkinsRule = new JenkinsRule().withPresetData("update-test-data");

/**
* Covers JENKINS-40920. The preset data contains a job containing < 1.2.0 plugin format, and
* whose credentials should therefore be migrated.
* The test does verify that the old job does indeed exist in the preset data.
* @throws IOException
*/
@Test
public void should_migrate_both_builder() throws IOException {
Jenkins jenkins = jenkinsRule.getInstance();
List<Project> projects = jenkins.getItems(Project.class);

boolean presetDataIncludedLiquibaseBuilder = false;
boolean projectContainedMoreThanOneBuilder = false;

int builderCounter = 0;

for (Project project : projects) {
List all = project.getBuildersList().getAll(AbstractLiquibaseBuilder.class);
for (Object o : all) {
AbstractLiquibaseBuilder liquibaseBuilder = (AbstractLiquibaseBuilder) o;
builderCounter++;
if (liquibaseBuilder!=null) {
assertThat(liquibaseBuilder.getCredentialsId(), is(notNullValue()));
assertThat(liquibaseBuilder.hasLegacyCredentials(), is(false));
if (!presetDataIncludedLiquibaseBuilder) {
presetDataIncludedLiquibaseBuilder = true;
}
}
}
projectContainedMoreThanOneBuilder = builderCounter>1;
}

assertThat(presetDataIncludedLiquibaseBuilder, is(true));
assertThat(projectContainedMoreThanOneBuilder, is(true));
}

}
37 changes: 0 additions & 37 deletions src/test/resources/scripted-upgrade-test/oldauth_job_config.xml

This file was deleted.

39 changes: 0 additions & 39 deletions src/test/resources/scripted-upgrade-test/unsecured-jenkins.xml

This file was deleted.

118 changes: 0 additions & 118 deletions src/test/resources/scripted-upgrade-test/upgrade-credentials-test.sh

This file was deleted.

Binary file added src/test/resources/update-test-data.zip
Binary file not shown.

0 comments on commit 4073144

Please sign in to comment.