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/TestPdpGroupDeployProvider.java50
-rw-r--r--main/src/test/java/org/onap/policy/pap/main/rest/depundep/TestSessionData.java14
-rw-r--r--main/src/test/resources/simpleDeploy/createGroupsNewSubNotFound.json56
-rw-r--r--main/src/test/resources/simpleDeploy/createGroupsVersPrefix.json39
-rw-r--r--main/src/test/resources/simpleDeploy/createGroupsVersPrefixMismatch.json39
5 files changed, 194 insertions, 4 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 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));
@@ -452,6 +454,45 @@ public class TestPdpGroupDeployProvider extends ProviderSuper {
}
@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");
PdpGroup newgrp = groups.getGroups().get(0);
@@ -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
@@ -189,6 +189,20 @@ public class TestSessionData extends ProviderSuper {
}
@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
PdpUpdate update2 = makeUpdate(PDP2);
diff --git a/main/src/test/resources/simpleDeploy/createGroupsNewSubNotFound.json b/main/src/test/resources/simpleDeploy/createGroupsNewSubNotFound.json
new file mode 100644
index 00000000..f4717008
--- /dev/null
+++ b/main/src/test/resources/simpleDeploy/createGroupsNewSubNotFound.json
@@ -0,0 +1,56 @@
+{
+ "groups": [
+ {
+ "name": "groupA",
+ "version": "200.2.3",
+ "description": "my description",
+ "pdpGroupState": "ACTIVE",
+ "properties": {
+ "hello": "world"
+ },
+ "pdpSubgroups": [
+ {
+ "pdpType": "pdpTypeA",
+ "desiredInstanceCount": 1,
+ "properties": {
+ "abc": "def"
+ },
+ "supportedPolicyTypes": [
+ {
+ "name": "typeA",
+ "version": "100.2.3"
+ }
+ ],
+ "pdpInstances": [
+ {
+ "instanceId": "pdpA"
+ }
+ ],
+ "policies": [
+ {
+ "name": "policy-unknown",
+ "version": "9.9.9"
+ }
+ ]
+ },
+ {
+ "pdpType": "pdpTypeB",
+ "desiredInstanceCount": 1,
+ "currentInstanceCount": 22,
+ "supportedPolicyTypes": [
+ {
+ "name": "typeA",
+ "version": "100.2.3"
+ }
+ ],
+ "pdpInstances": [
+ {
+ "instanceId": "pdpB"
+ }
+ ],
+ "policies": []
+ }
+ ]
+ }
+ ]
+}
diff --git a/main/src/test/resources/simpleDeploy/createGroupsVersPrefix.json b/main/src/test/resources/simpleDeploy/createGroupsVersPrefix.json
new file mode 100644
index 00000000..e53d927d
--- /dev/null
+++ b/main/src/test/resources/simpleDeploy/createGroupsVersPrefix.json
@@ -0,0 +1,39 @@
+{
+ "groups": [
+ {
+ "name": "groupA",
+ "version": "200.2.3",
+ "description": "my description",
+ "pdpGroupState": "ACTIVE",
+ "properties": {
+ "hello": "world"
+ },
+ "pdpSubgroups": [
+ {
+ "pdpType": "pdpTypeA",
+ "desiredInstanceCount": 1,
+ "properties": {
+ "abc": "def"
+ },
+ "supportedPolicyTypes": [
+ {
+ "name": "typeA",
+ "version": "100.2.3"
+ }
+ ],
+ "pdpInstances": [
+ {
+ "instanceId": "pdpA"
+ }
+ ],
+ "policies": [
+ {
+ "name": "policyA",
+ "version": "1"
+ }
+ ]
+ }
+ ]
+ }
+ ]
+}
diff --git a/main/src/test/resources/simpleDeploy/createGroupsVersPrefixMismatch.json b/main/src/test/resources/simpleDeploy/createGroupsVersPrefixMismatch.json
new file mode 100644
index 00000000..2bf06419
--- /dev/null
+++ b/main/src/test/resources/simpleDeploy/createGroupsVersPrefixMismatch.json
@@ -0,0 +1,39 @@
+{
+ "groups": [
+ {
+ "name": "groupA",
+ "version": "200.2.3",
+ "description": "my description",
+ "pdpGroupState": "ACTIVE",
+ "properties": {
+ "hello": "world"
+ },
+ "pdpSubgroups": [
+ {
+ "pdpType": "pdpTypeA",
+ "desiredInstanceCount": 1,
+ "properties": {
+ "abc": "def"
+ },
+ "supportedPolicyTypes": [
+ {
+ "name": "typeA",
+ "version": "100.2.3"
+ }
+ ],
+ "pdpInstances": [
+ {
+ "instanceId": "pdpA"
+ }
+ ],
+ "policies": [
+ {
+ "name": "policyA",
+ "version": "9"
+ }
+ ]
+ }
+ ]
+ }
+ ]
+}