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

DAT-15075. added possibility to run only one test case in HarnessNoSqlCompatibility test #378

Merged
merged 3 commits into from
Jun 7, 2023
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,32 +15,57 @@ class CompatibilityTestHelper {
final static List supportedChangeLogFormats = ['xml', 'json', 'yml', 'yaml'].asImmutable()

static List<TestInput> buildTestInput(String changelogPathSpecification) {
String commandLineInputFormat = System.getProperty("inputFormat")
String specificChangelogPath = baseChangelogPath + changelogPathSpecification
if (commandLineInputFormat) {
if (!supportedChangeLogFormats.contains(commandLineInputFormat)) {
throw new IllegalArgumentException(commandLineInputFormat + " inputFormat is not supported")
String commandLineInputFormats = System.getProperty("inputFormat")
String commandLineChangeObjects = System.getProperty("changeObjects")

List inputFormatList = Collections.emptyList()
List commandLineChangeObjectList = Collections.emptyList()

if (commandLineInputFormats) {
TestConfig.instance.inputFormat = commandLineInputFormats
}

inputFormatList = Arrays.asList(TestConfig.instance.inputFormat.contains(",")
? TestConfig.instance.inputFormat.split(",")
: TestConfig.instance.inputFormat)

for(String inputFormat: inputFormatList){
if (!supportedChangeLogFormats.contains(inputFormat)) {
throw new IllegalArgumentException(inputFormat + " inputFormat is not supported")
}
TestConfig.instance.inputFormat = commandLineInputFormat
}

if (commandLineChangeObjects) {
commandLineChangeObjectList = Arrays.asList(commandLineChangeObjects.contains(",")
? commandLineChangeObjects.split(",")
: commandLineChangeObjects)
}

Scope.getCurrentScope().getUI().sendMessage("Only " + TestConfig.instance.inputFormat
+ " input files are taken into account for this test run")

List<TestInput> inputList = new ArrayList<>()
DatabaseConnectionUtil databaseConnectionUtil = new DatabaseConnectionUtil()
for (DatabaseUnderTest databaseUnderTest : databaseConnectionUtil
.initializeDatabasesConnection(TestConfig.instance.getFilteredDatabasesUnderTest())) {
for (def changeLogEntry : FileUtils.resolveInputFilePaths(databaseUnderTest, specificChangelogPath, "xml").entrySet()) {
inputList.add(TestInput.builder()
.databaseName(databaseUnderTest.name)
.url(databaseUnderTest.url)
.dbSchema(databaseUnderTest.dbSchema)
.username(databaseUnderTest.username)
.password(databaseUnderTest.password)
.version(databaseUnderTest.version)
.change(changeLogEntry.key)
.database(databaseUnderTest.database)
.build())
for (String inputFormat: inputFormatList) {
for (def changeLogEntry : FileUtils.resolveInputFilePaths(databaseUnderTest, specificChangelogPath, inputFormat).entrySet()) {
if (!commandLineChangeObjectList || commandLineChangeObjectList.contains(changeLogEntry.key)) {
inputList.add(TestInput.builder()
.databaseName(databaseUnderTest.name)
.url(databaseUnderTest.url)
.dbSchema(databaseUnderTest.dbSchema)
.username(databaseUnderTest.username)
.password(databaseUnderTest.password)
.version(databaseUnderTest.version)
.change(changeLogEntry.key)
.inputFormat(inputFormat)
.pathToChangeLogFile(changeLogEntry.value)
.database(databaseUnderTest.database)
.build())
}
}
}
}
return inputList
Expand All @@ -56,6 +81,8 @@ class CompatibilityTestHelper {
String url
String dbSchema
String change
String pathToChangeLogFile
String inputFormat
Database database
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,15 @@ class HarnessNoSqlCompatibility extends Specification {
strategy.prepareForRollback(databases)
}

def "apply #testInput.change against #testInput.databaseName #testInput.version"() {
def "apply #testInput.change #testInput.inputFormat against #testInput.databaseName #testInput.version"() {
given: "read input data"
String expectedResultSet = getJSONFileContent(testInput.change, testInput.databaseName, testInput.version,
"liquibase/harness/compatibility/foundational/expectedResultSet")
"liquibase/harness/compatibility/foundational/expectedResultSet/" + testInput.inputFormat + "_changelog")
Map<String, Object> argsMap = new HashMap()
argsMap.put("url", testInput.url)
argsMap.put("username", testInput.username)
argsMap.put("password", testInput.password)

String basePath = "liquibase/harness/compatibility/foundational/changelogs/nosql"
ArrayList<String> changelogList = new ArrayList<>()
changelogList.add("${basePath}/${testInput.change}.xml")
changelogList.add("${basePath}/${testInput.change}.json")
changelogList.add("${basePath}/${testInput.change}.yaml")
argsMap.put("changeLogFile", testInput.pathToChangeLogFile)

boolean shouldRunChangeSet

Expand All @@ -59,22 +54,16 @@ class HarnessNoSqlCompatibility extends Specification {
assert shouldRunChangeSet: "Database ${testInput.databaseName} ${testInput.version} is offline!"

and: "execute Liquibase validate command to ensure that changelog is valid"
for (int i = 0; i < changelogList.size(); i++) {
argsMap.put("changeLogFile", changelogList.get(i))
MongoTestUtils.executeCommandScope("validate", argsMap)
}
MongoTestUtils.executeCommandScope("validate", argsMap)

List<String> collectionNames = new ArrayList<>()

when: "execute changelogs using liquibase update command"
for (int i = 0; i < changelogList.size(); i++) {
argsMap.put("changeLogFile", changelogList.get(i))
MongoTestUtils.executeCommandScope("update", argsMap)
if (!testInput.change.contains("Command")) {
final String collectionName = ((CreateCollectionChange) MongoTestUtils.getChangesets(changelogList.get(i), testInput.database)
.get(0).getChanges().get(0)).getCollectionName()
collectionNames.add(collectionName)
}
MongoTestUtils.executeCommandScope("update", argsMap)
if (!testInput.change.contains("Command")) {
final String collectionName = ((CreateCollectionChange) MongoTestUtils.getChangesets(testInput.pathToChangeLogFile, testInput.database)
.get(0).getChanges().get(0)).getCollectionName()
collectionNames.add(collectionName)
}

and: "execute Liquibase tag command. Tagging last row of DATABASECHANGELOG table"
Expand All @@ -83,15 +72,11 @@ class HarnessNoSqlCompatibility extends Specification {
MongoTestUtils.executeCommandScope("tag", argsMap)

and: "execute Liquibase history command"
for (int i = 0; i < changelogList.size(); i++) {
assert MongoTestUtils.executeCommandScope("history", argsMap).toString().contains(changelogList.get(i))
}
assert MongoTestUtils.executeCommandScope("history", argsMap).toString().contains(testInput.pathToChangeLogFile)

and: "execute Liquibase status command"
for (int i = 0; i < changelogList.size(); i++) {
argsMap.put("changeLogFile", changelogList.get(i))
assert MongoTestUtils.executeCommandScope("status", argsMap).toString().contains("is up to date")
}
argsMap.put("changeLogFile", testInput.pathToChangeLogFile)
assert MongoTestUtils.executeCommandScope("status", argsMap).toString().contains("is up to date")

then: "obtain result set, compare it to expected result set"
def generatedResultSet = ((MongoConnection) connection).getMongoDatabase().getCollection("DATABASECHANGELOG").find().iterator().collect()
Expand All @@ -106,10 +91,7 @@ class HarnessNoSqlCompatibility extends Specification {

cleanup: "rollback changes if we ran changeSet"
if (shouldRunChangeSet) {
for (int i = 0; i < changelogList.size(); i++) {
argsMap.put("changeLogFile", changelogList.get(i))
strategy.performRollback(argsMap)
}
strategy.performRollback(argsMap)
}

where: "test input in next data table"
Expand Down
2 changes: 1 addition & 1 deletion src/test/resources/harness-config.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
inputFormat: xml
inputFormat: xml,json,yaml
context: testContext

databasesUnderTest:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"adminCommand": [
{
"fileName":"liquibase\/harness\/compatibility\/foundational\/changelogs\/nosql\/adminCommand.json",
"author":"as",
"description":"adminCommand",
"id":"1",
"execType":"EXECUTED"
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"createCollection": [
{
"fileName":"liquibase\/harness\/compatibility\/foundational\/changelogs\/nosql\/createCollection.json",
"comments":"test_comment",
"author":"as",
"description":"createCollection collectionName=towns_json",
"contexts":"test_context",
"id":"1",
"execType":"EXECUTED"
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"createIndex": [
{
"fileName":"liquibase\/harness\/compatibility\/foundational\/changelogs\/nosql\/createIndex.json",
"author":"as",
"description":"createCollection collectionName=countries_json",
"id":"1",
"execType":"EXECUTED"
},
{
"fileName":"liquibase\/harness\/compatibility\/foundational\/changelogs\/nosql\/createIndex.json",
"author":"as",
"description":"insertMany collectionName=countries_json",
"id":"2",
"execType":"EXECUTED"
},
{
"fileName":"liquibase\/harness\/compatibility\/foundational\/changelogs\/nosql\/createIndex.json",
"author":"as",
"description":"createIndex collectionName=countries_json",
"id":"3",
"execType":"EXECUTED"
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"dropCollection": [
{
"fileName":"liquibase\/harness\/compatibility\/foundational\/changelogs\/nosql\/dropCollection.json",
"author":"as",
"description":"createCollection collectionName=towns_json; dropCollection collectionName=towns_json",
"id":"1",
"execType":"EXECUTED"
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"dropIndex": [
{
"fileName":"liquibase\/harness\/compatibility\/foundational\/changelogs\/nosql\/dropIndex.json",
"author":"as",
"description":"createCollection collectionName=countries_json",
"id":"1",
"execType":"EXECUTED"
},
{
"fileName":"liquibase\/harness\/compatibility\/foundational\/changelogs\/nosql\/dropIndex.json",
"author":"as",
"description":"insertMany collectionName=countries_json",
"id":"2",
"execType":"EXECUTED"
},
{
"fileName":"liquibase\/harness\/compatibility\/foundational\/changelogs\/nosql\/dropIndex.json",
"author":"as",
"description":"createIndex collectionName=countries_json; dropIndex collectionName=countries_json",
"id":"3",
"execType":"EXECUTED"
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"insertMany": [
{
"fileName":"liquibase\/harness\/compatibility\/foundational\/changelogs\/nosql\/insertMany.json",
"author":"as",
"description":"createCollection collectionName=countries_json",
"id":"1",
"execType":"EXECUTED"
},
{
"fileName":"liquibase\/harness\/compatibility\/foundational\/changelogs\/nosql\/insertMany.json",
"author":"as",
"description":"insertMany collectionName=countries_json",
"id":"2",
"execType":"EXECUTED"
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"insertOne": [
{
"fileName":"liquibase\/harness\/compatibility\/foundational\/changelogs\/nosql\/insertOne.json",
"author":"as",
"description":"createCollection collectionName=towns_json",
"id":"1",
"execType":"EXECUTED"
},
{
"fileName":"liquibase\/harness\/compatibility\/foundational\/changelogs\/nosql\/insertOne.json",
"author":"as",
"description":"insertOne collectionName=towns_json",
"id":"2",
"execType":"EXECUTED"
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"runCommand": [
{
"fileName":"liquibase\/harness\/compatibility\/foundational\/changelogs\/nosql\/runCommand.json",
"author":"as",
"description":"runCommand",
"id":"1",
"execType":"EXECUTED"
}
]
}

This file was deleted.

This file was deleted.

Loading