summaryrefslogtreecommitdiffstats
path: root/models-interactions/model-actors/actor.cds/src/test
diff options
context:
space:
mode:
authorRashmi Pujar <rashmi.pujar@bell.ca>2019-11-25 12:56:24 -0500
committerRashmi Pujar <rashmi.pujar@bell.ca>2019-11-26 13:27:37 -0500
commit281f653d38161409b553ff01b30f80a6903827b5 (patch)
tree11b17c1add60dd00089f9e2cb5a74128967b310a /models-interactions/model-actors/actor.cds/src/test
parent0ca7816c5f88288ed72f7b69f0813c8da3b63ebe (diff)
CDS actor payload to be JSON object when applicable
When the policy-payload supplied by CLAMP is a valid JSON string the CDS Blueprint payload must be a JSON object, else retain the CDS Blueprint payload to be a string. Issue-ID: POLICY-2253 Signed-off-by: Rashmi Pujar <rashmi.pujar@bell.ca> Change-Id: I6380ab0424339603ecf52d298e4f6f0cd8df754b
Diffstat (limited to 'models-interactions/model-actors/actor.cds/src/test')
-rw-r--r--models-interactions/model-actors/actor.cds/src/test/java/org/onap/policy/controlloop/actor/cds/request/CdsActionRequestTest.java62
1 files changed, 54 insertions, 8 deletions
diff --git a/models-interactions/model-actors/actor.cds/src/test/java/org/onap/policy/controlloop/actor/cds/request/CdsActionRequestTest.java b/models-interactions/model-actors/actor.cds/src/test/java/org/onap/policy/controlloop/actor/cds/request/CdsActionRequestTest.java
index e34fa33ab..7266d0311 100644
--- a/models-interactions/model-actors/actor.cds/src/test/java/org/onap/policy/controlloop/actor/cds/request/CdsActionRequestTest.java
+++ b/models-interactions/model-actors/actor.cds/src/test/java/org/onap/policy/controlloop/actor/cds/request/CdsActionRequestTest.java
@@ -18,10 +18,13 @@
package org.onap.policy.controlloop.actor.cds.request;
+import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import com.google.common.collect.ImmutableMap;
+import java.util.HashMap;
import java.util.Map;
+import org.junit.Before;
import org.junit.Test;
import org.onap.policy.common.utils.coder.CoderException;
import org.onap.policy.controlloop.actor.cds.constants.CdsActorConstants;
@@ -29,23 +32,65 @@ import org.onap.policy.controlloop.actor.cds.constants.CdsActorConstants;
public class CdsActionRequestTest {
private static final String TEST_ACTION_NAME = "vfw-modify-config";
+ private CdsActionRequest req = new CdsActionRequest();
- @Test
- public void testGenerateCdsPayload() throws CoderException {
- // Setup the CdsActionRequest object
- CdsActionRequest req = new CdsActionRequest();
+ /**
+ * Setup the CdsActionRequest object.
+ */
+ @Before
+ public void setUp() {
req.setActionName(TEST_ACTION_NAME);
req.setResolutionKey("1234567890");
- Map<String, String> payloadProps = ImmutableMap.of("data", "{\"active-streams\":\"5\"}");
- req.setPolicyPayload(payloadProps);
Map<String, String> aaiParams =
ImmutableMap.of("service-instance.service-instance-id", "1234", "generic-vnf.vnf-id", "5678");
req.setAaiProperties(aaiParams);
- Map<String, String> eventParams =
- ImmutableMap.of("event-param-1", "1234", "event-param-2", "5678");
+ Map<String, String> eventParams = ImmutableMap.of("event-param-1", "1234", "event-param-2", "5678");
req.setAdditionalEventParams(eventParams);
+ }
+
+ @Test
+ public void testGenerateCdsPayloadWhenPolicyPayloadIsNotValidJsonString() throws CoderException {
+ String payloadStr = "active-streams=5";
+ Map<String, String> payloadProps = ImmutableMap.of(CdsActorConstants.KEY_POLICY_PAYLOAD_DATA, payloadStr);
+ req.setPolicyPayload(payloadProps);
+
+ // Act
+ String result = req.generateCdsPayload();
+
+ // Assert
+ assertTrue(result.contains(TEST_ACTION_NAME + CdsActorConstants.CDS_REQUEST_PROPERTIES_SUFFIX));
+ assertTrue(result.contains(TEST_ACTION_NAME + CdsActorConstants.CDS_REQUEST_SUFFIX));
+ assertTrue(result.contains(CdsActorConstants.KEY_RESOLUTION_KEY));
+ assertTrue(result.contains("\"" + CdsActorConstants.KEY_POLICY_PAYLOAD_DATA + "\":\"" + payloadStr + "\""));
+ }
+
+ @Test
+ public void testGenerateCdsPayloadWhenPolicyPayloadIsValidJsonString() throws CoderException {
+ String payloadStr = "{\"active-streams\":\"5\"}";
+ Map<String, String> payloadProps = ImmutableMap.of(CdsActorConstants.KEY_POLICY_PAYLOAD_DATA, payloadStr);
+ req.setPolicyPayload(payloadProps);
+
+ // Act
+ String result = req.generateCdsPayload();
+
+ // Assert
+ assertTrue(result.contains(TEST_ACTION_NAME + CdsActorConstants.CDS_REQUEST_PROPERTIES_SUFFIX));
+ assertTrue(result.contains(TEST_ACTION_NAME + CdsActorConstants.CDS_REQUEST_SUFFIX));
+ assertTrue(result.contains(CdsActorConstants.KEY_RESOLUTION_KEY));
+ assertTrue(result.contains("\"" + CdsActorConstants.KEY_POLICY_PAYLOAD_DATA + "\":" + payloadStr));
+ }
+
+ @Test
+ public void testGenerateCdsPayloadWhenPolicyPayloadIsNull() throws CoderException {
+ Map<String, String> payloadProps = new HashMap<String, String>() {
+ private static final long serialVersionUID = 1L;
+ {
+ put(CdsActorConstants.KEY_POLICY_PAYLOAD_DATA, null);
+ }
+ };
+ req.setPolicyPayload(payloadProps);
// Act
String result = req.generateCdsPayload();
@@ -54,5 +99,6 @@ public class CdsActionRequestTest {
assertTrue(result.contains(TEST_ACTION_NAME + CdsActorConstants.CDS_REQUEST_PROPERTIES_SUFFIX));
assertTrue(result.contains(TEST_ACTION_NAME + CdsActorConstants.CDS_REQUEST_SUFFIX));
assertTrue(result.contains(CdsActorConstants.KEY_RESOLUTION_KEY));
+ assertFalse(result.contains(CdsActorConstants.KEY_POLICY_PAYLOAD_DATA));
}
}