diff options
Diffstat (limited to 'models-tosca/src/test')
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); } } |