summaryrefslogtreecommitdiffstats
path: root/models-provider
diff options
context:
space:
mode:
authorliamfallon <liam.fallon@est.tech>2019-03-25 08:09:14 +0000
committerliamfallon <liam.fallon@est.tech>2019-03-25 08:09:14 +0000
commitbde47d7867610f36042d3ce1440c1598d1248fcc (patch)
tree41824c940daa78c00a6c4b8f75b19faccd4638af /models-provider
parent2a245ef80e39a101015efb164de53f1753fa5d47 (diff)
Add provider for Tosca Policies
Provider working from JAVA API call through to database and back for TOSCA policies with full unit test. Issue-ID: POLICY-1195 Change-Id: I82cf3b513b4921dcb2e6726856aa4fbeb7d0d816 Signed-off-by: liamfallon <liam.fallon@est.tech>
Diffstat (limited to 'models-provider')
-rw-r--r--models-provider/src/test/java/org/onap/policy/models/provider/impl/DatabasePolicyModelsProviderTest.java58
-rw-r--r--models-provider/src/test/resources/META-INF/persistence.xml1
2 files changed, 51 insertions, 8 deletions
diff --git a/models-provider/src/test/java/org/onap/policy/models/provider/impl/DatabasePolicyModelsProviderTest.java b/models-provider/src/test/java/org/onap/policy/models/provider/impl/DatabasePolicyModelsProviderTest.java
index 3b30f98f5..498000a89 100644
--- a/models-provider/src/test/java/org/onap/policy/models/provider/impl/DatabasePolicyModelsProviderTest.java
+++ b/models-provider/src/test/java/org/onap/policy/models/provider/impl/DatabasePolicyModelsProviderTest.java
@@ -37,6 +37,9 @@ import org.onap.policy.models.provider.PolicyModelsProviderParameters;
import org.onap.policy.models.tosca.legacy.concepts.LegacyGuardPolicy;
import org.onap.policy.models.tosca.legacy.concepts.LegacyOperationalPolicy;
import org.onap.policy.models.tosca.simple.concepts.ToscaServiceTemplate;
+import org.onap.policy.models.tosca.simple.provider.SimpleToscaProvider;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
* Test the database models provider implementation.
@@ -44,6 +47,8 @@ import org.onap.policy.models.tosca.simple.concepts.ToscaServiceTemplate;
* @author Liam Fallon (liam.fallon@est.tech)
*/
public class DatabasePolicyModelsProviderTest {
+ private static final Logger LOGGER = LoggerFactory.getLogger(SimpleToscaProvider.class);
+
PolicyModelsProviderParameters parameters;
/**
@@ -266,15 +271,51 @@ public class DatabasePolicyModelsProviderTest {
new PolicyModelsProviderFactory().createPolicyModelsProvider(parameters)) {
databaseProvider.init();
- assertNull(databaseProvider.getPolicyTypes(new PfConceptKey()));
- assertNull(databaseProvider.createPolicyTypes(new ToscaServiceTemplate()));
- assertNull(databaseProvider.updatePolicyTypes(new ToscaServiceTemplate()));
- assertNull(databaseProvider.deletePolicyTypes(new PfConceptKey()));
+ try {
+ databaseProvider.getPolicyTypes(new PfConceptKey());
+ fail("test should throw an exception");
+ } catch (Exception npe) {
+ assertEquals("policy type not found: NULL:0.0.0", npe.getMessage());
+ }
+ try {
+ databaseProvider.createPolicyTypes(new ToscaServiceTemplate());
+ } catch (Exception npe) {
+ assertEquals("no policy types specified on service template", npe.getMessage());
+ }
+ try {
+ databaseProvider.updatePolicyTypes(new ToscaServiceTemplate());
+ } catch (Exception npe) {
+ assertEquals("no policy types specified on service template", npe.getMessage());
+ }
+ try {
+ databaseProvider.deletePolicyTypes(new PfConceptKey());
+ fail("test should throw an exception");
+ } catch (Exception npe) {
+ assertEquals("policy type not found: NULL:0.0.0", npe.getMessage());
+ }
- assertNull(databaseProvider.getPolicies(new PfConceptKey()));
- assertNull(databaseProvider.createPolicies(new ToscaServiceTemplate()));
- assertNull(databaseProvider.updatePolicies(new ToscaServiceTemplate()));
- assertNull(databaseProvider.deletePolicies(new PfConceptKey()));
+ try {
+ databaseProvider.getPolicies(new PfConceptKey());
+ fail("test should throw an exception");
+ } catch (Exception npe) {
+ assertEquals("policy not found: NULL:0.0.0", npe.getMessage());
+ }
+ try {
+ databaseProvider.createPolicies(new ToscaServiceTemplate());
+ } catch (Exception npe) {
+ assertEquals("topology template not specified on service template", npe.getMessage());
+ }
+ try {
+ databaseProvider.updatePolicies(new ToscaServiceTemplate());
+ } catch (Exception npe) {
+ assertEquals("topology template not specified on service template", npe.getMessage());
+ }
+ try {
+ databaseProvider.deletePolicies(new PfConceptKey());
+ fail("test should throw an exception");
+ } catch (Exception npe) {
+ assertEquals("policy not found: NULL:0.0.0", npe.getMessage());
+ }
assertNull(databaseProvider.getOperationalPolicy("policy_id"));
assertNull(databaseProvider.createOperationalPolicy(new LegacyOperationalPolicy()));
@@ -292,6 +333,7 @@ public class DatabasePolicyModelsProviderTest {
assertNotNull(databaseProvider.deletePdpGroups("filter"));
} catch (Exception exc) {
+ LOGGER.warn("test should not throw an exception", exc);
fail("test should not throw an exception");
}
}
diff --git a/models-provider/src/test/resources/META-INF/persistence.xml b/models-provider/src/test/resources/META-INF/persistence.xml
index 491505341..68340901b 100644
--- a/models-provider/src/test/resources/META-INF/persistence.xml
+++ b/models-provider/src/test/resources/META-INF/persistence.xml
@@ -26,6 +26,7 @@
<class>org.onap.policy.models.dao.converters.CDataConditioner</class>
<class>org.onap.policy.models.dao.converters.Uuid2String</class>
<class>org.onap.policy.models.base.PfConceptKey</class>
+ <class>org.onap.policy.models.tosca.simple.concepts.ToscaPolicyType</class>
<class>org.onap.policy.models.tosca.simple.concepts.ToscaPolicy</class>
<properties>