diff options
Diffstat (limited to 'models-provider/src')
5 files changed, 119 insertions, 5 deletions
diff --git a/models-provider/src/test/java/org/onap/policy/models/provider/impl/PolicyLegacyGuardPersistenceTest.java b/models-provider/src/test/java/org/onap/policy/models/provider/impl/PolicyLegacyGuardPersistenceTest.java index 741ae8998..16956ce0a 100644 --- a/models-provider/src/test/java/org/onap/policy/models/provider/impl/PolicyLegacyGuardPersistenceTest.java +++ b/models-provider/src/test/java/org/onap/policy/models/provider/impl/PolicyLegacyGuardPersistenceTest.java @@ -32,16 +32,19 @@ import lombok.NonNull; 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.provider.PolicyModelsProvider; import org.onap.policy.models.provider.PolicyModelsProviderFactory; import org.onap.policy.models.provider.PolicyModelsProviderParameters; +import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate; import org.onap.policy.models.tosca.legacy.concepts.LegacyGuardPolicyInput; import org.onap.policy.models.tosca.legacy.concepts.LegacyGuardPolicyOutput; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.yaml.snakeyaml.Yaml; /** * Test persistence of monitoring policies to and from the database. @@ -72,9 +75,10 @@ public class PolicyLegacyGuardPersistenceTest { * Initialize provider. * * @throws PfModelException on exceptions in the tests + * @throws CoderException on JSON encoding and decoding errors */ @Before - public void setupParameters() throws PfModelException { + public void setupParameters() throws PfModelException, CoderException { PolicyModelsProviderParameters parameters = new PolicyModelsProviderParameters(); parameters.setDatabaseDriver("org.h2.Driver"); parameters.setDatabaseUrl("jdbc:h2:mem:testdb"); @@ -83,6 +87,8 @@ public class PolicyLegacyGuardPersistenceTest { parameters.setPersistenceUnit("ToscaConceptTest"); databaseProvider = new PolicyModelsProviderFactory().createPolicyModelsProvider(parameters); + + createPolicyTypes(); } /** @@ -150,4 +156,25 @@ public class PolicyLegacyGuardPersistenceTest { // All of this dash/underscore stuff is to avoid a checkstyle error around escaping unicode characters assertEquals(policyOutputString.replaceAll("\\s+", ""), actualRetrievedJson.replaceAll("\\s+", "")); } + + 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); + databaseProvider.createPolicyTypes(toscaServiceTemplatePolicyType); + + yamlObject = new Yaml().load( + ResourceUtils.getResourceAsString("policytypes/onap.policies.controlloop.guard.MinMax.yaml")); + yamlAsJsonString = new StandardCoder().encode(yamlObject); + + toscaServiceTemplatePolicyType = standardCoder.decode(yamlAsJsonString, ToscaServiceTemplate.class); + + assertNotNull(toscaServiceTemplatePolicyType); + databaseProvider.createPolicyTypes(toscaServiceTemplatePolicyType); + } } diff --git a/models-provider/src/test/java/org/onap/policy/models/provider/impl/PolicyLegacyOperationalPersistenceTest.java b/models-provider/src/test/java/org/onap/policy/models/provider/impl/PolicyLegacyOperationalPersistenceTest.java index 2e33a11a0..1cb64a835 100644 --- a/models-provider/src/test/java/org/onap/policy/models/provider/impl/PolicyLegacyOperationalPersistenceTest.java +++ b/models-provider/src/test/java/org/onap/policy/models/provider/impl/PolicyLegacyOperationalPersistenceTest.java @@ -31,15 +31,18 @@ import lombok.NonNull; 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.provider.PolicyModelsProvider; import org.onap.policy.models.provider.PolicyModelsProviderFactory; import org.onap.policy.models.provider.PolicyModelsProviderParameters; +import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate; import org.onap.policy.models.tosca.legacy.concepts.LegacyOperationalPolicy; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.yaml.snakeyaml.Yaml; /** * Test persistence of monitoring policies to and from the database. @@ -72,9 +75,10 @@ public class PolicyLegacyOperationalPersistenceTest { * Initialize provider. * * @throws PfModelException on exceptions in the tests + * @throws CoderException on JSON encoding and decoding errors */ @Before - public void setupParameters() throws PfModelException { + public void setupParameters() throws PfModelException, CoderException { PolicyModelsProviderParameters parameters = new PolicyModelsProviderParameters(); parameters.setDatabaseDriver("org.h2.Driver"); parameters.setDatabaseUrl("jdbc:h2:mem:testdb"); @@ -83,6 +87,8 @@ public class PolicyLegacyOperationalPersistenceTest { parameters.setPersistenceUnit("ToscaConceptTest"); databaseProvider = new PolicyModelsProviderFactory().createPolicyModelsProvider(parameters); + + createPolicyTypes(); } /** @@ -145,4 +151,17 @@ public class PolicyLegacyOperationalPersistenceTest { actualRetrievedJson.replaceAll("\\s+", "").replaceAll("u0027", "_-_-_-_").replaceAll("\\\\_-_-_-_", "'")); } + + 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); + databaseProvider.createPolicyTypes(toscaServiceTemplatePolicyType); + } } diff --git a/models-provider/src/test/java/org/onap/policy/models/provider/impl/PolicyPersistenceTest.java b/models-provider/src/test/java/org/onap/policy/models/provider/impl/PolicyPersistenceTest.java index 668f63497..a855d5d24 100644 --- a/models-provider/src/test/java/org/onap/policy/models/provider/impl/PolicyPersistenceTest.java +++ b/models-provider/src/test/java/org/onap/policy/models/provider/impl/PolicyPersistenceTest.java @@ -34,6 +34,7 @@ import lombok.NonNull; 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; @@ -81,9 +82,10 @@ public class PolicyPersistenceTest { * Initialize provider. * * @throws PfModelException on exceptions in the tests + * @throws CoderException on JSON encoding and decoding errors */ @Before - public void setupParameters() throws PfModelException { + public void setupParameters() throws PfModelException, CoderException { PolicyModelsProviderParameters parameters = new PolicyModelsProviderParameters(); parameters.setDatabaseDriver("org.h2.Driver"); parameters.setDatabaseUrl("jdbc:h2:mem:testdb"); @@ -92,6 +94,8 @@ public class PolicyPersistenceTest { parameters.setPersistenceUnit("ToscaConceptTest"); databaseProvider = new PolicyModelsProviderFactory().createPolicyModelsProvider(parameters); + + createPolicyTypes(); } /** @@ -167,4 +171,34 @@ public class PolicyPersistenceTest { } } } + + 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); + databaseProvider.createPolicyTypes(toscaServiceTemplatePolicyType); + + yamlObject = new Yaml().load( + ResourceUtils.getResourceAsString("policytypes/onap.policies.controlloop.Operational.yaml")); + yamlAsJsonString = new StandardCoder().encode(yamlObject); + + toscaServiceTemplatePolicyType = standardCoder.decode(yamlAsJsonString, ToscaServiceTemplate.class); + + assertNotNull(toscaServiceTemplatePolicyType); + databaseProvider.createPolicyTypes(toscaServiceTemplatePolicyType); + + yamlObject = new Yaml().load( + ResourceUtils.getResourceAsString("policytypes/onap.policies.controlloop.guard.FrequencyLimiter.yaml")); + yamlAsJsonString = new StandardCoder().encode(yamlObject); + + toscaServiceTemplatePolicyType = standardCoder.decode(yamlAsJsonString, ToscaServiceTemplate.class); + + assertNotNull(toscaServiceTemplatePolicyType); + databaseProvider.createPolicyTypes(toscaServiceTemplatePolicyType); + } } diff --git a/models-provider/src/test/java/org/onap/policy/models/provider/impl/PolicyToscaPersistenceTest.java b/models-provider/src/test/java/org/onap/policy/models/provider/impl/PolicyToscaPersistenceTest.java index 613c5a2c6..140194276 100644 --- a/models-provider/src/test/java/org/onap/policy/models/provider/impl/PolicyToscaPersistenceTest.java +++ b/models-provider/src/test/java/org/onap/policy/models/provider/impl/PolicyToscaPersistenceTest.java @@ -33,6 +33,7 @@ import lombok.NonNull; 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; @@ -79,9 +80,10 @@ public class PolicyToscaPersistenceTest { * Initialize provider. * * @throws PfModelException on exceptions in the tests + * @throws CoderException on JSON encoding and decoding errors */ @Before - public void setupParameters() throws PfModelException { + public void setupParameters() throws PfModelException, CoderException { PolicyModelsProviderParameters parameters = new PolicyModelsProviderParameters(); parameters.setDatabaseDriver("org.h2.Driver"); parameters.setDatabaseUrl("jdbc:h2:mem:testdb"); @@ -90,6 +92,8 @@ public class PolicyToscaPersistenceTest { parameters.setPersistenceUnit("ToscaConceptTest"); databaseProvider = new PolicyModelsProviderFactory().createPolicyModelsProvider(parameters); + + createPolicyTypes(); } /** @@ -151,4 +155,34 @@ public class PolicyToscaPersistenceTest { assertEquals(incomingPolicy.getType(), databasePolicy.getType()); } } + + 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); + databaseProvider.createPolicyTypes(toscaServiceTemplatePolicyType); + + yamlObject = new Yaml().load( + ResourceUtils.getResourceAsString("policytypes/onap.policies.controlloop.Operational.yaml")); + yamlAsJsonString = new StandardCoder().encode(yamlObject); + + toscaServiceTemplatePolicyType = standardCoder.decode(yamlAsJsonString, ToscaServiceTemplate.class); + + assertNotNull(toscaServiceTemplatePolicyType); + databaseProvider.createPolicyTypes(toscaServiceTemplatePolicyType); + + yamlObject = new Yaml().load( + ResourceUtils.getResourceAsString("policytypes/onap.policies.controlloop.guard.FrequencyLimiter.yaml")); + yamlAsJsonString = new StandardCoder().encode(yamlObject); + + toscaServiceTemplatePolicyType = standardCoder.decode(yamlAsJsonString, ToscaServiceTemplate.class); + + assertNotNull(toscaServiceTemplatePolicyType); + databaseProvider.createPolicyTypes(toscaServiceTemplatePolicyType); + } } diff --git a/models-provider/src/test/java/org/onap/policy/models/provider/impl/PolicyTypePersistenceTest.java b/models-provider/src/test/java/org/onap/policy/models/provider/impl/PolicyTypePersistenceTest.java index 7b541e128..7b7690009 100644 --- a/models-provider/src/test/java/org/onap/policy/models/provider/impl/PolicyTypePersistenceTest.java +++ b/models-provider/src/test/java/org/onap/policy/models/provider/impl/PolicyTypePersistenceTest.java @@ -72,7 +72,7 @@ public class PolicyTypePersistenceTest { "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 |