Add unit tests
[clamp.git] / src / main / java / org / onap / clamp / policy / microservice / MicroServicePolicy.java
index 7ebe0ed..857a3d7 100644 (file)
@@ -39,6 +39,8 @@ import javax.persistence.Table;
 import org.hibernate.annotations.Type;
 import org.hibernate.annotations.TypeDef;
 import org.hibernate.annotations.TypeDefs;
+import org.onap.clamp.clds.tosca.ToscaYamlToJsonConvertor;
+import org.onap.clamp.clds.util.JsonUtils;
 import org.onap.clamp.dao.model.jsontype.StringJsonUserType;
 import org.onap.clamp.loop.Loop;
 import org.onap.clamp.policy.Policy;
@@ -66,7 +68,7 @@ public class MicroServicePolicy implements Serializable, Policy {
     @Column(name = "shared", nullable = false)
     private Boolean shared;
 
-    @Column(name = "policy_tosca", nullable = false)
+    @Column(columnDefinition = "MEDIUMTEXT", name = "policy_tosca", nullable = false)
     private String policyTosca;
 
     @Expose
@@ -81,13 +83,22 @@ public class MicroServicePolicy implements Serializable, Policy {
         // serialization
     }
 
+    public MicroServicePolicy(String name, String policyTosca, Boolean shared, Set<Loop> usedByLoops) {
+        this.name = name;
+        this.policyTosca = policyTosca;
+        this.shared = shared;
+        this.jsonRepresentation = JsonUtils.GSON_JPA_MODEL
+            .fromJson(new ToscaYamlToJsonConvertor(null).parseToscaYaml(policyTosca), JsonObject.class);
+        this.usedByLoops = usedByLoops;
+    }
+
     public MicroServicePolicy(String name, String policyTosca, Boolean shared, JsonObject jsonRepresentation,
         Set<Loop> usedByLoops) {
         this.name = name;
         this.policyTosca = policyTosca;
         this.shared = shared;
-        this.jsonRepresentation = jsonRepresentation;
         this.usedByLoops = usedByLoops;
+        this.jsonRepresentation = jsonRepresentation;
     }
 
     @Override