summaryrefslogtreecommitdiffstats
path: root/main/src/test
diff options
context:
space:
mode:
Diffstat (limited to 'main/src/test')
-rw-r--r--main/src/test/java/org/onap/policy/pap/main/rest/depundep/ProviderSuper.java21
-rw-r--r--main/src/test/java/org/onap/policy/pap/main/rest/depundep/TestGroupData.java49
-rw-r--r--main/src/test/java/org/onap/policy/pap/main/rest/depundep/TestPdpGroupDeleteProvider.java12
-rw-r--r--main/src/test/java/org/onap/policy/pap/main/rest/depundep/TestPdpGroupDeployProvider.java6
-rw-r--r--main/src/test/java/org/onap/policy/pap/main/rest/depundep/TestProviderBase.java22
-rw-r--r--main/src/test/java/org/onap/policy/pap/main/rest/depundep/TestSessionData.java116
-rw-r--r--main/src/test/resources/simpleDeploy/getGroupDao.json61
7 files changed, 42 insertions, 245 deletions
diff --git a/main/src/test/java/org/onap/policy/pap/main/rest/depundep/ProviderSuper.java b/main/src/test/java/org/onap/policy/pap/main/rest/depundep/ProviderSuper.java
index 4cc69176..65b1234f 100644
--- a/main/src/test/java/org/onap/policy/pap/main/rest/depundep/ProviderSuper.java
+++ b/main/src/test/java/org/onap/policy/pap/main/rest/depundep/ProviderSuper.java
@@ -59,12 +59,6 @@ public class ProviderSuper {
@Mock
protected PolicyModelsProvider dao;
- /**
- * Used to capture input to dao.createPdpGroups().
- */
- @Captor
- private ArgumentCaptor<List<PdpGroup>> createCaptor;
-
/**
* Used to capture input to dao.updatePdpGroups().
@@ -108,11 +102,10 @@ public class ProviderSuper {
Registry.register(PapConstants.REG_PAP_DAO_FACTORY, daofact);
}
- protected void assertGroup(List<PdpGroup> groups, String name, String version) {
+ protected void assertGroup(List<PdpGroup> groups, String name) {
PdpGroup group = groups.remove(0);
assertEquals(name, group.getName());
- assertEquals(version, group.getVersion());
}
protected void assertUpdateIgnorePolicy(List<PdpUpdate> updates, String groupName, String pdpType, String pdpName) {
@@ -127,18 +120,6 @@ public class ProviderSuper {
/**
* Gets the input to the method.
*
- * @return the input that was passed to the dao.createPdpGroups() method
- * @throws Exception if an error occurred
- */
- protected List<PdpGroup> getGroupCreates() throws Exception {
- verify(dao).createPdpGroups(createCaptor.capture());
-
- return copyList(createCaptor.getValue());
- }
-
- /**
- * Gets the input to the method.
- *
* @return the input that was passed to the dao.updatePdpGroups() method
* @throws Exception if an error occurred
*/
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 a0d4989f..8313d193 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
@@ -21,25 +21,20 @@
package org.onap.policy.pap.main.rest.depundep;
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
-import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
-import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import org.junit.Before;
import org.junit.Test;
-import org.onap.policy.common.utils.validation.Version;
import org.onap.policy.models.pdp.concepts.PdpGroup;
public class TestGroupData {
- private static final String NEW_VERSION = "2.0.0";
private static final String NAME = "my-name";
private PdpGroup oldGroup;
private PdpGroup newGroup;
private GroupData data;
- private Version version;
/**
* Sets up.
@@ -51,47 +46,29 @@ public class TestGroupData {
newGroup = new PdpGroup(oldGroup);
- version = new Version(1, 2, 3);
-
data = new GroupData(oldGroup);
}
@Test
public void test() {
- assertFalse(data.isNew());
- assertSame(oldGroup, data.getOldGroup());
- assertSame(oldGroup, data.getCurrentGroup());
+ assertFalse(data.isUpdated());
+ assertSame(oldGroup, data.getGroup());
- data.setLatestVersion(version);
- data.setNewGroup(newGroup);
+ data.update(newGroup);
- assertTrue(data.isNew());
- assertSame(oldGroup, data.getOldGroup());
- assertSame(newGroup, data.getCurrentGroup());
- assertEquals(NEW_VERSION, data.getLatestVersion().toString());
- assertEquals(NEW_VERSION, newGroup.getVersion());
+ assertTrue(data.isUpdated());
+ assertSame(newGroup, data.getGroup());
// repeat
newGroup = new PdpGroup(oldGroup);
- data.setNewGroup(newGroup);
- assertSame(oldGroup, data.getOldGroup());
- assertSame(newGroup, data.getCurrentGroup());
- assertEquals(NEW_VERSION, data.getLatestVersion().toString());
- assertEquals(NEW_VERSION, newGroup.getVersion());
- }
-
- @Test
- public void testSetNewGroup_DifferentName() {
- newGroup.setName("different-name");
+ data.update(newGroup);
+ assertTrue(data.isUpdated());
+ assertSame(newGroup, data.getGroup());
- data.setLatestVersion(version);
- assertThatIllegalArgumentException().isThrownBy(() -> data.setNewGroup(newGroup))
- .withMessage("attempt to change group name from my-name to different-name");
- }
-
- @Test
- public void testSetNewGroup_VersionNotSet() {
- assertThatIllegalStateException().isThrownBy(() -> data.setNewGroup(newGroup))
- .withMessage("latestVersion not set for group: my-name");
+ // incorrect name
+ newGroup = new PdpGroup(oldGroup);
+ newGroup.setName("other");
+ assertThatIllegalArgumentException().isThrownBy(() -> data.update(newGroup))
+ .withMessage("expected group my-name, but received other");
}
}
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 31dfb398..dbb7951e 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
@@ -128,18 +128,10 @@ public class TestPdpGroupDeleteProvider extends ProviderSuper {
List<PdpGroup> updates = getGroupUpdates();
assertEquals(1, updates.size());
assertSame(group, updates.get(0));
- assertEquals(PdpState.PASSIVE, group.getPdpGroupState());
-
- // should have created a new group
- List<PdpGroup> creates = getGroupCreates();
- assertEquals(1, creates.size());
- PdpGroup group2 = creates.get(0);
- assertEquals(group.getName(), group2.getName());
- assertEquals(PdpState.ACTIVE, group2.getPdpGroupState());
+ assertEquals(PdpState.ACTIVE, group.getPdpGroupState());
// should be one less item in the new group
- assertEquals(group.getPdpSubgroups().get(0).getPolicies().size() - 1,
- group2.getPdpSubgroups().get(0).getPolicies().size());
+ assertEquals(2, group.getPdpSubgroups().get(0).getPolicies().size());
// should have updated the PDPs
List<PdpUpdate> requests = getUpdateRequests(1);
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 018f117c..8ca205cd 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
@@ -41,7 +41,6 @@ import org.onap.policy.models.pap.concepts.PdpDeployPolicies;
import org.onap.policy.models.pap.concepts.PdpGroupDeployResponse;
import org.onap.policy.models.pdp.concepts.PdpGroups;
import org.onap.policy.models.pdp.concepts.PdpUpdate;
-import org.onap.policy.pap.main.rest.depundep.PdpGroupDeployProvider;
public class TestPdpGroupDeployProvider extends ProviderSuper {
private static final String EXPECTED_EXCEPTION = "expected exception";
@@ -50,8 +49,6 @@ public class TestPdpGroupDeployProvider extends ProviderSuper {
private static final String POLICY1_NAME = "policyA";
private static final String POLICY1_VERSION = "1.2.3";
private static final String GROUP1_NAME = "groupA";
- private static final String GROUP1_VERSION = "200.2.3";
- private static final String GROUP1_NEW_VERSION = "201.0.0";
private static final String PDP1_TYPE = "pdpTypeA";
private static final String PDP2_TYPE = "pdpTypeB";
private static final String PDP4_TYPE = "pdpTypeD";
@@ -149,8 +146,7 @@ public class TestPdpGroupDeployProvider extends ProviderSuper {
assertEquals(Status.OK, pair.getLeft());
assertNull(pair.getRight().getErrorDetails());
- assertGroup(getGroupUpdates(), GROUP1_NAME, GROUP1_VERSION);
- assertGroup(getGroupCreates(), GROUP1_NAME, GROUP1_NEW_VERSION);
+ assertGroup(getGroupUpdates(), GROUP1_NAME);
List<PdpUpdate> requests = getUpdateRequests(2);
assertUpdate(requests, GROUP1_NAME, PDP2_TYPE, PDP2);
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 883b3d55..01b29b10 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
@@ -61,8 +61,6 @@ public class TestProviderBase extends ProviderSuper {
private static final String POLICY1_NAME = "policyA";
private static final String POLICY1_VERSION = "1.2.3";
private static final String GROUP1_NAME = "groupA";
- private static final String GROUP1_VERSION = "200.2.3";
- private static final String GROUP1_NEW_VERSION = "201.0.0";
private static final String GROUP2_NAME = "groupB";
private static final String PDP1_TYPE = "pdpTypeA";
private static final String PDP2_TYPE = "pdpTypeB";
@@ -109,8 +107,7 @@ public class TestProviderBase extends ProviderSuper {
assertEquals(Status.OK, pair.getLeft());
assertNull(pair.getRight().getErrorDetails());
- assertGroup(getGroupUpdates(), GROUP1_NAME, GROUP1_VERSION);
- assertGroup(getGroupCreates(), GROUP1_NAME, GROUP1_NEW_VERSION);
+ assertGroup(getGroupUpdates(), GROUP1_NAME);
assertUpdate(getUpdateRequests(1), GROUP1_NAME, PDP1_TYPE, PDP1);
}
@@ -197,8 +194,7 @@ public class TestProviderBase extends ProviderSuper {
assertEquals(Status.OK, pair.getLeft());
assertNull(pair.getRight().getErrorDetails());
- assertGroup(getGroupUpdates(), GROUP1_NAME, GROUP1_VERSION);
- assertGroup(getGroupCreates(), GROUP1_NAME, GROUP1_NEW_VERSION);
+ assertGroup(getGroupUpdates(), GROUP1_NAME);
}
@Test
@@ -224,8 +220,7 @@ public class TestProviderBase extends ProviderSuper {
assertEquals(Status.OK, pair.getLeft());
assertNull(pair.getRight().getErrorDetails());
- assertGroup(getGroupUpdates(), GROUP1_NAME, GROUP1_VERSION);
- assertGroup(getGroupCreates(), GROUP1_NAME, GROUP1_NEW_VERSION);
+ assertGroup(getGroupUpdates(), GROUP1_NAME);
List<PdpUpdate> requests = getUpdateRequests(2);
assertUpdate(requests, GROUP1_NAME, PDP2_TYPE, PDP2);
@@ -282,15 +277,10 @@ public class TestProviderBase extends ProviderSuper {
assertEquals(Status.OK, pair.getLeft());
assertNull(pair.getRight().getErrorDetails());
- // verify creates
- List<PdpGroup> changes = getGroupCreates();
- assertGroup(changes, GROUP1_NAME, GROUP1_NEW_VERSION);
- assertGroup(changes, GROUP2_NAME, "301.0.0");
-
// verify updates
- changes = getGroupUpdates();
- assertGroup(changes, GROUP1_NAME, GROUP1_VERSION);
- assertGroup(changes, GROUP2_NAME, "300.2.3");
+ List<PdpGroup> changes = getGroupUpdates();
+ assertGroup(changes, GROUP1_NAME);
+ assertGroup(changes, GROUP2_NAME);
List<PdpUpdate> requests = getUpdateRequests(3);
assertUpdateIgnorePolicy(requests, GROUP1_NAME, PDP1_TYPE, PDP1);
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 1c2b8233..fd351c89 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
@@ -23,9 +23,7 @@ package org.onap.policy.pap.main.rest.depundep;
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertSame;
-import static org.junit.Assert.assertTrue;
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.times;
@@ -47,15 +45,10 @@ import org.onap.policy.models.pdp.concepts.PdpUpdate;
import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyIdentifier;
import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyTypeIdentifier;
-import org.onap.policy.pap.main.PolicyPapRuntimeException;
public class TestSessionData extends ProviderSuper {
- private static final String GROUP_VERSION_PREFIX = "9.8.";
private static final String GROUP_NAME = "groupA";
- private static final String GROUP_VERSION = GROUP_VERSION_PREFIX + "7";
- private static final String GROUP_NEW_VERSION = "10.0.0";
private static final String GROUP_NAME2 = "groupB";
- private static final String GROUP_VERSION2 = GROUP_VERSION_PREFIX + "6";
private static final String PDP1 = "pdp_1";
private static final String PDP2 = "pdp_2";
private static final String PDP3 = "pdp_3";
@@ -85,8 +78,8 @@ public class TestSessionData extends ProviderSuper {
ident = new ToscaPolicyIdentifier(POLICY_NAME, POLICY_VERSION);
type = new ToscaPolicyTypeIdentifier(POLICY_TYPE, POLICY_TYPE_VERSION);
type2 = new ToscaPolicyTypeIdentifier(POLICY_TYPE, POLICY_TYPE_VERSION + "0");
- group1 = makeGroup(GROUP_NAME, GROUP_VERSION);
- group2 = makeGroup(GROUP_NAME2, GROUP_VERSION2);
+ group1 = makeGroup(GROUP_NAME);
+ group2 = makeGroup(GROUP_NAME2);
session = new SessionData(dao);
}
@@ -190,51 +183,16 @@ public class TestSessionData extends ProviderSuper {
assertThatThrownBy(() -> session.getPolicyMaxVersion(POLICY_NAME)).hasMessage("cannot find policy: myPolicy");
}
- @Test
- public void testIsNewlyCreated_testCreatePdpGroup() throws Exception {
- assertFalse(session.isNewlyCreated(GROUP_NAME));
-
- // cause the group to be loaded into the cache
- when(dao.getFilteredPdpGroups(any())).thenReturn(Arrays.asList(group1));
- session.getActivePdpGroupsByPolicyType(type);
-
- // not new yet
- assertFalse(session.isNewlyCreated(GROUP_NAME));
-
- // update it
- session.setNewGroup(new PdpGroup(group1));
- assertTrue(session.isNewlyCreated(GROUP_NAME));
-
- /*
- * now try group2
- */
- assertFalse(session.isNewlyCreated(GROUP_NAME2));
-
- // cause the group to be loaded into the cache
- when(dao.getFilteredPdpGroups(any())).thenReturn(Arrays.asList(group2));
- session.getActivePdpGroupsByPolicyType(type2);
-
- // not new yet
- assertFalse(session.isNewlyCreated(GROUP_NAME2));
- assertTrue(session.isNewlyCreated(GROUP_NAME));
-
- // update it
- session.setNewGroup(new PdpGroup(group2));
- assertTrue(session.isNewlyCreated(GROUP_NAME2));
- assertTrue(session.isNewlyCreated(GROUP_NAME));
- }
-
- private PdpGroup makeGroup(String name, String version) {
+ private PdpGroup makeGroup(String name) {
PdpGroup group = new PdpGroup();
group.setName(name);
- group.setVersion(version);
return group;
}
@Test
- public void testSetNewGroup() throws Exception {
+ public void testUpdate() throws Exception {
// force the groups into the cache
when(dao.getFilteredPdpGroups(any())).thenReturn(Arrays.asList(group1, group2));
session.getActivePdpGroupsByPolicyType(type);
@@ -244,66 +202,33 @@ public class TestSessionData extends ProviderSuper {
*/
when(dao.getFilteredPdpGroups(any())).thenReturn(Arrays.asList(group1));
PdpGroup newgrp = new PdpGroup(group1);
- session.setNewGroup(newgrp);
- assertEquals(GROUP_NEW_VERSION, newgrp.getVersion().toString());
+ session.update(newgrp);
- // repeat - version should be unchanged
+ // repeat
newgrp = new PdpGroup(group1);
- session.setNewGroup(newgrp);
- assertEquals(GROUP_NEW_VERSION, newgrp.getVersion().toString());
+ session.update(newgrp);
/*
* try group 2
*/
when(dao.getFilteredPdpGroups(any())).thenReturn(Arrays.asList(group2));
newgrp = new PdpGroup(group2);
- session.setNewGroup(newgrp);
- assertEquals(GROUP_NEW_VERSION, newgrp.getVersion().toString());
+ session.update(newgrp);
- // repeat - version should be unchanged
+ // repeat
newgrp = new PdpGroup(group2);
- session.setNewGroup(newgrp);
- assertEquals(GROUP_NEW_VERSION, newgrp.getVersion().toString());
-
- // should have queried the DB once by type and twice by for latest version
- verify(dao, times(3)).getFilteredPdpGroups(any());
+ session.update(newgrp);
}
@Test
- public void testSetNewGroup_NotInCache() throws Exception {
+ public void testUpdate_NotInCache() throws Exception {
when(dao.getFilteredPdpGroups(any())).thenReturn(Arrays.asList(group1));
- assertThatIllegalStateException().isThrownBy(() -> session.setNewGroup(new PdpGroup(group1)))
+ assertThatIllegalStateException().isThrownBy(() -> session.update(new PdpGroup(group1)))
.withMessage("group not cached: groupA");
}
@Test
- public void testSetNewGroup_NotFound() throws Exception {
- // force the group into the cache
- when(dao.getFilteredPdpGroups(any())).thenReturn(Arrays.asList(group1));
- session.getActivePdpGroupsByPolicyType(type);
-
- // query for latest version will return an empty list
- when(dao.getFilteredPdpGroups(any())).thenReturn(Collections.emptyList());
-
- assertThatThrownBy(() -> session.setNewGroup(new PdpGroup(group1)))
- .isInstanceOf(PolicyPapRuntimeException.class).hasMessage("cannot find group: groupA");
- }
-
- @Test
- public void testSetNewGroup_InvalidVersion() throws Exception {
- // force the groups into the cache
- group1.setVersion("invalid version");
- when(dao.getFilteredPdpGroups(any())).thenReturn(Arrays.asList(group1));
- session.getActivePdpGroupsByPolicyType(type);
-
- when(dao.getFilteredPdpGroups(any())).thenReturn(Arrays.asList(group1));
- PdpGroup newgrp = new PdpGroup(group1);
- session.setNewGroup(newgrp);
- assertEquals("1.0.0", newgrp.getVersion().toString());
- }
-
- @Test
public void testGetActivePdpGroupsByPolicyType() throws Exception {
List<PdpGroup> groups = Arrays.asList(group1, group2);
when(dao.getFilteredPdpGroups(any())).thenReturn(groups);
@@ -338,36 +263,31 @@ public class TestSessionData extends ProviderSuper {
@Test
public void testUpdateDb() throws Exception {
// force the groups into the cache
- PdpGroup group3 = makeGroup("groupC", GROUP_VERSION2);
+ PdpGroup group3 = makeGroup("groupC");
when(dao.getFilteredPdpGroups(any())).thenReturn(Arrays.asList(group1, group2, group3));
session.getActivePdpGroupsByPolicyType(type);
// update group 1
when(dao.getFilteredPdpGroups(any())).thenReturn(Arrays.asList(group1));
PdpGroup newgrp1 = new PdpGroup(group1);
- session.setNewGroup(newgrp1);
+ session.update(newgrp1);
// another update
newgrp1 = new PdpGroup(newgrp1);
- session.setNewGroup(newgrp1);
+ session.update(newgrp1);
// update group 3
when(dao.getFilteredPdpGroups(any())).thenReturn(Arrays.asList(group3));
PdpGroup newgrp3 = new PdpGroup(group3);
- session.setNewGroup(newgrp3);
+ session.update(newgrp3);
// push the changes to the DB
session.updateDb();
- // expect one create for groups 1 & 3
- List<PdpGroup> changes = getGroupCreates();
+ // expect one update for groups 1 & 3
+ List<PdpGroup> changes = getGroupUpdates();
assertSame(newgrp1, changes.get(0));
assertSame(newgrp3, changes.get(1));
-
- // expect one update for groups 1 & 3
- changes = getGroupUpdates();
- assertSame(group1, changes.get(0));
- assertSame(group3, changes.get(1));
}
@Test
diff --git a/main/src/test/resources/simpleDeploy/getGroupDao.json b/main/src/test/resources/simpleDeploy/getGroupDao.json
index 65d0907a..7fd7684b 100644
--- a/main/src/test/resources/simpleDeploy/getGroupDao.json
+++ b/main/src/test/resources/simpleDeploy/getGroupDao.json
@@ -16,67 +16,8 @@
{
"instanceId": "pdpA"
}
- ]
- }
- ]
- },
- {
- "name": "groupA",
- "version": "200.2.3",
- "pdpSubgroups": [
- {
- "pdpType": "pdpTypeA",
- "supportedPolicyTypes": [
- {
- "name": "typeA",
- "version": "100.2.3"
- }
],
- "pdpInstances": [
- {
- "instanceId": "pdpA"
- }
- ]
- }
- ]
- },
- {
- "name": "groupA",
- "version": "0.0.1",
- "pdpSubgroups": [
- {
- "pdpType": "pdpTypeA",
- "supportedPolicyTypes": [
- {
- "name": "typeA",
- "version": "100.2.3"
- }
- ],
- "pdpInstances": [
- {
- "instanceId": "pdpA"
- }
- ]
- }
- ]
- },
- {
- "name": "groupA",
- "version": "non-numeric-version",
- "pdpSubgroups": [
- {
- "pdpType": "pdpTypeA",
- "supportedPolicyTypes": [
- {
- "name": "typeA",
- "version": "100.2.3"
- }
- ],
- "pdpInstances": [
- {
- "instanceId": "pdpA"
- }
- ]
+ "policies": []
}
]
}