--- /dev/null
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2026 OpenInfra Foundation Europe. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.clamp.acm.runtime.liquibase;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.SQLException;
+import liquibase.Liquibase;
+import liquibase.database.DatabaseFactory;
+import liquibase.database.jvm.JdbcConnection;
+import liquibase.exception.DatabaseException;
+import liquibase.resource.ClassLoaderResourceAccessor;
+import org.testcontainers.containers.PostgreSQLContainer;
+import org.testcontainers.junit.jupiter.Container;
+
+public abstract class AbstractLiquibaseTestBase {
+ @Container
+ protected static final PostgreSQLContainer<?> postgres = new PostgreSQLContainer<>("postgres");
+
+ protected static Liquibase initLiquibase(Connection connection) throws DatabaseException {
+ var database = DatabaseFactory.getInstance().findCorrectDatabaseImplementation(new JdbcConnection(connection));
+ return new Liquibase("db/changelog/db.changelog-master.yaml", new ClassLoaderResourceAccessor(), database);
+ }
+
+ protected static Connection initConnection() throws SQLException {
+ return DriverManager.getConnection(
+ postgres.getJdbcUrl(),
+ postgres.getUsername(),
+ postgres.getPassword());
+ }
+}
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.DynamicPropertyRegistry;
import org.springframework.test.context.DynamicPropertySource;
-import org.testcontainers.containers.PostgreSQLContainer;
-import org.testcontainers.junit.jupiter.Container;
import org.testcontainers.junit.jupiter.Testcontainers;
-import org.testcontainers.utility.DockerImageName;
/**
* This test enables Hibernate validation during context startup.
@SpringBootTest
@ActiveProfiles("hibernate-validation")
@Testcontainers
-class HibernateValidationTest {
-
- @Container
- private static final PostgreSQLContainer<?> postgres = new PostgreSQLContainer<>(
- DockerImageName.parse("registry.nordix.org/onaptest/postgres:14.1").asCompatibleSubstituteFor("postgres"));
+class HibernateValidationTest extends AbstractLiquibaseTestBase {
@DynamicPropertySource
static void overrideProperties(DynamicPropertyRegistry registry) {
import java.io.PrintStream;
import java.sql.Connection;
-import java.sql.DriverManager;
-import java.sql.SQLException;
import java.sql.Statement;
import java.util.stream.Stream;
import liquibase.Liquibase;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
-import org.testcontainers.containers.PostgreSQLContainer;
-import org.testcontainers.junit.jupiter.Container;
import org.testcontainers.junit.jupiter.Testcontainers;
-import org.testcontainers.utility.DockerImageName;
// This test class verifies that rollbacks for each Liquibase release tag works correctly.
@Testcontainers
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
-class LiquibaseRollbackTest {
-
- @Container
- private static final PostgreSQLContainer<?> postgres = new PostgreSQLContainer<>(
- DockerImageName.parse("registry.nordix.org/onaptest/postgres:14.1").asCompatibleSubstituteFor("postgres"));
+class LiquibaseRollbackTest extends AbstractLiquibaseTestBase {
private Liquibase liquibase;
database.setDefaultSchemaName(schema);
return new Liquibase("db/changelog/db.changelog-master.yaml", new ClassLoaderResourceAccessor(), database);
}
-
- private Connection initConnection() throws SQLException {
- return DriverManager.getConnection(
- postgres.getJdbcUrl(),
- postgres.getUsername(),
- postgres.getPassword());
- }
-
}
import static org.junit.jupiter.api.Assertions.fail;
import java.sql.Connection;
-import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.concurrent.TimeUnit;
import liquibase.Liquibase;
-import liquibase.database.DatabaseFactory;
-import liquibase.database.jvm.JdbcConnection;
-import liquibase.exception.DatabaseException;
import liquibase.exception.LiquibaseException;
-import liquibase.resource.ClassLoaderResourceAccessor;
import org.junit.jupiter.api.Test;
-import org.testcontainers.containers.PostgreSQLContainer;
-import org.testcontainers.junit.jupiter.Container;
import org.testcontainers.junit.jupiter.Testcontainers;
-import org.testcontainers.utility.DockerImageName;
@Testcontainers
-class LiquibaseSessionLockTest {
-
- @Container
- private static final PostgreSQLContainer<?> postgres = new PostgreSQLContainer<>(
- DockerImageName.parse("registry.nordix.org/onaptest/postgres:14.1").asCompatibleSubstituteFor("postgres"));
+class LiquibaseSessionLockTest extends AbstractLiquibaseTestBase {
@Test
void shouldCleanupStaleLockWhenConnectionFails() throws Exception {
private static int getLockCount(Liquibase liquibase) throws LiquibaseException {
return liquibase.listLocks().length;
}
-
- private static Liquibase initLiquibase(Connection connection) throws DatabaseException {
- var database = DatabaseFactory.getInstance().findCorrectDatabaseImplementation(new JdbcConnection(connection));
- return new Liquibase("db/changelog/db.changelog-master.yaml", new ClassLoaderResourceAccessor(), database);
- }
-
- private static Connection initConnection() throws SQLException {
- return DriverManager.getConnection(
- postgres.getJdbcUrl(),
- postgres.getUsername(),
- postgres.getPassword());
- }
}
--- /dev/null
+postgres.container.image=registry.nordix.org/onaptest/postgres:14.1
\ No newline at end of file