summaryrefslogtreecommitdiffstats
path: root/models-provider/src/test/java/org
diff options
context:
space:
mode:
authorliamfallon <liam.fallon@est.tech>2020-03-20 12:50:35 +0000
committerliamfallon <liam.fallon@est.tech>2020-03-20 12:50:38 +0000
commit99bfdc2584c408970d9d9cdc0e8ab869dc126edb (patch)
tree82d06fc27c428539cc407aa9c8f6b9a1c022a604 /models-provider/src/test/java/org
parentdba4f913f6e130fa14db3b3465e922310d683cd5 (diff)
Test cascaded multiple revision gets
This patch tests cascaded get requests with multiple revisions. Issue-ID: POLICY-2377 Change-Id: Ie7dc849d7b930b861d38c386a9950ae7e84e2a05 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/revisionhierarchy/HierarchyFetchTest.java269
1 files changed, 269 insertions, 0 deletions
diff --git a/models-provider/src/test/java/org/onap/policy/models/provider/revisionhierarchy/HierarchyFetchTest.java b/models-provider/src/test/java/org/onap/policy/models/provider/revisionhierarchy/HierarchyFetchTest.java
index 2f36f9a3c..043968bc7 100644
--- a/models-provider/src/test/java/org/onap/policy/models/provider/revisionhierarchy/HierarchyFetchTest.java
+++ b/models-provider/src/test/java/org/onap/policy/models/provider/revisionhierarchy/HierarchyFetchTest.java
@@ -21,8 +21,12 @@
package org.onap.policy.models.provider.revisionhierarchy;
import static org.assertj.core.api.Assertions.assertThatCode;
+import static org.junit.Assert.assertEquals;
import java.util.Base64;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
import org.junit.BeforeClass;
import org.junit.Test;
@@ -31,6 +35,8 @@ import org.onap.policy.common.utils.resources.TextFileUtils;
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.ToscaPolicy;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyType;
import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
public class HierarchyFetchTest {
@@ -61,6 +67,269 @@ public class HierarchyFetchTest {
databaseProvider.createPolicies(serviceTemplate);
}).doesNotThrowAnyException();
+ ToscaServiceTemplate fetchedServiceTemplate = databaseProvider.getPolicies(null, null);
+
+ assertLatestDataTypesAreReturned(fetchedServiceTemplate);
+ assertLatestPolicyTypesAreReturned(fetchedServiceTemplate);
+ assertEquals(12, countReturnedPolicies(fetchedServiceTemplate));
+
+ fetchedServiceTemplate = databaseProvider.getPolicyTypes(null, null);
+ assertLatestDataTypesAreReturned(fetchedServiceTemplate);
+ assertLatestPolicyTypesAreReturned(fetchedServiceTemplate);
+
+ fetchedServiceTemplate = databaseProvider.getPolicies("onap.policies.PolicyLevel0", null);
+ assertLatestDataTypesAreReturned(fetchedServiceTemplate);
+ assertEquals(1, fetchedServiceTemplate.getPolicyTypes().size());
+ ToscaPolicyType fetchedPolicyType = fetchedServiceTemplate.getPolicyTypes().values().iterator().next();
+ assertEquals("onap.policies.PolicyTypeLevel0", fetchedPolicyType.getName());
+ assertEquals("3.0.0", fetchedPolicyType.getVersion());
+ assertEquals(3, countReturnedPolicies(fetchedServiceTemplate));
+
+ fetchedServiceTemplate = databaseProvider.getPolicies("onap.policies.PolicyLevel0", "1.0.0");
+ assertOldDataTypesAreReturned(fetchedServiceTemplate);
+ assertEquals(1, fetchedServiceTemplate.getPolicyTypes().size());
+ fetchedPolicyType = fetchedServiceTemplate.getPolicyTypes().values().iterator().next();
+ assertEquals("onap.policies.PolicyTypeLevel0", fetchedPolicyType.getName());
+ assertEquals("1.0.0", fetchedPolicyType.getVersion());
+ assertEquals(1, countReturnedPolicies(fetchedServiceTemplate));
+
+ fetchedServiceTemplate = databaseProvider.getPolicies("onap.policies.PolicyLevel0", "1.1.0");
+ assertOldDataTypesAreReturned(fetchedServiceTemplate);
+ assertEquals(1, fetchedServiceTemplate.getPolicyTypes().size());
+ fetchedPolicyType = fetchedServiceTemplate.getPolicyTypes().values().iterator().next();
+ assertEquals("onap.policies.PolicyTypeLevel0", fetchedPolicyType.getName());
+ assertEquals("2.0.0", fetchedPolicyType.getVersion());
+ assertEquals(1, countReturnedPolicies(fetchedServiceTemplate));
+
+ fetchedServiceTemplate = databaseProvider.getPolicies("onap.policies.PolicyLevel0", "1.2.0");
+ assertLatestDataTypesAreReturned(fetchedServiceTemplate);
+ assertEquals(1, fetchedServiceTemplate.getPolicyTypes().size());
+ fetchedPolicyType = fetchedServiceTemplate.getPolicyTypes().values().iterator().next();
+ assertEquals("onap.policies.PolicyTypeLevel0", fetchedPolicyType.getName());
+ assertEquals("3.0.0", fetchedPolicyType.getVersion());
+ assertEquals(1, countReturnedPolicies(fetchedServiceTemplate));
+
+ fetchedServiceTemplate = databaseProvider.getPolicies("onap.policies.PolicyLevel0.1", null);
+ assertLatestDataTypesAreReturned(fetchedServiceTemplate);
+ assertEquals(2, fetchedServiceTemplate.getPolicyTypes().size());
+ Iterator<ToscaPolicyType> fetchedPolicyTypeIterator =
+ fetchedServiceTemplate.getPolicyTypes().values().iterator();
+ fetchedPolicyType = fetchedPolicyTypeIterator.next();
+ assertEquals("onap.policies.PolicyTypeLevel0", fetchedPolicyType.getName());
+ assertEquals("3.0.0", fetchedPolicyType.getVersion());
+ fetchedPolicyType = fetchedPolicyTypeIterator.next();
+ assertEquals("onap.policies.PolicyTypeLevel0.1", fetchedPolicyType.getName());
+ assertEquals("3.0.0", fetchedPolicyType.getVersion());
+ assertEquals(3, countReturnedPolicies(fetchedServiceTemplate));
+
+ fetchedServiceTemplate = databaseProvider.getPolicies("onap.policies.PolicyLevel0.1", "1.0.0");
+ assertLatestDataTypesAreReturned(fetchedServiceTemplate);
+ assertEquals(2, fetchedServiceTemplate.getPolicyTypes().size());
+ fetchedPolicyTypeIterator = fetchedServiceTemplate.getPolicyTypes().values().iterator();
+ fetchedPolicyType = fetchedPolicyTypeIterator.next();
+ assertEquals("onap.policies.PolicyTypeLevel0", fetchedPolicyType.getName());
+ assertEquals("3.0.0", fetchedPolicyType.getVersion());
+ fetchedPolicyType = fetchedPolicyTypeIterator.next();
+ assertEquals("onap.policies.PolicyTypeLevel0.1", fetchedPolicyType.getName());
+ assertEquals("1.0.0", fetchedPolicyType.getVersion());
+ assertEquals(1, countReturnedPolicies(fetchedServiceTemplate));
+
+ fetchedServiceTemplate = databaseProvider.getPolicies("onap.policies.PolicyLevel0.1", "1.1.0");
+ assertLatestDataTypesAreReturned(fetchedServiceTemplate);
+ assertEquals(2, fetchedServiceTemplate.getPolicyTypes().size());
+ fetchedPolicyTypeIterator = fetchedServiceTemplate.getPolicyTypes().values().iterator();
+ fetchedPolicyType = fetchedPolicyTypeIterator.next();
+ assertEquals("onap.policies.PolicyTypeLevel0", fetchedPolicyType.getName());
+ assertEquals("3.0.0", fetchedPolicyType.getVersion());
+ fetchedPolicyType = fetchedPolicyTypeIterator.next();
+ assertEquals("onap.policies.PolicyTypeLevel0.1", fetchedPolicyType.getName());
+ assertEquals("2.0.0", fetchedPolicyType.getVersion());
+ assertEquals(1, countReturnedPolicies(fetchedServiceTemplate));
+
+ fetchedServiceTemplate = databaseProvider.getPolicies("onap.policies.PolicyLevel0.1", "1.2.0");
+ assertLatestDataTypesAreReturned(fetchedServiceTemplate);
+ assertEquals(2, fetchedServiceTemplate.getPolicyTypes().size());
+ fetchedPolicyTypeIterator = fetchedServiceTemplate.getPolicyTypes().values().iterator();
+ fetchedPolicyType = fetchedPolicyTypeIterator.next();
+ assertEquals("onap.policies.PolicyTypeLevel0", fetchedPolicyType.getName());
+ assertEquals("3.0.0", fetchedPolicyType.getVersion());
+ fetchedPolicyType = fetchedPolicyTypeIterator.next();
+ assertEquals("onap.policies.PolicyTypeLevel0.1", fetchedPolicyType.getName());
+ assertEquals("3.0.0", fetchedPolicyType.getVersion());
+ assertEquals(1, countReturnedPolicies(fetchedServiceTemplate));
+
+ fetchedServiceTemplate = databaseProvider.getPolicies("onap.policies.PolicyLevel0.1.2", null);
+ assertLatestDataTypesAreReturned(fetchedServiceTemplate);
+ assertEquals(3, fetchedServiceTemplate.getPolicyTypes().size());
+ fetchedPolicyTypeIterator = fetchedServiceTemplate.getPolicyTypes().values().iterator();
+ fetchedPolicyType = fetchedPolicyTypeIterator.next();
+ assertEquals("onap.policies.PolicyTypeLevel0", fetchedPolicyType.getName());
+ assertEquals("3.0.0", fetchedPolicyType.getVersion());
+ fetchedPolicyType = fetchedPolicyTypeIterator.next();
+ assertEquals("onap.policies.PolicyTypeLevel0.1", fetchedPolicyType.getName());
+ assertEquals("3.0.0", fetchedPolicyType.getVersion());
+ fetchedPolicyType = fetchedPolicyTypeIterator.next();
+ assertEquals("onap.policies.PolicyTypeLevel0.1.2", fetchedPolicyType.getName());
+ assertEquals("3.0.0", fetchedPolicyType.getVersion());
+ assertEquals(3, countReturnedPolicies(fetchedServiceTemplate));
+
+ fetchedServiceTemplate = databaseProvider.getPolicies("onap.policies.PolicyLevel0.1.2", "1.0.0");
+ assertLatestDataTypesAreReturned(fetchedServiceTemplate);
+ assertEquals(3, fetchedServiceTemplate.getPolicyTypes().size());
+ fetchedPolicyTypeIterator = fetchedServiceTemplate.getPolicyTypes().values().iterator();
+ fetchedPolicyType = fetchedPolicyTypeIterator.next();
+ assertEquals("onap.policies.PolicyTypeLevel0", fetchedPolicyType.getName());
+ assertEquals("3.0.0", fetchedPolicyType.getVersion());
+ fetchedPolicyType = fetchedPolicyTypeIterator.next();
+ assertEquals("onap.policies.PolicyTypeLevel0.1", fetchedPolicyType.getName());
+ assertEquals("3.0.0", fetchedPolicyType.getVersion());
+ fetchedPolicyType = fetchedPolicyTypeIterator.next();
+ assertEquals("onap.policies.PolicyTypeLevel0.1.2", fetchedPolicyType.getName());
+ assertEquals("1.0.0", fetchedPolicyType.getVersion());
+ assertEquals(1, countReturnedPolicies(fetchedServiceTemplate));
+
+ fetchedServiceTemplate = databaseProvider.getPolicies("onap.policies.PolicyLevel0.1.2", "1.1.0");
+ assertLatestDataTypesAreReturned(fetchedServiceTemplate);
+ assertEquals(3, fetchedServiceTemplate.getPolicyTypes().size());
+ fetchedPolicyTypeIterator = fetchedServiceTemplate.getPolicyTypes().values().iterator();
+ fetchedPolicyType = fetchedPolicyTypeIterator.next();
+ assertEquals("onap.policies.PolicyTypeLevel0", fetchedPolicyType.getName());
+ assertEquals("3.0.0", fetchedPolicyType.getVersion());
+ fetchedPolicyType = fetchedPolicyTypeIterator.next();
+ assertEquals("onap.policies.PolicyTypeLevel0.1", fetchedPolicyType.getName());
+ assertEquals("3.0.0", fetchedPolicyType.getVersion());
+ fetchedPolicyType = fetchedPolicyTypeIterator.next();
+ assertEquals("onap.policies.PolicyTypeLevel0.1.2", fetchedPolicyType.getName());
+ assertEquals("2.0.0", fetchedPolicyType.getVersion());
+ assertEquals(1, countReturnedPolicies(fetchedServiceTemplate));
+
+ fetchedServiceTemplate = databaseProvider.getPolicies("onap.policies.PolicyLevel0.1.2", "1.2.0");
+ assertLatestDataTypesAreReturned(fetchedServiceTemplate);
+ assertEquals(3, fetchedServiceTemplate.getPolicyTypes().size());
+ fetchedPolicyTypeIterator = fetchedServiceTemplate.getPolicyTypes().values().iterator();
+ fetchedPolicyType = fetchedPolicyTypeIterator.next();
+ assertEquals("onap.policies.PolicyTypeLevel0", fetchedPolicyType.getName());
+ assertEquals("3.0.0", fetchedPolicyType.getVersion());
+ fetchedPolicyType = fetchedPolicyTypeIterator.next();
+ assertEquals("onap.policies.PolicyTypeLevel0.1", fetchedPolicyType.getName());
+ assertEquals("3.0.0", fetchedPolicyType.getVersion());
+ fetchedPolicyType = fetchedPolicyTypeIterator.next();
+ assertEquals("onap.policies.PolicyTypeLevel0.1.2", fetchedPolicyType.getName());
+ assertEquals("3.0.0", fetchedPolicyType.getVersion());
+ assertEquals(1, countReturnedPolicies(fetchedServiceTemplate));
+
+ fetchedServiceTemplate = databaseProvider.getPolicies("onap.policies.PolicyLevel0.1.2.3", null);
+ assertLatestDataTypesAreReturned(fetchedServiceTemplate);
+ assertEquals(4, fetchedServiceTemplate.getPolicyTypes().size());
+ fetchedPolicyTypeIterator = fetchedServiceTemplate.getPolicyTypes().values().iterator();
+ fetchedPolicyType = fetchedPolicyTypeIterator.next();
+ assertEquals("onap.policies.PolicyTypeLevel0", fetchedPolicyType.getName());
+ assertEquals("3.0.0", fetchedPolicyType.getVersion());
+ fetchedPolicyType = fetchedPolicyTypeIterator.next();
+ assertEquals("onap.policies.PolicyTypeLevel0.1", fetchedPolicyType.getName());
+ assertEquals("3.0.0", fetchedPolicyType.getVersion());
+ fetchedPolicyType = fetchedPolicyTypeIterator.next();
+ assertEquals("onap.policies.PolicyTypeLevel0.1.2", fetchedPolicyType.getName());
+ assertEquals("3.0.0", fetchedPolicyType.getVersion());
+ fetchedPolicyType = fetchedPolicyTypeIterator.next();
+ assertEquals("onap.policies.PolicyTypeLevel0.1.2.3", fetchedPolicyType.getName());
+ assertEquals("3.0.0", fetchedPolicyType.getVersion());
+ assertEquals(3, countReturnedPolicies(fetchedServiceTemplate));
+
+ fetchedServiceTemplate = databaseProvider.getPolicies("onap.policies.PolicyLevel0.1.2.3", "1.0.0");
+ assertLatestDataTypesAreReturned(fetchedServiceTemplate);
+ assertEquals(4, fetchedServiceTemplate.getPolicyTypes().size());
+ fetchedPolicyTypeIterator = fetchedServiceTemplate.getPolicyTypes().values().iterator();
+ fetchedPolicyType = fetchedPolicyTypeIterator.next();
+ assertEquals("onap.policies.PolicyTypeLevel0", fetchedPolicyType.getName());
+ assertEquals("3.0.0", fetchedPolicyType.getVersion());
+ fetchedPolicyType = fetchedPolicyTypeIterator.next();
+ assertEquals("onap.policies.PolicyTypeLevel0.1", fetchedPolicyType.getName());
+ assertEquals("3.0.0", fetchedPolicyType.getVersion());
+ fetchedPolicyType = fetchedPolicyTypeIterator.next();
+ assertEquals("onap.policies.PolicyTypeLevel0.1.2", fetchedPolicyType.getName());
+ assertEquals("3.0.0", fetchedPolicyType.getVersion());
+ fetchedPolicyType = fetchedPolicyTypeIterator.next();
+ assertEquals("onap.policies.PolicyTypeLevel0.1.2.3", fetchedPolicyType.getName());
+ assertEquals("1.0.0", fetchedPolicyType.getVersion());
+ assertEquals(1, countReturnedPolicies(fetchedServiceTemplate));
+
+ fetchedServiceTemplate = databaseProvider.getPolicies("onap.policies.PolicyLevel0.1.2.3", "1.1.0");
+ assertLatestDataTypesAreReturned(fetchedServiceTemplate);
+ assertEquals(4, fetchedServiceTemplate.getPolicyTypes().size());
+ fetchedPolicyTypeIterator = fetchedServiceTemplate.getPolicyTypes().values().iterator();
+ fetchedPolicyType = fetchedPolicyTypeIterator.next();
+ assertEquals("onap.policies.PolicyTypeLevel0", fetchedPolicyType.getName());
+ assertEquals("3.0.0", fetchedPolicyType.getVersion());
+ fetchedPolicyType = fetchedPolicyTypeIterator.next();
+ assertEquals("onap.policies.PolicyTypeLevel0.1", fetchedPolicyType.getName());
+ assertEquals("3.0.0", fetchedPolicyType.getVersion());
+ fetchedPolicyType = fetchedPolicyTypeIterator.next();
+ assertEquals("onap.policies.PolicyTypeLevel0.1.2", fetchedPolicyType.getName());
+ assertEquals("3.0.0", fetchedPolicyType.getVersion());
+ fetchedPolicyType = fetchedPolicyTypeIterator.next();
+ assertEquals("onap.policies.PolicyTypeLevel0.1.2.3", fetchedPolicyType.getName());
+ assertEquals("2.0.0", fetchedPolicyType.getVersion());
+ assertEquals(1, countReturnedPolicies(fetchedServiceTemplate));
+
+ fetchedServiceTemplate = databaseProvider.getPolicies("onap.policies.PolicyLevel0.1.2.3", "1.2.0");
+ assertLatestDataTypesAreReturned(fetchedServiceTemplate);
+ assertEquals(4, fetchedServiceTemplate.getPolicyTypes().size());
+ fetchedPolicyTypeIterator = fetchedServiceTemplate.getPolicyTypes().values().iterator();
+ fetchedPolicyType = fetchedPolicyTypeIterator.next();
+ assertEquals("onap.policies.PolicyTypeLevel0", fetchedPolicyType.getName());
+ assertEquals("3.0.0", fetchedPolicyType.getVersion());
+ fetchedPolicyType = fetchedPolicyTypeIterator.next();
+ assertEquals("onap.policies.PolicyTypeLevel0.1", fetchedPolicyType.getName());
+ assertEquals("3.0.0", fetchedPolicyType.getVersion());
+ fetchedPolicyType = fetchedPolicyTypeIterator.next();
+ assertEquals("onap.policies.PolicyTypeLevel0.1.2", fetchedPolicyType.getName());
+ assertEquals("3.0.0", fetchedPolicyType.getVersion());
+ fetchedPolicyType = fetchedPolicyTypeIterator.next();
+ assertEquals("onap.policies.PolicyTypeLevel0.1.2.3", fetchedPolicyType.getName());
+ assertEquals("3.0.0", fetchedPolicyType.getVersion());
+ assertEquals(1, countReturnedPolicies(fetchedServiceTemplate));
+
databaseProvider.close();
}
+
+ private void assertOldDataTypesAreReturned(final ToscaServiceTemplate fetchedServiceTemplate) {
+ assertEquals(6, fetchedServiceTemplate.getDataTypes().size());
+ assertEquals("1.0.0", fetchedServiceTemplate.getDataTypes().get("policy.data.DataType0").getVersion());
+ assertEquals("1.0.0", fetchedServiceTemplate.getDataTypes().get("policy.data.DataType1").getVersion());
+ assertEquals("1.0.0", fetchedServiceTemplate.getDataTypes().get("policy.data.DataType2").getVersion());
+ assertEquals("1.0.0", fetchedServiceTemplate.getDataTypes().get("policy.data.DataType3").getVersion());
+ assertEquals("1.0.0", fetchedServiceTemplate.getDataTypes().get("policy.data.DataType4").getVersion());
+ assertEquals("3.0.0", fetchedServiceTemplate.getDataTypes().get("policy.data.DataType5").getVersion());
+ }
+
+ private void assertLatestDataTypesAreReturned(final ToscaServiceTemplate fetchedServiceTemplate) {
+ assertEquals(7, fetchedServiceTemplate.getDataTypes().size());
+ assertEquals("1.0.0", fetchedServiceTemplate.getDataTypes().get("policy.data.DataType0").getVersion());
+ assertEquals("1.0.0", fetchedServiceTemplate.getDataTypes().get("policy.data.DataType1").getVersion());
+ assertEquals("1.0.0", fetchedServiceTemplate.getDataTypes().get("policy.data.DataType2").getVersion());
+ assertEquals("1.0.0", fetchedServiceTemplate.getDataTypes().get("policy.data.DataType3").getVersion());
+ assertEquals("1.0.0", fetchedServiceTemplate.getDataTypes().get("policy.data.DataType4").getVersion());
+ assertEquals("3.0.0", fetchedServiceTemplate.getDataTypes().get("policy.data.DataType5").getVersion());
+ assertEquals("2.0.0", fetchedServiceTemplate.getDataTypes().get("policy.data.DataType6").getVersion());
+ }
+
+ private void assertLatestPolicyTypesAreReturned(final ToscaServiceTemplate fetchedServiceTemplate) {
+ assertEquals(4, fetchedServiceTemplate.getPolicyTypes().size());
+
+ for (ToscaPolicyType policyType : fetchedServiceTemplate.getPolicyTypes().values()) {
+ assertEquals("3.0.0", policyType.getVersion());
+ }
+ }
+
+ private int countReturnedPolicies(final ToscaServiceTemplate fetchedServiceTemplate) {
+ List<Map<String, ToscaPolicy>> policyMapList = fetchedServiceTemplate.getToscaTopologyTemplate().getPolicies();
+
+ int totalPolicies = 0;
+ for (Map<String, ToscaPolicy> policyMap : policyMapList) {
+ totalPolicies += policyMap.size();
+ }
+
+ return totalPolicies;
+ }
}