PDP Group support
[clamp.git] / src / test / java / org / onap / clamp / loop / LoopToJsonTest.java
index 92a0e14..dcad1a5 100644 (file)
@@ -29,15 +29,18 @@ import static org.junit.Assert.assertNotNull;
 import com.google.gson.Gson;
 import com.google.gson.JsonObject;
 
+import java.io.IOException;
 import java.util.HashSet;
 import java.util.Random;
 
 import org.junit.Test;
+import org.onap.clamp.clds.util.JsonUtils;
+import org.onap.clamp.clds.util.ResourceFileUtil;
 import org.onap.clamp.loop.log.LogType;
 import org.onap.clamp.loop.log.LoopLog;
 import org.onap.clamp.policy.microservice.MicroServicePolicy;
 import org.onap.clamp.policy.operational.OperationalPolicy;
-import org.onap.clamp.clds.util.JsonUtils;
+import org.skyscreamer.jsonassert.JSONAssert;
 
 public class LoopToJsonTest {
 
@@ -58,33 +61,33 @@ public class LoopToJsonTest {
         return loop;
     }
 
-    private MicroServicePolicy getMicroServicePolicy(String name, String jsonRepresentation, String policyTosca,
-        String jsonProperties, boolean shared) {
-        MicroServicePolicy µService = new MicroServicePolicy(name, policyTosca, shared,
+    private MicroServicePolicy getMicroServicePolicy(String name, String modelType, String jsonRepresentation,
+        String policyTosca, String jsonProperties, boolean shared) {
+        MicroServicePolicy µService = new MicroServicePolicy(name, modelType, policyTosca, shared,
             gson.fromJson(jsonRepresentation, JsonObject.class), new HashSet<>());
         µService.setProperties(new Gson().fromJson(jsonProperties, JsonObject.class));
 
         return µService;
     }
 
-    private LoopLog getLoopLog(LogType type, String message) {
-        LoopLog log = new LoopLog();
-        log.setLogType(type);
-        log.setMessage(message);
+    private LoopLog getLoopLog(LogType type, String message, Loop loop) {
+        LoopLog log = new LoopLog(message, type, loop);
         log.setId(Long.valueOf(new Random().nextInt()));
         return log;
     }
 
     @Test
-    public void LoopGsonTest() {
+    public void LoopGsonTest() throws IOException {
         Loop loopTest = getLoop("ControlLoopTest", "<xml></xml>", "yamlcontent", "{\"testname\":\"testvalue\"}",
             "123456789", "https://dcaetest.org", "UUID-blueprint");
-        OperationalPolicy opPolicy = this.getOperationalPolicy("{\"type\":\"GUARD\"}", "GuardOpPolicyTest");
+        OperationalPolicy opPolicy = this.getOperationalPolicy(
+            ResourceFileUtil.getResourceAsString("tosca/operational-policy-properties.json"), "GuardOpPolicyTest");
         loopTest.addOperationalPolicy(opPolicy);
-        MicroServicePolicy microServicePolicy = getMicroServicePolicy("configPolicyTest", "{\"configtype\":\"json\"}",
-            "YamlContent", "{\"param1\":\"value1\"}", true);
+        MicroServicePolicy microServicePolicy = getMicroServicePolicy("configPolicyTest", "",
+            "{\"configtype\":\"json\"}", "tosca_definitions_version: tosca_simple_yaml_1_0_0",
+            "{\"param1\":\"value1\"}", true);
         loopTest.addMicroServicePolicy(microServicePolicy);
-        LoopLog loopLog = getLoopLog(LogType.INFO, "test message");
+        LoopLog loopLog = getLoopLog(LogType.INFO, "test message", loopTest);
         loopTest.addLog(loopLog);
 
         String jsonSerialized = JsonUtils.GSON_JPA_MODEL.toJson(loopTest);
@@ -94,7 +97,7 @@ public class LoopToJsonTest {
         assertNotNull(loopTestDeserialized);
         assertThat(loopTestDeserialized).isEqualToIgnoringGivenFields(loopTest, "svgRepresentation", "blueprint");
 
-        //svg and blueprint not exposed so wont be deserialized
+        // svg and blueprint not exposed so wont be deserialized
         assertThat(loopTestDeserialized.getBlueprint()).isEqualTo(null);
         assertThat(loopTestDeserialized.getSvgRepresentation()).isEqualTo(null);
 
@@ -104,4 +107,20 @@ public class LoopToJsonTest {
         assertThat((LoopLog) loopTestDeserialized.getLoopLogs().toArray()[0]).isEqualToIgnoringGivenFields(loopLog,
             "loop");
     }
+
+    @Test
+    public void createPoliciesPayloadPdpGroupTest() throws IOException {
+        Loop loopTest = getLoop("ControlLoopTest", "<xml></xml>", "yamlcontent", "{\"testname\":\"testvalue\"}",
+            "123456789", "https://dcaetest.org", "UUID-blueprint");
+        OperationalPolicy opPolicy = this.getOperationalPolicy(
+            ResourceFileUtil.getResourceAsString("tosca/operational-policy-properties.json"), "GuardOpPolicyTest");
+        loopTest.addOperationalPolicy(opPolicy);
+        MicroServicePolicy microServicePolicy = getMicroServicePolicy("configPolicyTest", "",
+            "{\"configtype\":\"json\"}", "tosca_definitions_version: tosca_simple_yaml_1_0_0",
+            "{\"param1\":\"value1\"}", true);
+        loopTest.addMicroServicePolicy(microServicePolicy);
+
+        JSONAssert.assertEquals(ResourceFileUtil.getResourceAsString("tosca/pdp-group-policy-payload.json"),
+            loopTest.createPoliciesPayloadPdpGroup(), false);
+    }
 }