From: JoeOLeary Date: Mon, 28 Jan 2019 13:44:27 +0000 (+0000) Subject: POM Updates X-Git-Tag: 1.0.0~33 X-Git-Url: https://gerrit.onap.org/r/gitweb?a=commitdiff_plain;h=becd8eebb1079e8cb970824ef704f5eebfdbdd42;p=dcaegen2%2Fservices%2Fpm-mapper.git POM Updates *Added the ONAP parent POM to the project POM *Introduced support for building and pushing Docker images in the POM *Added basic Dockerfile *Updated source to comply with checkstyles in parent POM Change-Id: Ieabd0a911359b107ea0a5b2e65ca3260f990e3cd Issue-ID: DCAEGEN2-1123 Signed-off-by: JoeOLeary --- diff --git a/pom.xml b/pom.xml index 266a8c0..4edcd0f 100644 --- a/pom.xml +++ b/pom.xml @@ -28,6 +28,12 @@ pm-mapper 1.0-SNAPSHOT + + org.onap.oparent + oparent + 1.2.0 + + 1.18.4 @@ -45,8 +51,15 @@ 3.2.0 0.8.2 - + 1.4.10 2.22.0 + + java + jacoco + ${project.build.directory}/surefire-reports + ${project.build.directory}/coverage-reports/jacoco.exec + ${project.build.directory}/coverage-reports/jacoco-it.exec + ${project.version} 1.8 1.8 org.onap.dcaegen2.services.pmmapper.App @@ -126,17 +139,30 @@ + + com.spotify + dockerfile-maven-plugin + ${dockerfile.version} + + ${docker.push.registry}/${project.artifactId} + ${project.version} + ${project.build.outputDirectory}/Dockerfile + + ${project.build.finalName}-jar-with-dependencies.jar + + + org.apache.maven.plugins maven-surefire-plugin ${surefire.version} + org.apache.maven.plugins maven-failsafe-plugin ${surefire.version} - org.apache.maven.plugins maven-shade-plugin @@ -148,6 +174,7 @@ true + jar-with-dependencies ${shade.main} @@ -161,8 +188,8 @@ org.apache.maven.plugins maven-compiler-plugin - 8 - 8 + ${maven.compiler.source} + ${maven.compiler.target} diff --git a/src/main/resources/Dockerfile b/src/main/resources/Dockerfile new file mode 100644 index 0000000..e48427c --- /dev/null +++ b/src/main/resources/Dockerfile @@ -0,0 +1,23 @@ +# +# ============LICENSE_START======================================================= +# Copyright (C) 2019 Nordix Foundation. +# ================================================================================ +# 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========================================================= +# +FROM openjdk:8-jre +ENTRYPOINT ["/usr/bin/java", "-jar", "/opt/pm-mapper.jar"] +ARG JAR +ADD target/${JAR} /opt/pm-mapper.jar diff --git a/src/test/java/org/onap/dcaegen2/services/pmmapper/datarouter/DataRouterSubscriberTest.java b/src/test/java/org/onap/dcaegen2/services/pmmapper/datarouter/DataRouterSubscriberTest.java index 8f73c91..25fb8ae 100644 --- a/src/test/java/org/onap/dcaegen2/services/pmmapper/datarouter/DataRouterSubscriberTest.java +++ b/src/test/java/org/onap/dcaegen2/services/pmmapper/datarouter/DataRouterSubscriberTest.java @@ -17,48 +17,46 @@ * SPDX-License-Identifier: Apache-2.0 * ============LICENSE_END========================================================= */ + package org.onap.dcaegen2.services.pmmapper.datarouter; +import static org.mockito.Mockito.RETURNS_DEEP_STUBS; +import static org.mockito.Mockito.any; +import static org.mockito.Mockito.anyInt; +import static org.mockito.Mockito.doAnswer; +import static org.mockito.Mockito.doThrow; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + import com.google.gson.GsonBuilder; import com.google.gson.JsonObject; import com.google.gson.JsonParser; +import io.undertow.io.Receiver; +import io.undertow.io.Sender; +import io.undertow.server.HttpServerExchange; +import io.undertow.util.StatusCodes; +import java.io.IOException; +import java.net.HttpURLConnection; +import java.net.URL; +import java.nio.file.Files; +import java.nio.file.Paths; import org.junit.Before; import org.junit.Test; import org.junit.jupiter.api.Assertions; import org.junit.runner.RunWith; import org.mockito.Mock; +import org.mockito.invocation.InvocationOnMock; +import org.mockito.stubbing.Answer; import org.onap.dcaegen2.services.pmmapper.config.BusControllerConfig; import org.onap.dcaegen2.services.pmmapper.exceptions.TooManyTriesException; import org.onap.dcaegen2.services.pmmapper.model.Event; import org.onap.dcaegen2.services.pmmapper.model.EventMetadata; -import io.undertow.io.Receiver; -import io.undertow.io.Sender; -import io.undertow.server.HttpServerExchange; -import io.undertow.util.StatusCodes; - -import org.mockito.invocation.InvocationOnMock; -import org.mockito.stubbing.Answer; import org.powermock.api.mockito.PowerMockito; import org.powermock.core.classloader.annotations.PrepareForTest; import org.powermock.modules.junit4.PowerMockRunner; -import java.io.IOException; -import java.net.HttpURLConnection; -import java.net.URL; -import java.nio.file.Files; -import java.nio.file.Paths; - -import static org.mockito.Mockito.RETURNS_DEEP_STUBS; -import static org.mockito.Mockito.any; -import static org.mockito.Mockito.anyInt; -import static org.mockito.Mockito.doAnswer; -import static org.mockito.Mockito.doThrow; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; - - @RunWith(PowerMockRunner.class) @PrepareForTest(DataRouterSubscriber.class) @@ -79,22 +77,22 @@ public class DataRouterSubscriberTest { public void testStartTooManyTriesWithResponse() throws IOException { PowerMockito.mockStatic(Thread.class); - URL subURL = mock(URL.class); + URL subEndpoint = mock(URL.class); BusControllerConfig config = new BusControllerConfig(); - config.setDataRouterSubscribeEndpoint(subURL); + config.setDataRouterSubscribeEndpoint(subEndpoint); HttpURLConnection huc = mock(HttpURLConnection.class, RETURNS_DEEP_STUBS); - when(subURL.openConnection()).thenReturn(huc); + when(subEndpoint.openConnection()).thenReturn(huc); when(huc.getResponseCode()).thenReturn(300); Assertions.assertThrows(TooManyTriesException.class, () -> objUnderTest.start(config)); } @Test public void testStartImmediateSuccess() throws IOException, TooManyTriesException, InterruptedException { - URL subURL = mock(URL.class); + URL subEndpoint = mock(URL.class); BusControllerConfig config = new BusControllerConfig(); - config.setDataRouterSubscribeEndpoint(subURL); + config.setDataRouterSubscribeEndpoint(subEndpoint); HttpURLConnection huc = mock(HttpURLConnection.class, RETURNS_DEEP_STUBS); - when(subURL.openConnection()).thenReturn(huc); + when(subEndpoint.openConnection()).thenReturn(huc); when(huc.getResponseCode()).thenReturn(200); objUnderTest.start(config); verify(huc, times(1)).getResponseCode(); @@ -104,11 +102,11 @@ public class DataRouterSubscriberTest { public void testStartDelayedSuccess() throws IOException, TooManyTriesException, InterruptedException { PowerMockito.mockStatic(Thread.class); - URL subURL = mock(URL.class); + URL subEndpoint = mock(URL.class); BusControllerConfig config = new BusControllerConfig(); - config.setDataRouterSubscribeEndpoint(subURL); + config.setDataRouterSubscribeEndpoint(subEndpoint); HttpURLConnection huc = mock(HttpURLConnection.class, RETURNS_DEEP_STUBS); - when(subURL.openConnection()).thenReturn(huc); + when(subEndpoint.openConnection()).thenReturn(huc); doAnswer(new Answer() { boolean forceRetry = true; @@ -129,11 +127,11 @@ public class DataRouterSubscriberTest { public void testStartReadTimeout() throws IOException { PowerMockito.mockStatic(Thread.class); - URL subURL = mock(URL.class); + URL subEndpoint = mock(URL.class); BusControllerConfig config = new BusControllerConfig(); - config.setDataRouterSubscribeEndpoint(subURL); + config.setDataRouterSubscribeEndpoint(subEndpoint); HttpURLConnection huc = mock(HttpURLConnection.class, RETURNS_DEEP_STUBS); - when(subURL.openConnection()).thenReturn(huc); + when(subEndpoint.openConnection()).thenReturn(huc); doThrow(new IOException()).when(huc).getResponseCode(); Assertions.assertThrows(TooManyTriesException.class, () -> objUnderTest.start(config)); } @@ -160,13 +158,13 @@ public class DataRouterSubscriberTest { verify(eventReceiver, times(0)).receive(any()); } - - @Test public void testRequestInboundInvalidMetadata() throws Exception { HttpServerExchange httpServerExchange = mock(HttpServerExchange.class, RETURNS_DEEP_STUBS); - JsonObject metadata = new JsonParser().parse(new String(Files.readAllBytes(Paths.get("src/test/resources/invalid_metadata.json")))).getAsJsonObject(); - when(httpServerExchange.getRequestHeaders().get(any(String.class)).get(anyInt())).thenReturn(metadata.toString()); + JsonObject metadata = new JsonParser().parse(new String(Files + .readAllBytes(Paths.get("src/test/resources/invalid_metadata.json")))).getAsJsonObject(); + when(httpServerExchange.getRequestHeaders().get(any(String.class)).get(anyInt())) + .thenReturn(metadata.toString()); when(httpServerExchange.setStatusCode(anyInt())).thenReturn(httpServerExchange); objUnderTest.handleRequest(httpServerExchange); verify(httpServerExchange, times(1)).setStatusCode(StatusCodes.BAD_REQUEST); @@ -175,7 +173,7 @@ public class DataRouterSubscriberTest { } @Test - public void testRequestInboundNoMetadata() throws Exception{ + public void testRequestInboundNoMetadata() throws Exception { HttpServerExchange httpServerExchange = mock(HttpServerExchange.class, RETURNS_DEEP_STUBS); Receiver receiver = mock(Receiver.class); when(httpServerExchange.getRequestReceiver()).thenReturn(receiver); @@ -203,10 +201,10 @@ public class DataRouterSubscriberTest { Receiver receiver = mock(Receiver.class); when(httpServerExchange.getRequestReceiver()).thenReturn(receiver); String testString = "MESSAGE BODY"; - JsonObject metadata = new JsonParser().parse(new String(Files.readAllBytes(Paths.get("src/test/resources/valid_metadata.json")))).getAsJsonObject(); - EventMetadata metadataObj = new GsonBuilder().create().fromJson(metadata, EventMetadata.class); - - when(httpServerExchange.getRequestHeaders().get(any(String.class)).get(anyInt())).thenReturn(metadata.toString()); + JsonObject metadata = new JsonParser().parse( + new String(Files.readAllBytes(Paths.get("src/test/resources/valid_metadata.json")))).getAsJsonObject(); + when(httpServerExchange.getRequestHeaders().get(any(String.class)).get(anyInt())) + .thenReturn(metadata.toString()); doAnswer((Answer) invocationOnMock -> { Receiver.FullStringCallback callback = invocationOnMock.getArgument(0); callback.handle(httpServerExchange, testString); @@ -220,6 +218,9 @@ public class DataRouterSubscriberTest { }).when(httpServerExchange).dispatch(any(Runnable.class)); objUnderTest.handleRequest(httpServerExchange); - verify(eventReceiver, times(1)).receive(new Event(httpServerExchange, testString, metadataObj)); + verify(eventReceiver, times(1)) + .receive(new Event(httpServerExchange, testString, + new GsonBuilder().create() + .fromJson(metadata, EventMetadata.class))); } }