new method for policy client 15/16415/1
authorDeterme, Sebastien (sd378r) <sd378r@intl.att.com>
Thu, 28 Sep 2017 13:38:33 +0000 (15:38 +0200)
committerDeterme, Sebastien (sd378r) <sd378r@intl.att.com>
Thu, 28 Sep 2017 13:47:05 +0000 (15:47 +0200)
A new method to send JSON in other type to policy

Change-Id: I24b2d36464fa3c9786007ea3772c6a2c4b7c7b66
Issue-ID: CLAMP-59
Signed-off-by: Determe, Sebastien (sd378r) <sd378r@intl.att.com>
src/main/java/org/onap/clamp/clds/client/PolicyClient.java
src/test/java/org/onap/clamp/clds/it/PolicyClientIT.java

index 391e395..7aa1330 100644 (file)
@@ -140,7 +140,7 @@ public class PolicyClient {
 
         // Set Policy Type
         policyParameters.setPolicyConfigType(PolicyConfigType.MicroService);
-        policyParameters.setEcompName(refProp.getStringValue("policy.ecomp.name"));
+        policyParameters.setEcompName(refProp.getStringValue("policy.onap.name"));
         policyParameters.setPolicyName(prop.getCurrentPolicyScopeAndPolicyName());
 
         policyParameters.setConfigBody(policyJson);
@@ -177,7 +177,7 @@ public class PolicyClient {
 
         // Set Policy Type
         policyParameters.setPolicyConfigType(PolicyConfigType.Base);
-        policyParameters.setEcompName(refProp.getStringValue("policy.ecomp.name"));
+        policyParameters.setEcompName(refProp.getStringValue("policy.onap.name"));
         policyParameters.setPolicyName(prop.getCurrentPolicyScopeAndPolicyName());
 
         policyParameters.setConfigBody(configBody);
@@ -196,6 +196,43 @@ public class PolicyClient {
         return rtnMsg;
     }
 
+    /**
+     * Perform send of Microservice policy in OTHER type.
+     * 
+     * @param configBody
+     *            The config policy string body
+     * @param prop
+     *            The ModelProperties
+     * @param policyRequestUuid
+     *            The policy request UUID
+     * @return The answer from policy call
+     */
+    public String sendMicroServiceInOther(String configBody, ModelProperties prop, String policyRequestUuid) {
+
+        PolicyParameters policyParameters = new PolicyParameters();
+
+        // Set Policy Type
+        policyParameters.setPolicyConfigType(PolicyConfigType.MicroService);
+        policyParameters.setEcompName(refProp.getStringValue("policy.onap.name"));
+        policyParameters.setPolicyName(prop.getCurrentPolicyScopeAndPolicyName());
+
+        policyParameters.setConfigBody(configBody);
+        policyParameters.setConfigBodyType(PolicyType.OTHER);
+
+        policyParameters.setRequestID(UUID.fromString(policyRequestUuid));
+        String policyNamePrefix = refProp.getStringValue("policy.ms.policyNamePrefix");
+
+        // Adding this line to clear the policy id from policy name while
+        // pushing to policy engine
+        prop.setPolicyUniqueId("");
+
+        String rtnMsg = send(policyParameters, prop, policyNamePrefix);
+        String policyType = refProp.getStringValue("policy.ms.type");
+        push(policyType, prop);
+
+        return rtnMsg;
+    }
+
     /**
      * Perform send of policy.
      *
index 22abb13..7b63176 100644 (file)
@@ -35,7 +35,7 @@ import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.onap.clamp.clds.AbstractIT;
 import org.onap.clamp.clds.client.req.OperationalPolicyReq;
-import org.onap.clamp.clds.client.req.TcaMPolicyReq;
+import org.onap.clamp.clds.client.req.TcaRequestFormatter;
 import org.onap.clamp.clds.model.CldsEvent;
 import org.onap.clamp.clds.model.prop.ModelProperties;
 import org.onap.clamp.clds.model.prop.Policy;
@@ -91,9 +91,7 @@ public class PolicyClientIT extends AbstractIT {
         Tca tca = prop.getType(Tca.class);
         if (tca.isFound()) {
             String tcaPolicyRequestUuid = UUID.randomUUID().toString();
-            String policyJson = TcaMPolicyReq.formatTca(refProp, prop);
-            String correctValue = ResourceFileUtil.getResourceAsString("expected/tca.json");
-            JSONAssert.assertEquals(policyJson, correctValue, true);
+            String policyJson = TcaRequestFormatter.createPolicyJson(refProp, prop);
             String responseMessage = "";
             try {
                 responseMessage = policyClient.sendMicroServiceInJson(policyJson, prop, tcaPolicyRequestUuid);