Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

general changes to support flow file validation (DAT-10588) #2986

Merged
merged 5 commits into from
Jun 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 11 additions & 5 deletions liquibase-core/src/main/java/liquibase/command/CommandScope.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import liquibase.Scope;
import liquibase.configuration.*;
import liquibase.exception.CommandExecutionException;
import liquibase.exception.CommandValidationException;
import liquibase.util.StringUtil;

import java.io.OutputStream;
Expand Down Expand Up @@ -131,11 +132,7 @@ public CommandScope setOutput(OutputStream outputStream) {
return this;
}

/**
* Executes the command in this scope, and returns the results.
*/
public CommandResults execute() throws CommandExecutionException {
CommandResultsBuilder resultsBuilder = new CommandResultsBuilder(this, outputStream);
public void validate() throws CommandValidationException {
for (ConfigurationValueProvider provider : Scope.getCurrentScope().getSingleton(LiquibaseConfiguration.class).getProviders()) {
provider.validate(this);
}
Expand All @@ -151,6 +148,15 @@ public CommandResults execute() throws CommandExecutionException {
for (CommandStep step : pipeline) {
step.validate(this);
}
}

/**
* Executes the command in this scope, and returns the results.
*/
public CommandResults execute() throws CommandExecutionException {
CommandResultsBuilder resultsBuilder = new CommandResultsBuilder(this, outputStream);
final List<CommandStep> pipeline = commandDefinition.getPipeline();
validate();
try {
for (CommandStep command : pipeline) {
command.run(resultsBuilder);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ public CommandValidationException(String message) {
super(message);
}

public CommandValidationException(Throwable cause) {
super(cause);
}

public CommandValidationException(String argument, String message, Throwable cause) {
super(buildMessage(argument, message), cause);
}
Expand Down
13 changes: 12 additions & 1 deletion liquibase-core/src/main/java/liquibase/util/CollectionUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public static <T> T[] createIfNull(T[] arguments) {
}

/**
* Returns a new empty set if the passed array is null.
* Returns a new empty set if the passed set is null.
*/
public static <T> Set<T> createIfNull(Set<T> currentValue) {
if (currentValue == null) {
Expand All @@ -88,6 +88,17 @@ public static <T> Set<T> createIfNull(Set<T> currentValue) {
}
}

/**
* Returns a new empty map if the passed map is null.
*/
public static <T, E> Map<T, E> createIfNull(Map<T, E> currentValue) {
if (currentValue == null) {
return new HashMap<>();
} else {
return currentValue;
}
}

/**
* Converts a set of nested maps (like from yaml/json) into a flat map with dot-separated properties
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1105,6 +1105,9 @@ Long Description: ${commandDefinition.getLongDescription() ?: "NOT SET"}
this.setups.add(new SetupModifyTextFile(textFile, originalString, newString))
}

void modifyDbCredentials(File textFile) {
this.setups.add(new SetupModifyDbCredentials(textFile))
}
private void validate() throws IllegalArgumentException {

}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package liquibase.extension.testing.setup

import liquibase.util.FileUtil

/**
*
* This class allows modification of a text file to
* replace tokens with the actual database credential
* as specified in the environment
*
*/
class SetupModifyDbCredentials extends TestSetup {

private static final String URL = "_URL_"
private static final String USERNAME = "_USERNAME_"
private static final String PASSWORD = "_PASSWORD_"
private final File textFile

SetupModifyDbCredentials(File textFile) {
this.textFile = textFile
}

@Override
void setup(TestSetupEnvironment testSetupEnvironment) throws Exception {
String contents = FileUtil.getContents(textFile)
contents = contents.replaceAll(URL, testSetupEnvironment.url)
contents = contents.replaceAll(USERNAME, testSetupEnvironment.username)
contents = contents.replaceAll(PASSWORD, testSetupEnvironment.password)
FileUtil.write(contents, textFile)
}
}