summaryrefslogtreecommitdiffstats
path: root/examples/examples-onap-vcpe/src/test
diff options
context:
space:
mode:
authorliamfallon <liam.fallon@est.tech>2019-11-07 21:33:12 +0000
committerliamfallon <liam.fallon@est.tech>2019-11-07 21:33:17 +0000
commitccf72b37d15930a8ede20ec4391b776cc60bf3c5 (patch)
treef032090c972f7a8f545ebe668a59847b74bc6bb9 /examples/examples-onap-vcpe/src/test
parent262c8cbc5d92d22afee12451dca72d13b514f826 (diff)
Fix vCPE example apex-pdp policy
The changes in policy-models for appclcm had knock-on impacts on the apex-pdp example policies. This patch fixes the vCPE policy to comply with the new APPCLCM POJOs. Issue-ID: POLICY-2043 Change-Id: Ieebc2cf97a05efde560a2f5a819924ff63dfd695 Signed-off-by: liamfallon <liam.fallon@est.tech>
Diffstat (limited to 'examples/examples-onap-vcpe/src/test')
-rw-r--r--examples/examples-onap-vcpe/src/test/java/org/onap/policy/apex/domains/onap/vcpe/AppcResponseCreator.java32
-rw-r--r--examples/examples-onap-vcpe/src/test/java/org/onap/policy/apex/domains/onap/vcpe/OnapVCpeSimEndpoint.java11
2 files changed, 20 insertions, 23 deletions
diff --git a/examples/examples-onap-vcpe/src/test/java/org/onap/policy/apex/domains/onap/vcpe/AppcResponseCreator.java b/examples/examples-onap-vcpe/src/test/java/org/onap/policy/apex/domains/onap/vcpe/AppcResponseCreator.java
index 10f425302..d989ba361 100644
--- a/examples/examples-onap-vcpe/src/test/java/org/onap/policy/apex/domains/onap/vcpe/AppcResponseCreator.java
+++ b/examples/examples-onap-vcpe/src/test/java/org/onap/policy/apex/domains/onap/vcpe/AppcResponseCreator.java
@@ -20,24 +20,24 @@
package org.onap.policy.apex.domains.onap.vcpe;
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
+
+import java.time.Instant;
import java.util.Timer;
import java.util.TimerTask;
import java.util.concurrent.BlockingQueue;
+import org.onap.policy.appclcm.AppcLcmBody;
import org.onap.policy.appclcm.AppcLcmDmaapWrapper;
import org.onap.policy.appclcm.AppcLcmInput;
import org.onap.policy.appclcm.AppcLcmOutput;
-import org.onap.policy.common.utils.coder.CoderException;
-import org.onap.policy.common.utils.coder.StandardCoder;
-import org.slf4j.ext.XLogger;
-import org.slf4j.ext.XLoggerFactory;
+import org.onap.policy.controlloop.util.Serialization;
/**
* Respond to an APPC request with a given delay.
*/
public class AppcResponseCreator {
- private static final XLogger LOGGER = XLoggerFactory.getXLogger(AppcResponseCreator.class);
-
// The request from APPC
private final String jsonRequestString;
@@ -47,6 +47,9 @@ public class AppcResponseCreator {
// The timer task for response generation
private final Timer appcTimer;
+ private static final Gson gson = new GsonBuilder()
+ .registerTypeAdapter(Instant.class, new Serialization.GsonInstantAdapter()).create();
+
/**
* Respond to the given APPC request after the given amount of milliseconds.
*
@@ -70,15 +73,8 @@ public class AppcResponseCreator {
@Override
public void run() {
- StandardCoder standardCoder = new StandardCoder();
-
AppcLcmDmaapWrapper requestWrapper = null;
- try {
- requestWrapper = standardCoder.decode(jsonRequestString, AppcLcmDmaapWrapper.class);
- } catch (CoderException e) {
- LOGGER.warn("decoding of the APPC request message failed", e);
- return;
- }
+ requestWrapper = gson.fromJson(jsonRequestString, AppcLcmDmaapWrapper.class);
AppcLcmInput request = requestWrapper.getBody().getInput();
@@ -87,6 +83,7 @@ public class AppcResponseCreator {
response.getStatus().setMessage("Restart Successful");
AppcLcmDmaapWrapper responseWrapper = new AppcLcmDmaapWrapper();
+ responseWrapper.setBody(new AppcLcmBody());
responseWrapper.getBody().setOutput(response);
responseWrapper.setVersion(requestWrapper.getVersion());
@@ -94,12 +91,7 @@ public class AppcResponseCreator {
responseWrapper.setCorrelationId(requestWrapper.getCorrelationId());
responseWrapper.setType(requestWrapper.getType());
- try {
- appcResponseQueue.add(standardCoder.encode(responseWrapper));
- } catch (CoderException e) {
- LOGGER.warn("encoding of the APPC request message failed", e);
- return;
- }
+ appcResponseQueue.add(gson.toJson(responseWrapper));
}
}
}
diff --git a/examples/examples-onap-vcpe/src/test/java/org/onap/policy/apex/domains/onap/vcpe/OnapVCpeSimEndpoint.java b/examples/examples-onap-vcpe/src/test/java/org/onap/policy/apex/domains/onap/vcpe/OnapVCpeSimEndpoint.java
index 936c319a9..f08bf010c 100644
--- a/examples/examples-onap-vcpe/src/test/java/org/onap/policy/apex/domains/onap/vcpe/OnapVCpeSimEndpoint.java
+++ b/examples/examples-onap-vcpe/src/test/java/org/onap/policy/apex/domains/onap/vcpe/OnapVCpeSimEndpoint.java
@@ -26,6 +26,7 @@ import static org.junit.Assert.assertTrue;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
+import java.time.Instant;
import java.util.Map;
import java.util.Random;
import java.util.concurrent.BlockingQueue;
@@ -46,6 +47,7 @@ import org.onap.policy.aai.AaiNqRequest;
import org.onap.policy.aai.AaiNqResponse;
import org.onap.policy.aai.AaiNqVfModule;
import org.onap.policy.apex.core.infrastructure.threading.ThreadUtilities;
+import org.onap.policy.controlloop.util.Serialization;
import org.slf4j.ext.XLogger;
import org.slf4j.ext.XLoggerFactory;
@@ -64,6 +66,9 @@ public class OnapVCpeSimEndpoint {
private static AtomicInteger statMessagesReceived = new AtomicInteger();
private static AtomicInteger getMessagesReceived = new AtomicInteger();
+ private static final Gson gson = new GsonBuilder()
+ .registerTypeAdapter(Instant.class, new Serialization.GsonInstantAdapter()).create();
+
/**
* Service get stats.
*
@@ -121,7 +126,7 @@ public class OnapVCpeSimEndpoint {
LOGGER.info("\n*** AAI REQUEST START ***\n" + jsonString + "\n *** AAI REQUEST END ***");
- AaiNqRequest request = new Gson().fromJson(jsonString, AaiNqRequest.class);
+ AaiNqRequest request = gson.fromJson(jsonString, AaiNqRequest.class);
String vnfId = request.getInstanceFilters().getInstanceFilter().iterator().next().get("generic-vnf")
.get("vnf-id");
String vnfSuffix = vnfId.substring(vnfId.length() - 4);
@@ -295,7 +300,7 @@ public class OnapVCpeSimEndpoint {
postMessagesReceived.incrementAndGet();
@SuppressWarnings("unchecked")
- final Map<String, Object> jsonMap = new Gson().fromJson(jsonString, Map.class);
+ final Map<String, Object> jsonMap = gson.fromJson(jsonString, Map.class);
assertTrue(jsonMap.containsKey("name"));
assertEquals("0.0.1", jsonMap.get("version"));
assertEquals("org.onap.policy.apex.sample.events", jsonMap.get("nameSpace"));
@@ -330,7 +335,7 @@ public class OnapVCpeSimEndpoint {
putMessagesReceived.incrementAndGet();
@SuppressWarnings("unchecked")
- final Map<String, Object> jsonMap = new Gson().fromJson(jsonString, Map.class);
+ final Map<String, Object> jsonMap = gson.fromJson(jsonString, Map.class);
assertTrue(jsonMap.containsKey("name"));
assertEquals("0.0.1", jsonMap.get("version"));
assertEquals("org.onap.policy.apex.sample.events", jsonMap.get("nameSpace"));