POM Updates 45/77445/2
authorJoeOLeary <joseph.o.leary@est.tech>
Mon, 28 Jan 2019 13:44:27 +0000 (13:44 +0000)
committerJoeOLeary <joseph.o.leary@est.tech>
Mon, 28 Jan 2019 13:44:27 +0000 (13:44 +0000)
*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 <joseph.o.leary@est.tech>
pom.xml
src/main/resources/Dockerfile [new file with mode: 0644]
src/test/java/org/onap/dcaegen2/services/pmmapper/datarouter/DataRouterSubscriberTest.java

diff --git a/pom.xml b/pom.xml
index 266a8c0..4edcd0f 100644 (file)
--- a/pom.xml
+++ b/pom.xml
     <artifactId>pm-mapper</artifactId>
     <version>1.0-SNAPSHOT</version>
 
+    <parent>
+        <groupId>org.onap.oparent</groupId>
+        <artifactId>oparent</artifactId>
+        <version>1.2.0</version>
+    </parent>
+
     <properties>
         <!-- Dependency Versions -->
         <lombok.version>1.18.4</lombok.version>
         <!-- Plugin Versions -->
         <shade.plugin.version>3.2.0</shade.plugin.version>
         <jacoco.version>0.8.2</jacoco.version>
-        <!-- Plugin Settings -->
+        <dockerfile.version>1.4.10</dockerfile.version>
         <surefire.version>2.22.0</surefire.version>
+        <!-- Plugin Settings -->
+        <sonar.language>java</sonar.language>
+        <sonar.java.coveragePlugin>jacoco</sonar.java.coveragePlugin>
+        <sonar.surefire.reportsPath>${project.build.directory}/surefire-reports</sonar.surefire.reportsPath>
+        <sonar.jacoco.reportPaths>${project.build.directory}/coverage-reports/jacoco.exec</sonar.jacoco.reportPaths>
+        <sonar.jacoco.itReportPath>${project.build.directory}/coverage-reports/jacoco-it.exec</sonar.jacoco.itReportPath>
+        <sonar.projectVersion>${project.version}</sonar.projectVersion>
         <compiler.target.version>1.8</compiler.target.version>
         <compiler.source.version>1.8</compiler.source.version>
         <shade.main>org.onap.dcaegen2.services.pmmapper.App</shade.main>
 
     <build>
         <plugins>
+            <plugin>
+                <groupId>com.spotify</groupId>
+                <artifactId>dockerfile-maven-plugin</artifactId>
+                <version>${dockerfile.version}</version>
+                <configuration>
+                    <repository>${docker.push.registry}/${project.artifactId}</repository>
+                    <tag>${project.version}</tag>
+                    <dockerfile>${project.build.outputDirectory}/Dockerfile</dockerfile>
+                    <buildArgs>
+                        <JAR>${project.build.finalName}-jar-with-dependencies.jar</JAR>
+                    </buildArgs>
+                </configuration>
+            </plugin>
             <plugin>
                 <groupId>org.apache.maven.plugins</groupId>
                 <artifactId>maven-surefire-plugin</artifactId>
                 <version>${surefire.version}</version>
+                <configuration combine.self="override"/>
             </plugin>
             <plugin>
                 <groupId>org.apache.maven.plugins</groupId>
                 <artifactId>maven-failsafe-plugin</artifactId>
                 <version>${surefire.version}</version>
             </plugin>
-
             <plugin>
                 <groupId>org.apache.maven.plugins</groupId>
                 <artifactId>maven-shade-plugin</artifactId>
                         </goals>
                         <configuration>
                             <shadedArtifactAttached>true</shadedArtifactAttached>
+                            <shadedClassifierName>jar-with-dependencies</shadedClassifierName>
                             <transformers>
                                 <transformer implementation="${shade.transformer}">
                                     <mainClass>${shade.main}</mainClass>
                 <groupId>org.apache.maven.plugins</groupId>
                 <artifactId>maven-compiler-plugin</artifactId>
                 <configuration>
-                    <source>8</source>
-                    <target>8</target>
+                    <source>${maven.compiler.source}</source>
+                    <target>${maven.compiler.target}</target>
                 </configuration>
             </plugin>
             <plugin>
diff --git a/src/main/resources/Dockerfile b/src/main/resources/Dockerfile
new file mode 100644 (file)
index 0000000..e48427c
--- /dev/null
@@ -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
index 8f73c91..25fb8ae 100644 (file)
  * 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<Void>) 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)));
     }
 }