summaryrefslogtreecommitdiffstats
path: root/prh-app-server/src/test/java
diff options
context:
space:
mode:
authorJoanna Jeremicz <joanna.jeremicz@nokia.com>2019-03-22 12:25:44 +0100
committerJoanna Jeremicz <joanna.jeremicz@nokia.com>2019-03-22 12:25:44 +0100
commit2f1c390f984a9b61b7b218243f06e26f5173fd9b (patch)
tree3bcae1e53c6d90fdf77bd652e3fc9471789aded3 /prh-app-server/src/test/java
parentd4fc5abcb85f2caa2d5062a063ca2d5ea339e73f (diff)
Fix DmaapConsumerJsonParserTest
Change-Id: I4fd1092608c3f75e60e0495caf5753dec7c0703a Issue-ID: DCAEGEN2-1312 Signed-off-by: Joanna Jeremicz <joanna.jeremicz@nokia.com>
Diffstat (limited to 'prh-app-server/src/test/java')
-rw-r--r--prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/service/DmaapConsumerJsonParserTest.java159
1 files changed, 64 insertions, 95 deletions
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 e065fc77..cdcef07c 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
@@ -245,6 +245,70 @@ class DmaapConsumerJsonParserTest {
}
@Test
+ void whenPassingCorrectJsonWithoutIpv4andIpv6_validationNotThrowingAnException() {
+ //given
+ String message = "[{\"event\": {"
+ + "\"commonEventHeader\": { "
+ + " \"sourceName\":\"NOKQTFCOC540002E\","
+ + " \"nfNamingCode\":\"gNB\" "
+ + "},"
+ + "\"pnfRegistrationFields\": {"
+ + " \"vendorName\": \"nokia\","
+ + " \"serialNumber\": \"QTFCOC540002E\","
+ + " \"pnfRegistrationFieldsVersion\": \"2.0\","
+ + " \"modelNumber\": \"3310\","
+ + " \"unitType\": \"type\",\n"
+ + " \"unitFamily\": \"BBU\","
+ + " \"softwareVersion\": \"v4.5.0.1\","
+ + " \"additionalFields\": {}"
+ + "}}}]";
+
+ String parsed = "{\"event\": {"
+ + "\"commonEventHeader\": { "
+ + " \"sourceName\":\"NOKQTFCOC540002E\","
+ + " \"nfNamingCode\":\"gNB\" "
+ + "},"
+ + "\"pnfRegistrationFields\": {"
+ + " \"vendorName\": \"nokia\","
+ + " \"serialNumber\": \"QTFCOC540002E\","
+ + " \"pnfRegistrationFieldsVersion\": \"2.0\","
+ + " \"modelNumber\": \"3310\","
+ + " \"unitType\": \"type\",\n"
+ + " \"unitFamily\": \"BBU\","
+ + " \"softwareVersion\": \"v4.5.0.1\","
+ + " \"additionalFields\": {}"
+ + "}}}";
+
+ ConsumerDmaapModel expectedObject = ImmutableConsumerDmaapModel.builder()
+ .correlationId("NOKQTFCOC540002E")
+ .serialNumber("QTFCOC540002E")
+ .ipv4("")
+ .ipv6("")
+ .equipVendor("nokia")
+ .equipModel("3310")
+ .equipType("type")
+ .nfRole("gNB")
+ .swVersion("v4.5.0.1")
+ .additionalFields(new JsonObject())
+ .build();
+
+ JsonArray messageAsJsonArray = (JsonArray) jsonParser.parse(message);
+
+ //when
+ DmaapConsumerJsonParser dmaapConsumerJsonParser = spy(new DmaapConsumerJsonParser());
+ JsonElement jsonElement = jsonParser.parse(parsed);
+ Mockito.doReturn(Optional.of(jsonElement.getAsJsonObject()))
+ .when(dmaapConsumerJsonParser).getJsonObjectFromAnArray(jsonElement);
+
+ ConsumerDmaapModel consumerDmaapModel = dmaapConsumerJsonParser
+ .getJsonObject(Mono.just((messageAsJsonArray))).blockFirst();
+ //then
+ Assertions.assertNotNull(consumerDmaapModel);
+ Assertions.assertEquals(expectedObject, consumerDmaapModel);
+ }
+
+
+ @Test
void whenPassingJsonWithoutMandatoryHeaderInformation_validationAddingAnException() {
String parsed = "{\"event\": {"
+ "\"commonEventHeader\": {},"
@@ -512,101 +576,6 @@ class DmaapConsumerJsonParserTest {
}
@Test
- void whenPassingCorrectJsonWithoutIpv4andIpv6_validationAddingAnException() {
- //given
- String message = "[{\"event\": {"
- + "\"commonEventHeader\": { "
- + " \"sourceName\":\"NOKQTFCOC540002E\","
- + " \"nfNamingCode\":\"gNB\" "
- + "},"
- + "\"pnfRegistrationFields\": {"
- + " \"vendorName\": \"nokia\","
- + " \"serialNumber\": \"QTFCOC540002E\","
- + " \"pnfRegistrationFieldsVersion\": \"2.0\","
- + " \"modelNumber\": \"3310\","
- + " \"unitType\": \"type\",\n"
- + " \"unitFamily\": \"BBU\","
- + " \"softwareVersion\": \"v4.5.0.1\","
- + " \"additionalFields\": {}"
- + "}}}]";
-
- String parsed = "{\"event\": {"
- + "\"commonEventHeader\": { "
- + " \"sourceName\":\"NOKQTFCOC540002E\","
- + " \"nfNamingCode\":\"gNB\" "
- + "},"
- + "\"pnfRegistrationFields\": {"
- + " \"vendorName\": \"nokia\","
- + " \"serialNumber\": \"QTFCOC540002E\","
- + " \"pnfRegistrationFieldsVersion\": \"2.0\","
- + " \"modelNumber\": \"3310\","
- + " \"unitType\": \"type\",\n"
- + " \"unitFamily\": \"BBU\","
- + " \"softwareVersion\": \"v4.5.0.1\","
- + " \"additionalFields\": {}"
- + "}}}";
-
- JsonArray messageAsJsonArray = (JsonArray) jsonParser.parse(message);
-
- DmaapConsumerJsonParser dmaapConsumerJsonParser = spy(new DmaapConsumerJsonParser());
- JsonElement jsonElement = jsonParser.parse(parsed);
- Mockito.doReturn(Optional.of(jsonElement.getAsJsonObject()))
- .when(dmaapConsumerJsonParser).getJsonObjectFromAnArray(jsonElement);
-
- StepVerifier.create(dmaapConsumerJsonParser.getJsonObject(Mono.just(messageAsJsonArray)))
- .expectSubscription().thenRequest(1).verifyComplete();
-
- }
-
- @Test
- void whenPassingJsonWithoutIpInformation_validationAddingAnException() {
- String parsed =
- "{\"event\": {"
- + "\"commonEventHeader\": {\"sourceName\": \"NOKQTFCOC540002E\"},"
- + "\"pnfRegistrationFields\": {"
- + " \"unitType\": \"AirScale\","
- + " \"serialNumber\": \"QTFCOC540002E\","
- + " \"pnfRegistrationFieldsVersion\": \"2.0\","
- + " \"manufactureDate\": \"1535014037024\","
- + " \"modelNumber\": \"7BEA\",\n"
- + " \"lastServiceDate\": \"1535014037024\","
- + " \"unitFamily\": \"BBU\","
- + " \"vendorName\": \"Nokia\","
- + " \"softwareVersion\": \"v4.5.0.1\","
- + " \"oamV4IpAddress\": \"\","
- + " \"oamV6IpAddress\": \"\","
- + " \"additionalFields\": {}"
- + "}}}";
-
- DmaapConsumerJsonParser dmaapConsumerJsonParser = spy(new DmaapConsumerJsonParser());
- JsonElement jsonElement = jsonParser.parse(parsed);
- Mockito.doReturn(Optional.of(jsonElement.getAsJsonObject()))
- .when(dmaapConsumerJsonParser).getJsonObjectFromAnArray(jsonElement);
- String jsonWithoutIpInformation =
- "[{\"event\": {"
- + "\"commonEventHeader\": {\"sourceName\": \"NOKQTFCOC540002E\"},"
- + "\"pnfRegistrationFields\": {"
- + " \"unitType\": \"AirScale\","
- + " \"serialNumber\": \"QTFCOC540002E\","
- + " \"pnfRegistrationFieldsVersion\": \"2.0\","
- + " \"manufactureDate\": \"1535014037024\","
- + " \"modelNumber\": \"7BEA\",\n"
- + " \"lastServiceDate\": \"1535014037024\","
- + " \"unitFamily\": \"BBU\","
- + " \"vendorName\": \"Nokia\","
- + " \"softwareVersion\": \"v4.5.0.1\","
- + " \"oamV4IpAddress\": \"\","
- + " \"oamV6IpAddress\": \"\","
- + " \"additionalFields\": {}"
- + "}}}]";
-
- JsonArray jsonWithoutOpInformationAsJsonArray = (JsonArray) jsonParser.parse(jsonWithoutIpInformation);
-
- StepVerifier.create(dmaapConsumerJsonParser.getJsonObject(Mono.just(jsonWithoutOpInformationAsJsonArray)))
- .expectSubscription().thenRequest(1).verifyComplete();
- }
-
- @Test
void whenPassingCorrectJsoArrayWithoutIpv4_validationNotThrowingAnException() {
//given
String message = "[{\"event\": {"