aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--main/src/main/java/org/onap/policy/pap/main/rest/depundep/GroupData.java9
-rw-r--r--main/src/main/java/org/onap/policy/pap/main/rest/depundep/SessionData.java2
-rw-r--r--main/src/test/java/org/onap/policy/pap/main/rest/depundep/TestGroupData.java6
-rw-r--r--main/src/test/java/org/onap/policy/pap/main/rest/depundep/TestSessionData.java15
4 files changed, 27 insertions, 5 deletions
diff --git a/main/src/main/java/org/onap/policy/pap/main/rest/depundep/GroupData.java b/main/src/main/java/org/onap/policy/pap/main/rest/depundep/GroupData.java
index f97107f7..9ad9be28 100644
--- a/main/src/main/java/org/onap/policy/pap/main/rest/depundep/GroupData.java
+++ b/main/src/main/java/org/onap/policy/pap/main/rest/depundep/GroupData.java
@@ -61,6 +61,15 @@ public class GroupData {
}
/**
+ * Determines if the group is unchanged (i.e., neither new nor updated).
+ *
+ * @return {@code true} if the group is unchanged, {@code false} otherwise
+ */
+ public boolean isUnchanged() {
+ return (state == State.UNCHANGED);
+ }
+
+ /**
* Determines if the group is new.
*
* @return {@code true} if the group is new, {@code false} otherwise
diff --git a/main/src/main/java/org/onap/policy/pap/main/rest/depundep/SessionData.java b/main/src/main/java/org/onap/policy/pap/main/rest/depundep/SessionData.java
index ab06befb..ee83fb74 100644
--- a/main/src/main/java/org/onap/policy/pap/main/rest/depundep/SessionData.java
+++ b/main/src/main/java/org/onap/policy/pap/main/rest/depundep/SessionData.java
@@ -221,7 +221,7 @@ public class SessionData {
* @return {@code true} if nothing was changed, {@code false} if something was changed
*/
public boolean isUnchanged() {
- return pdpRequests.isEmpty();
+ return groupCache.values().stream().allMatch(GroupData::isUnchanged);
}
/**
diff --git a/main/src/test/java/org/onap/policy/pap/main/rest/depundep/TestGroupData.java b/main/src/test/java/org/onap/policy/pap/main/rest/depundep/TestGroupData.java
index 0c14aa2f..92b30b2e 100644
--- a/main/src/test/java/org/onap/policy/pap/main/rest/depundep/TestGroupData.java
+++ b/main/src/test/java/org/onap/policy/pap/main/rest/depundep/TestGroupData.java
@@ -54,10 +54,12 @@ public class TestGroupData {
data = new GroupData(oldGroup, true);
assertSame(oldGroup, data.getGroup());
+ assertFalse(data.isUnchanged());
assertTrue(data.isNew());
assertFalse(data.isUpdated());
data.update(newGroup);
+ assertFalse(data.isUnchanged());
assertTrue(data.isNew());
assertFalse(data.isUpdated());
assertSame(newGroup, data.getGroup());
@@ -65,6 +67,7 @@ public class TestGroupData {
// repeat with a new group
newGroup = new PdpGroup(oldGroup);
data.update(newGroup);
+ assertFalse(data.isUnchanged());
assertTrue(data.isNew());
assertFalse(data.isUpdated());
assertSame(newGroup, data.getGroup());
@@ -72,11 +75,13 @@ public class TestGroupData {
@Test
public void testUpdateOnly() {
+ assertTrue(data.isUnchanged());
assertFalse(data.isUpdated());
assertSame(oldGroup, data.getGroup());
data.update(newGroup);
+ assertFalse(data.isUnchanged());
assertTrue(data.isUpdated());
assertFalse(data.isNew());
assertSame(newGroup, data.getGroup());
@@ -84,6 +89,7 @@ public class TestGroupData {
// repeat
newGroup = new PdpGroup(oldGroup);
data.update(newGroup);
+ assertFalse(data.isUnchanged());
assertTrue(data.isUpdated());
assertFalse(data.isNew());
assertSame(newGroup, data.getGroup());
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 e7027c51..180c0320 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
@@ -189,9 +189,7 @@ public class TestSessionData extends ProviderSuper {
}
@Test
- public void testIsUnchanged_testAddRequests_testGetPdpStateChanges_testGetPdpUpdates() {
- assertTrue(session.isUnchanged());
-
+ public void testAddRequests_testGetPdpStateChanges_testGetPdpUpdates() {
// pre-load with a update and state-change for other PDPs
PdpUpdate update2 = makeUpdate(PDP2);
session.addUpdate(update2);
@@ -203,7 +201,6 @@ public class TestSessionData extends ProviderSuper {
PdpUpdate update = makeUpdate(PDP1);
PdpStateChange change = makeStateChange(PDP1);
session.addRequests(update, change);
- assertFalse(session.isUnchanged());
verifyRequests(update, update2, change, change3);
/*
@@ -322,13 +319,17 @@ public class TestSessionData extends ProviderSuper {
@Test
public void testCreate() throws Exception {
+ assertTrue(session.isUnchanged());
+
session.create(group1);
assertSame(group1, session.getGroup(group1.getName()));
+ assertFalse(session.isUnchanged());
// can add another
session.create(group2);
assertSame(group1, session.getGroup(group1.getName()));
assertSame(group2, session.getGroup(group2.getName()));
+ assertFalse(session.isUnchanged());
// cannot overwrite
assertThatIllegalStateException().isThrownBy(() -> session.create(group1))
@@ -337,6 +338,8 @@ public class TestSessionData extends ProviderSuper {
@Test
public void testUpdate() throws Exception {
+ assertTrue(session.isUnchanged());
+
// force the groups into the cache
when(dao.getFilteredPdpGroups(any())).thenReturn(Arrays.asList(group1, group2));
session.getActivePdpGroupsByPolicyType(type);
@@ -347,10 +350,12 @@ public class TestSessionData extends ProviderSuper {
when(dao.getFilteredPdpGroups(any())).thenReturn(Arrays.asList(group1));
PdpGroup newgrp = new PdpGroup(group1);
session.update(newgrp);
+ assertFalse(session.isUnchanged());
// repeat
newgrp = new PdpGroup(group1);
session.update(newgrp);
+ assertFalse(session.isUnchanged());
/*
* try group 2
@@ -358,10 +363,12 @@ public class TestSessionData extends ProviderSuper {
when(dao.getFilteredPdpGroups(any())).thenReturn(Arrays.asList(group2));
newgrp = new PdpGroup(group2);
session.update(newgrp);
+ assertFalse(session.isUnchanged());
// repeat
newgrp = new PdpGroup(group2);
session.update(newgrp);
+ assertFalse(session.isUnchanged());
}
@Test