From 942cd0a012a2a4e9fd44e680dc6c4c7f4bcf8c62 Mon Sep 17 00:00:00 2001 From: liamfallon Date: Tue, 9 Apr 2019 16:58:20 +0000 Subject: Add unit tests for policy type and policy filters THis review adds unit tests for the authorative concepts in the models-tosc module and adds unit tests for the authorative and and database providers. Issue-ID: POLICY-1095 Change-Id: If98deea99658056030dd47725b0c0a4266d84106 Signed-off-by: liamfallon --- .../models/provider/impl/PolicyPersistenceTest.java | 16 ++++++++++++++-- .../provider/impl/PolicyTypePersistenceTest.java | 18 ++++++++++++++++++ 2 files changed, 32 insertions(+), 2 deletions(-) (limited to 'models-provider/src/test/java') 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 468d4d74b..e8c344189 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 @@ -41,6 +41,7 @@ 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.ToscaPolicyFilter; import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -145,10 +146,21 @@ public class PolicyPersistenceTest { for (Map policyMap : serviceTemplate.getToscaTopologyTemplate().getPolicies()) { for (ToscaPolicy policy : policyMap.values()) { - ToscaServiceTemplate goToscaServiceTemplate = + ToscaServiceTemplate gotToscaServiceTemplate = databaseProvider.getPolicies(policy.getName(), policy.getVersion()); - assertEquals(goToscaServiceTemplate.getToscaTopologyTemplate().getPolicies().get(0) + assertEquals(gotToscaServiceTemplate.getToscaTopologyTemplate().getPolicies().get(0) + .get(policy.getName()).getType(), policy.getType()); + + gotToscaServiceTemplate = databaseProvider.getFilteredPolicies(ToscaPolicyFilter.builder().build()); + + assertEquals(gotToscaServiceTemplate.getToscaTopologyTemplate().getPolicies().get(0) + .get(policy.getName()).getType(), policy.getType()); + + gotToscaServiceTemplate = databaseProvider.getFilteredPolicies( + ToscaPolicyFilter.builder().name(policy.getName()).version(policy.getVersion()).build()); + + assertEquals(gotToscaServiceTemplate.getToscaTopologyTemplate().getPolicies().get(0) .get(policy.getName()).getType(), policy.getType()); } } 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 7f90a0b58..96360ec93 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 @@ -41,6 +41,7 @@ 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.ToscaPolicyType; +import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyTypeFilter; import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -146,7 +147,24 @@ public class PolicyTypePersistenceTest { List policyTypeList = databaseProvider.getPolicyTypeList(inPolicyType.getName(), inPolicyType.getVersion()); + policyTypeList = databaseProvider.getFilteredPolicyTypeList(ToscaPolicyTypeFilter.builder() + .name(inPolicyType.getName()).version(inPolicyType.getVersion()).build()); + + assertEquals(1, policyTypeList.size()); + assertEquals(inPolicyType.getName(), policyTypeList.get(0).getName()); + + policyTypeList = databaseProvider + .getFilteredPolicyTypeList(ToscaPolicyTypeFilter.builder().name(inPolicyType.getName()).build()); + assertEquals(1, policyTypeList.size()); assertEquals(inPolicyType.getName(), policyTypeList.get(0).getName()); + + policyTypeList = databaseProvider.getFilteredPolicyTypeList(ToscaPolicyTypeFilter.builder().build()); + assertEquals(2, policyTypeList.size()); + assertEquals(inPolicyType.getName(), policyTypeList.get(0).getName()); + + for (ToscaPolicyType policyType: databaseProvider.getPolicyTypeList(null, null)) { + databaseProvider.deletePolicyType(policyType.getName(), policyType.getVersion()); + } } } -- cgit 1.2.3-korg