aboutsummaryrefslogtreecommitdiffstats
path: root/models-provider/src/test/java/org
diff options
context:
space:
mode:
authorliamfallon <liam.fallon@est.tech>2019-05-07 12:42:26 +0000
committerliamfallon <liam.fallon@est.tech>2019-05-07 12:42:26 +0000
commitf53879588a464c727ece62f87c7625b47e6de7f1 (patch)
tree980cddab937c38610587b50cc45a9c36540a2470 /models-provider/src/test/java/org
parente936413c9082afed0fef4646b8f12d351c87800c (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-provider/src/test/java/org')
-rw-r--r--models-provider/src/test/java/org/onap/policy/models/provider/impl/PolicyLegacyGuardPersistenceTest.java29
-rw-r--r--models-provider/src/test/java/org/onap/policy/models/provider/impl/PolicyLegacyOperationalPersistenceTest.java21
-rw-r--r--models-provider/src/test/java/org/onap/policy/models/provider/impl/PolicyPersistenceTest.java36
-rw-r--r--models-provider/src/test/java/org/onap/policy/models/provider/impl/PolicyToscaPersistenceTest.java36
-rw-r--r--models-provider/src/test/java/org/onap/policy/models/provider/impl/PolicyTypePersistenceTest.java2
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