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 5083 :: Support for Maven surefire #2

Merged
merged 3 commits into from
Aug 20, 2020
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
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
target/
.gitignore
.idea/
*.iml
*.iml
bin/
.project
.DS_Store
28 changes: 16 additions & 12 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -60,23 +60,27 @@
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M5</version>
<configuration>
<argLine>
--illegal-access=permit
</argLine>
</configuration>
<groupId>org.codehaus.gmavenplus</groupId>
<artifactId>gmavenplus-plugin</artifactId>
<version>1.6.2</version>
<executions>
<execution>
<goals>
<goal>addTestSources</goal>
<goal>compileTests</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M5</version>
<configuration>
<argLine>
--illegal-access=permit
</argLine>
<includes>
<include>**/*Test.java</include>
<include>**/*Spec.java</include>
</includes>
</configuration>
</plugin>
</plugins>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ class ChangeObjectsTest extends Specification {
ArrayList<String> expectedSqlList = TestUtils.parseValuesToList(expectedSql, "\n")

when:
List<String> generatedSql = TestUtils.toSqlFromLiquibaseChangeSets(liquibase);
List<String> generatedSql = TestUtils.toSqlFromLiquibaseChangeSets(liquibase)

then:
expectedSqlList == generatedSql;
expectedSqlList == generatedSql

when:
liquibase.update(testInput.context);
liquibase.update(testInput.context)

String jsonSnapshot = SnapshotHelpers.getJsonSnapshot(database, catalogAndSchemaList)
liquibase.rollback(liquibase.databaseChangeLog.changeSets.size(), testInput.context)
Expand All @@ -54,8 +54,8 @@ class ChangeObjectsTest extends Specification {
testInput << TestUtils.buildTestInput(config)
}

void snapshotMatchesSpecifiedStructure(String expected, String actual) {
JSONAssert.assertEquals(expected, actual, new SnapshotHelpers.GeneralSnapshotComparator());
static void snapshotMatchesSpecifiedStructure(String expected, String actual) {
JSONAssert.assertEquals(expected, actual, new SnapshotHelpers.GeneralSnapshotComparator())
}

}
Original file line number Diff line number Diff line change
@@ -1,41 +1,41 @@
package liquibase.harness.util

import liquibase.Scope;
import liquibase.changelog.ChangeLogHistoryServiceFactory;
import liquibase.database.Database;
import liquibase.database.DatabaseConnection;
import liquibase.database.DatabaseFactory;
import liquibase.Scope
import liquibase.changelog.ChangeLogHistoryServiceFactory
import liquibase.database.Database
import liquibase.database.DatabaseConnection
import liquibase.database.DatabaseFactory
import liquibase.exception.DatabaseException
import liquibase.harness.config.TestInput;
import liquibase.lockservice.LockServiceFactory;
import liquibase.logging.Logger;
import liquibase.snapshot.SnapshotGeneratorFactory;
import liquibase.harness.config.TestInput
import liquibase.lockservice.LockServiceFactory
import liquibase.logging.Logger
import liquibase.snapshot.SnapshotGeneratorFactory

class DatabaseConnectionUtil {
private static Logger logger = Scope.getCurrentScope().getLog(getClass());
private static Logger logger = Scope.getCurrentScope().getLog(getClass())

static Database initializeDatabase(TestInput testInput) {
try {
Database database = openConnection(testInput.url, testInput.username, testInput.password);
return init(database);
Database database = openConnection(testInput.url, testInput.username, testInput.password)
return init(database)
}
catch (Exception e) {
logger.severe("Unable to initialize database connection", e);
return null;
logger.severe("Unable to initialize database connection", e)
return null
}
}

private static Database openConnection(String url, String username, String password) throws Exception {
DatabaseConnection connection = DatabaseTestContext.getInstance().getConnection(url, username, password);
return DatabaseFactory.getInstance().findCorrectDatabaseImplementation(connection);
DatabaseConnection connection = DatabaseTestContext.getInstance().getConnection(url, username, password)
return DatabaseFactory.getInstance().findCorrectDatabaseImplementation(connection)

}

private static Database init(Database database) throws DatabaseException {
SnapshotGeneratorFactory.resetAll();
LockServiceFactory.getInstance().resetAll();
LockServiceFactory.getInstance().getLockService(database).init();
ChangeLogHistoryServiceFactory.getInstance().resetAll();
SnapshotGeneratorFactory.resetAll()
LockServiceFactory.getInstance().resetAll()
LockServiceFactory.getInstance().getLockService(database).init()
ChangeLogHistoryServiceFactory.getInstance().resetAll()
return database
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,7 @@ private DatabaseConnection openConnection(final String givenUrl,
if (!tempDir.endsWith(System.getProperty("file.separator")))
tempDir += System.getProperty("file.separator");

String tempUrl = givenUrl.replace("***TEMPDIR***/", tempDir);
final String url = tempUrl;
final String url = givenUrl.replace("***TEMPDIR***/", tempDir);

if (connectionsAttempted.containsKey(url)) {
JdbcConnection connection = (JdbcConnection) connectionsByUrl.get(url);
Expand All @@ -85,7 +84,7 @@ private DatabaseConnection openConnection(final String givenUrl,
boolean shouldTest = false;
String[] databasesToTest = System.getProperty(TEST_DATABASES_PROPERTY).split("\\s*,\\s*");
for (String database : databasesToTest) {
if (url.indexOf(database) >= 0) {
if (url.contains(database)) {
shouldTest = true;
}
}
Expand Down Expand Up @@ -144,13 +143,7 @@ private DatabaseConnection openConnection(final String givenUrl,

connectionsByUrl.put(url, databaseConnection);

Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {

@Override
public void run() {
shutdownConnection((JdbcConnection) databaseConnection);
}
}));
Runtime.getRuntime().addShutdownHook(new Thread(() -> shutdownConnection((JdbcConnection) databaseConnection)));

return databaseConnection;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import liquibase.harness.config.TestInput
import org.yaml.snakeyaml.Yaml

class FileUtils {
static final String resourceBaseDir = "src/main/resources/"
static final String resourceBaseDir = "src/test/resources/"

static String getFileContent (TestInput testInput, String expectedFolder, String fileExtension){
return new File(new StringBuilder(resourceBaseDir)
Expand Down Expand Up @@ -39,7 +39,7 @@ class FileUtils {
dir.eachFileRecurse(FileType.FILES) { file ->
changeObjects.put(file.getName(), file.getPath())
}
return changeObjects;
return changeObjects
}

static Map<String, String> getVersionSpecificChangeObjects(String dbName, String dbVersion) {
Expand All @@ -53,11 +53,11 @@ class FileUtils {
dir.eachFileRecurse(FileType.FILES) { file ->
changeTypes.put(file.getName().substring(0, file.getName().lastIndexOf('.')),file.getPath())
}
return changeTypes;
return changeTypes
}

static Map<String, String> mapChangeObjectsToFilePaths(List<String> strings) {
Map <String, String> changeTypeToFilePathMap = new HashMap<>();
Map <String, String> changeTypeToFilePathMap = new HashMap<>()
strings.each {
changeTypeToFilePathMap.put(it, resourceBaseDir + "changelogs/" + it + ".xml")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class HarnessResourceAccessor extends ClassLoaderResourceAccessor {
HarnessResourceAccessor() throws Exception {
super(new URLClassLoader(new URL[]{
new File(System.getProperty("user.dir")).toURI().toURL(),
new File("src/main/resources/").toURI().toURL(),
new File("src/test/resources/").toURI().toURL(),
new File(System.getProperty("java.io.tmpdir")).toURI().toURL(),
}))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class SnapshotHelpers {
result.passed()
}
else if (!StringUtil.equalsIgnoreCaseAndEmpty(expectedValue, actualValue)) {
result.fail(prefix, expectedValue, actualValue);
result.fail(prefix, expectedValue, actualValue)
}
} else {
super.compareValues(prefix, expectedValue, actualValue, result)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,4 @@ class TestUtils {
return inputList
}

static Map<String, String> mergeChangeObjects(Map<String, String> versionSpecificChangeObjects, Map<String, String> changeObjects) {
changeObjects.putAll(versionSpecificChangeObjects)
return changeObjects
}
}
File renamed without changes.