summaryrefslogtreecommitdiffstats
path: root/main/src/test/java/org
diff options
context:
space:
mode:
Diffstat (limited to 'main/src/test/java/org')
-rw-r--r--main/src/test/java/org/onap/policy/pap/main/rest/depundep/TestPdpGroupDeleteProvider.java34
-rw-r--r--main/src/test/java/org/onap/policy/pap/main/rest/depundep/TestProviderBase.java4
2 files changed, 30 insertions, 8 deletions
diff --git a/main/src/test/java/org/onap/policy/pap/main/rest/depundep/TestPdpGroupDeleteProvider.java b/main/src/test/java/org/onap/policy/pap/main/rest/depundep/TestPdpGroupDeleteProvider.java
index 8ef9b653..a577e07b 100644
--- a/main/src/test/java/org/onap/policy/pap/main/rest/depundep/TestPdpGroupDeleteProvider.java
+++ b/main/src/test/java/org/onap/policy/pap/main/rest/depundep/TestPdpGroupDeleteProvider.java
@@ -56,6 +56,7 @@ public class TestPdpGroupDeleteProvider extends ProviderSuper {
private MyProvider prov;
private SessionData session;
private ToscaPolicyIdentifierOptVersion optIdent;
+ private ToscaPolicyIdentifierOptVersion fullIdent;
private ToscaPolicyIdentifier ident;
private BiFunction<PdpGroup, PdpSubGroup, Boolean> updater;
@@ -78,10 +79,11 @@ public class TestPdpGroupDeleteProvider extends ProviderSuper {
session = mock(SessionData.class);
ident = policy1.getIdentifier();
optIdent = new ToscaPolicyIdentifierOptVersion(ident.getName(), null);
+ fullIdent = new ToscaPolicyIdentifierOptVersion(ident.getName(), ident.getVersion());
prov = new MyProvider();
- updater = prov.makeUpdater(policy1);
+ updater = prov.makeUpdater(policy1, fullIdent);
}
@Test
@@ -163,7 +165,7 @@ public class TestPdpGroupDeleteProvider extends ProviderSuper {
when(dao.getFilteredPdpGroups(any())).thenReturn(Arrays.asList(group));
when(dao.getFilteredPolicyList(any())).thenReturn(Arrays.asList(policy1));
- new PdpGroupDeleteProvider().undeploy(optIdent);
+ new PdpGroupDeleteProvider().undeploy(fullIdent);
// should have updated the old group
List<PdpGroup> updates = getGroupUpdates();
@@ -171,7 +173,7 @@ public class TestPdpGroupDeleteProvider extends ProviderSuper {
assertSame(group, updates.get(0));
assertEquals(PdpState.ACTIVE, group.getPdpGroupState());
- // should be one less item in the new group
+ // should be one less item in the new subgroup
assertEquals(2, group.getPdpSubgroups().get(0).getPolicies().size());
// should have updated the PDPs
@@ -213,17 +215,16 @@ public class TestPdpGroupDeleteProvider extends ProviderSuper {
}
@Test
- public void testMakeUpdater() {
+ public void testMakeUpdater_WithVersion() {
/*
- * this group has one policy with a different name, one matching policy, and one
- * with a different version.
+ * this group has two matching policies and one policy with a different name.
*/
PdpGroup group = loadGroup("undeploy.json");
PdpSubGroup subgroup = group.getPdpSubgroups().get(0);
int origSize = subgroup.getPolicies().size();
- // invoke updater
+ // invoke updater - matching both name and version
assertTrue(updater.apply(group, subgroup));
// identified policy should have been removed
@@ -232,6 +233,25 @@ public class TestPdpGroupDeleteProvider extends ProviderSuper {
}
@Test
+ public void testMakeUpdater_NullVersion() {
+ /*
+ * this group has two matching policies and one policy with a different name.
+ */
+ PdpGroup group = loadGroup("undeploy.json");
+
+ PdpSubGroup subgroup = group.getPdpSubgroups().get(0);
+ int origSize = subgroup.getPolicies().size();
+
+ // invoke updater - matching the name, but with a null (i.e., wild-card) version
+ updater = prov.makeUpdater(policy1, optIdent);
+ assertTrue(updater.apply(group, subgroup));
+
+ // identified policy should have been removed
+ assertEquals(origSize - 2, subgroup.getPolicies().size());
+ assertFalse(subgroup.getPolicies().contains(ident));
+ }
+
+ @Test
public void testMakeUpdater_NotFound() {
/*
* this group has one policy with a different name and one with a different
diff --git a/main/src/test/java/org/onap/policy/pap/main/rest/depundep/TestProviderBase.java b/main/src/test/java/org/onap/policy/pap/main/rest/depundep/TestProviderBase.java
index c171e946..3a91363f 100644
--- a/main/src/test/java/org/onap/policy/pap/main/rest/depundep/TestProviderBase.java
+++ b/main/src/test/java/org/onap/policy/pap/main/rest/depundep/TestProviderBase.java
@@ -345,7 +345,9 @@ public class TestProviderBase extends ProviderSuper {
}
@Override
- protected BiFunction<PdpGroup, PdpSubGroup, Boolean> makeUpdater(ToscaPolicy policy) {
+ protected BiFunction<PdpGroup, PdpSubGroup, Boolean> makeUpdater(ToscaPolicy policy,
+ ToscaPolicyIdentifierOptVersion desiredPolicy) {
+
return (group, subgroup) -> {
if (shouldUpdate.remove()) {
// queue indicated that the update should succeed