summaryrefslogtreecommitdiffstats
path: root/models-tosca/src/test
diff options
context:
space:
mode:
authorliamfallon <liam.fallon@est.tech>2019-03-20 16:08:21 +0000
committerliamfallon <liam.fallon@est.tech>2019-03-20 16:08:21 +0000
commit8fc237cc606b6e9c8c7d7e7a2c811fc671a4b40e (patch)
tree1dc4369a5f94683a2140f28968a1bd32566743df /models-tosca/src/test
parentd614f2f3871ea6b46b0e8b0bbd8be70414710164 (diff)
Implement persistence test for policies
The unit test MonitoringPolicySerializationTest tests persistence for policies and shows how persistence works. Issue-ID: POLICY-1195 Change-Id: I933eb538238f9ccd41ce69614e0c9afcac869c29 Signed-off-by: liamfallon <liam.fallon@est.tech>
Diffstat (limited to 'models-tosca/src/test')
-rw-r--r--models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/ToscaPolicyTest.java2
-rw-r--r--models-tosca/src/test/java/org/onap/policy/models/tosca/simple/serialization/MonitoringPolicySerializationTest.java17
2 files changed, 17 insertions, 2 deletions
diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/ToscaPolicyTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/ToscaPolicyTest.java
index 7af5cc754..807f33ed2 100644
--- a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/ToscaPolicyTest.java
+++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/ToscaPolicyTest.java
@@ -89,7 +89,7 @@ public class ToscaPolicyTest {
PfConceptKey ptKey = new PfConceptKey("policyType", "0.0.1");
ToscaPolicy tp = new ToscaPolicy(tpKey, ptKey);
- Map<String, Object> propertyMap = new HashMap<>();
+ Map<String, String> propertyMap = new HashMap<>();
propertyMap.put("Property", "Property Value");
tp.setProperties(propertyMap);
assertEquals(propertyMap, tp.getProperties());
diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/serialization/MonitoringPolicySerializationTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/serialization/MonitoringPolicySerializationTest.java
index 565fd6cb4..95f0ac971 100644
--- a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/serialization/MonitoringPolicySerializationTest.java
+++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/serialization/MonitoringPolicySerializationTest.java
@@ -25,6 +25,7 @@ import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
import com.google.gson.JsonSyntaxException;
import java.io.IOException;
@@ -66,6 +67,13 @@ public class MonitoringPolicySerializationTest {
assertEquals("onap.restart.tca:1.0.0",
serviceTemplate.getTopologyTemplate().getPolicies().get("onap.restart.tca").getId());
+
+ String reserializedString = gson.toJson(serviceTemplate, ToscaServiceTemplate.class);
+ assertEquals(vcpePolicyJson.replaceAll("\\s+", ""), reserializedString.replaceAll("\\s+", ""));
+
+ ToscaServiceTemplate serviceTemplate2 = gson.fromJson(reserializedString, ToscaServiceTemplate.class);
+ assertNotNull(serviceTemplate2);
+ assertEquals(serviceTemplate, serviceTemplate2);
}
@Test
@@ -75,7 +83,7 @@ public class MonitoringPolicySerializationTest {
String vcpePolicyYaml = ResourceUtils.getResourceAsString("policies/vCPE.policy.monitoring.input.tosca.yaml");
Object yamlObject = yaml.load(vcpePolicyYaml);
- String yamlAsJsonString = new Gson().toJson(yamlObject);
+ String yamlAsJsonString = new GsonBuilder().setPrettyPrinting().create().toJson(yamlObject);
ToscaServiceTemplate serviceTemplate = gson.fromJson(yamlAsJsonString, ToscaServiceTemplate.class);
@@ -85,5 +93,12 @@ public class MonitoringPolicySerializationTest {
assertEquals("onap.restart.tca:1.0.0",
serviceTemplate.getTopologyTemplate().getPolicies().get("onap.restart.tca").getId());
+
+ String reserializedString = gson.toJson(serviceTemplate, ToscaServiceTemplate.class);
+ assertEquals(yamlAsJsonString.replaceAll("\\s+", ""), reserializedString.replaceAll("\\s+", ""));
+
+ ToscaServiceTemplate serviceTemplate2 = gson.fromJson(reserializedString, ToscaServiceTemplate.class);
+ assertNotNull(serviceTemplate2);
+ assertEquals(serviceTemplate, serviceTemplate2);
}
}