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-12932. improved assertions in HarnessNoSqlCompatibility test #327

Merged
merged 11 commits into from
Jan 26, 2023
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import groovy.transform.ToString
import groovy.transform.builder.Builder
import liquibase.Scope
import liquibase.database.Database
import liquibase.database.DatabaseConnection
import liquibase.harness.config.DatabaseUnderTest
import liquibase.harness.config.TestConfig
import liquibase.harness.util.DatabaseConnectionUtil
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package liquibase.harness.compatibility.foundational


import liquibase.ext.mongodb.change.CreateCollectionChange
import liquibase.ext.mongodb.database.MongoConnection
import liquibase.harness.config.DatabaseUnderTest
import liquibase.harness.config.TestConfig
Expand Down Expand Up @@ -66,6 +68,11 @@ class HarnessNoSqlCompatibility extends Specification {
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)
}
}

and: "execute Liquibase tag command. Tagging last row of DATABASECHANGELOG table"
Expand All @@ -74,7 +81,9 @@ class HarnessNoSqlCompatibility extends Specification {
MongoTestUtils.executeCommandScope("tag", argsMap)

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

and: "execute Liquibase status command"
for (int i = 0; i < changelogList.size(); i++) {
Expand All @@ -90,7 +99,7 @@ class HarnessNoSqlCompatibility extends Specification {

and: "check for actual presence of created object"
if (!testInput.change.startsWith("drop")) {
assert (MongoTestUtils.getCollections(connection as MongoConnection)).containsAll(collectionNames)
assert MongoTestUtils.getCollections(connection as MongoConnection).containsAll(collectionNames)
}

cleanup: "rollback changes if we ran changeSet"
Expand Down
22 changes: 21 additions & 1 deletion src/test/groovy/liquibase/harness/util/MongoTestUtils.groovy
Original file line number Diff line number Diff line change
@@ -1,13 +1,33 @@
package liquibase.harness.util


import liquibase.changelog.ChangeLogParameters
import liquibase.changelog.ChangeSet
import liquibase.changelog.DatabaseChangeLog
import liquibase.exception.LiquibaseException
import liquibase.ext.mongodb.database.MongoConnection
import liquibase.ext.mongodb.database.MongoLiquibaseDatabase
import liquibase.parser.ChangeLogParser
import liquibase.parser.ChangeLogParserFactory
import liquibase.resource.ClassLoaderResourceAccessor

import java.util.stream.Collectors
import java.util.stream.StreamSupport

class MongoTestUtils extends TestUtils {


static List<ChangeSet> getChangesets(final String changeSetPath, final MongoLiquibaseDatabase database) throws LiquibaseException {
final ClassLoaderResourceAccessor resourceAccessor = new ClassLoaderResourceAccessor();
final ChangeLogParser parser =
ChangeLogParserFactory.getInstance().getParser(
changeSetPath, resourceAccessor
);

final DatabaseChangeLog changeLog =
parser.parse(changeSetPath, new ChangeLogParameters(database), resourceAccessor);
return changeLog.getChangeSets();
}

static List<String> getCollections(final MongoConnection connection) {
return StreamSupport.stream(connection.getMongoDatabase().listCollectionNames().spliterator(), false)
.collect(Collectors.toList());
Expand Down