From 8fc237cc606b6e9c8c7d7e7a2c811fc671a4b40e Mon Sep 17 00:00:00 2001 From: liamfallon Date: Wed, 20 Mar 2019 16:08:21 +0000 Subject: [PATCH] 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 --- .../org/onap/policy/models/base/PfConceptKey.java | 4 +- .../onap/policy/models/base/PfReferenceKey.java | 8 +- models-dao/pom.xml | 1 - models-provider/pom.xml | 16 ++- .../impl/MonitoringPolicyPersistenceTest.java | 118 +++++++++++++++++++++ .../src/test/resources/META-INF/persistence.xml | 73 +++++++++++++ .../mapping/LegacyOperationalPolicyMapper.java | 2 +- .../tosca/simple/concepts/ToscaEntityType.java | 25 +++-- .../models/tosca/simple/concepts/ToscaPolicy.java | 15 ++- .../serialization/ToscaPoliciesJsonAdapter.java | 3 +- .../serialization/ToscaPolicyJsonAdapter.java | 34 +++--- .../ToscaServiceTemplateMessageBodyHandler.java | 1 + .../tosca/simple/concepts/ToscaPolicyTest.java | 2 +- .../MonitoringPolicySerializationTest.java | 17 ++- 14 files changed, 275 insertions(+), 44 deletions(-) create mode 100644 models-provider/src/test/java/org/onap/policy/models/provider/impl/MonitoringPolicyPersistenceTest.java create mode 100644 models-provider/src/test/resources/META-INF/persistence.xml diff --git a/models-base/src/main/java/org/onap/policy/models/base/PfConceptKey.java b/models-base/src/main/java/org/onap/policy/models/base/PfConceptKey.java index 695ca4712..9f575851b 100644 --- a/models-base/src/main/java/org/onap/policy/models/base/PfConceptKey.java +++ b/models-base/src/main/java/org/onap/policy/models/base/PfConceptKey.java @@ -50,10 +50,10 @@ public class PfConceptKey extends PfKey { private static final String NAME_TOKEN = "name"; private static final String VERSION_TOKEN = "version"; - @Column(name = NAME_TOKEN) + @Column(name = NAME_TOKEN, length = 128) private String name; - @Column(name = VERSION_TOKEN) + @Column(name = VERSION_TOKEN, length = 128) private String version; /** diff --git a/models-base/src/main/java/org/onap/policy/models/base/PfReferenceKey.java b/models-base/src/main/java/org/onap/policy/models/base/PfReferenceKey.java index 2e9f48ba5..19e8beee9 100644 --- a/models-base/src/main/java/org/onap/policy/models/base/PfReferenceKey.java +++ b/models-base/src/main/java/org/onap/policy/models/base/PfReferenceKey.java @@ -72,16 +72,16 @@ public class PfReferenceKey extends PfKey { private static final int PARENT_LOCAL_NAME_FIELD = 2; private static final int LOCAL_NAME_FIELD = 3; - @Column(name = PARENT_KEY_NAME) + @Column(name = PARENT_KEY_NAME, length = 128) private String parentKeyName; - @Column(name = PARENT_KEY_VERSION) + @Column(name = PARENT_KEY_VERSION, length = 128) private String parentKeyVersion; - @Column(name = PARENT_LOCAL_NAME) + @Column(name = PARENT_LOCAL_NAME, length = 128) private String parentLocalName; - @Column(name = LOCAL_NAME) + @Column(name = LOCAL_NAME, length = 128) private String localName; /** diff --git a/models-dao/pom.xml b/models-dao/pom.xml index d71fce868..ceec2a1e4 100644 --- a/models-dao/pom.xml +++ b/models-dao/pom.xml @@ -43,6 +43,5 @@ h2 test - diff --git a/models-provider/pom.xml b/models-provider/pom.xml index 8da16edab..44756beb9 100644 --- a/models-provider/pom.xml +++ b/models-provider/pom.xml @@ -17,8 +17,7 @@ SPDX-License-Identifier: Apache-2.0 ============LICENSE_END========================================================= --> - 4.0.0 @@ -56,5 +55,18 @@ policy-models-tosca ${project.version} + + + com.h2database + h2 + test + + + + org.mariadb.jdbc + mariadb-java-client + test + + diff --git a/models-provider/src/test/java/org/onap/policy/models/provider/impl/MonitoringPolicyPersistenceTest.java b/models-provider/src/test/java/org/onap/policy/models/provider/impl/MonitoringPolicyPersistenceTest.java new file mode 100644 index 000000000..b26e762af --- /dev/null +++ b/models-provider/src/test/java/org/onap/policy/models/provider/impl/MonitoringPolicyPersistenceTest.java @@ -0,0 +1,118 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.models.provider.impl; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +import com.google.gson.Gson; +import com.google.gson.JsonSyntaxException; + +import java.io.IOException; +import java.sql.Connection; +import java.sql.DriverManager; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.onap.policy.common.utils.resources.ResourceUtils; +import org.onap.policy.models.base.PfConceptKey; +import org.onap.policy.models.base.PfValidationResult; +import org.onap.policy.models.dao.DaoParameters; +import org.onap.policy.models.dao.PfDao; +import org.onap.policy.models.dao.PfDaoFactory; +import org.onap.policy.models.dao.impl.DefaultPfDao; +import org.onap.policy.models.tosca.simple.concepts.ToscaPolicy; +import org.onap.policy.models.tosca.simple.concepts.ToscaServiceTemplate; +import org.onap.policy.models.tosca.simple.serialization.ToscaServiceTemplateMessageBodyHandler; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Test persistence of monitoring policies to and from the database. + * + * @author Liam Fallon (liam.fallon@est.tech) + */ +public class MonitoringPolicyPersistenceTest { + // Logger for this class + private static final Logger LOGGER = LoggerFactory.getLogger(MonitoringPolicyPersistenceTest.class); + + private Gson gson; + + private Connection connection; + private PfDao pfDao; + + /** + * Set up the DAO towards the database. + * + * @throws Exception on database errors + */ + @Before + public void setupDao() throws Exception { + // Use the JDBC UI "jdbc:h2:mem:testdb" to test towards the h2 database + // Use the JDBC UI "jdbc:mariadb://localhost:3306/policy" to test towards a locally installed mariadb instance + connection = DriverManager.getConnection("jdbc:h2:mem:testdb", "policy", "P01icY"); + + final DaoParameters daoParameters = new DaoParameters(); + daoParameters.setPluginClass(DefaultPfDao.class.getCanonicalName()); + + // Use the persistence unit ToscaConceptTest to test towards the h2 database + // Use the persistence unit ToscaConceptMariaDBTest to test towards a locally installed mariadb instance + daoParameters.setPersistenceUnit("ToscaConceptTest"); + + pfDao = new PfDaoFactory().createPfDao(daoParameters); + pfDao.init(daoParameters); + } + + /** + * Set up GSON. + */ + @Before + public void setupGson() { + gson = new ToscaServiceTemplateMessageBodyHandler().getGson(); + } + + @After + public void teardown() throws Exception { + pfDao.close(); + connection.close(); + } + + @Test + public void testJsonDeserialization() throws JsonSyntaxException, IOException { + ToscaServiceTemplate serviceTemplate = + gson.fromJson(ResourceUtils.getResourceAsString("policies/vCPE.policy.monitoring.input.tosca.json"), + ToscaServiceTemplate.class); + + assertNotNull(serviceTemplate); + LOGGER.info(serviceTemplate.validate(new PfValidationResult()).toString()); + assertTrue(serviceTemplate.validate(new PfValidationResult()).isValid()); + + ToscaPolicy policyBeforeDb = serviceTemplate.getTopologyTemplate().getPolicies().get("onap.restart.tca"); + + pfDao.create(policyBeforeDb); + + ToscaPolicy policyAfterDb = pfDao.get(ToscaPolicy.class, new PfConceptKey("onap.restart.tca:1.0.0")); + + assertEquals(policyBeforeDb, policyAfterDb); + } +} diff --git a/models-provider/src/test/resources/META-INF/persistence.xml b/models-provider/src/test/resources/META-INF/persistence.xml new file mode 100644 index 000000000..491505341 --- /dev/null +++ b/models-provider/src/test/resources/META-INF/persistence.xml @@ -0,0 +1,73 @@ + + + + + + org.eclipse.persistence.jpa.PersistenceProvider + + org.onap.policy.models.dao.converters.CDataConditioner + org.onap.policy.models.dao.converters.Uuid2String + org.onap.policy.models.base.PfConceptKey + org.onap.policy.models.tosca.simple.concepts.ToscaPolicy + + + + + + + + + + + + + + org.eclipse.persistence.jpa.PersistenceProvider + + org.onap.policy.models.dao.converters.CDataConditioner + org.onap.policy.models.dao.converters.Uuid2String + org.onap.policy.models.base.PfConceptKey + org.onap.policy.models.tosca.simple.concepts.ToscaPolicy + + + + + + + + + + + + + + + + diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/legacy/mapping/LegacyOperationalPolicyMapper.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/legacy/mapping/LegacyOperationalPolicyMapper.java index 781602a7e..2c0d5084d 100644 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/legacy/mapping/LegacyOperationalPolicyMapper.java +++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/legacy/mapping/LegacyOperationalPolicyMapper.java @@ -54,7 +54,7 @@ public class LegacyOperationalPolicyMapper // TODO: Check if this is the correct way to set the policy type version toscaPolicy.setType(new PfConceptKey("SomeDerivedPolicyType", "1.0.0")); - Map propertyMap = new HashMap<>(); + Map propertyMap = new HashMap<>(); toscaPolicy.setProperties(propertyMap); toscaPolicy.getProperties().put("Content", legacyOperationalPolicy.getContent()); diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/ToscaEntityType.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/ToscaEntityType.java index 7eaf58b2e..f2ae05119 100644 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/ToscaEntityType.java +++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/ToscaEntityType.java @@ -20,20 +20,17 @@ package org.onap.policy.models.tosca.simple.concepts; -import com.google.gson.annotations.SerializedName; - import java.util.List; import java.util.Map; import java.util.Map.Entry; import java.util.TreeMap; -import javax.persistence.CascadeType; +import javax.persistence.AttributeOverride; +import javax.persistence.AttributeOverrides; import javax.persistence.Column; +import javax.persistence.ElementCollection; import javax.persistence.EmbeddedId; -import javax.persistence.Inheritance; -import javax.persistence.InheritanceType; import javax.persistence.MappedSuperclass; -import javax.persistence.OneToMany; import lombok.Data; import lombok.EqualsAndHashCode; @@ -54,7 +51,6 @@ import org.onap.policy.models.base.PfValidationResult.ValidationResult; * Class to represent the EntrySchema of list/map property in TOSCA definition. */ @MappedSuperclass -@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS) @Data @EqualsAndHashCode(callSuper = false) public class ToscaEntityType extends PfConcept { @@ -63,15 +59,22 @@ public class ToscaEntityType extends PfConcept { @EmbeddedId private PfConceptKey key; - @SerializedName("derived_from") - @Column(name = "derivedFrom") + // @formatter:off + @Column + @AttributeOverrides({ + @AttributeOverride(name = "name", + column = @Column(name = "derived_from_name")), + @AttributeOverride(name = "version", + column = @Column(name = "derived_from_version")) + }) private PfConceptKey derivedFrom; - @OneToMany(cascade = CascadeType.ALL) + @ElementCollection private Map metadata; - @Column(name = "description") + @Column private String description; + // @formatter:on /** * The Default Constructor creates a {@link ToscaEntityType} object with a null key. diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/ToscaPolicy.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/ToscaPolicy.java index af94af08d..e08079c40 100644 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/ToscaPolicy.java +++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/ToscaPolicy.java @@ -28,6 +28,8 @@ import java.util.List; import java.util.Map; import java.util.Map.Entry; +import javax.persistence.AttributeOverride; +import javax.persistence.AttributeOverrides; import javax.persistence.Column; import javax.persistence.ElementCollection; import javax.persistence.Entity; @@ -63,14 +65,23 @@ import org.onap.policy.models.base.PfValidationResult.ValidationResult; public class ToscaPolicy extends ToscaEntityType { private static final long serialVersionUID = 3265174757061982805L; + // @formatter:off @Column + @AttributeOverrides({ + @AttributeOverride(name = "name", + column = @Column(name = "type_name")), + @AttributeOverride(name = "version", + column = @Column(name = "type_version")) + }) private PfConceptKey type; @ElementCollection - private Map properties; + @Column(length = 10000) + private Map properties; @ElementCollection private List targets; + // @formatter:on /** * The Default Constructor creates a {@link ToscaPolicy} object with a null key. @@ -166,7 +177,7 @@ public class ToscaPolicy extends ToscaEntityType { private PfValidationResult validateProperties(@NonNull final PfValidationResult resultIn) { PfValidationResult result = resultIn; - for (Entry propertyEntry : properties.entrySet()) { + for (Entry propertyEntry : properties.entrySet()) { if (!ParameterValidationUtils.validateStringParameter(propertyEntry.getKey())) { result.addValidationMessage(new PfValidationMessage(getKey(), this.getClass(), ValidationResult.INVALID, "policy property key may not be null ")); diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/serialization/ToscaPoliciesJsonAdapter.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/serialization/ToscaPoliciesJsonAdapter.java index 3f25b708f..53088d637 100644 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/serialization/ToscaPoliciesJsonAdapter.java +++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/serialization/ToscaPoliciesJsonAdapter.java @@ -71,8 +71,7 @@ public class ToscaPoliciesJsonAdapter implements JsonSerializer, JsonArray policiesJsonArray = new JsonArray(); for (ToscaPolicy policy: policies.getConceptMap().values()) { - JsonElement policyEntry = new ToscaPolicyJsonAdapter().serialize(policy, type, context); - policiesJsonArray.add(policyEntry); + policiesJsonArray.add(new ToscaPolicyJsonAdapter().serialize(policy, type, context)); } return policiesJsonArray; diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/serialization/ToscaPolicyJsonAdapter.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/serialization/ToscaPolicyJsonAdapter.java index aef854710..95b4b3bba 100644 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/serialization/ToscaPolicyJsonAdapter.java +++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/serialization/ToscaPolicyJsonAdapter.java @@ -21,6 +21,8 @@ package org.onap.policy.models.tosca.simple.serialization; +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; import com.google.gson.JsonDeserializationContext; import com.google.gson.JsonDeserializer; import com.google.gson.JsonElement; @@ -58,6 +60,8 @@ public class ToscaPolicyJsonAdapter implements JsonSerializer, Json private static final String METADATA = "metadata"; private static final String PROPERTIES = "properties"; + private final Gson gson = new GsonBuilder().setPrettyPrinting().create(); + @Override public ToscaPolicy deserialize(@NonNull final JsonElement policyElement, @NonNull final Type type, @NonNull final JsonDeserializationContext context) { @@ -94,9 +98,7 @@ public class ToscaPolicyJsonAdapter implements JsonSerializer, Json final JsonObject policyMetadataMapObject = policyJsonObject.get(METADATA).getAsJsonObject(); Map policyMetadataMap = new HashMap<>(); for (Entry entry : policyMetadataMapObject.entrySet()) { - final String policyMetadataEntryKey = entry.getKey(); - final String policyMetadataEntryValue = entry.getValue().getAsString(); - policyMetadataMap.put(policyMetadataEntryKey, policyMetadataEntryValue); + policyMetadataMap.put(entry.getKey(), entry.getValue().getAsString()); } policy.setMetadata(policyMetadataMap); } @@ -104,11 +106,14 @@ public class ToscaPolicyJsonAdapter implements JsonSerializer, Json // Set properties if (policyJsonObject.has(PROPERTIES)) { final JsonObject policyPropertiesMapObject = policyJsonObject.get(PROPERTIES).getAsJsonObject(); - Map propertiesMap = new HashMap<>(); + Map propertiesMap = new HashMap<>(); for (Entry entry : policyPropertiesMapObject.entrySet()) { - final String policyPropertiesEntryKey = entry.getKey(); - final JsonElement policyPropertiesEntryValue = entry.getValue(); - propertiesMap.put(policyPropertiesEntryKey, policyPropertiesEntryValue); + // TODO: This is a HACK, we need to validate the properties against their + // TODO: their data type in their policy type definition in TOSCA, which means reading + // TODO: the policy type from the database and parsing the property value object correctly + // TODO: Here we are simply serializing the property value into a string and storing it + // TODO: unvalidated into the database + propertiesMap.put(entry.getKey(), gson.toJson(entry.getValue())); } policy.setProperties(propertiesMap); } @@ -136,9 +141,7 @@ public class ToscaPolicyJsonAdapter implements JsonSerializer, Json if (policy.getMetadata() != null) { JsonObject metadataMapObject = new JsonObject(); for (Entry entry : policy.getMetadata().entrySet()) { - final String entryKey = entry.getKey(); - final String entryVal = entry.getValue(); - metadataMapObject.addProperty(entryKey, entryVal); + metadataMapObject.addProperty(entry.getKey(), entry.getValue()); } policyValJsonObject.add(METADATA, metadataMapObject); } @@ -146,13 +149,10 @@ public class ToscaPolicyJsonAdapter implements JsonSerializer, Json // Add properties if (policy.getProperties() != null) { JsonObject propertiesMapObject = new JsonObject(); - for (Entry entry : policy.getProperties().entrySet()) { - final String entryKey = entry.getKey(); - JsonElement entryVal = null; - if (entry.getValue() instanceof JsonElement) { - entryVal = (JsonElement) entry.getValue(); - } - propertiesMapObject.add(entryKey, entryVal); + for (Entry entry : policy.getProperties().entrySet()) { + // TODO: This is the other direction of the HACK + JsonObject valueObject = gson.fromJson(entry.getValue(), JsonObject.class); + propertiesMapObject.add(entry.getKey(), valueObject); } policyValJsonObject.add(PROPERTIES, propertiesMapObject); } diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/serialization/ToscaServiceTemplateMessageBodyHandler.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/serialization/ToscaServiceTemplateMessageBodyHandler.java index a386a9cc5..cf3e668b3 100644 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/serialization/ToscaServiceTemplateMessageBodyHandler.java +++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/serialization/ToscaServiceTemplateMessageBodyHandler.java @@ -56,6 +56,7 @@ public class ToscaServiceTemplateMessageBodyHandler extends GsonMessageBodyHandl .registerTypeAdapter(ToscaTopologyTemplate.class, new ToscaTopologyTemplateJsonAdapter()) .registerTypeAdapter(ToscaPolicies.class, new ToscaPoliciesJsonAdapter()) .registerTypeAdapter(ToscaPolicy.class, new ToscaPolicyJsonAdapter()) + .setPrettyPrinting() .create() ); // @formatter:on 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 propertyMap = new HashMap<>(); + Map 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); } } -- 2.16.6