aboutsummaryrefslogtreecommitdiffstats
path: root/prh-app-server
diff options
context:
space:
mode:
authorwasala <przemyslaw.wasala@nokia.com>2018-06-05 12:15:44 +0200
committerwasala <przemyslaw.wasala@nokia.com>2018-06-05 12:15:44 +0200
commite30c7d54b34daf855303f32035827ee19555b536 (patch)
tree5c6c1c0043df03bd8f9200352fe3ae7625d0abf5 /prh-app-server
parent53e33ec68a6eb0a06ea130215e03a7725da9d22d (diff)
Correction for DmaapJsonParser
*Added cases fo uTests *Changed schedule tasks to 5s *Changed batching message to 1 Change-Id: I8daa4f143699488c8a593634ad67452b4a194437 Issue-ID: DCAEGEN2-540 Signed-off-by: wasala <przemyslaw.wasala@nokia.com>
Diffstat (limited to 'prh-app-server')
-rw-r--r--prh-app-server/config/prh_endpoints.json10
-rw-r--r--prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/controllers/ScheduleController.java2
-rw-r--r--prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/service/DmaapConsumerJsonParser.java38
-rw-r--r--prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/DmaapConsumerTaskImpl.java9
-rw-r--r--prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/service/DmaapConsumerJsonParserTest.java113
-rw-r--r--prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/tasks/DmaapConsumerTaskImplTest.java21
6 files changed, 156 insertions, 37 deletions
diff --git a/prh-app-server/config/prh_endpoints.json b/prh-app-server/config/prh_endpoints.json
index 7cb83c07..8aed235f 100644
--- a/prh-app-server/config/prh_endpoints.json
+++ b/prh-app-server/config/prh_endpoints.json
@@ -9,15 +9,15 @@
"dmaapUserName": "admin",
"dmaapUserPassword": "admin",
"dmaapContentType": "application/json",
- "consumerId": "1",
- "consumerGroup": "other",
- "timeoutMS": 1000,
- "messageLimit": 1000
+ "consumerId": "c12",
+ "consumerGroup": "OpenDcae-c12",
+ "timeoutMS": -1,
+ "messageLimit": 1
},
"dmaapProducerConfiguration": {
"dmaapHostName": "localhost",
"dmaapPortNumber": 2223,
- "dmaapTopicName": "/events/pnfReady",
+ "dmaapTopicName": "/events/unauthenticated.PNF_READY",
"dmaapProtocol": "http",
"dmaapUserName": "admin",
"dmaapUserPassword": "admin",
diff --git a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/controllers/ScheduleController.java b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/controllers/ScheduleController.java
index 96b69b7b..dbac6a53 100644
--- a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/controllers/ScheduleController.java
+++ b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/controllers/ScheduleController.java
@@ -45,7 +45,7 @@ import java.util.concurrent.ScheduledFuture;
public class ScheduleController {
private static final Logger logger = LoggerFactory.getLogger(ScheduleController.class);
- private static final int SCHEDULING_DELAY = 20000;
+ private static final int SCHEDULING_DELAY = 5000;
private static volatile List<ScheduledFuture> scheduledFutureList = new ArrayList<>();
private final TaskScheduler taskScheduler;
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 ba0ec0e8..3bac7c36 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
@@ -22,13 +22,12 @@ package org.onap.dcaegen2.services.prh.service;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
+import java.util.Optional;
+import java.util.stream.StreamSupport;
import org.onap.dcaegen2.services.prh.exceptions.DmaapNotFoundException;
import org.onap.dcaegen2.services.prh.model.ConsumerDmaapModel;
import org.onap.dcaegen2.services.prh.model.ImmutableConsumerDmaapModel;
-import java.util.Optional;
-import java.util.stream.StreamSupport;
-
/**
* @author <a href="mailto:przemyslaw.wasala@nokia.com">Przemysław Wąsala</a> on 5/8/18
*/
@@ -41,23 +40,22 @@ public class DmaapConsumerJsonParser {
private static final String PNF_VENDOR_NAME = "pnfVendorName";
private static final String PNF_SERIAL_NUMBER = "pnfSerialNumber";
-
- private DmaapConsumerJsonParser() {}
-
-
- public static ConsumerDmaapModel getJsonObject(String message) throws DmaapNotFoundException {
+ public ConsumerDmaapModel getJsonObject(String message) throws DmaapNotFoundException {
JsonElement jsonElement = new JsonParser().parse(message);
+ if (jsonElement.isJsonObject()) {
+ return create(jsonElement.getAsJsonObject());
+ } else {
+ return create(StreamSupport.stream(jsonElement.getAsJsonArray().spliterator(), false).findFirst()
+ .flatMap(this::getJsonObjectFromAnArray)
+ .orElseThrow(() -> new DmaapNotFoundException("Json object not found in json array")));
+ }
+ }
- JsonObject jsonObject = jsonElement.isJsonObject() ? jsonElement.getAsJsonObject() :
- StreamSupport.stream(jsonElement.getAsJsonArray().spliterator(), false).findFirst()
- .flatMap(element -> Optional.of(new JsonParser().parse(element.toString()).getAsJsonObject()))
- .orElseThrow(() -> new DmaapNotFoundException("Json object not found in json array"))
- .getAsJsonObject();
-
- return create(jsonObject);
+ public Optional<JsonObject> getJsonObjectFromAnArray(JsonElement element) {
+ return Optional.of(new JsonParser().parse(element.getAsString()).getAsJsonObject());
}
- private static ConsumerDmaapModel create(JsonObject jsonObject) throws DmaapNotFoundException {
+ private ConsumerDmaapModel create(JsonObject jsonObject) throws DmaapNotFoundException {
if (containsHeader(jsonObject)) {
jsonObject = jsonObject.getAsJsonObject(EVENT).getAsJsonObject(OTHER_FIELDS);
String pnfVendorName = getValueFromJson(jsonObject, PNF_VENDOR_NAME);
@@ -76,21 +74,21 @@ public class DmaapConsumerJsonParser {
throw new DmaapNotFoundException("Incorrect JsonObject - missing header");
}
- private static String getValueFromJson(JsonObject jsonObject, String jsonKey) {
+ private String getValueFromJson(JsonObject jsonObject, String jsonKey) {
return jsonObject.has(jsonKey) ? jsonObject.get(jsonKey).getAsString() : "";
}
- private static boolean isVendorAndSerialNotEmpty(String pnfSerialNumber, String pnfVendorName) {
+ private boolean isVendorAndSerialNotEmpty(String pnfSerialNumber, String pnfVendorName) {
return ((pnfSerialNumber != null && !pnfSerialNumber.isEmpty()) && (pnfVendorName != null && !pnfVendorName
.isEmpty()));
}
- private static boolean isIpPropertiesNotEmpty(String ipv4, String ipv6) {
+ private boolean isIpPropertiesNotEmpty(String ipv4, String ipv6) {
return (ipv4 != null && !ipv4.isEmpty()) || (ipv6 != null
&& !ipv6.isEmpty());
}
- private static boolean containsHeader(JsonObject jsonObject) {
+ private boolean containsHeader(JsonObject jsonObject) {
return jsonObject.has(EVENT) && jsonObject.getAsJsonObject(EVENT).has(OTHER_FIELDS);
}
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 a78d33b2..01b85a9d 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
@@ -44,16 +44,23 @@ public class DmaapConsumerTaskImpl extends
private static final Logger logger = LoggerFactory.getLogger(DmaapConsumerTaskImpl.class);
private final Config prhAppConfig;
private ExtendedDmaapConsumerHttpClientImpl extendedDmaapConsumerHttpClient;
+ private DmaapConsumerJsonParser dmaapConsumerJsonParser;
@Autowired
public DmaapConsumerTaskImpl(AppConfig prhAppConfig) {
this.prhAppConfig = prhAppConfig;
+ this.dmaapConsumerJsonParser = new DmaapConsumerJsonParser();
+ }
+
+ DmaapConsumerTaskImpl(AppConfig prhAppConfig, DmaapConsumerJsonParser dmaapConsumerJsonParser) {
+ this.prhAppConfig = prhAppConfig;
+ this.dmaapConsumerJsonParser = dmaapConsumerJsonParser;
}
@Override
ConsumerDmaapModel consume(String message) throws DmaapNotFoundException {
logger.trace("Method called with arg {}", message);
- return DmaapConsumerJsonParser.getJsonObject(message);
+ return dmaapConsumerJsonParser.getJsonObject(message);
}
@Override
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 da293a45..3dc81070 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
@@ -19,8 +19,14 @@
*/
package org.onap.dcaegen2.services.prh.service;
+import static org.mockito.Mockito.spy;
+
+import com.google.gson.JsonElement;
+import com.google.gson.JsonParser;
+import java.util.Optional;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
+import org.mockito.Mockito;
import org.onap.dcaegen2.services.prh.exceptions.DmaapNotFoundException;
import org.onap.dcaegen2.services.prh.model.ConsumerDmaapModel;
import org.onap.dcaegen2.services.prh.model.ImmutableConsumerDmaapModel;
@@ -72,17 +78,30 @@ class DmaapConsumerJsonParserTest {
+ "\"pnfOamIpv6Address\":\"0:0:0:0:0:FFFF:0A10:7BEA\",\"pnfSerialNumber\":\"QTFCOC540002E\","
+ "\"pnfSoftwareVersion\":\"v4.5.0.1\",\"pnfType\":\"AirScale\",\"pnfVendorName\":\"Nokia\"}}}]";
+ String parsed =
+ "{\"event\":{\"commonEventHeader\":{\"domain\":\"other\",\"eventId\":\"<<SerialNumber>>-reg\",\"eventName\""
+ + ":\"pnfRegistration_5GDU\",\"eventType\":\"pnfRegistration\",\"internalHeaderFields\":{},"
+ + "\"lastEpochMicrosec\":1519837825682,\"nfNamingCode\":\"5GRAN\",\"nfcNamingCode\":\"5DU\","
+ + "\"priority\":\"Normal\",\"reportingEntityName\":\"5GRAN_DU\",\"sequence\":0,\"sourceId\":"
+ + "\"<<SerialNumber>>\",\"sourceName\":\"5GRAN_DU\",\"startEpochMicrosec\":1519837825682,\"version\":3},"
+ + "\"otherFields\":{\"otherFieldsVersion\":1,\"pnfFamily\":\"BBU\",\"pnfLastServiceDate\":1517206400,"
+ + "\"pnfManufactureDate\":1516406400,\"pnfModelNumber\":\"AJ02\",\"pnfOamIpv4Address\":\"10.16.123.234\","
+ + "\"pnfOamIpv6Address\":\"0:0:0:0:0:FFFF:0A10:7BEA\",\"pnfSerialNumber\":\"QTFCOC540002E\","
+ + "\"pnfSoftwareVersion\":\"v4.5.0.1\",\"pnfType\":\"AirScale\",\"pnfVendorName\":\"Nokia\"}}}";
ConsumerDmaapModel expectedObject = ImmutableConsumerDmaapModel.builder().ipv4("10.16.123.234")
.ipv6("0:0:0:0:0:FFFF:0A10:7BEA")
.pnfName("NOKQTFCOC540002E").build();
//when
- ConsumerDmaapModel consumerDmaapModel = DmaapConsumerJsonParser.getJsonObject(message);
+ DmaapConsumerJsonParser dmaapConsumerJsonParser = spy(new DmaapConsumerJsonParser());
+ JsonElement jsonElement = new JsonParser().parse(parsed);
+ Mockito.doReturn(Optional.of(jsonElement.getAsJsonObject()))
+ .when(dmaapConsumerJsonParser).getJsonObjectFromAnArray(jsonElement);
+ ConsumerDmaapModel consumerDmaapModel = dmaapConsumerJsonParser.getJsonObject(message);
//then
Assertions.assertNotNull(consumerDmaapModel);
Assertions.assertEquals(expectedObject, consumerDmaapModel);
}
-
@Test
void whenPassingCorrectJsonWithoutIPV4_validationNotThrowingAnException() throws DmaapNotFoundException {
//given
@@ -97,11 +116,26 @@ class DmaapConsumerJsonParserTest {
+ "\"0:0:0:0:0:FFFF:0A10:7BEA\",\"pnfSerialNumber\":\"QTFCOC540002E\",\"pnfSoftwareVersion\""
+ ":\"v4.5.0.1\",\"pnfType\":\"AirScale\",\"pnfVendorName\":\"Nokia\"}}}]";
+ String parsed =
+ "{\"event\":{\"commonEventHeader\":{\"domain\":\"other\",\"eventId\":\"<<SerialNumber>>-reg\",\"eventName\""
+ + ":\"pnfRegistration_5GDU\",\"eventType\":\"pnfRegistration\",\"internalHeaderFields\":{},"
+ + "\"lastEpochMicrosec\":1519837825682,\"nfNamingCode\":\"5GRAN\",\"nfcNamingCode\":\"5DU\","
+ + "\"priority\":\"Normal\",\"reportingEntityName\":\"5GRAN_DU\",\"sequence\":0,\"sourceId\":"
+ + "\"<<SerialNumber>>\",\"sourceName\":\"5GRAN_DU\",\"startEpochMicrosec\":1519837825682,\"version\":3}"
+ + ",\"otherFields\":{\"otherFieldsVersion\":1,\"pnfFamily\":\"BBU\",\"pnfLastServiceDate\":1517206400,"
+ + "\"pnfManufactureDate\":1516406400,\"pnfModelNumber\":\"AJ02\",\"pnfOamIpv6Address\":"
+ + "\"0:0:0:0:0:FFFF:0A10:7BEA\",\"pnfSerialNumber\":\"QTFCOC540002E\",\"pnfSoftwareVersion\""
+ + ":\"v4.5.0.1\",\"pnfType\":\"AirScale\",\"pnfVendorName\":\"Nokia\"}}}";
+
ConsumerDmaapModel expectedObject = ImmutableConsumerDmaapModel.builder().ipv4("")
.ipv6("0:0:0:0:0:FFFF:0A10:7BEA")
.pnfName("NOKQTFCOC540002E").build();
//when
- ConsumerDmaapModel consumerDmaapModel = DmaapConsumerJsonParser.getJsonObject(message);
+ DmaapConsumerJsonParser dmaapConsumerJsonParser = spy(new DmaapConsumerJsonParser());
+ JsonElement jsonElement = new JsonParser().parse(parsed);
+ Mockito.doReturn(Optional.of(jsonElement.getAsJsonObject()))
+ .when(dmaapConsumerJsonParser).getJsonObjectFromAnArray(jsonElement);
+ ConsumerDmaapModel consumerDmaapModel = dmaapConsumerJsonParser.getJsonObject(message);
//then
Assertions.assertNotNull(consumerDmaapModel);
Assertions.assertEquals(expectedObject, consumerDmaapModel);
@@ -120,11 +154,25 @@ class DmaapConsumerJsonParserTest {
+ "\":1517206400,\"pnfManufactureDate\":1516406400,\"pnfModelNumber\":\"AJ02\",\"pnfOamIpv4Address"
+ "\":\"10.16.123.234\",\"pnfSerialNumber\":\"QTFCOC540002E\",\"pnfSoftwareVersion\":\"v4.5.0.1\","
+ "\"pnfType\":\"AirScale\",\"pnfVendorName\":\"Nokia\"}}}]";
+ String parsed =
+ "{\"event\":{\"commonEventHeader\":{\"domain\":\"other\",\"eventId\":\"<<SerialNumber>>-reg\",\"eventName\""
+ + ":\"pnfRegistration_5GDU\",\"eventType\":\"pnfRegistration\",\"internalHeaderFields\":{},"
+ + "\"lastEpochMicrosec\":1519837825682,\"nfNamingCode\":\"5GRAN\",\"nfcNamingCode\":\"5DU\","
+ + "\"priority\":\"Normal\",\"reportingEntityName\":\"5GRAN_DU\",\"sequence\":0,\"sourceId\":"
+ + "\"<<SerialNumber>>\",\"sourceName\":\"5GRAN_DU\",\"startEpochMicrosec\":1519837825682,"
+ + "\"version\":3},\"otherFields\":{\"otherFieldsVersion\":1,\"pnfFamily\":\"BBU\",\"pnfLastServiceDate"
+ + "\":1517206400,\"pnfManufactureDate\":1516406400,\"pnfModelNumber\":\"AJ02\",\"pnfOamIpv4Address"
+ + "\":\"10.16.123.234\",\"pnfSerialNumber\":\"QTFCOC540002E\",\"pnfSoftwareVersion\":\"v4.5.0.1\","
+ + "\"pnfType\":\"AirScale\",\"pnfVendorName\":\"Nokia\"}}}";
ConsumerDmaapModel expectedObject = ImmutableConsumerDmaapModel.builder().ipv4("10.16.123.234").ipv6("")
.pnfName("NOKQTFCOC540002E").build();
//when
- ConsumerDmaapModel consumerDmaapModel = DmaapConsumerJsonParser.getJsonObject(message);
+ DmaapConsumerJsonParser dmaapConsumerJsonParser = spy(new DmaapConsumerJsonParser());
+ JsonElement jsonElement = new JsonParser().parse(parsed);
+ Mockito.doReturn(Optional.of(jsonElement.getAsJsonObject()))
+ .when(dmaapConsumerJsonParser).getJsonObjectFromAnArray(jsonElement);
+ ConsumerDmaapModel consumerDmaapModel = dmaapConsumerJsonParser.getJsonObject(message);
//then
Assertions.assertNotNull(consumerDmaapModel);
Assertions.assertEquals(expectedObject, consumerDmaapModel);
@@ -141,26 +189,73 @@ class DmaapConsumerJsonParserTest {
+ ":3},\"otherFields\":{\"otherFieldsVersion\":1,\"pnfFamily\":\"BBU\",\"pnfLastServiceDate\""
+ ":1517206400,\"pnfManufactureDate\":1516406400,\"pnfModelNumber\":\"AJ02\",\"pnfSoftwareVersion\":"
+ "\"v4.5.0.1\",\"pnfType\":\"AirScale\",\"pnfVendorName\":\"Nokia\"}}}]";
-
+ String parsed =
+ "{\"event\":{\"commonEventHeader\":{\"domain\":\"other\",\"eventId\":\"<<SerialNumber>>-reg\",\"eventName\""
+ + ":\"pnfRegistration_5GDU\",\"eventType\":\"pnfRegistration\",\"internalHeaderFields\":{},"
+ + "\"lastEpochMicrosec\":1519837825682,\"nfNamingCode\":\"5GRAN\",\"nfcNamingCode\":\"5DU\","
+ + "\"priority\":\"Normal\",\"reportingEntityName\":\"5GRAN_DU\",\"sequence\":0,\"sourceId\":"
+ + "\"<<SerialNumber>>\",\"sourceName\":\"5GRAN_DU\",\"startEpochMicrosec\":1519837825682,\"version\""
+ + ":3},\"otherFields\":{\"otherFieldsVersion\":1,\"pnfFamily\":\"BBU\",\"pnfLastServiceDate\""
+ + ":1517206400,\"pnfManufactureDate\":1516406400,\"pnfModelNumber\":\"AJ02\",\"pnfSoftwareVersion\":"
+ + "\"v4.5.0.1\",\"pnfType\":\"AirScale\",\"pnfVendorName\":\"Nokia\"}}}";
+ DmaapConsumerJsonParser dmaapConsumerJsonParser = spy(new DmaapConsumerJsonParser());
+ JsonElement jsonElement = new JsonParser().parse(parsed);
+ Mockito.doReturn(Optional.of(jsonElement.getAsJsonObject()))
+ .when(dmaapConsumerJsonParser).getJsonObjectFromAnArray(jsonElement);
Assertions.assertThrows(DmaapNotFoundException.class,
- () -> DmaapConsumerJsonParser.getJsonObject(message));
+ () -> dmaapConsumerJsonParser.getJsonObject(message));
}
@Test
void whenPassingJsonWithoutMandatoryHeaderInformation_validationThrowingAnException() {
+ String parsed = "{\"event\":{\"commonEventHeader\":{\"domain\":\"other\",\"eventId\":\"<<SerialNumber>>-reg\""
+ + ",\"eventName\":\"pnfRegistration_5GDU\",\"eventType\":\"pnfRegistration\",\"internalHeaderFields\":{},"
+ + "\"lastEpochMicrosec\":1519837825682,\"nfNamingCode\":\"5GRAN\",\"nfcNamingCode\":\"5DU\",\"priority\""
+ + ":\"Normal\",\"reportingEntityName\":\"5GRAN_DU\",\"sequence\":0,\"sourceId\":\"<<SerialNumber>>\","
+ + "\"sourceName\":\"5GRAN_DU\",\"startEpochMicrosec\":1519837825682,\"version\":3}}}";
+ DmaapConsumerJsonParser dmaapConsumerJsonParser = spy(new DmaapConsumerJsonParser());
+ JsonElement jsonElement = new JsonParser().parse(parsed);
+ Mockito.doReturn(Optional.of(jsonElement.getAsJsonObject()))
+ .when(dmaapConsumerJsonParser).getJsonObjectFromAnArray(jsonElement);
Assertions.assertThrows(DmaapNotFoundException.class,
- () -> DmaapConsumerJsonParser.getJsonObject(incorrectMessage));
+ () -> dmaapConsumerJsonParser.getJsonObject(incorrectMessage));
}
@Test
void whenPassingJsonWithoutPnfSerialNumberOrPnfVendorName_validationThrowingAnException() {
+ String parsed = "{\"event\":{\"commonEventHeader\":{\"domain\":\"other\",\"eventId\":"
+ + "\"<<SerialNumber>>-reg\",\"eventName\":\"pnfRegistration_5GDU\",\"eventType\":\"pnfRegistration\",\""
+ + "internalHeaderFields\":{},\"lastEpochMicrosec\":1519837825682,\"nfNamingCode\":\"5GRAN\",\"nfcNamingCode\""
+ + ":\"5DU\",\"priority\":\"Normal\",reportingEntityName\":\"5GRAN_DU\",\"sequence\":0,\"sourceId\":\""
+ + "<<SerialNumber>>\",\"sourceName\":\"5GRAN_DU\",startEpochMicrosec\":1519837825682,\"version\":3},"
+ + "\"otherFields\":{\"otherFieldsVersion\":1,\"pnfFamily\":\"BBU\",\"pnfLastServiceDate\":1517206400,"
+ + "\"pnfManufactureDate\":1516406400,\"pnfModelNumber\":\"AJ02\",\"pnfOamIpv4Address\":"
+ + "\"10.16.123.234\",\"pnfOamIpv6Address\":\"0:0:0:0:0:FFFF:0A10:7BEA\",\"pnfSoftwareVersion\":\"v4.5.0.1\","
+ + "\"pnfType\":\"AirScale\"}}}";
+ DmaapConsumerJsonParser dmaapConsumerJsonParser = spy(new DmaapConsumerJsonParser());
+ JsonElement jsonElement = new JsonParser().parse(parsed);
+ Mockito.doReturn(Optional.of(jsonElement.getAsJsonObject()))
+ .when(dmaapConsumerJsonParser).getJsonObjectFromAnArray(jsonElement);
Assertions.assertThrows(DmaapNotFoundException.class,
- () -> DmaapConsumerJsonParser.getJsonObject(jsonWithoutPnfVendorAndSerialNumber));
+ () -> dmaapConsumerJsonParser.getJsonObject(jsonWithoutPnfVendorAndSerialNumber));
}
@Test
void whenPassingJsonWithoutIPInformation_validationThrowingAnException() {
+ String parsed =
+ "{\"event\":{\"commonEventHeader\":{\"domain\":\"other\",\"eventId\":\"<<SerialNumber>>-reg\",\"eventName\":"
+ + "\"pnfRegistration_5GDU\",\"eventType\":\"pnfRegistration\",\"internalHeaderFields\":{},\"lastEpochMicrosec\""
+ + ":1519837825682,\"nfNamingCode\":\"5GRAN\",\"nfcNamingCode\":\"5DU\",\"priority\":\"Normal\","
+ + "\"reportingEntityName\":\"5GRAN_DU\",\"sequence\":0,\"sourceId\":\"<<SerialNumber>>\",\"sourceName\":"
+ + "\"5GRAN_DU\",\"startEpochMicrosec\":1519837825682,\"version\":3},\"otherFields\":{\"otherFieldsVersion\":1,"
+ + "\"pnfFamily\":\"BBU\",\"pnfLastServiceDate\":1517206400,\"pnfManufactureDate\":1516406400,\"pnfModelNumber\":"
+ + "\"AJ02\",\"pnfSerialNumber\":\"QTFCOC540002E\",\"pnfSoftwareVersion\":\"v4.5.0.1\",\"pnfType\":\"AirScale\","
+ + "\"pnfVendorName\":\"Nokia\"}}}";
+ DmaapConsumerJsonParser dmaapConsumerJsonParser = spy(new DmaapConsumerJsonParser());
+ JsonElement jsonElement = new JsonParser().parse(parsed);
+ Mockito.doReturn(Optional.of(jsonElement.getAsJsonObject()))
+ .when(dmaapConsumerJsonParser).getJsonObjectFromAnArray(jsonElement);
Assertions.assertThrows(DmaapNotFoundException.class,
- () -> DmaapConsumerJsonParser.getJsonObject(jsonWithoutIPInformation));
+ () -> dmaapConsumerJsonParser.getJsonObject(jsonWithoutIPInformation));
}
} \ No newline at end of file
diff --git a/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/tasks/DmaapConsumerTaskImplTest.java b/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/tasks/DmaapConsumerTaskImplTest.java
index 7e15e51e..32b7d858 100644
--- a/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/tasks/DmaapConsumerTaskImplTest.java
+++ b/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/tasks/DmaapConsumerTaskImplTest.java
@@ -27,17 +27,21 @@ import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.mockito.Mockito.when;
+import com.google.gson.JsonElement;
+import com.google.gson.JsonParser;
import java.util.Optional;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.function.Executable;
+import org.mockito.Mockito;
import org.onap.dcaegen2.services.prh.config.DmaapConsumerConfiguration;
import org.onap.dcaegen2.services.prh.config.ImmutableDmaapConsumerConfiguration;
import org.onap.dcaegen2.services.prh.configuration.AppConfig;
import org.onap.dcaegen2.services.prh.exceptions.PrhTaskException;
import org.onap.dcaegen2.services.prh.model.ConsumerDmaapModel;
import org.onap.dcaegen2.services.prh.model.ImmutableConsumerDmaapModel;
+import org.onap.dcaegen2.services.prh.service.DmaapConsumerJsonParser;
import org.onap.dcaegen2.services.prh.service.consumer.ExtendedDmaapConsumerHttpClientImpl;
/**
@@ -51,6 +55,7 @@ class DmaapConsumerTaskImplTest {
private static AppConfig appConfig;
private static DmaapConsumerConfiguration dmaapConsumerConfiguration;
private static String message;
+ private static String parsed;
@BeforeAll
public static void setUp() {
@@ -73,6 +78,16 @@ class DmaapConsumerTaskImplTest {
+ "\"pnfManufactureDate\":1516406400,\"pnfModelNumber\":\"AJ02\",\"pnfOamIpv4Address\":\"10.16.123.234\","
+ "\"pnfOamIpv6Address\":\"0:0:0:0:0:FFFF:0A10:7BEA\",\"pnfSerialNumber\":\"QTFCOC540002E\","
+ "\"pnfSoftwareVersion\":\"v4.5.0.1\",\"pnfType\":\"AirScale\",\"pnfVendorName\":\"Nokia\"}}}]";
+ parsed =
+ "{\"event\":{\"commonEventHeader\":{\"domain\":\"other\",\"eventId\":\"<<SerialNumber>>-reg\",\"eventName\""
+ + ":\"pnfRegistration_5GDU\",\"eventType\":\"pnfRegistration\",\"internalHeaderFields\":{},"
+ + "\"lastEpochMicrosec\":1519837825682,\"nfNamingCode\":\"5GRAN\",\"nfcNamingCode\":\"5DU\","
+ + "\"priority\":\"Normal\",\"reportingEntityName\":\"5GRAN_DU\",\"sequence\":0,\"sourceId\":"
+ + "\"<<SerialNumber>>\",\"sourceName\":\"5GRAN_DU\",\"startEpochMicrosec\":1519837825682,\"version\":3},"
+ + "\"otherFields\":{\"otherFieldsVersion\":1,\"pnfFamily\":\"BBU\",\"pnfLastServiceDate\":1517206400,"
+ + "\"pnfManufactureDate\":1516406400,\"pnfModelNumber\":\"AJ02\",\"pnfOamIpv4Address\":\"10.16.123.234\","
+ + "\"pnfOamIpv6Address\":\"0:0:0:0:0:FFFF:0A10:7BEA\",\"pnfSerialNumber\":\"QTFCOC540002E\","
+ + "\"pnfSoftwareVersion\":\"v4.5.0.1\",\"pnfType\":\"AirScale\",\"pnfVendorName\":\"Nokia\"}}}";
}
@Test
@@ -107,10 +122,14 @@ class DmaapConsumerTaskImplTest {
}
private void prepareMocksForDmaapConsumer(Optional<String> message) {
+ DmaapConsumerJsonParser dmaapConsumerJsonParser = spy(new DmaapConsumerJsonParser());
+ JsonElement jsonElement = new JsonParser().parse(parsed);
+ Mockito.doReturn(Optional.of(jsonElement.getAsJsonObject()))
+ .when(dmaapConsumerJsonParser).getJsonObjectFromAnArray(jsonElement);
extendedDmaapConsumerHttpClient = mock(ExtendedDmaapConsumerHttpClientImpl.class);
when(extendedDmaapConsumerHttpClient.getHttpConsumerResponse()).thenReturn(message);
when(appConfig.getDmaapConsumerConfiguration()).thenReturn(dmaapConsumerConfiguration);
- dmaapConsumerTask = spy(new DmaapConsumerTaskImpl(appConfig));
+ dmaapConsumerTask = spy(new DmaapConsumerTaskImpl(appConfig, dmaapConsumerJsonParser));
when(dmaapConsumerTask.resolveConfiguration()).thenReturn(dmaapConsumerConfiguration);
doReturn(extendedDmaapConsumerHttpClient).when(dmaapConsumerTask).resolveClient();
}