App uses Postgress DB running in a docker container, and Liquibase creates tables perfectly.
Test uses H2 in memory DB, Liquibase configured in application.yml as follows:
spring:
profiles:
active: jdbc
test:
database:
replace=none:
application:
name: “Coding Example UNDER_TEST”
main:
allow-bean-definition-overriding: true
thymeleaf:
cache: false
datasource:
url: jdbc:h2:mem:app_example
username: SA
password:
statement-cache-size: 250
statement-cache-sql-limit: 2048
liquibase:
enabled: true
contextFilter: test
change-log: classpath:db/changelog/db.changelog-master.yaml
url: jdbc:h2:mem:app_example;DB_CLOSE_DELAY=-1;INIT=CREATE SCHEMA IF NOT EXISTS app_example
user: sa
password:
default-schema: app_example
drop-first: true
Does not run as expected.
Added code to the test class to run programmatically always get error:
liquibase.exception.ChangeLogParseException: /D:/coding-example/coding-example/build/resources/test/db/changelog/db.changelog-master.yaml does not exist
tried various versions of the following code in the test, always same result.
public boolean setUp() {
Liquibase liquibase = null;
try {
DatabaseConnection connection = new JdbcConnection(myDatasource.getDataSource().getConnection());
Database database = DatabaseFactory.getInstance().findCorrectDatabaseImplementation(connection);
URL resourceUrl = getClass().getResource("/db/changelog");
URL otherResourceUrl = DatabaseDefaultAccessTests.class.getClassLoader().getResource("db/changelog/db.changelog-master.yaml");
ResourceAccessor resourceAccessor = new DirectoryResourceAccessor(new File(resourceUrl.getPath()));
String changeLogFile = otherResourceUrl.getPath();
liquibase = new liquibase.Liquibase(changeLogFile, resourceAccessor, database);
liquibase.update();
return true;
} catch (SQLException | LiquibaseException | FileNotFoundException e) {
// handle exception
return false;
} finally {
// close resources
if (liquibase != null) {
try {
Database database = liquibase.getDatabase();
if (database != null) {
database.close();
}
} catch (DatabaseException ignored) {}
}
}
}
Using Java 21
IntelliJ on Windows
Springboot 3.2.3
Liquibase 4.26.0
junit-jupiter 5.10.2
Any help is much appreciated.