summaryrefslogtreecommitdiffstats
path: root/models-tosca/src/test/java
diff options
context:
space:
mode:
authorliamfallon <liam.fallon@est.tech>2020-01-07 18:26:53 +0000
committerliamfallon <liam.fallon@est.tech>2020-01-08 09:23:18 +0000
commit2ed313e69cfd0a587f072079e23ab8f6499518db (patch)
tree9e461ea953297a02d07337a46a021dcd86f03f07 /models-tosca/src/test/java
parentf69b6681486e4d1c5859f649a3293488c1859712 (diff)
Store and return data types for policies
In this change, the data types of policy types are persisted to the database. All policy types currently in the database are returned on all policy type get requests. This will be made more intelligent in the next review. Issue-ID: POLICY-2315 Change-Id: I10065ab9b90e72114a453494fc706d8aabc50c0a Signed-off-by: liamfallon <liam.fallon@est.tech>
Diffstat (limited to 'models-tosca/src/test/java')
-rw-r--r--models-tosca/src/test/java/org/onap/policy/models/tosca/simple/provider/SimpleToscaProviderTest.java98
-rw-r--r--models-tosca/src/test/java/org/onap/policy/models/tosca/utils/ToscaUtilsTest.java31
2 files changed, 129 insertions, 0 deletions
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 db6dc52b6..63ebcbd24 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
@@ -46,6 +46,8 @@ import org.onap.policy.models.tosca.authorative.provider.AuthorativeToscaProvide
import org.onap.policy.models.tosca.simple.concepts.JpaToscaDataType;
import org.onap.policy.models.tosca.simple.concepts.JpaToscaDataTypes;
import org.onap.policy.models.tosca.simple.concepts.JpaToscaPolicies;
+import org.onap.policy.models.tosca.simple.concepts.JpaToscaPolicyType;
+import org.onap.policy.models.tosca.simple.concepts.JpaToscaPolicyTypes;
import org.onap.policy.models.tosca.simple.concepts.JpaToscaServiceTemplate;
import org.onap.policy.models.tosca.simple.concepts.JpaToscaTopologyTemplate;
import org.yaml.snakeyaml.Yaml;
@@ -114,6 +116,7 @@ public class SimpleToscaProviderTest {
JpaToscaServiceTemplate createdServiceTemplate =
new SimpleToscaProvider().createDataTypes(pfDao, serviceTemplate);
+ assertEquals(1, createdServiceTemplate.getDataTypes().getConceptMap().size());
assertEquals(dataType0, createdServiceTemplate.getDataTypes().get(dataType0Key));
assertEquals(null, createdServiceTemplate.getDataTypes().get(dataType0Key).getDescription());
@@ -143,6 +146,101 @@ public class SimpleToscaProviderTest {
}
@Test
+ public void testCreateUpdateGetDeletePolicyType() throws PfModelException {
+ JpaToscaServiceTemplate serviceTemplate = new JpaToscaServiceTemplate();
+
+ PfConceptKey dataType0Key = new PfConceptKey("DataType0", "0.0.1");
+ JpaToscaDataType dataType0 = new JpaToscaDataType();
+ dataType0.setKey(dataType0Key);
+ serviceTemplate.setDataTypes(new JpaToscaDataTypes());
+ serviceTemplate.getDataTypes().getConceptMap().put(dataType0Key, dataType0);
+
+ PfConceptKey policyType0Key = new PfConceptKey("PolicyType0", "0.0.1");
+ JpaToscaPolicyType policyType0 = new JpaToscaPolicyType();
+ policyType0.setKey(policyType0Key);
+ serviceTemplate.setPolicyTypes(new JpaToscaPolicyTypes());
+ serviceTemplate.getPolicyTypes().getConceptMap().put(policyType0Key, policyType0);
+
+ JpaToscaServiceTemplate createdServiceTemplate =
+ new SimpleToscaProvider().createPolicyTypes(pfDao, serviceTemplate);
+
+ assertEquals(1, createdServiceTemplate.getPolicyTypes().getConceptMap().size());
+ assertEquals(policyType0, createdServiceTemplate.getPolicyTypes().get(policyType0Key));
+ assertEquals(null, createdServiceTemplate.getPolicyTypes().get(policyType0Key).getDescription());
+
+ policyType0.setDescription("Updated Description");
+
+ JpaToscaServiceTemplate updatedServiceTemplate =
+ new SimpleToscaProvider().updatePolicyTypes(pfDao, serviceTemplate);
+
+ assertEquals(policyType0, updatedServiceTemplate.getPolicyTypes().get(policyType0Key));
+ assertEquals("Updated Description",
+ updatedServiceTemplate.getPolicyTypes().get(policyType0Key).getDescription());
+
+ JpaToscaServiceTemplate gotServiceTemplate =
+ new SimpleToscaProvider().getPolicyTypes(pfDao, policyType0Key.getName(), policyType0Key.getVersion());
+
+ assertEquals(policyType0, gotServiceTemplate.getPolicyTypes().get(policyType0Key));
+ assertEquals("Updated Description", gotServiceTemplate.getPolicyTypes().get(policyType0Key).getDescription());
+
+ JpaToscaServiceTemplate deletedServiceTemplate =
+ new SimpleToscaProvider().deletePolicyType(pfDao, policyType0Key);
+
+ assertEquals(policyType0, deletedServiceTemplate.getPolicyTypes().get(policyType0Key));
+ assertEquals("Updated Description",
+ deletedServiceTemplate.getPolicyTypes().get(policyType0Key).getDescription());
+
+ JpaToscaServiceTemplate doesNotExistServiceTemplate =
+ new SimpleToscaProvider().deletePolicyType(pfDao, policyType0Key);
+
+ assertEquals(null, doesNotExistServiceTemplate.getPolicyTypes().get(policyType0Key));
+ }
+
+ @Test
+ public void testCreateUpdateGetDeletePolicyTypeWithDataType() throws PfModelException {
+ JpaToscaServiceTemplate serviceTemplate = new JpaToscaServiceTemplate();
+
+ PfConceptKey policyType0Key = new PfConceptKey("PolicyType0", "0.0.1");
+ JpaToscaPolicyType policyType0 = new JpaToscaPolicyType();
+ policyType0.setKey(policyType0Key);
+ serviceTemplate.setPolicyTypes(new JpaToscaPolicyTypes());
+ serviceTemplate.getPolicyTypes().getConceptMap().put(policyType0Key, policyType0);
+
+ JpaToscaServiceTemplate createdServiceTemplate =
+ new SimpleToscaProvider().createPolicyTypes(pfDao, serviceTemplate);
+
+ assertEquals(policyType0, createdServiceTemplate.getPolicyTypes().get(policyType0Key));
+ assertEquals(null, createdServiceTemplate.getPolicyTypes().get(policyType0Key).getDescription());
+
+ policyType0.setDescription("Updated Description");
+
+ JpaToscaServiceTemplate updatedServiceTemplate =
+ new SimpleToscaProvider().updatePolicyTypes(pfDao, serviceTemplate);
+
+ assertEquals(policyType0, updatedServiceTemplate.getPolicyTypes().get(policyType0Key));
+ assertEquals("Updated Description",
+ updatedServiceTemplate.getPolicyTypes().get(policyType0Key).getDescription());
+
+ JpaToscaServiceTemplate gotServiceTemplate =
+ new SimpleToscaProvider().getPolicyTypes(pfDao, policyType0Key.getName(), policyType0Key.getVersion());
+
+ assertEquals(policyType0, gotServiceTemplate.getPolicyTypes().get(policyType0Key));
+ assertEquals("Updated Description", gotServiceTemplate.getPolicyTypes().get(policyType0Key).getDescription());
+
+ JpaToscaServiceTemplate deletedServiceTemplate =
+ new SimpleToscaProvider().deletePolicyType(pfDao, policyType0Key);
+
+ assertEquals(policyType0, deletedServiceTemplate.getPolicyTypes().get(policyType0Key));
+ assertEquals("Updated Description",
+ deletedServiceTemplate.getPolicyTypes().get(policyType0Key).getDescription());
+
+ JpaToscaServiceTemplate doesNotExistServiceTemplate =
+ new SimpleToscaProvider().deletePolicyType(pfDao, policyType0Key);
+
+ assertEquals(null, doesNotExistServiceTemplate.getPolicyTypes().get(policyType0Key));
+ }
+
+ @Test
public void testPoliciesGet() throws Exception {
ToscaServiceTemplate toscaServiceTemplate =
standardCoder.decode(ResourceUtils.getResourceAsString(VCPE_INPUT_JSON), ToscaServiceTemplate.class);
diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/utils/ToscaUtilsTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/utils/ToscaUtilsTest.java
index b7c814a5e..82636940c 100644
--- a/models-tosca/src/test/java/org/onap/policy/models/tosca/utils/ToscaUtilsTest.java
+++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/utils/ToscaUtilsTest.java
@@ -22,6 +22,9 @@ package org.onap.policy.models.tosca.utils;
import static org.assertj.core.api.Assertions.assertThatCode;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
import org.junit.Test;
import org.onap.policy.models.base.PfConceptKey;
@@ -42,39 +45,56 @@ public class ToscaUtilsTest {
public void testAssertDataTypes() {
JpaToscaServiceTemplate jpaToscaServiceTemplate = new JpaToscaServiceTemplate();
+ assertFalse(ToscaUtils.doDataTypesExist(jpaToscaServiceTemplate));
+ assertEquals("no data types specified on service template",
+ ToscaUtils.checkDataTypesExist(jpaToscaServiceTemplate));
assertThatThrownBy(() -> {
ToscaUtils.assertDataTypesExist(jpaToscaServiceTemplate);
}).hasMessage("no data types specified on service template");
jpaToscaServiceTemplate.setDataTypes(new JpaToscaDataTypes());
+ assertFalse(ToscaUtils.doDataTypesExist(jpaToscaServiceTemplate));
+ assertEquals("list of data types specified on service template is empty",
+ ToscaUtils.checkDataTypesExist(jpaToscaServiceTemplate));
assertThatThrownBy(() -> {
ToscaUtils.assertDataTypesExist(jpaToscaServiceTemplate);
}).hasMessage("list of data types specified on service template is empty");
jpaToscaServiceTemplate.getDataTypes().getConceptMap().put(new PfConceptKey(), null);
+ assertTrue(ToscaUtils.doDataTypesExist(jpaToscaServiceTemplate));
+ assertEquals(null, ToscaUtils.checkDataTypesExist(jpaToscaServiceTemplate));
assertThatCode(() -> {
ToscaUtils.assertDataTypesExist(jpaToscaServiceTemplate);
}).doesNotThrowAnyException();
+
}
@Test
public void testAssertPolicyTypes() {
JpaToscaServiceTemplate jpaToscaServiceTemplate = new JpaToscaServiceTemplate();
+ assertFalse(ToscaUtils.doPolicyTypesExist(jpaToscaServiceTemplate));
+ assertEquals("no policy types specified on service template",
+ ToscaUtils.checkPolicyTypesExist(jpaToscaServiceTemplate));
assertThatThrownBy(() -> {
ToscaUtils.assertPolicyTypesExist(jpaToscaServiceTemplate);
}).hasMessage("no policy types specified on service template");
jpaToscaServiceTemplate.setPolicyTypes(new JpaToscaPolicyTypes());
+ assertFalse(ToscaUtils.doPolicyTypesExist(jpaToscaServiceTemplate));
+ assertEquals("list of policy types specified on service template is empty",
+ ToscaUtils.checkPolicyTypesExist(jpaToscaServiceTemplate));
assertThatThrownBy(() -> {
ToscaUtils.assertPolicyTypesExist(jpaToscaServiceTemplate);
}).hasMessage("list of policy types specified on service template is empty");
jpaToscaServiceTemplate.getPolicyTypes().getConceptMap().put(new PfConceptKey(), null);
+ assertTrue(ToscaUtils.doPolicyTypesExist(jpaToscaServiceTemplate));
+ assertEquals(null, ToscaUtils.checkPolicyTypesExist(jpaToscaServiceTemplate));
assertThatCode(() -> {
ToscaUtils.assertPolicyTypesExist(jpaToscaServiceTemplate);
}).doesNotThrowAnyException();
@@ -84,24 +104,35 @@ public class ToscaUtilsTest {
public void testAssertPolicies() {
JpaToscaServiceTemplate jpaToscaServiceTemplate = new JpaToscaServiceTemplate();
+ assertFalse(ToscaUtils.doPoliciesExist(jpaToscaServiceTemplate));
+ assertEquals("topology template not specified on service template",
+ ToscaUtils.checkPoliciesExist(jpaToscaServiceTemplate));
assertThatThrownBy(() -> {
ToscaUtils.assertPoliciesExist(jpaToscaServiceTemplate);
}).hasMessage("topology template not specified on service template");
jpaToscaServiceTemplate.setTopologyTemplate(new JpaToscaTopologyTemplate());
+ assertFalse(ToscaUtils.doPoliciesExist(jpaToscaServiceTemplate));
+ assertEquals("no policies specified on topology template of service template",
+ ToscaUtils.checkPoliciesExist(jpaToscaServiceTemplate));
assertThatThrownBy(() -> {
ToscaUtils.assertPoliciesExist(jpaToscaServiceTemplate);
}).hasMessage("no policies specified on topology template of service template");
jpaToscaServiceTemplate.getTopologyTemplate().setPolicies(new JpaToscaPolicies());
+ assertFalse(ToscaUtils.doPoliciesExist(jpaToscaServiceTemplate));
+ assertEquals("list of policies specified on topology template of service template is empty",
+ ToscaUtils.checkPoliciesExist(jpaToscaServiceTemplate));
assertThatThrownBy(() -> {
ToscaUtils.assertPoliciesExist(jpaToscaServiceTemplate);
}).hasMessage("list of policies specified on topology template of service template is empty");
jpaToscaServiceTemplate.getTopologyTemplate().getPolicies().getConceptMap().put(new PfConceptKey(), null);
+ assertTrue(ToscaUtils.doPoliciesExist(jpaToscaServiceTemplate));
+ assertEquals(null, ToscaUtils.checkPoliciesExist(jpaToscaServiceTemplate));
assertThatCode(() -> {
ToscaUtils.assertPoliciesExist(jpaToscaServiceTemplate);
}).doesNotThrowAnyException();