summaryrefslogtreecommitdiffstats
path: root/prh-commons
diff options
context:
space:
mode:
authorgrabinsk <maciej.grabinski@nokia.com>2019-05-23 14:25:24 +0200
committergrabinsk <maciej.grabinski@nokia.com>2019-05-23 14:25:24 +0200
commit14433b1454dd4b881b8b36f184d63528a43931ba (patch)
tree1b37d5de5dee6d701f43165ca4e35232c47a0129 /prh-commons
parente2f12ecdee8f9320e23b95a1671cb7c8fcacf361 (diff)
Fix sending PNF_READY notification after update to El Alto SDK version usage
Change-Id: I06c1ae2b2a9831a4c31e09fafbe1500c10714caa Issue-ID: DCAEGEN2-1501 Signed-off-by: grabinsk <maciej.grabinski@nokia.com>
Diffstat (limited to 'prh-commons')
-rw-r--r--prh-commons/src/main/java/org/onap/dcaegen2/services/prh/model/PnfReadyJsonBodyBuilder.java (renamed from prh-commons/src/main/java/org/onap/dcaegen2/services/prh/model/PnfReadyJsonBodyBuilderImpl.java)15
-rw-r--r--prh-commons/src/test/java/org/onap/dcaegen2/services/prh/model/PnfReadyJsonBodyBuilderTest.java24
2 files changed, 19 insertions, 20 deletions
diff --git a/prh-commons/src/main/java/org/onap/dcaegen2/services/prh/model/PnfReadyJsonBodyBuilderImpl.java b/prh-commons/src/main/java/org/onap/dcaegen2/services/prh/model/PnfReadyJsonBodyBuilder.java
index 8584f01f..b39c4690 100644
--- a/prh-commons/src/main/java/org/onap/dcaegen2/services/prh/model/PnfReadyJsonBodyBuilderImpl.java
+++ b/prh-commons/src/main/java/org/onap/dcaegen2/services/prh/model/PnfReadyJsonBodyBuilder.java
@@ -20,16 +20,13 @@
package org.onap.dcaegen2.services.prh.model;
-import com.google.gson.GsonBuilder;
+import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
-import com.google.gson.TypeAdapterFactory;
import org.onap.dcaegen2.services.prh.model.ImmutableConsumerDmaapModel.Builder;
-import org.onap.dcaegen2.services.sdk.rest.services.model.JsonBodyBuilder;
+import org.onap.dcaegen2.services.prh.model.utils.PrhModelAwareGsonBuilder;
-import java.util.ServiceLoader;
-
-public class PnfReadyJsonBodyBuilderImpl implements JsonBodyBuilder<ConsumerDmaapModel> {
+public class PnfReadyJsonBodyBuilder {
/**
* Method for serialization object by GSON.
@@ -37,9 +34,7 @@ public class PnfReadyJsonBodyBuilderImpl implements JsonBodyBuilder<ConsumerDmaa
* @param consumerDmaapModel - object which will be serialized
* @return string from serialization
*/
- public String createJsonBody(ConsumerDmaapModel consumerDmaapModel) {
- GsonBuilder gsonBuilder = new GsonBuilder();
- ServiceLoader.load(TypeAdapterFactory.class).forEach(gsonBuilder::registerTypeAdapterFactory);
+ public JsonElement createJsonBody(ConsumerDmaapModel consumerDmaapModel) {
Builder builder = ImmutableConsumerDmaapModel.builder()
.correlationId(consumerDmaapModel.getCorrelationId());
@@ -47,6 +42,6 @@ public class PnfReadyJsonBodyBuilderImpl implements JsonBodyBuilder<ConsumerDmaa
if(additionalFields != null && !additionalFields.equals(new JsonObject())) {
builder.additionalFields(additionalFields);
}
- return gsonBuilder.create().toJson(builder.build());
+ return PrhModelAwareGsonBuilder.createGson().toJsonTree(builder.build());
}
} \ No newline at end of file
diff --git a/prh-commons/src/test/java/org/onap/dcaegen2/services/prh/model/PnfReadyJsonBodyBuilderTest.java b/prh-commons/src/test/java/org/onap/dcaegen2/services/prh/model/PnfReadyJsonBodyBuilderTest.java
index e104f54e..769e1673 100644
--- a/prh-commons/src/test/java/org/onap/dcaegen2/services/prh/model/PnfReadyJsonBodyBuilderTest.java
+++ b/prh-commons/src/test/java/org/onap/dcaegen2/services/prh/model/PnfReadyJsonBodyBuilderTest.java
@@ -31,23 +31,23 @@ class PnfReadyJsonBodyBuilderTest {
@Test
void createJsonBody_shouldReturnJsonInString() {
- JsonObject jsonObject = new JsonParser().parse("{\n"
+ JsonObject jsonObject = parse("{\n"
+ " \"attachmentPoint\": \"bla-bla-30-3\",\n"
+ " \"cvlan\": \"678\",\n"
+ " \"svlan\": \"1005\"\n"
- + " }").getAsJsonObject();
+ + " }");
ConsumerDmaapModel model = ImmutableConsumerDmaapModel.builder()
.correlationId("NOKnhfsadhff")
.additionalFields(jsonObject)
.build();
- String expectedResult = "{"
+ JsonObject expectedResult = parse("{"
+ "\"correlationId\":\"NOKnhfsadhff\","
+ "\"additionalFields\":{\"attachmentPoint\":\"bla-bla-30-3\",\"cvlan\":\"678\",\"svlan\":\"1005\"}"
- + "}";
+ + "}");
- assertEquals(expectedResult, new PnfReadyJsonBodyBuilderImpl().createJsonBody(model));
+ assertEquals(expectedResult, new PnfReadyJsonBodyBuilder().createJsonBody(model));
}
@Test
@@ -57,22 +57,26 @@ class PnfReadyJsonBodyBuilderTest {
.correlationId("NOKnhfsadhff")
.build();
- String expectedResult = "{\"correlationId\":\"NOKnhfsadhff\"}";
+ JsonObject expectedResult = parse("{\"correlationId\":\"NOKnhfsadhff\"}");
- assertEquals(expectedResult, new PnfReadyJsonBodyBuilderImpl().createJsonBody(model));
+ assertEquals(expectedResult, new PnfReadyJsonBodyBuilder().createJsonBody(model));
}
@Test
void createJsonBodyWithEmptyOptionalPnfRegistrationFields_shouldReturnJsonInString() {
- JsonObject jsonObject = new JsonParser().parse("{}").getAsJsonObject();
+ JsonObject jsonObject = new JsonObject();
ConsumerDmaapModel model = ImmutableConsumerDmaapModel.builder()
.correlationId("NOKnhfsadhff")
.additionalFields(jsonObject)
.build();
- String expectedResult = "{\"correlationId\":\"NOKnhfsadhff\"}";
+ JsonObject expectedResult = parse("{\"correlationId\":\"NOKnhfsadhff\"}");
- assertEquals(expectedResult, new PnfReadyJsonBodyBuilderImpl().createJsonBody(model));
+ assertEquals(expectedResult, new PnfReadyJsonBodyBuilder().createJsonBody(model));
+ }
+
+ private static JsonObject parse(String jsonString) {
+ return new JsonParser().parse(jsonString).getAsJsonObject();
}
}