Skip to content

Commit

Permalink
- Fixed tests
Browse files Browse the repository at this point in the history
- Fixed findbugs errors
  • Loading branch information
nvoxland committed Apr 20, 2020
1 parent ed17a03 commit df5bbb6
Show file tree
Hide file tree
Showing 9 changed files with 43 additions and 13 deletions.
13 changes: 13 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,19 @@
<version>2.38</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-basic-steps</artifactId>
<version>2.19</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>pipeline-build-step</artifactId>
<version>2.12</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>job-dsl</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,10 @@ public Boolean getUseIncludedDriver() {
return useIncludedDriver;
}

public void setUseIncludedDriver(Boolean useIncludedDriver) {
this.useIncludedDriver = useIncludedDriver;
}

public String getCredentialsId() {
return credentialsId;
}
Expand Down Expand Up @@ -202,8 +206,8 @@ public String composeChangeLogString() {
StringBuilder sb = new StringBuilder("");
String result = null;
if (changeLogParameters != null) {
for (String key : changeLogParameters.keySet()) {
sb.append(key).append("=").append(changeLogParameters.get(key)).append("\n");
for (Map.Entry<String, String> entry : changeLogParameters.entrySet()) {
sb.append(entry.getKey()).append("=").append(entry.getValue()).append("\n");
}
result = sb.substring(0, sb.length() - 1);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.jenkinsci.remoting.RoleChecker;
import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.DataBoundSetter;
import org.slf4j.LoggerFactory;

public class DatabaseDocBuilder extends AbstractLiquibaseBuilder {

Expand Down Expand Up @@ -54,9 +55,12 @@ public void runPerform(Run<?, ?> build,
}
private static class DatabaseDocGenerationCallback implements FilePath.FileCallable<Void> {

Liquibase liquibase;
Contexts contexts;
LabelExpression labelExpression;
transient Liquibase liquibase;
transient Contexts contexts;
transient LabelExpression labelExpression;

private static final long serialVersionUID = 3472462442L;


public DatabaseDocGenerationCallback(Liquibase liquibase, Contexts contexts, LabelExpression labelExpression) {
this.liquibase = liquibase;
Expand All @@ -66,7 +70,9 @@ public DatabaseDocGenerationCallback(Liquibase liquibase, Contexts contexts, Lab

@Override
public Void invoke(File f, VirtualChannel channel) throws IOException, InterruptedException {
f.mkdirs();
if (!f.mkdirs()) {
LoggerFactory.getLogger(getClass()).debug("Did not create "+f.getAbsolutePath());
}
try {
liquibase.generateDocumentation(f.getAbsolutePath(), contexts, labelExpression);
} catch (LiquibaseException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

public class DbDocExecution extends AbstractSynchronousStepExecution<Void> {

private static final long serialVersionUID = 842377246724L;

@Inject
private transient DbDocBuildStep step;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

public class LiquibaseUpdateExecution extends AbstractSynchronousStepExecution<Void> {

private static final long serialVersionUID = 1236313L;

@Inject
private transient LiquibaseUpdateBuildStep step;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
import com.google.inject.Inject;

public class RollbackStepExecution extends AbstractSynchronousStepExecution<Void> {

private static final long serialVersionUID = 865832747L;

@Inject
private transient RollbackStep step;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<f:section title="Database Driver">
<f:radioBlock inline="true" name="useIncludedDriver"
checked="${instance.databaseEngine==null || instance.databaseEngine!=''}" value="true"
checked="${instance.databaseEngine!=null &amp;&amp; instance.databaseEngine!=''}" value="true"
title="${%Use one of the included drivers}">
<f:entry title="${%Database engine}" field="databaseEngine">
<select class="setting-input" name="LiquibaseBuilder.databaseEngine">
Expand Down Expand Up @@ -67,4 +67,4 @@
<f:textarea value="${instance.changeLogProperties}"/>
</f:entry>
</f:section>
</j:jelly>
</j:jelly>
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public void should_allow_friendly_update_name() throws ExecutionException, Inter

@Test
public void should_allow_dbdoc_generation() throws IOException, ExecutionException, InterruptedException {
String script = generatePipelineScript(workspace, "/pipeline-scripts/db-doc-template.groovy");
String script = generatePipelineScript(workspace, "/pipelinescripts/db-doc-template.groovy");
LiquibaseTestUtil.createFileFromResource(workspace, LiquibaseTestUtil.SUNNY_DAY_CHANGESET_XML);
job.setDefinition(new CpsFlowDefinition(script));
WorkflowRun workflowRun = job.scheduleBuild2(0).get();
Expand All @@ -81,7 +81,7 @@ public void should_allow_dbdoc_generation() throws IOException, ExecutionExcepti
}
@Test
public void should_allow_changelog_parameters() throws IOException, ExecutionException, InterruptedException {
String baseScript = generatePipelineScript(workspace, "/pipeline-scripts/pipeline-with-changelog-params.groovy");
String baseScript = generatePipelineScript(workspace, "/pipelinescripts/pipeline-with-changelog-params.groovy");
String parameterValue = RandomStringUtils.randomAlphabetic(5);
String pipelineScript = baseScript.replaceAll("@PARAM_VALUE@", parameterValue);
job.setDefinition(new CpsFlowDefinition(pipelineScript));
Expand All @@ -103,7 +103,7 @@ public void should_allow_rollback_dsl()
throws IOException, SQLException, LiquibaseException, ExecutionException, InterruptedException {
File databaseFile = temporaryFolder.newFile();
String jdbcUrl = LiquibaseTestUtil.composeJdbcUrl(databaseFile);
String baseScript = generatePipelineScript(workspace, "/pipeline-scripts/rollback-pipeline-template.groovy");
String baseScript = generatePipelineScript(workspace, "/pipelinescripts/rollback-pipeline-template.groovy");
String script = baseScript.replaceAll("@DB_URL@", jdbcUrl);
CpsFlowDefinition cpsFlowDefinition = new CpsFlowDefinition(script);
job.setDefinition(cpsFlowDefinition);
Expand All @@ -119,7 +119,7 @@ private static File copyChangeLogFileToWorkspace(File workspace) throws IOExcept
}

private String generateUpdatePipelineScript(File workspace) throws IOException {
return generatePipelineScript(workspace, "/pipeline-scripts/pipeline-template.groovy");
return generatePipelineScript(workspace, "/pipelinescripts/pipeline-template.groovy");
}

private String generatePipelineScript(File workspace, String resourcePath) throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package pipelinescripts;
node {
ws('@WORKSPACE@') {

liquibaseUpdate(changeLogFile: 'with-changelog-property.xml',
liquibaseUpdate(changeLogFile: 'example-changesets/with-changelog-property.xml',
changeLogParameterList: ['sample.table.name=@PARAM_VALUE@'])
}
}
Expand Down

0 comments on commit df5bbb6

Please sign in to comment.