<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>
* 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)
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();
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;
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));
}
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);
}
@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);
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);
}).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)));
}
}