Skip to content

Commit

Permalink
Added testing framework to help with flow
Browse files Browse the repository at this point in the history
DAT-10586
  • Loading branch information
wwillard7800 committed Jun 21, 2022
1 parent 9ccf1a9 commit 0f32b7b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1105,8 +1105,8 @@ Long Description: ${commandDefinition.getLongDescription() ?: "NOT SET"}
this.setups.add(new SetupModifyTextFile(textFile, originalString, newString))
}

void modifyDbCredentials(File textFile, String originalString, String newString) {
this.setups.add(new SetupModifyDbCredentials(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
Expand Up @@ -2,29 +2,30 @@ 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
private String originalString
private String newString

SetupModifyDbCredentials(File textFile, String originalString, String newString) {
SetupModifyDbCredentials(File textFile) {
this.textFile = textFile
this.originalString = originalString
this.newString = newString
}

@Override
void setup(TestSetupEnvironment testSetupEnvironment) throws Exception {
if (this.originalString == "_URL_") {
this.newString = testSetupEnvironment.url
} else if (this.originalString == "_USERNAME_") {
this.newString = testSetupEnvironment.username
} else if (this.originalString == "_PASSWORD_") {
this.newString = testSetupEnvironment.password
}
String contents = FileUtil.getContents(textFile)
contents = contents.replaceAll(originalString, newString)
contents = contents.replaceAll(URL, testSetupEnvironment.url)
contents = contents.replaceAll(USERNAME, testSetupEnvironment.username)
contents = contents.replaceAll(PASSWORD, testSetupEnvironment.password)
FileUtil.write(contents, textFile)
}
}
}

0 comments on commit 0f32b7b

Please sign in to comment.