summaryrefslogtreecommitdiffstats
path: root/models-interactions/model-actors/actor.cds/src/test
diff options
context:
space:
mode:
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));
}
}