Skip to content
Permalink
Browse files

JENKINS-40920

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 40731449b9dba29bc91019d95fab224109225c50
@@ -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;
@@ -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);
}
}
@@ -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));
}

}

This file was deleted.

This file was deleted.

This file was deleted.

Binary file not shown.

0 comments on commit 4073144

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