aboutsummaryrefslogtreecommitdiffstats
path: root/src/test/java/org/onap
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/java/org/onap')
-rw-r--r--src/test/java/org/onap/cps/temporal/ApplicationTest.java8
-rw-r--r--src/test/java/org/onap/cps/temporal/repository/TimescaleContainer.java68
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();
+ }
+
+}