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/TestPdpGroupDeleteControllerV1.java4
-rw-r--r--main/src/test/java/org/onap/policy/pap/main/rest/depundep/TestPdpGroupDeleteProvider.java6
-rw-r--r--main/src/test/java/org/onap/policy/pap/main/rest/depundep/TestPdpGroupDeployProvider.java11
-rw-r--r--main/src/test/java/org/onap/policy/pap/main/rest/depundep/TestProviderBase.java36
-rw-r--r--main/src/test/java/org/onap/policy/pap/main/rest/depundep/TestSessionData.java94
-rw-r--r--main/src/test/resources/simpleDeploy/getPolicyReqNullVersion.json7
6 files changed, 70 insertions, 88 deletions
diff --git a/main/src/test/java/org/onap/policy/pap/main/rest/depundep/TestPdpGroupDeleteControllerV1.java b/main/src/test/java/org/onap/policy/pap/main/rest/depundep/TestPdpGroupDeleteControllerV1.java
index 458ca9e7..f7390553 100644
--- a/main/src/test/java/org/onap/policy/pap/main/rest/depundep/TestPdpGroupDeleteControllerV1.java
+++ b/main/src/test/java/org/onap/policy/pap/main/rest/depundep/TestPdpGroupDeleteControllerV1.java
@@ -70,12 +70,12 @@ public class TestPdpGroupDeleteControllerV1 extends CommonPapRestServer {
Response rawresp = invocationBuilder.delete();
PdpGroupDeleteResponse resp = rawresp.readEntity(PdpGroupDeleteResponse.class);
assertEquals(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), rawresp.getStatus());
- assertEquals("cannot find policy: my-name", resp.getErrorDetails());
+ assertEquals("cannot find policy: my-name null", resp.getErrorDetails());
rawresp = invocationBuilder.delete();
resp = rawresp.readEntity(PdpGroupDeleteResponse.class);
assertEquals(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), rawresp.getStatus());
- assertEquals("cannot find policy: my-name", resp.getErrorDetails());
+ assertEquals("cannot find policy: my-name null", resp.getErrorDetails());
// verify it fails when no authorization info is included
checkUnauthRequest(uri, req -> req.delete());
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 c0b08644..5824b4b0 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,8 +56,6 @@ import org.onap.policy.pap.main.PolicyPapRuntimeException;
public class TestPdpGroupDeleteProvider extends ProviderSuper {
private static final String EXPECTED_EXCEPTION = "expected exception";
- private static final String POLICY1_NAME = "policyA";
- private static final String POLICY1_VERSION = "1.2.3";
private static final String GROUP1_NAME = "groupA";
private MyProvider prov;
@@ -169,9 +167,7 @@ public class TestPdpGroupDeleteProvider extends ProviderSuper {
PdpGroup group = loadGroup("undeploy.json");
when(dao.getFilteredPdpGroups(any())).thenReturn(Arrays.asList(group));
-
- when(dao.getPolicyList(POLICY1_NAME, "1.2.300")).thenReturn(Arrays.asList(policy1));
- when(dao.getPolicyList("policyB", POLICY1_VERSION)).thenReturn(Arrays.asList(policy1));
+ when(dao.getFilteredPolicyList(any())).thenReturn(Arrays.asList(policy1));
Pair<Status, PdpGroupDeleteResponse> pair = new PdpGroupDeleteProvider().undeploy(optIdent);
assertEquals(Status.OK, pair.getLeft());
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 cad73d92..12c2adad 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
@@ -58,7 +58,6 @@ public class TestPdpGroupDeployProvider extends ProviderSuper {
private static final String EXPECTED_EXCEPTION = "expected exception";
private static final Object REQUEST_FAILED_MSG = "request failed";
- private static final String POLICY1_NAME = "policyA";
private static final String POLICY2_NAME = "policyB";
private static final String POLICY1_VERSION = "1.2.3";
private static final String GROUP1_NAME = "groupA";
@@ -86,7 +85,7 @@ public class TestPdpGroupDeployProvider extends ProviderSuper {
super.setUp();
- when(dao.getPolicyList(POLICY1_NAME, POLICY1_VERSION)).thenReturn(loadPolicies("daoPolicyList.json"));
+ when(dao.getFilteredPolicyList(any())).thenReturn(loadPolicies("daoPolicyList.json"));
prov = new PdpGroupDeployProvider();
}
@@ -279,7 +278,8 @@ 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.getPolicyList(POLICY2_NAME, POLICY1_VERSION)).thenReturn(loadPolicies("createGroupNewPolicy.json"));
+ when(dao.getFilteredPolicyList(any())).thenReturn(loadPolicies("daoPolicyList.json"))
+ .thenReturn(loadPolicies("createGroupNewPolicy.json"));
assertEquals(Status.OK, prov.createOrUpdateGroups(groups).getLeft());
@@ -424,7 +424,8 @@ public class TestPdpGroupDeployProvider extends ProviderSuper {
PdpSubGroup subgrp = newgrp.getPdpSubgroups().get(0);
subgrp.getPolicies().add(new ToscaPolicyIdentifier(POLICY2_NAME, POLICY1_VERSION));
- when(dao.getPolicyList(POLICY2_NAME, POLICY1_VERSION)).thenReturn(loadPolicies("createGroupNewPolicy.json"));
+ when(dao.getFilteredPolicyList(any())).thenReturn(loadPolicies("daoPolicyList.json"))
+ .thenReturn(loadPolicies("createGroupNewPolicy.json"));
assertEquals(Status.OK, prov.createOrUpdateGroups(groups).getLeft());
@@ -478,7 +479,7 @@ public class TestPdpGroupDeployProvider extends ProviderSuper {
@Test
public void testDeploySimplePolicies_RuntimeEx() throws Exception {
- when(dao.getPolicyList(any(), any())).thenThrow(new RuntimeException(EXPECTED_EXCEPTION));
+ when(dao.getFilteredPolicyList(any())).thenThrow(new RuntimeException(EXPECTED_EXCEPTION));
Pair<Status, PdpGroupDeployResponse> pair = prov.deployPolicies(loadRequest());
assertEquals(Status.INTERNAL_SERVER_ERROR, pair.getLeft());
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 01b29b10..bec93e2d 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
@@ -89,7 +89,7 @@ public class TestProviderBase extends ProviderSuper {
super.setUp();
- when(dao.getPolicyList(POLICY1_NAME, POLICY1_VERSION)).thenReturn(loadPolicies("daoPolicyList.json"));
+ when(dao.getFilteredPolicyList(any())).thenReturn(loadPolicies("daoPolicyList.json"));
prov = new MyProvider();
}
@@ -156,33 +156,7 @@ public class TestProviderBase extends ProviderSuper {
assertEquals(Status.OK, pair.getLeft());
assertNull(pair.getRight().getErrorDetails());
- verify(dao).getPolicyList(any(), any());
- verify(dao, never()).getFilteredPolicyList(any());
- }
-
- @Test
- public void testGetPolicy_NullVersion() throws Exception {
- // only allow this query once
- when(dao.getPolicyList(POLICY1_NAME, POLICY1_VERSION)).thenReturn(loadPolicies("daoPolicyList.json"))
- .thenThrow(new RuntimeException(EXPECTED_EXCEPTION));
-
- when(dao.getFilteredPolicyList(any())).thenReturn(loadPolicies("daoPolicyList.json"));
-
- Pair<Status, MyResponse> pair = prov.process(loadRequest("getPolicyReqNullVersion.json"), this::handle);
- assertEquals(Status.OK, pair.getLeft());
- assertNull(pair.getRight().getErrorDetails());
-
verify(dao).getFilteredPolicyList(any());
- verify(dao, never()).getPolicies(any(), any());
- }
-
- @Test
- public void testGetPolicy_NotFound() throws Exception {
- when(dao.getPolicyList(any(), any())).thenReturn(Collections.emptyList());
-
- Pair<Status, MyResponse> pair = prov.process(loadRequest(), this::handle);
- assertEquals(Status.INTERNAL_SERVER_ERROR, pair.getLeft());
- assertEquals("cannot find policy: " + POLICY1_NAME + " " + POLICY1_VERSION, pair.getRight().getErrorDetails());
}
@Test
@@ -245,10 +219,10 @@ public class TestProviderBase extends ProviderSuper {
* Should generate updates to pdp1, pdp2, and pdp3.
*/
- when(dao.getPolicyList(POLICY1_NAME, POLICY1_VERSION)).thenReturn(loadPolicies("daoPolicyList.json"));
- when(dao.getPolicyList("policyB", POLICY1_VERSION)).thenReturn(loadPolicies("upgradeGroupPolicy2.json"));
- when(dao.getPolicyList("policyC", POLICY1_VERSION)).thenReturn(loadPolicies("upgradeGroupPolicy3.json"));
- when(dao.getPolicyList("policyD", POLICY1_VERSION)).thenReturn(loadPolicies("upgradeGroupPolicy4.json"));
+ when(dao.getFilteredPolicyList(any())).thenReturn(loadPolicies("daoPolicyList.json"))
+ .thenReturn(loadPolicies("upgradeGroupPolicy2.json"))
+ .thenReturn(loadPolicies("upgradeGroupPolicy3.json"))
+ .thenReturn(loadPolicies("upgradeGroupPolicy4.json"));
List<PdpGroup> groups1 = loadGroups("upgradeGroupGroup1.json");
List<PdpGroup> groups2 = loadGroups("upgradeGroupGroup2.json");
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 2eac4324..e74f9f86 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
@@ -43,12 +43,14 @@ import javax.ws.rs.core.Response.Status;
import org.apache.commons.lang3.tuple.Pair;
import org.junit.Before;
import org.junit.Test;
+import org.mockito.ArgumentCaptor;
import org.onap.policy.models.base.PfModelException;
import org.onap.policy.models.pdp.concepts.PdpGroup;
import org.onap.policy.models.pdp.concepts.PdpStateChange;
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.ToscaPolicyFilter;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyIdentifierOptVersion;
import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyTypeIdentifier;
import org.onap.policy.pap.main.PolicyPapRuntimeException;
@@ -60,13 +62,12 @@ public class TestSessionData extends ProviderSuper {
private static final String POLICY_VERSION_PREFIX = "1.2.";
private static final String POLICY_NAME = "myPolicy";
private static final String POLICY_VERSION = POLICY_VERSION_PREFIX + "3";
- private static final String POLICY_VERSION2 = POLICY_VERSION_PREFIX + "4";
private static final String POLICY_TYPE = "myType";
private static final String POLICY_TYPE_VERSION = "10.20.30";
private static final String EXPECTED_EXCEPTION = "expected exception";
private SessionData session;
- private ToscaPolicyIdentifier ident;
+ private ToscaPolicyIdentifierOptVersion ident;
private ToscaPolicyTypeIdentifier type;
private ToscaPolicyTypeIdentifier type2;
private PdpGroup group1;
@@ -81,7 +82,7 @@ public class TestSessionData extends ProviderSuper {
public void setUp() throws Exception {
super.setUp();
- ident = new ToscaPolicyIdentifier(POLICY_NAME, POLICY_VERSION);
+ ident = new ToscaPolicyIdentifierOptVersion(POLICY_NAME, POLICY_VERSION);
type = new ToscaPolicyTypeIdentifier(POLICY_TYPE, POLICY_TYPE_VERSION);
type2 = new ToscaPolicyTypeIdentifier(POLICY_TYPE, POLICY_TYPE_VERSION + "0");
group1 = loadGroup("group1.json");
@@ -91,32 +92,62 @@ public class TestSessionData extends ProviderSuper {
}
@Test
- public void testGetPolicy() throws Exception {
+ public void testGetPolicy_NullVersion() throws Exception {
ToscaPolicy policy1 = makePolicy(POLICY_NAME, POLICY_VERSION);
- when(dao.getPolicyList(POLICY_NAME, POLICY_VERSION)).thenReturn(Arrays.asList(policy1));
+ when(dao.getFilteredPolicyList(any())).thenReturn(Arrays.asList(policy1));
- ToscaPolicy policy2 = makePolicy(POLICY_NAME, POLICY_VERSION2);
- when(dao.getPolicyList(POLICY_NAME, POLICY_VERSION2)).thenReturn(Arrays.asList(policy2));
+ ident.setVersion(null);
+ assertSame(policy1, session.getPolicy(ident));
- ToscaPolicyIdentifier ident2 = new ToscaPolicyIdentifier(POLICY_NAME, POLICY_VERSION2);
+ ToscaPolicyFilter filter = getPolicyFilter();
+ assertEquals(POLICY_NAME, filter.getName());
+ assertEquals(ToscaPolicyFilter.LATEST_VERSION, filter.getVersion());
+ assertEquals(null, filter.getVersionPrefix());
- assertSame(policy1, session.getPolicy(ident));
- assertSame(policy2, session.getPolicy(ident2));
+ // retrieve a second time using full version - should use cache
+ assertSame(policy1, session.getPolicy(new ToscaPolicyIdentifierOptVersion(policy1.getIdentifier())));
+ verify(dao).getFilteredPolicyList(any());
+ }
- // repeat
+ @Test
+ public void testGetPolicy_MajorVersion() throws Exception {
+ ToscaPolicy policy1 = makePolicy(POLICY_NAME, POLICY_VERSION);
+ when(dao.getFilteredPolicyList(any())).thenReturn(Arrays.asList(policy1));
+
+ ident.setVersion("1");
assertSame(policy1, session.getPolicy(ident));
- assertSame(policy2, session.getPolicy(ident2));
+ ToscaPolicyFilter filter = getPolicyFilter();
+ assertEquals(POLICY_NAME, filter.getName());
+ assertEquals(ToscaPolicyFilter.LATEST_VERSION, filter.getVersion());
+ assertEquals("1.", filter.getVersionPrefix());
+
+ // retrieve a second time using full version - should use cache
+ assertSame(policy1, session.getPolicy(new ToscaPolicyIdentifierOptVersion(policy1.getIdentifier())));
+ verify(dao).getFilteredPolicyList(any());
+ }
+
+ @Test
+ public void testGetPolicy_MajorMinorVersion() throws Exception {
+ ToscaPolicy policy1 = makePolicy(POLICY_NAME, POLICY_VERSION);
+ when(dao.getFilteredPolicyList(any())).thenReturn(Arrays.asList(policy1));
+
+ ident.setVersion(POLICY_VERSION);
assertSame(policy1, session.getPolicy(ident));
- assertSame(policy2, session.getPolicy(ident2));
- // should have only invoked this once for each policy
- verify(dao, times(2)).getPolicyList(any(), any());
+ ToscaPolicyFilter filter = getPolicyFilter();
+ assertEquals(POLICY_NAME, filter.getName());
+ assertEquals(POLICY_VERSION, filter.getVersion());
+ assertEquals(null, filter.getVersionPrefix());
+
+ // retrieve a second time using full version - should use cache
+ assertSame(policy1, session.getPolicy(new ToscaPolicyIdentifierOptVersion(policy1.getIdentifier())));
+ verify(dao).getFilteredPolicyList(any());
}
@Test
public void testGetPolicy_NotFound() throws Exception {
- when(dao.getPolicyList(any(), any())).thenReturn(Collections.emptyList());
+ when(dao.getFilteredPolicyList(any())).thenReturn(Collections.emptyList());
assertThatThrownBy(() -> session.getPolicy(ident)).hasMessage("cannot find policy: myPolicy 1.2.3");
}
@@ -124,7 +155,7 @@ public class TestSessionData extends ProviderSuper {
@Test
public void testGetPolicy_DaoEx() throws Exception {
PfModelException ex = new PfModelException(Status.INTERNAL_SERVER_ERROR, "expected exception");
- when(dao.getPolicyList(any(), any())).thenThrow(ex);
+ when(dao.getFilteredPolicyList(any())).thenThrow(ex);
assertThatThrownBy(() -> session.getPolicy(ident)).hasMessage("cannot get policy: myPolicy 1.2.3").hasCause(ex);
}
@@ -250,26 +281,6 @@ public class TestSessionData extends ProviderSuper {
}
@Test
- public void testGetPolicyMaxVersion() throws Exception {
- ToscaPolicy policy1 = makePolicy(POLICY_NAME, POLICY_VERSION);
-
- when(dao.getFilteredPolicyList(any())).thenReturn(Arrays.asList(policy1));
-
- assertSame(policy1, session.getPolicyMaxVersion(POLICY_NAME));
- assertSame(policy1, session.getPolicyMaxVersion(POLICY_NAME));
- assertSame(policy1, session.getPolicyMaxVersion(POLICY_NAME));
-
- // should have only invoked DAO once; used cache for other requests
- verify(dao, times(1)).getFilteredPolicyList(any());
- }
-
- @Test
- public void testGetPolicyMaxVersion_NotFound() throws Exception {
- when(dao.getFilteredPolicyList(any())).thenReturn(Collections.emptyList());
- assertThatThrownBy(() -> session.getPolicyMaxVersion(POLICY_NAME)).hasMessage("cannot find policy: myPolicy");
- }
-
- @Test
public void testCreate() throws Exception {
session.create(group1);
assertSame(group1, session.getGroup(group1.getName()));
@@ -478,6 +489,13 @@ public class TestSessionData extends ProviderSuper {
return change;
}
+ private ToscaPolicyFilter getPolicyFilter() throws Exception {
+ ArgumentCaptor<ToscaPolicyFilter> captor = ArgumentCaptor.forClass(ToscaPolicyFilter.class);
+ verify(dao).getFilteredPolicyList(captor.capture());
+
+ return captor.getValue();
+ }
+
private List<PdpUpdate> getUpdateRequests() {
return session.getPdpUpdates();
}
diff --git a/main/src/test/resources/simpleDeploy/getPolicyReqNullVersion.json b/main/src/test/resources/simpleDeploy/getPolicyReqNullVersion.json
deleted file mode 100644
index 5f9f8c9e..00000000
--- a/main/src/test/resources/simpleDeploy/getPolicyReqNullVersion.json
+++ /dev/null
@@ -1,7 +0,0 @@
-{
- "policies": [
- {
- "policy-id": "policyA"
- }
- ]
-}