diff options
author | Jim Hahn <jrh3@att.com> | 2019-11-06 12:19:33 -0500 |
---|---|---|
committer | Jim Hahn <jrh3@att.com> | 2019-11-06 15:52:56 -0500 |
commit | a3bf3134c01d979cebc94f5b2c915cfa400a9a72 (patch) | |
tree | fdb7488ae7e79ab6b130927a81463cf379346084 /main/src/test/java/org | |
parent | 43f8999d3f94e23231bc3cbb45089d8541c4f2cf (diff) |
Support policy types with wild-cards
Allow supported policy types to end with ".*", which causes the prefix
to be matched when new policies are deployed. This entailed updates
in three areas:
- when a subgroup is added via the group api
- when a subgroup is updated via the group api
- when a policy is deployed via the simple api
Issue-ID: POLICY-1636
Signed-off-by: Jim Hahn <jrh3@att.com>
Change-Id: I4ae15971481ce5b2042b5d6fdfd16e11ad099c50
Signed-off-by: Jim Hahn <jrh3@att.com>
Diffstat (limited to 'main/src/test/java/org')
-rw-r--r-- | main/src/test/java/org/onap/policy/pap/main/rest/depundep/TestPdpGroupDeployProvider.java | 83 |
1 files changed, 81 insertions, 2 deletions
diff --git a/main/src/test/java/org/onap/policy/pap/main/rest/depundep/TestPdpGroupDeployProvider.java b/main/src/test/java/org/onap/policy/pap/main/rest/depundep/TestPdpGroupDeployProvider.java index c2d368ad..899b5695 100644 --- a/main/src/test/java/org/onap/policy/pap/main/rest/depundep/TestPdpGroupDeployProvider.java +++ b/main/src/test/java/org/onap/policy/pap/main/rest/depundep/TestPdpGroupDeployProvider.java @@ -325,7 +325,7 @@ public class TestPdpGroupDeployProvider extends ProviderSuper { PdpSubGroup subgrp = newgrp.getPdpSubgroups().get(0); subgrp.setDesiredInstanceCount(30); subgrp.getPolicies().add(new ToscaPolicyIdentifier(POLICY2_NAME, POLICY1_VERSION)); - subgrp.getSupportedPolicyTypes().add(new ToscaPolicyTypeIdentifier("typeX", "9.8.7")); + subgrp.getSupportedPolicyTypes().add(new ToscaPolicyTypeIdentifier("typeX.*", "9.8.7")); when(dao.getFilteredPolicyList(any())) .thenReturn(loadPolicies("createGroupNewPolicy.json")) @@ -418,6 +418,49 @@ public class TestPdpGroupDeployProvider extends ProviderSuper { assertGroupUpdateOnly(group); } + /** + * Tests addSubgroup() when the new subgroup has a wild-card policy type. + * + * @throws Exception if an error occurs + */ + @Test + public void testAddSubGroupWildCardPolicyType() throws Exception { + when(dao.getFilteredPolicyList(any())).thenReturn(loadPolicies("daoPolicyListWildCard.json")); + when(dao.getPolicyTypeList("some.*", "2.3.4")).thenReturn(Collections.emptyList()); + + PdpGroups groups = loadPdpGroups("createGroupsWildCard.json"); + PdpGroup group = loadPdpGroups("createGroups.json").getGroups().get(0); + when(dao.getPdpGroups(group.getName())).thenReturn(Arrays.asList(group)); + + prov.createOrUpdateGroups(groups); + + PdpGroup newgrp = groups.getGroups().get(0); + + PdpSubGroup newsub = newgrp.getPdpSubgroups().get(1); + newsub.setCurrentInstanceCount(0); + newsub.setPdpInstances(new ArrayList<>(0)); + + assertEquals(newgrp.toString(), group.toString()); + } + + /** + * Tests addSubgroup() when the new subgroup has a wild-card policy type, but the + * policy doesn't have a matching type. + * + * @throws PfModelException if an error occurs + */ + @Test + public void testAddSubGroupWildCardPolicyTypeUnmatched() throws PfModelException { + when(dao.getFilteredPolicyList(any())).thenReturn(loadPolicies("daoPolicyListWildCardUnmatched.json")); + when(dao.getPolicyTypeList("some.*", "2.3.4")).thenReturn(Collections.emptyList()); + + PdpGroups groups = loadPdpGroups("createGroupsWildCard.json"); + PdpGroup group = loadPdpGroups("createGroups.json").getGroups().get(0); + when(dao.getPdpGroups(group.getName())).thenReturn(Arrays.asList(group)); + + assertThatThrownBy(() -> prov.createOrUpdateGroups(groups)).isInstanceOf(PfModelException.class); + } + @Test public void testAddSubGroup_ValidationPolicyTypeNotFound() throws Exception { PdpGroups groups = loadPdpGroups("createGroupsNewSub.json"); @@ -526,7 +569,8 @@ public class TestPdpGroupDeployProvider extends ProviderSuper { PdpGroup group = new PdpGroup(newgrp); when(dao.getPdpGroups(group.getName())).thenReturn(Arrays.asList(group)); - newgrp.getPdpSubgroups().get(0).getSupportedPolicyTypes().add(new ToscaPolicyTypeIdentifier("typeX", "9.8.7")); + newgrp.getPdpSubgroups().get(0).getSupportedPolicyTypes() + .add(new ToscaPolicyTypeIdentifier("typeX.*", "9.8.7")); prov.createOrUpdateGroups(groups); @@ -652,6 +696,41 @@ public class TestPdpGroupDeployProvider extends ProviderSuper { prov.deployPolicies(loadEmptyRequest()); } + /** + * Tests deployPolicies() when the supported policy type uses a wild-card. + * + * @throws Exception if an error occurs + */ + @Test + public void testDeployPoliciesWildCard() throws Exception { + when(dao.getFilteredPdpGroups(any())).thenReturn(loadGroups("deployPoliciesWildCard.json")); + when(dao.getFilteredPolicyList(any())).thenReturn(loadPolicies("daoPolicyListWildCard.json")); + when(dao.getPolicyTypeList(any(), any())).thenReturn(Collections.emptyList()); + + policy1.setName("policy.some"); + policy1.setVersion(POLICY1_VERSION); + policy1.setType("some.type"); + policy1.setTypeVersion("100.2.3"); + + PdpDeployPolicies depreq = loadRequest(); + depreq.getPolicies().get(0).setName("policy.some"); + + prov.deployPolicies(depreq); + + assertGroup(getGroupUpdates(), GROUP1_NAME); + + List<PdpUpdate> requests = getUpdateRequests(1); + assertUpdate(requests, GROUP1_NAME, PDP2_TYPE, PDP2); + + // should have notified of added policy/PDPs + ArgumentCaptor<PolicyPdpNotificationData> captor = ArgumentCaptor.forClass(PolicyPdpNotificationData.class); + verify(notifier).addDeploymentData(captor.capture()); + assertDeploymentData(captor, policy1.getIdentifier(), "[pdpB]"); + + // no undeployment notifications + verify(notifier, never()).addUndeploymentData(any()); + } + @Test public void testDeploySimplePolicies() throws Exception { prov.deployPolicies(loadEmptyRequest()); |