From b346fda03f450ccf9f8adb143f872cfce6ba76a8 Mon Sep 17 00:00:00 2001 From: jrh3 Date: Thu, 20 Jun 2019 14:57:50 -0400 Subject: Allow integer version when using PDP Group Deploy The policies listed in a "PDP Group Deploy" request may not have fully qualified versions. Modified the code to replace the versions in the request with fully qualified versions. Also improved performance by avoiding look-ups of policies that are already in the subgroup. Change-Id: I37899c2b45228b97a80b7ef44f69694ba57e8f4a Issue-ID: POLICY-1784 Signed-off-by: jrh3 --- .../rest/depundep/TestPdpGroupDeployProvider.java | 50 ++++++++++++++++++++-- .../pap/main/rest/depundep/TestSessionData.java | 14 ++++++ 2 files changed, 60 insertions(+), 4 deletions(-) (limited to 'main/src/test/java/org') 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 7590c645..90ea1658 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 @@ -316,7 +316,9 @@ public class TestPdpGroupDeployProvider extends ProviderSuper { subgrp.getPolicies().add(new ToscaPolicyIdentifier(POLICY2_NAME, POLICY1_VERSION)); subgrp.getSupportedPolicyTypes().add(new ToscaPolicyTypeIdentifier("typeX", "9.8.7")); - when(dao.getFilteredPolicyList(any())).thenReturn(loadPolicies("daoPolicyList.json")) + when(dao.getFilteredPolicyList(any())) + .thenReturn(loadPolicies("createGroupNewPolicy.json")) + .thenReturn(loadPolicies("daoPolicyList.json")) .thenReturn(loadPolicies("createGroupNewPolicy.json")); prov.createOrUpdateGroups(groups); @@ -430,7 +432,7 @@ public class TestPdpGroupDeployProvider extends ProviderSuper { @Test public void testAddSubGroup_ValidationPolicyNotFound() throws Exception { - PdpGroups groups = loadPdpGroups("createGroupsNewSub.json"); + PdpGroups groups = loadPdpGroups("createGroupsNewSubNotFound.json"); PdpGroup group = loadPdpGroups("createGroups.json").getGroups().get(0); when(dao.getPdpGroups(group.getName())).thenReturn(Arrays.asList(group)); @@ -441,7 +443,7 @@ public class TestPdpGroupDeployProvider extends ProviderSuper { @Test public void testAddSubGroup_ValidationPolicyDaoEx() throws Exception { - PdpGroups groups = loadPdpGroups("createGroupsNewSub.json"); + PdpGroups groups = loadPdpGroups("createGroupsNewSubNotFound.json"); PdpGroup group = loadPdpGroups("createGroups.json").getGroups().get(0); when(dao.getPdpGroups(group.getName())).thenReturn(Arrays.asList(group)); @@ -451,6 +453,45 @@ public class TestPdpGroupDeployProvider extends ProviderSuper { assertThatThrownBy(() -> prov.createOrUpdateGroups(groups)).isSameAs(exc); } + @Test + public void testAddSubGroup_ValidateVersionPrefixMatch() throws Exception { + PdpGroups groups = loadPdpGroups("createGroups.json"); + PdpGroup newgrp = groups.getGroups().get(0); + PdpGroup dbgroup = new PdpGroup(newgrp); + when(dao.getPdpGroups(dbgroup.getName())).thenReturn(Arrays.asList(dbgroup)); + + when(dao.getFilteredPolicyList(any())).thenReturn(loadPolicies("createGroupNewPolicy.json")) + .thenReturn(loadPolicies("daoPolicyList.json")) + .thenReturn(loadPolicies("createGroupNewPolicy.json")); + + PdpGroups reqgroups = loadPdpGroups("createGroupsVersPrefix.json"); + + prov.createOrUpdateGroups(reqgroups); + + Collections.sort(newgrp.getPdpSubgroups().get(0).getPolicies()); + Collections.sort(dbgroup.getPdpSubgroups().get(0).getPolicies()); + + assertEquals(newgrp.toString(), dbgroup.toString()); + } + + @Test + public void testAddSubGroup_ValidateVersionPrefixMismatch() throws Exception { + PdpGroups groups = loadPdpGroups("createGroups.json"); + PdpGroup newgrp = groups.getGroups().get(0); + PdpGroup dbgroup = new PdpGroup(newgrp); + when(dao.getPdpGroups(dbgroup.getName())).thenReturn(Arrays.asList(dbgroup)); + + when(dao.getFilteredPolicyList(any())).thenReturn(loadPolicies("daoPolicyList.json")); + + + PdpGroups reqgroups = loadPdpGroups("createGroupsVersPrefixMismatch.json"); + + assertThatThrownBy(() -> prov.createOrUpdateGroups(reqgroups)).isInstanceOf(PfModelException.class) + .hasMessageContaining("different version already deployed"); + + assertNoGroupAction(); + } + @Test public void testUpdateSubGroup_Invalid() throws Exception { PdpGroups groups = loadPdpGroups("createGroups.json"); @@ -507,7 +548,8 @@ public class TestPdpGroupDeployProvider extends ProviderSuper { PdpSubGroup subgrp = newgrp.getPdpSubgroups().get(0); subgrp.getPolicies().add(new ToscaPolicyIdentifier(POLICY2_NAME, POLICY1_VERSION)); - when(dao.getFilteredPolicyList(any())).thenReturn(loadPolicies("daoPolicyList.json")) + when(dao.getFilteredPolicyList(any())).thenReturn(loadPolicies("createGroupNewPolicy.json")) + .thenReturn(loadPolicies("daoPolicyList.json")) .thenReturn(loadPolicies("createGroupNewPolicy.json")); prov.createOrUpdateGroups(groups); diff --git a/main/src/test/java/org/onap/policy/pap/main/rest/depundep/TestSessionData.java b/main/src/test/java/org/onap/policy/pap/main/rest/depundep/TestSessionData.java index 180c0320..d7d9b677 100644 --- a/main/src/test/java/org/onap/policy/pap/main/rest/depundep/TestSessionData.java +++ b/main/src/test/java/org/onap/policy/pap/main/rest/depundep/TestSessionData.java @@ -188,6 +188,20 @@ public class TestSessionData extends ProviderSuper { assertThatThrownBy(() -> session.getPolicy(ident)).isSameAs(ex); } + @Test + public void testIsVersionPrefix() { + assertTrue(SessionData.isVersionPrefix("1")); + assertTrue(SessionData.isVersionPrefix("12")); + assertTrue(SessionData.isVersionPrefix("1.2")); + assertTrue(SessionData.isVersionPrefix("1.23")); + + assertFalse(SessionData.isVersionPrefix("1.")); + assertFalse(SessionData.isVersionPrefix("1.2.")); + assertFalse(SessionData.isVersionPrefix("1.2.3")); + assertFalse(SessionData.isVersionPrefix("1.2.3.")); + assertFalse(SessionData.isVersionPrefix("1.2.3.4")); + } + @Test public void testAddRequests_testGetPdpStateChanges_testGetPdpUpdates() { // pre-load with a update and state-change for other PDPs -- cgit 1.2.3-korg