diff options
author | liamfallon <liam.fallon@est.tech> | 2019-04-09 16:58:20 +0000 |
---|---|---|
committer | liamfallon <liam.fallon@est.tech> | 2019-04-09 16:58:20 +0000 |
commit | 942cd0a012a2a4e9fd44e680dc6c4c7f4bcf8c62 (patch) | |
tree | 532643c15d2a4dc0823fce3c0372ac1ee07e444b /models-provider/src/test/java | |
parent | e678e5af567040022f23ed7a1ba1723b82434418 (diff) |
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 <liam.fallon@est.tech>
Diffstat (limited to 'models-provider/src/test/java')
2 files changed, 32 insertions, 2 deletions
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<String, ToscaPolicy> 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<ToscaPolicyType> 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()); + } } } |