aboutsummaryrefslogtreecommitdiffstats
path: root/main/src/test/java/org/onap/policy/pap/main/rest/depundep/TestSessionData.java
diff options
context:
space:
mode:
Diffstat (limited to 'main/src/test/java/org/onap/policy/pap/main/rest/depundep/TestSessionData.java')
-rw-r--r--main/src/test/java/org/onap/policy/pap/main/rest/depundep/TestSessionData.java40
1 files changed, 38 insertions, 2 deletions
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 17acd5a2..f586d167 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
@@ -51,6 +51,7 @@ 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.ToscaPolicyFilter;
import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyIdentifierOptVersion;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyType;
import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyTypeIdentifier;
public class TestSessionData extends ProviderSuper {
@@ -91,6 +92,32 @@ public class TestSessionData extends ProviderSuper {
}
@Test
+ public void testGetPolicyType() throws Exception {
+ ToscaPolicyType policy1 = makePolicyType(POLICY_TYPE, POLICY_TYPE_VERSION);
+ when(dao.getPolicyTypeList(POLICY_TYPE, POLICY_TYPE_VERSION)).thenReturn(Arrays.asList(policy1));
+
+ assertSame(policy1, session.getPolicyType(type));
+
+ // retrieve a second time - should use cache
+ assertSame(policy1, session.getPolicyType(type));
+ }
+
+ @Test
+ public void testGetPolicyType_NotFound() throws Exception {
+ when(dao.getPolicyTypeList(any(), any())).thenReturn(Collections.emptyList());
+
+ assertNull(session.getPolicyType(type));
+ }
+
+ @Test
+ public void testGetPolicyType_DaoEx() throws Exception {
+ PfModelException ex = new PfModelException(Status.INTERNAL_SERVER_ERROR, EXPECTED_EXCEPTION);
+ when(dao.getPolicyTypeList(POLICY_TYPE, POLICY_TYPE_VERSION)).thenThrow(ex);
+
+ assertThatThrownBy(() -> session.getPolicyType(type)).isSameAs(ex);
+ }
+
+ @Test
public void testGetPolicy_NullVersion() throws Exception {
ToscaPolicy policy1 = makePolicy(POLICY_NAME, POLICY_VERSION);
when(dao.getFilteredPolicyList(any())).thenReturn(Arrays.asList(policy1));
@@ -148,12 +175,12 @@ public class TestSessionData extends ProviderSuper {
public void testGetPolicy_NotFound() throws Exception {
when(dao.getFilteredPolicyList(any())).thenReturn(Collections.emptyList());
- assertThatThrownBy(() -> session.getPolicy(ident)).hasMessage("cannot find policy: myPolicy 1.2.3");
+ assertNull(session.getPolicy(ident));
}
@Test
public void testGetPolicy_DaoEx() throws Exception {
- PfModelException ex = new PfModelException(Status.INTERNAL_SERVER_ERROR, "expected exception");
+ PfModelException ex = new PfModelException(Status.INTERNAL_SERVER_ERROR, EXPECTED_EXCEPTION);
when(dao.getFilteredPolicyList(any())).thenThrow(ex);
assertThatThrownBy(() -> session.getPolicy(ident)).isSameAs(ex);
@@ -270,6 +297,15 @@ public class TestSessionData extends ProviderSuper {
assertEquals(Arrays.asList(change1, change2, change3).toString(), lst.toString());
}
+ private ToscaPolicyType makePolicyType(String name, String version) {
+ ToscaPolicyType type = new ToscaPolicyType();
+
+ type.setName(name);
+ type.setVersion(version);
+
+ return type;
+ }
+
private ToscaPolicy makePolicy(String name, String version) {
ToscaPolicy policy = new ToscaPolicy();