From d31d8e1cc167abf7835a1771b5ddc8d78aba9ac6 Mon Sep 17 00:00:00 2001 From: "puthuparambil.aditya" Date: Thu, 6 May 2021 16:12:44 +0100 Subject: Implement service and repository layers for storing temporal data 1. Basic structure created 2. Basic tests added 3. lombok.config included for coverage Issue-ID: CPS-194 Signed-off-by: puthuparambil.aditya Change-Id: Icf23c2e647106f7985dff14d9901806f7c4aa55a --- .../org/onap/cps/temporal/ApplicationTest.java | 43 -------------- .../temporal/repository/TimescaleContainer.java | 68 ---------------------- .../repository/containers/TimescaleContainer.java | 68 ++++++++++++++++++++++ 3 files changed, 68 insertions(+), 111 deletions(-) delete mode 100644 src/test/java/org/onap/cps/temporal/ApplicationTest.java delete mode 100644 src/test/java/org/onap/cps/temporal/repository/TimescaleContainer.java create mode 100644 src/test/java/org/onap/cps/temporal/repository/containers/TimescaleContainer.java (limited to 'src/test/java/org/onap') diff --git a/src/test/java/org/onap/cps/temporal/ApplicationTest.java b/src/test/java/org/onap/cps/temporal/ApplicationTest.java deleted file mode 100644 index bae6e65..0000000 --- a/src/test/java/org/onap/cps/temporal/ApplicationTest.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * ============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; - -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. -// Its only purpose is to be able to cover current code. -// It should be deleted when more code will be added to the project. -@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 deleted file mode 100644 index 73b8c13..0000000 --- a/src/test/java/org/onap/cps/temporal/repository/TimescaleContainer.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * ============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 { - - 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(); - } - -} diff --git a/src/test/java/org/onap/cps/temporal/repository/containers/TimescaleContainer.java b/src/test/java/org/onap/cps/temporal/repository/containers/TimescaleContainer.java new file mode 100644 index 0000000..a6ad5db --- /dev/null +++ b/src/test/java/org/onap/cps/temporal/repository/containers/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.containers; + +import org.testcontainers.containers.PostgreSQLContainer; +import org.testcontainers.utility.DockerImageName; + +/** + * Container for timescale database. + */ +public class TimescaleContainer extends PostgreSQLContainer { + + 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(); + } + +} -- cgit 1.2.3-korg