diff options
author | Bruno Sakoto <bruno.sakoto@bell.ca> | 2021-04-20 08:22:56 -0400 |
---|---|---|
committer | Bruno Sakoto <bruno.sakoto@bell.ca> | 2021-04-22 10:00:22 -0400 |
commit | 05855d531b912698ee63b1fd9de4303baff83670 (patch) | |
tree | 0496540ac248dff37629cdcffde6215b3096a343 /src/test/java | |
parent | 472d2e8d8df431e46b0f0dead8448bff5e80ab0d (diff) |
Implement db schema with liquibase
Issue-ID: CPS-193
Signed-off-by: Bruno Sakoto <bruno.sakoto@bell.ca>
Change-Id: Ieabee4b86bbe7a42c05bb225499487cfcc9deb1d
Diffstat (limited to 'src/test/java')
-rw-r--r-- | src/test/java/org/onap/cps/temporal/ApplicationTest.java | 8 | ||||
-rw-r--r-- | src/test/java/org/onap/cps/temporal/repository/TimescaleContainer.java | 68 |
2 files changed, 75 insertions, 1 deletions
diff --git a/src/test/java/org/onap/cps/temporal/ApplicationTest.java b/src/test/java/org/onap/cps/temporal/ApplicationTest.java index 842b94a..bae6e65 100644 --- a/src/test/java/org/onap/cps/temporal/ApplicationTest.java +++ b/src/test/java/org/onap/cps/temporal/ApplicationTest.java @@ -1,7 +1,6 @@ /* * ============LICENSE_START======================================================= * Copyright (c) 2021 Bell Canada. - * Modifications Copyright (C) 2021 Bell Canada. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,6 +20,7 @@ package org.onap.cps.temporal; import org.assertj.core.util.Arrays; import org.junit.jupiter.api.Test; +import org.onap.cps.temporal.repository.TimescaleContainer; import org.springframework.boot.test.context.SpringBootTest; // This test class without any assertion is obviously not really useful. @@ -29,6 +29,12 @@ import org.springframework.boot.test.context.SpringBootTest; @SpringBootTest class ApplicationTest { + private static final TimescaleContainer TIMESCALE_CONTAINER = TimescaleContainer.getInstance(); + + static { + TIMESCALE_CONTAINER.start(); + } + @Test void testMain() { Application.main(Arrays.array()); diff --git a/src/test/java/org/onap/cps/temporal/repository/TimescaleContainer.java b/src/test/java/org/onap/cps/temporal/repository/TimescaleContainer.java new file mode 100644 index 0000000..73b8c13 --- /dev/null +++ b/src/test/java/org/onap/cps/temporal/repository/TimescaleContainer.java @@ -0,0 +1,68 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (c) 2021 Bell Canada. + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ + +package org.onap.cps.temporal.repository; + +import org.testcontainers.containers.PostgreSQLContainer; +import org.testcontainers.utility.DockerImageName; + +/** + * Container for timescale database. + */ +public class TimescaleContainer extends PostgreSQLContainer<TimescaleContainer> { + + private static final String IMAGE_NAME = "timescale/timescaledb:2.1.1-pg13"; + private static final DockerImageName DOCKER_IMAGE_NAME = + DockerImageName.parse(IMAGE_NAME).asCompatibleSubstituteFor("postgres"); + + private static TimescaleContainer container; + + private TimescaleContainer() { + super(DOCKER_IMAGE_NAME); + } + + /** + * Get the unique container instance. + * @return the container instance. + */ + public static TimescaleContainer getInstance() { + if (container == null) { + container = new TimescaleContainer(); + Runtime.getRuntime().addShutdownHook(new Thread(container::terminate)); + } + return container; + } + + @Override + public void start() { + super.start(); + System.setProperty("DB_URL", container.getJdbcUrl()); + System.setProperty("DB_USERNAME", container.getUsername()); + System.setProperty("DB_PASSWORD", container.getPassword()); + } + + @Override + public void stop() { + // Do nothing on test completion, container removal is performed via terminate() on JVM shutdown. + } + + private void terminate() { + super.stop(); + } + +} |