summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoanna Jeremicz <joanna.jeremicz@nokia.com>2019-06-12 14:34:50 +0200
committerJoanna Jeremicz <joanna.jeremicz@nokia.com>2019-06-12 14:36:24 +0200
commitdc3940018875d8064c1eb51afdc39768a033328a (patch)
treea327a7e17acd2f3effa22458867a652257e2c696
parent459ec6bfe41c3c0368373c203e4d3b1fc70179a2 (diff)
Align to new SDK version
Change-Id: I06974c7f890bfa1cb875d776efa8b3a9f5b0a711 Issue-ID: DCAEGEN2-1613 Signed-off-by: Joanna Jeremicz <joanna.jeremicz@nokia.com>
-rw-r--r--prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/service/DmaapConsumerJsonParser.java4
-rw-r--r--prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/DmaapConsumerTaskImpl.java3
-rw-r--r--prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/service/DmaapConsumerJsonParserTest.java84
3 files changed, 47 insertions, 44 deletions
diff --git a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/service/DmaapConsumerJsonParser.java b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/service/DmaapConsumerJsonParser.java
index c059d34b..11939b53 100644
--- a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/service/DmaapConsumerJsonParser.java
+++ b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/service/DmaapConsumerJsonParser.java
@@ -20,10 +20,10 @@
package org.onap.dcaegen2.services.prh.service;
-import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
+import io.vavr.collection.List;
import org.onap.dcaegen2.services.prh.exceptions.DmaapNotFoundException;
import org.onap.dcaegen2.services.prh.model.ConsumerDmaapModel;
import org.onap.dcaegen2.services.prh.model.ImmutableConsumerDmaapModel;
@@ -85,7 +85,7 @@ public class DmaapConsumerJsonParser {
return monoMessage.flatMapMany(msgRouterResponse -> getConsumerDmaapModelFromJsonArray(msgRouterResponse.items()));
}
- private Flux<ConsumerDmaapModel> getConsumerDmaapModelFromJsonArray(JsonArray items) {
+ private Flux<ConsumerDmaapModel> getConsumerDmaapModelFromJsonArray(List<JsonElement> items) {
LOGGER.debug("DmaapConsumerJsonParser input for parsing: {}", items);
if (items.size() == 0) {
diff --git a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/DmaapConsumerTaskImpl.java b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/DmaapConsumerTaskImpl.java
index af5b2505..a990e502 100644
--- a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/DmaapConsumerTaskImpl.java
+++ b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/DmaapConsumerTaskImpl.java
@@ -50,8 +50,7 @@ public class DmaapConsumerTaskImpl implements DmaapConsumerTask {
public Flux<ConsumerDmaapModel> execute() {
MessageRouterSubscriber messageRouterSubscriber = config.getMessageRouterSubscriber();
MessageRouterSubscribeRequest messageRouterSubscribeRequest = config.getMessageRouterSubscribeRequest();
- Mono<MessageRouterSubscribeResponse> response = messageRouterSubscriber
- .get(messageRouterSubscribeRequest);
+ Mono<MessageRouterSubscribeResponse> response = messageRouterSubscriber.get(messageRouterSubscribeRequest);
return dmaapConsumerJsonParser.getJsonObject(response);
}
diff --git a/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/service/DmaapConsumerJsonParserTest.java b/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/service/DmaapConsumerJsonParserTest.java
index 98b73142..342460e3 100644
--- a/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/service/DmaapConsumerJsonParserTest.java
+++ b/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/service/DmaapConsumerJsonParserTest.java
@@ -20,10 +20,10 @@
package org.onap.dcaegen2.services.prh.service;
-import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
+import io.vavr.collection.List;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
@@ -48,7 +48,7 @@ class DmaapConsumerJsonParserTest {
@Test
void whenPassingCorrectJson_validationNotThrowingAnException() {
//given
- String message = "[{\"event\": {"
+ String message = "{\"event\": {"
+ "\"commonEventHeader\": { "
+ " \"sourceName\":\"NOKQTFCOC540002E\","
+ " \"nfNamingCode\":\"gNB\" "
@@ -64,7 +64,7 @@ class DmaapConsumerJsonParserTest {
+ " \"softwareVersion\": \"v4.5.0.1\","
+ " \"oamV6IpAddress\": \"0:0:0:0:0:FFFF:0A10:7BEA\","
+ " \"additionalFields\": {\"attachmentPoint\":\"bla-bla-30-3\",\"cvlan\":\"678\",\"svlan\":\"1005\"}"
- + "}}}]";
+ + "}}}";
String parsed = "{\"event\": {"
+ "\"commonEventHeader\": { "
@@ -103,8 +103,8 @@ class DmaapConsumerJsonParserTest {
.additionalFields(jsonObject)
.build();
- JsonArray messageAsJsonArray = (JsonArray) jsonParser.parse(message);
- MessageRouterSubscribeResponse response = ImmutableMessageRouterSubscribeResponse.builder().items(messageAsJsonArray).build();
+ List<JsonElement> messageAsJsonElementList = List.of(message).map(jsonParser::parse);
+ MessageRouterSubscribeResponse response = ImmutableMessageRouterSubscribeResponse.builder().items(messageAsJsonElementList).build();
//when
DmaapConsumerJsonParser dmaapConsumerJsonParser = spy(new DmaapConsumerJsonParser());
@@ -122,7 +122,7 @@ class DmaapConsumerJsonParserTest {
@Test
void whenPassingJsonWithoutAdditionalFields_validationNotThrowingAnException() {
//given
- String message = "[{\"event\": {"
+ String message = "{\"event\": {"
+ "\"commonEventHeader\": { "
+ " \"sourceName\":\"NOKQTFCOC540002E\","
+ " \"nfNamingCode\":\"gNB\" "
@@ -137,7 +137,7 @@ class DmaapConsumerJsonParserTest {
+ " \"oamV4IpAddress\": \"10.16.123.234\","
+ " \"oamV6IpAddress\": \"0:0:0:0:0:FFFF:0A10:7BEA\","
+ " \"softwareVersion\": \"v4.5.0.1\""
- + "}}}]";
+ + "}}}";
String parsed = "{\"event\": {"
+ "\"commonEventHeader\": { "
@@ -167,8 +167,8 @@ class DmaapConsumerJsonParserTest {
.nfRole("gNB")
.swVersion("v4.5.0.1")
.build();
- JsonArray messageAsJsonArray = (JsonArray) jsonParser.parse(message);
- MessageRouterSubscribeResponse response = ImmutableMessageRouterSubscribeResponse.builder().items(messageAsJsonArray).build();
+ List<JsonElement> messageAsJsonElementList = List.of(message).map(jsonParser::parse);
+ MessageRouterSubscribeResponse response = ImmutableMessageRouterSubscribeResponse.builder().items(messageAsJsonElementList).build();
//when
DmaapConsumerJsonParser dmaapConsumerJsonParser = spy(new DmaapConsumerJsonParser());
JsonElement jsonElement = new JsonParser().parse(parsed);
@@ -184,7 +184,7 @@ class DmaapConsumerJsonParserTest {
@Test
void whenPassingJsonWithEmptyAdditionalFields_validationNotThrowingAnException() {
//given
- String message = "[{\"event\": {"
+ String message = "{\"event\": {"
+ "\"commonEventHeader\": { "
+ " \"sourceName\":\"NOKQTFCOC540002E\","
+ " \"nfNamingCode\":\"gNB\" "
@@ -200,7 +200,7 @@ class DmaapConsumerJsonParserTest {
+ " \"oamV4IpAddress\": \"10.16.123.234\","
+ " \"oamV6IpAddress\": \"0:0:0:0:0:FFFF:0A10:7BEA\","
+ " \"additionalFields\": {}"
- + "}}}]";
+ + "}}}";
String parsed = "{\"event\": {"
+ "\"commonEventHeader\": { "
@@ -233,8 +233,8 @@ class DmaapConsumerJsonParserTest {
.additionalFields(new JsonObject())
.build();
- JsonArray messageAsJsonArray = (JsonArray) jsonParser.parse(message);
- MessageRouterSubscribeResponse response = ImmutableMessageRouterSubscribeResponse.builder().items(messageAsJsonArray).build();
+ List<JsonElement> messageAsJsonElementList = List.of(message).map(jsonParser::parse);
+ MessageRouterSubscribeResponse response = ImmutableMessageRouterSubscribeResponse.builder().items(messageAsJsonElementList).build();
//when
DmaapConsumerJsonParser dmaapConsumerJsonParser = spy(new DmaapConsumerJsonParser());
@@ -252,7 +252,7 @@ class DmaapConsumerJsonParserTest {
@Test
void whenPassingCorrectJsonWithoutIpv4andIpv6_validationNotThrowingAnException() {
//given
- String message = "[{\"event\": {"
+ String message = "{\"event\": {"
+ "\"commonEventHeader\": { "
+ " \"sourceName\":\"NOKQTFCOC540002E\","
+ " \"nfNamingCode\":\"gNB\" "
@@ -266,7 +266,7 @@ class DmaapConsumerJsonParserTest {
+ " \"unitFamily\": \"BBU\","
+ " \"softwareVersion\": \"v4.5.0.1\","
+ " \"additionalFields\": {}"
- + "}}}]";
+ + "}}}";
String parsed = "{\"event\": {"
+ "\"commonEventHeader\": { "
@@ -297,8 +297,8 @@ class DmaapConsumerJsonParserTest {
.additionalFields(new JsonObject())
.build();
- JsonArray messageAsJsonArray = (JsonArray) jsonParser.parse(message);
- MessageRouterSubscribeResponse response = ImmutableMessageRouterSubscribeResponse.builder().items(messageAsJsonArray).build();
+ List<JsonElement> messageAsJsonElementList = List.of(message).map(jsonParser::parse);
+ MessageRouterSubscribeResponse response = ImmutableMessageRouterSubscribeResponse.builder().items(messageAsJsonElementList).build();
//when
DmaapConsumerJsonParser dmaapConsumerJsonParser = spy(new DmaapConsumerJsonParser());
@@ -337,7 +337,7 @@ class DmaapConsumerJsonParserTest {
JsonElement jsonElement = jsonParser.parse(parsed);
Mockito.doReturn(Optional.of(jsonElement.getAsJsonObject()))
.when(dmaapConsumerJsonParser).getJsonObjectFromAnArray(jsonElement);
- String incorrectMessage = "[{\"event\": {"
+ String incorrectMessage = "{\"event\": {"
+ "\"commonEventHeader\": {},"
+ "\"pnfRegistrationFields\": {"
+ " \"unitType\": \"AirScale\","
@@ -352,10 +352,10 @@ class DmaapConsumerJsonParserTest {
+ " \"oamV4IpAddress\": \"10.16.123.234\","
+ " \"oamV6IpAddress\": \"0:0:0:0:0:FFFF:0A10:7BEA\","
+ " \"additionalFields\": {}"
- + "}}}]";
+ + "}}}";
- JsonArray incorrectMessageAsJsonArray = (JsonArray) jsonParser.parse(incorrectMessage);
- MessageRouterSubscribeResponse response = ImmutableMessageRouterSubscribeResponse.builder().items(incorrectMessageAsJsonArray).build();
+ List<JsonElement> incorrectMessageAsJsonElementList = List.of(incorrectMessage).map(jsonParser::parse);
+ MessageRouterSubscribeResponse response = ImmutableMessageRouterSubscribeResponse.builder().items(incorrectMessageAsJsonElementList).build();
StepVerifier.create(dmaapConsumerJsonParser.getJsonObject(Mono.just(response)))
.expectSubscription().thenRequest(1).verifyComplete();
@@ -384,7 +384,7 @@ class DmaapConsumerJsonParserTest {
Mockito.doReturn(Optional.of(jsonElement.getAsJsonObject()))
.when(dmaapConsumerJsonParser).getJsonObjectFromAnArray(jsonElement);
String jsonWithoutSourceName =
- "[{\"event\": {"
+ "{\"event\": {"
+ "\"commonEventHeader\": {},"
+ "\"pnfRegistrationFields\": {"
+ " \"unitType\": \"AirScale\","
@@ -398,10 +398,10 @@ class DmaapConsumerJsonParserTest {
+ " \"softwareVersion\": \"v4.5.0.1\","
+ " \"oamV6IpAddress\": \"0:0:0:0:0:FFFF:0A10:7BEA\","
+ " \"additionalFields\": {}"
- + "}}}]";
+ + "}}}";
- JsonArray jsonWithoutSourceNameAsJsonArray = (JsonArray) jsonParser.parse(jsonWithoutSourceName);
- MessageRouterSubscribeResponse response = ImmutableMessageRouterSubscribeResponse.builder().items(jsonWithoutSourceNameAsJsonArray).build();
+ List<JsonElement> jsonWithoutSourceNameAsJsonElementList = List.of(jsonWithoutSourceName).map(jsonParser::parse);
+ MessageRouterSubscribeResponse response = ImmutableMessageRouterSubscribeResponse.builder().items(jsonWithoutSourceNameAsJsonElementList).build();
StepVerifier
.create(dmaapConsumerJsonParser.getJsonObject(Mono.just(response)))
.expectSubscription().thenRequest(1)
@@ -434,7 +434,7 @@ class DmaapConsumerJsonParserTest {
Mockito.doReturn(Optional.of(jsonElement.getAsJsonObject()))
.when(dmaapConsumerJsonParser).getJsonObjectFromAnArray(jsonElement);
String jsonWithoutIpInformation =
- "[{\"event\": {"
+ "{\"event\": {"
+ "\"commonEventHeader\": {\"sourceName\": \"\"},"
+ "\"pnfRegistrationFields\": {"
+ " \"unitType\": \"AirScale\","
@@ -449,10 +449,10 @@ class DmaapConsumerJsonParserTest {
+ " \"oamV4IpAddress\": \"10.16.123.234\","
+ " \"oamV6IpAddress\": \"0:0:0:0:0:FFFF:0A10:7BEA\","
+ " \"additionalFields\": {}"
- + "}}}]";
+ + "}}}";
- JsonArray jsonWithoutIpInformationAsJsonArray = (JsonArray) jsonParser.parse(jsonWithoutIpInformation);
- MessageRouterSubscribeResponse response = ImmutableMessageRouterSubscribeResponse.builder().items(jsonWithoutIpInformationAsJsonArray).build();
+ List<JsonElement> jsonWithoutIpInformationAsJsonElementList = List.of(jsonWithoutIpInformation).map(jsonParser::parse);
+ MessageRouterSubscribeResponse response = ImmutableMessageRouterSubscribeResponse.builder().items(jsonWithoutIpInformationAsJsonElementList).build();
StepVerifier.create(dmaapConsumerJsonParser.getJsonObject(Mono.just(response)))
.expectSubscription().thenRequest(1).verifyComplete();
@@ -461,7 +461,7 @@ class DmaapConsumerJsonParserTest {
@Test
void whenPassingCorrectJsonWithoutIpv4_validationNotThrowingAnException() {
//given
- String message = "[{\"event\": {"
+ String message = "{\"event\": {"
+ "\"commonEventHeader\": { "
+ " \"sourceName\":\"NOKQTFCOC540002E\","
+ " \"nfNamingCode\":\"gNB\" "
@@ -475,7 +475,7 @@ class DmaapConsumerJsonParserTest {
+ " \"unitFamily\": \"BBU\","
+ " \"softwareVersion\": \"v4.5.0.1\","
+ " \"oamV6IpAddress\": \"0:0:0:0:0:FFFF:0A10:7BEA\""
- + "}}}]";
+ + "}}}";
String parsed = "{\"event\": {"
+ "\"commonEventHeader\": { "
@@ -493,8 +493,8 @@ class DmaapConsumerJsonParserTest {
+ " \"oamV6IpAddress\": \"0:0:0:0:0:FFFF:0A10:7BEA\""
+ "}}}";
- JsonArray messageAsJsonArray = (JsonArray) jsonParser.parse(message);
- MessageRouterSubscribeResponse response = ImmutableMessageRouterSubscribeResponse.builder().items(messageAsJsonArray).build();
+ List<JsonElement> messageAsJsonElementList = List.of(message).map(jsonParser::parse);
+ MessageRouterSubscribeResponse response = ImmutableMessageRouterSubscribeResponse.builder().items(messageAsJsonElementList).build();
//when
DmaapConsumerJsonParser dmaapConsumerJsonParser = spy(new DmaapConsumerJsonParser());
JsonElement jsonElement = jsonParser.parse(parsed);
@@ -524,7 +524,7 @@ class DmaapConsumerJsonParserTest {
@Test
void whenPassingCorrectJsonWithoutIpv6_validationNotThrowingAnException() {
//given
- String message = "[{\"event\": {"
+ String message = "{\"event\": {"
+ "\"commonEventHeader\": { "
+ " \"sourceName\":\"NOKQTFCOC540002E\","
+ " \"nfNamingCode\":\"gNB\" "
@@ -538,7 +538,7 @@ class DmaapConsumerJsonParserTest {
+ " \"unitFamily\": \"BBU\","
+ " \"oamV4IpAddress\": \"10.16.123.234\","
+ " \"softwareVersion\": \"v4.5.0.1\""
- + "}}}]";
+ + "}}}";
String parsed = "{\"event\": {"
+ "\"commonEventHeader\": { "
@@ -568,8 +568,8 @@ class DmaapConsumerJsonParserTest {
.swVersion("v4.5.0.1")
.build();
- JsonArray messageAsJsonArray = (JsonArray) jsonParser.parse(message);
- MessageRouterSubscribeResponse response = ImmutableMessageRouterSubscribeResponse.builder().items(messageAsJsonArray).build();
+ List<JsonElement> messageAsJsonElementList = List.of(message).map(jsonParser::parse);
+ MessageRouterSubscribeResponse response = ImmutableMessageRouterSubscribeResponse.builder().items(messageAsJsonElementList).build();
//when
DmaapConsumerJsonParser dmaapConsumerJsonParser = spy(new DmaapConsumerJsonParser());
@@ -586,7 +586,7 @@ class DmaapConsumerJsonParserTest {
}
@Test
- void whenPassingCorrectJsoArrayWithoutIpv4_validationNotThrowingAnException() {
+ void whenPassingCorrectJsonArrayWithoutIpv4_validationNotThrowingAnException() {
//given
String message = "[{\"event\": {"
+ "\"commonEventHeader\": { "
@@ -634,8 +634,12 @@ class DmaapConsumerJsonParserTest {
.additionalFields(new JsonObject())
.build();
- JsonArray messageAsJsonArray = (JsonArray) jsonParser.parse(message);
- MessageRouterSubscribeResponse response = ImmutableMessageRouterSubscribeResponse.builder().items(messageAsJsonArray).build();
+ List<JsonElement> messageAsJsonElementList = List.empty();
+ for(JsonElement el : jsonParser.parse(message).getAsJsonArray()) {
+ messageAsJsonElementList = messageAsJsonElementList.append(el);
+ }
+
+ MessageRouterSubscribeResponse response = ImmutableMessageRouterSubscribeResponse.builder().items(messageAsJsonElementList).build();
//when
DmaapConsumerJsonParser dmaapConsumerJsonParser = new DmaapConsumerJsonParser();