diff options
author | liamfallon <liam.fallon@est.tech> | 2019-05-07 12:42:26 +0000 |
---|---|---|
committer | liamfallon <liam.fallon@est.tech> | 2019-05-07 12:42:26 +0000 |
commit | f53879588a464c727ece62f87c7625b47e6de7f1 (patch) | |
tree | 980cddab937c38610587b50cc45a9c36540a2470 /models-tosca/src/test/java/org | |
parent | e936413c9082afed0fef4646b8f12d351c87800c (diff) |
Set default and check existance of Policy Type
The TOSCA specification has a "bug" in that it does not have a field to specify
the version of a policy type to use. We already had introduced the "type_version" field
for this.
This review introduces setting of the default version of a policy type to be
be used by a policy as the latest version of the policy type in the database.
As a side effect of this, we now have to check for existence of the policy type
of a policy in the database. This means that creation/update of a policy with
a non-existant policy type specified will now fail.
Issue-ID: POLICY-1738
Change-Id: I27080cf6cd358948810dab6897c72dfe4d41fe91
Signed-off-by: liamfallon <liam.fallon@est.tech>
Diffstat (limited to 'models-tosca/src/test/java/org')
10 files changed, 115 insertions, 15 deletions
diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyFilterTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyFilterTest.java index f7c9c7ef0..cba3fe591 100644 --- a/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyFilterTest.java +++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyFilterTest.java @@ -211,7 +211,7 @@ public class ToscaPolicyFilterTest { filter = ToscaPolicyFilter.builder().type("onap.policies.monitoring.cdap.tca.hi.lo.app").build(); filteredList = filter.filter(policyList); - assertEquals(2, filteredList.size()); + assertEquals(3, filteredList.size()); filter = ToscaPolicyFilter.builder().type("onap.policies.controlloop.NonOperational").build(); filteredList = filter.filter(policyList); diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyTypeFilterTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyTypeFilterTest.java index 12d81ed53..e0143e676 100644 --- a/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyTypeFilterTest.java +++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyTypeFilterTest.java @@ -63,7 +63,7 @@ public class ToscaPolicyTypeFilterTest { "policytypes/onap.policies.optimization.SubscriberPolicy.yaml", "policytypes/onap.policies.optimization.Vim_fit.yaml", "policytypes/onap.policies.optimization.VnfPolicy.yaml", - "policytypes/onap.policy.monitoring.cdap.tca.hi.lo.app.yaml" + "policytypes/onap.policies.monitoring.cdap.tca.hi.lo.app.yaml" }; // @formatter:on @@ -152,7 +152,7 @@ public class ToscaPolicyTypeFilterTest { List<ToscaPolicyType> filteredList = filter.filter(typeList); assertEquals(2, filteredList.size()); - filter = ToscaPolicyTypeFilter.builder().name("onap.policy.monitoring.cdap.tca.hi.lo.app").build(); + filter = ToscaPolicyTypeFilter.builder().name("onap.policies.monitoring.cdap.tca.hi.lo.app").build(); filteredList = filter.filter(typeList); assertEquals(1, filteredList.size()); diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/provider/AuthorativeToscaProviderPolicyTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/provider/AuthorativeToscaProviderPolicyTest.java index 5ad314ae6..a7f3761a5 100644 --- a/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/provider/AuthorativeToscaProviderPolicyTest.java +++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/provider/AuthorativeToscaProviderPolicyTest.java @@ -33,6 +33,7 @@ import org.eclipse.persistence.config.PersistenceUnitProperties; import org.junit.After; import org.junit.Before; import org.junit.Test; +import org.onap.policy.common.utils.coder.CoderException; import org.onap.policy.common.utils.coder.StandardCoder; import org.onap.policy.common.utils.resources.ResourceUtils; import org.onap.policy.models.base.PfConceptKey; @@ -45,6 +46,7 @@ import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy; import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyFilter; import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate; import org.onap.policy.models.tosca.authorative.concepts.ToscaTopologyTemplate; +import org.yaml.snakeyaml.Yaml; /** * Test of the {@link AuthorativeToscaProvider} class. @@ -75,7 +77,7 @@ public class AuthorativeToscaProviderPolicyTest { jdbcProperties.setProperty(PersistenceUnitProperties.JDBC_DRIVER, "org.h2.Driver"); jdbcProperties.setProperty(PersistenceUnitProperties.JDBC_URL, "jdbc:h2:mem:testdb"); - daoParameters.setJdbcProperties(jdbcProperties ); + daoParameters.setJdbcProperties(jdbcProperties); pfDao = new PfDaoFactory().createPfDao(daoParameters); pfDao.init(daoParameters); @@ -104,6 +106,8 @@ public class AuthorativeToscaProviderPolicyTest { new AuthorativeToscaProvider().getPolicyList(null, null, null); }).hasMessage("dao is marked @NonNull but is null"); + createPolicyTypes(); + ToscaServiceTemplate toscaServiceTemplate = standardCoder.decode( ResourceUtils.getResourceAsString("policies/vCPE.policy.monitoring.input.tosca.json"), ToscaServiceTemplate.class); @@ -176,6 +180,8 @@ public class AuthorativeToscaProviderPolicyTest { new AuthorativeToscaProvider().getFilteredPolicyList(pfDao, null); }).hasMessage("filter is marked @NonNull but is null"); + createPolicyTypes(); + ToscaServiceTemplate toscaServiceTemplate = standardCoder.decode( ResourceUtils.getResourceAsString("policies/vCPE.policy.monitoring.input.tosca.json"), ToscaServiceTemplate.class); @@ -250,6 +256,8 @@ public class AuthorativeToscaProviderPolicyTest { new AuthorativeToscaProvider().createPolicies(pfDao, null); }).hasMessage("serviceTemplate is marked @NonNull but is null"); + createPolicyTypes(); + ToscaServiceTemplate toscaServiceTemplate = standardCoder.decode( ResourceUtils.getResourceAsString("policies/vCPE.policy.monitoring.input.tosca.json"), ToscaServiceTemplate.class); @@ -268,7 +276,6 @@ public class AuthorativeToscaProviderPolicyTest { assertTrue(beforePolicy.getType().equals(createdPolicy.getType())); } - @Test public void testPolicyUpdate() throws Exception { assertThatThrownBy(() -> { @@ -287,6 +294,8 @@ public class AuthorativeToscaProviderPolicyTest { new AuthorativeToscaProvider().updatePolicies(pfDao, null); }).hasMessage("serviceTemplate is marked @NonNull but is null"); + createPolicyTypes(); + ToscaServiceTemplate toscaServiceTemplate = standardCoder.decode( ResourceUtils.getResourceAsString("policies/vCPE.policy.monitoring.input.tosca.json"), ToscaServiceTemplate.class); @@ -343,6 +352,8 @@ public class AuthorativeToscaProviderPolicyTest { new AuthorativeToscaProvider().deletePolicy(pfDao, "name", null); }).hasMessage("version is marked @NonNull but is null"); + createPolicyTypes(); + ToscaServiceTemplate toscaServiceTemplate = standardCoder.decode( ResourceUtils.getResourceAsString("policies/vCPE.policy.monitoring.input.tosca.json"), ToscaServiceTemplate.class); @@ -396,4 +407,16 @@ public class AuthorativeToscaProviderPolicyTest { new AuthorativeToscaProvider().createPolicies(pfDao, testServiceTemplate); }).hasMessage("An incoming list of concepts must have at least one entry"); } + + private void createPolicyTypes() throws CoderException, PfModelException { + Object yamlObject = new Yaml().load( + ResourceUtils.getResourceAsString("policytypes/onap.policies.monitoring.cdap.tca.hi.lo.app.yaml")); + String yamlAsJsonString = new StandardCoder().encode(yamlObject); + + ToscaServiceTemplate toscaServiceTemplatePolicyType = + standardCoder.decode(yamlAsJsonString, ToscaServiceTemplate.class); + + assertNotNull(toscaServiceTemplatePolicyType); + new AuthorativeToscaProvider().createPolicyTypes(pfDao, toscaServiceTemplatePolicyType); + } } diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/provider/ToscaServiceTemplateMappingTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/provider/ToscaServiceTemplateMappingTest.java index a4458a874..b44853428 100644 --- a/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/provider/ToscaServiceTemplateMappingTest.java +++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/provider/ToscaServiceTemplateMappingTest.java @@ -82,7 +82,7 @@ public class ToscaServiceTemplateMappingTest { try { Yaml yaml = new Yaml(); String inputYaml = ResourceUtils.getResourceAsString( - "policytypes/onap.policy.monitoring.cdap.tca.hi.lo.app.yaml"); + "policytypes/onap.policies.monitoring.cdap.tca.hi.lo.app.yaml"); Object yamlObject = yaml.load(inputYaml); String yamlAsJsonString = standardCoder.encode(yamlObject); diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/legacy/provider/LegacyProvider4LegacyGuardTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/legacy/provider/LegacyProvider4LegacyGuardTest.java index 71254ec6f..6ddf1aeeb 100644 --- a/models-tosca/src/test/java/org/onap/policy/models/tosca/legacy/provider/LegacyProvider4LegacyGuardTest.java +++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/legacy/provider/LegacyProvider4LegacyGuardTest.java @@ -31,15 +31,20 @@ import org.eclipse.persistence.config.PersistenceUnitProperties; import org.junit.After; import org.junit.Before; import org.junit.Test; +import org.onap.policy.common.utils.coder.CoderException; import org.onap.policy.common.utils.coder.StandardCoder; import org.onap.policy.common.utils.resources.ResourceUtils; +import org.onap.policy.models.base.PfModelException; 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.authorative.concepts.ToscaServiceTemplate; +import org.onap.policy.models.tosca.authorative.provider.AuthorativeToscaProvider; import org.onap.policy.models.tosca.legacy.concepts.LegacyGuardPolicyContent; import org.onap.policy.models.tosca.legacy.concepts.LegacyGuardPolicyInput; import org.onap.policy.models.tosca.legacy.concepts.LegacyGuardPolicyOutput; +import org.yaml.snakeyaml.Yaml; /** * Test the {@link LegacyProvider} class for legacy guard policies. @@ -108,6 +113,8 @@ public class LegacyProvider4LegacyGuardTest { new LegacyProvider().getGuardPolicy(pfDao, "I Dont Exist"); }).hasMessage("no policy found for policy ID: I Dont Exist"); + createPolicyTypes(); + LegacyGuardPolicyInput originalGip = standardCoder.decode( ResourceUtils.getResourceAsString("policies/vDNS.policy.guard.frequency.input.json"), LegacyGuardPolicyInput.class); @@ -148,6 +155,8 @@ public class LegacyProvider4LegacyGuardTest { new LegacyProvider().createGuardPolicy(pfDao, null); }).hasMessage("legacyGuardPolicy is marked @NonNull but is null"); + createPolicyTypes(); + LegacyGuardPolicyInput originalGip = standardCoder.decode( ResourceUtils.getResourceAsString("policies/vDNS.policy.guard.frequency.input.json"), LegacyGuardPolicyInput.class); @@ -174,7 +183,6 @@ public class LegacyProvider4LegacyGuardTest { assertEquals(expectedJsonOutput.replaceAll("\\s+", ""), actualJsonOutput.replaceAll("\\s+", "")); } - @Test public void testPolicyUpdate() throws Exception { assertThatThrownBy(() -> { @@ -193,6 +201,8 @@ public class LegacyProvider4LegacyGuardTest { new LegacyProvider().updateGuardPolicy(pfDao, new LegacyGuardPolicyInput()); }).hasMessage("policy type for guard policy \"null\" unknown"); + createPolicyTypes(); + LegacyGuardPolicyInput originalGip = standardCoder.decode( ResourceUtils.getResourceAsString("policies/vDNS.policy.guard.frequency.input.json"), LegacyGuardPolicyInput.class); @@ -246,6 +256,8 @@ public class LegacyProvider4LegacyGuardTest { new LegacyProvider().deleteGuardPolicy(pfDao, "I Dont Exist"); }).hasMessage("no policy found for policy ID: I Dont Exist"); + createPolicyTypes(); + LegacyGuardPolicyInput originalGip = standardCoder.decode( ResourceUtils.getResourceAsString("policies/vDNS.policy.guard.frequency.input.json"), LegacyGuardPolicyInput.class); @@ -294,4 +306,25 @@ public class LegacyProvider4LegacyGuardTest { new LegacyProvider().getGuardPolicy(pfDao, originalGip.getPolicyId()); }).hasMessage("no policy found for policy ID: guard.frequency.scaleout"); } + + private void createPolicyTypes() throws CoderException, PfModelException { + Object yamlObject = new Yaml().load( + ResourceUtils.getResourceAsString("policytypes/onap.policies.controlloop.guard.FrequencyLimiter.yaml")); + String yamlAsJsonString = new StandardCoder().encode(yamlObject); + + ToscaServiceTemplate toscaServiceTemplatePolicyType = + standardCoder.decode(yamlAsJsonString, ToscaServiceTemplate.class); + + assertNotNull(toscaServiceTemplatePolicyType); + new AuthorativeToscaProvider().createPolicyTypes(pfDao, toscaServiceTemplatePolicyType); + + yamlObject = new Yaml() + .load(ResourceUtils.getResourceAsString("policytypes/onap.policies.controlloop.guard.Blacklist.yaml")); + yamlAsJsonString = new StandardCoder().encode(yamlObject); + + toscaServiceTemplatePolicyType = standardCoder.decode(yamlAsJsonString, ToscaServiceTemplate.class); + + assertNotNull(toscaServiceTemplatePolicyType); + new AuthorativeToscaProvider().createPolicyTypes(pfDao, toscaServiceTemplatePolicyType); + } } diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/legacy/provider/LegacyProvider4LegacyOperationalTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/legacy/provider/LegacyProvider4LegacyOperationalTest.java index c018aae7b..7ab5c581e 100644 --- a/models-tosca/src/test/java/org/onap/policy/models/tosca/legacy/provider/LegacyProvider4LegacyOperationalTest.java +++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/legacy/provider/LegacyProvider4LegacyOperationalTest.java @@ -30,13 +30,18 @@ import org.eclipse.persistence.config.PersistenceUnitProperties; import org.junit.After; import org.junit.Before; import org.junit.Test; +import org.onap.policy.common.utils.coder.CoderException; import org.onap.policy.common.utils.coder.StandardCoder; import org.onap.policy.common.utils.resources.ResourceUtils; +import org.onap.policy.models.base.PfModelException; 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.authorative.concepts.ToscaServiceTemplate; +import org.onap.policy.models.tosca.authorative.provider.AuthorativeToscaProvider; import org.onap.policy.models.tosca.legacy.concepts.LegacyOperationalPolicy; +import org.yaml.snakeyaml.Yaml; /** * Test the {@link LegacyProvider} class for legacy operational policies. @@ -104,6 +109,8 @@ public class LegacyProvider4LegacyOperationalTest { new LegacyProvider().getOperationalPolicy(pfDao, "I Dont Exist"); }).hasMessage("no policy found for policy ID: I Dont Exist"); + createPolicyTypes(); + LegacyOperationalPolicy originalLop = standardCoder.decode(ResourceUtils.getResourceAsString("policies/vCPE.policy.operational.input.json"), LegacyOperationalPolicy.class); @@ -142,6 +149,8 @@ public class LegacyProvider4LegacyOperationalTest { new LegacyProvider().createOperationalPolicy(pfDao, null); }).hasMessage("legacyOperationalPolicy is marked @NonNull but is null"); + createPolicyTypes(); + LegacyOperationalPolicy originalLop = standardCoder.decode(ResourceUtils.getResourceAsString("policies/vCPE.policy.operational.input.json"), LegacyOperationalPolicy.class); @@ -162,7 +171,6 @@ public class LegacyProvider4LegacyOperationalTest { assertEquals(expectedJsonOutput.replaceAll("\\s+", ""), actualJsonOutput.replaceAll("\\s+", "")); } - @Test public void testPolicyUpdate() throws Exception { assertThatThrownBy(() -> { @@ -181,6 +189,8 @@ public class LegacyProvider4LegacyOperationalTest { new LegacyProvider().updateOperationalPolicy(pfDao, new LegacyOperationalPolicy()); }).hasMessage("no policy found for policy ID: null"); + createPolicyTypes(); + LegacyOperationalPolicy originalLop = standardCoder.decode(ResourceUtils.getResourceAsString("policies/vCPE.policy.operational.input.json"), LegacyOperationalPolicy.class); @@ -203,7 +213,6 @@ public class LegacyProvider4LegacyOperationalTest { assertEquals("Some New Content", gotUpdatedLop.getContent()); } - @Test public void testPoliciesDelete() throws Exception { assertThatThrownBy(() -> { @@ -212,17 +221,19 @@ public class LegacyProvider4LegacyOperationalTest { assertThatThrownBy(() -> { new LegacyProvider().deleteOperationalPolicy(null, ""); + }).hasMessage("dao is marked @NonNull but is null"); assertThatThrownBy(() -> { new LegacyProvider().deleteOperationalPolicy(pfDao, null); }).hasMessage("policyId is marked @NonNull but is null"); - assertThatThrownBy(() -> { new LegacyProvider().deleteOperationalPolicy(pfDao, "I Dont Exist"); }).hasMessage("no policy found for policy ID: I Dont Exist"); + createPolicyTypes(); + LegacyOperationalPolicy originalLop = standardCoder.decode(ResourceUtils.getResourceAsString("policies/vCPE.policy.operational.input.json"), LegacyOperationalPolicy.class); @@ -260,6 +271,17 @@ public class LegacyProvider4LegacyOperationalTest { assertThatThrownBy(() -> { new LegacyProvider().getOperationalPolicy(pfDao, originalLop.getPolicyId()); }).hasMessage("no policy found for policy ID: operational.restart"); + } + + private void createPolicyTypes() throws CoderException, PfModelException { + Object yamlObject = new Yaml().load( + ResourceUtils.getResourceAsString("policytypes/onap.policies.controlloop.Operational.yaml")); + String yamlAsJsonString = new StandardCoder().encode(yamlObject); + + ToscaServiceTemplate toscaServiceTemplatePolicyType = + standardCoder.decode(yamlAsJsonString, ToscaServiceTemplate.class); + assertNotNull(toscaServiceTemplatePolicyType); + new AuthorativeToscaProvider().createPolicyTypes(pfDao, toscaServiceTemplatePolicyType); } } diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicyTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicyTest.java index ae38ab916..924cdab53 100644 --- a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicyTest.java +++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicyTest.java @@ -129,7 +129,6 @@ public class JpaToscaPolicyTest { assertEquals(tdtClone0, tp); assertFalse(new JpaToscaPolicy().validate(new PfValidationResult()).isValid()); - System.err.println(tp.validate(new PfValidationResult())); assertTrue(tp.validate(new PfValidationResult()).isValid()); tp.getProperties().put(null, null); diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/provider/SimpleToscaProviderTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/provider/SimpleToscaProviderTest.java index 1f582cf84..4d71d0ddd 100644 --- a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/provider/SimpleToscaProviderTest.java +++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/provider/SimpleToscaProviderTest.java @@ -32,6 +32,7 @@ import org.eclipse.persistence.config.PersistenceUnitProperties; import org.junit.After; import org.junit.Before; import org.junit.Test; +import org.onap.policy.common.utils.coder.CoderException; import org.onap.policy.common.utils.coder.StandardCoder; import org.onap.policy.common.utils.resources.ResourceUtils; import org.onap.policy.models.base.PfConceptKey; @@ -41,9 +42,11 @@ 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.authorative.concepts.ToscaServiceTemplate; +import org.onap.policy.models.tosca.authorative.provider.AuthorativeToscaProvider; import org.onap.policy.models.tosca.simple.concepts.JpaToscaPolicies; import org.onap.policy.models.tosca.simple.concepts.JpaToscaServiceTemplate; import org.onap.policy.models.tosca.simple.concepts.JpaToscaTopologyTemplate; +import org.yaml.snakeyaml.Yaml; /** * Test the {@link SimpleToscaProvider} class. @@ -99,6 +102,8 @@ public class SimpleToscaProviderTest { ResourceUtils.getResourceAsString("policies/vCPE.policy.monitoring.input.tosca.json"), ToscaServiceTemplate.class); + createPolicyTypes(); + JpaToscaServiceTemplate originalServiceTemplate = new JpaToscaServiceTemplate(); originalServiceTemplate.fromAuthorative(toscaServiceTemplate); @@ -124,6 +129,8 @@ public class SimpleToscaProviderTest { ResourceUtils.getResourceAsString("policies/vCPE.policy.monitoring.input.tosca.json"), ToscaServiceTemplate.class); + createPolicyTypes(); + JpaToscaServiceTemplate originalServiceTemplate = new JpaToscaServiceTemplate(); originalServiceTemplate.fromAuthorative(toscaServiceTemplate); @@ -140,6 +147,8 @@ public class SimpleToscaProviderTest { ResourceUtils.getResourceAsString("policies/vCPE.policy.monitoring.input.tosca.json"), ToscaServiceTemplate.class); + createPolicyTypes(); + JpaToscaServiceTemplate originalServiceTemplate = new JpaToscaServiceTemplate(); originalServiceTemplate.fromAuthorative(toscaServiceTemplate); @@ -156,6 +165,8 @@ public class SimpleToscaProviderTest { ResourceUtils.getResourceAsString("policies/vCPE.policy.monitoring.input.tosca.json"), ToscaServiceTemplate.class); + createPolicyTypes(); + JpaToscaServiceTemplate originalServiceTemplate = new JpaToscaServiceTemplate(); originalServiceTemplate.fromAuthorative(toscaServiceTemplate); @@ -288,4 +299,16 @@ public class SimpleToscaProviderTest { new SimpleToscaProvider().deletePolicy(pfDao, null); }).hasMessage("policyKey is marked @NonNull but is null"); } + + private void createPolicyTypes() throws CoderException, PfModelException { + Object yamlObject = new Yaml().load( + ResourceUtils.getResourceAsString("policytypes/onap.policies.monitoring.cdap.tca.hi.lo.app.yaml")); + String yamlAsJsonString = new StandardCoder().encode(yamlObject); + + ToscaServiceTemplate toscaServiceTemplatePolicyType = + standardCoder.decode(yamlAsJsonString, ToscaServiceTemplate.class); + + assertNotNull(toscaServiceTemplatePolicyType); + new AuthorativeToscaProvider().createPolicyTypes(pfDao, toscaServiceTemplatePolicyType); + } } 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 9d9ee608d..f05e2e6ef 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 @@ -297,7 +297,7 @@ public class MonitoringPolicySerializationTest { JsonObject policy = policiesJsonArray.iterator().next().getAsJsonObject(); assertNotNull(policy.get("onap.vfirewall.tca")); JsonObject policyVal = policy.get("onap.vfirewall.tca").getAsJsonObject(); - assertEquals("onap.policy.monitoring.cdap.tca.hi.lo.app", policyVal.get("type").getAsString()); + assertEquals("onap.policies.monitoring.cdap.tca.hi.lo.app", policyVal.get("type").getAsString()); assertEquals("1.0.0", policyVal.get("version").getAsString()); assertEquals("onap.vfirewall.tca", policyVal.get("metadata").getAsJsonObject().get("policy-id") .getAsString()); diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/serialization/MonitoringPolicyTypeSerializationTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/serialization/MonitoringPolicyTypeSerializationTest.java index 569e1ad41..0e053f182 100644 --- a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/serialization/MonitoringPolicyTypeSerializationTest.java +++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/serialization/MonitoringPolicyTypeSerializationTest.java @@ -57,7 +57,7 @@ public class MonitoringPolicyTypeSerializationTest { private static final Logger LOGGER = LoggerFactory.getLogger(MonitoringPolicyTypeSerializationTest.class); - private static final String MONITORING_TCA_YAML = "policytypes/onap.policy.monitoring.cdap.tca.hi.lo.app.yaml"; + private static final String MONITORING_TCA_YAML = "policytypes/onap.policies.monitoring.cdap.tca.hi.lo.app.yaml"; private static final String MONITORING_COLLECTORS_YAML = "policytypes/onap.policies.monitoring.dcaegen2.collectors.datafile.datafile-app-server.yaml"; @@ -155,13 +155,13 @@ public class MonitoringPolicyTypeSerializationTest { firstPolicyType.getValue().getDescription()); Entry<PfConceptKey, JpaToscaPolicyType> secondPolicyType = policyTypesIter.next(); - assertEquals("onap.policy.monitoring.cdap.tca.hi.lo.app", secondPolicyType.getKey().getName()); + assertEquals("onap.policies.monitoring.cdap.tca.hi.lo.app", secondPolicyType.getKey().getName()); assertEquals("1.0.0", secondPolicyType.getKey().getVersion()); assertEquals("onap.policies.Monitoring", secondPolicyType.getValue().getDerivedFrom().getName()); assertTrue(secondPolicyType.getValue().getProperties().size() == 1); JpaToscaProperty property = secondPolicyType.getValue().getProperties().values().iterator().next(); - assertEquals("onap.policy.monitoring.cdap.tca.hi.lo.app", property.getKey().getParentKeyName()); + assertEquals("onap.policies.monitoring.cdap.tca.hi.lo.app", property.getKey().getParentKeyName()); assertEquals("1.0.0", property.getKey().getParentKeyVersion()); assertEquals("tca_policy", property.getKey().getLocalName()); assertEquals("map", property.getType().getName()); |