Support integer policy-version 47/85347/2
authorJim Hahn <jrh3@att.com>
Mon, 15 Apr 2019 14:19:26 +0000 (10:19 -0400)
committerJim Hahn <jrh3@att.com>
Mon, 15 Apr 2019 16:39:45 +0000 (12:39 -0400)
The deploy/undeploy APIs used by CLAMP only pass the major number
when specifying a policy-version.  Modified the code to handle
policy-versions of the form, major or major.minor.

Change-Id: I3251df162984f287bd1430b8e46da675b4c265ee
Issue-ID: POLICY-1542
Signed-off-by: Jim Hahn <jrh3@att.com>
main/src/main/java/org/onap/policy/pap/main/rest/depundep/PdpGroupDeployProvider.java
main/src/main/java/org/onap/policy/pap/main/rest/depundep/ProviderBase.java
main/src/main/java/org/onap/policy/pap/main/rest/depundep/SessionData.java
main/src/test/java/org/onap/policy/pap/main/rest/depundep/TestPdpGroupDeleteControllerV1.java
main/src/test/java/org/onap/policy/pap/main/rest/depundep/TestPdpGroupDeleteProvider.java
main/src/test/java/org/onap/policy/pap/main/rest/depundep/TestPdpGroupDeployProvider.java
main/src/test/java/org/onap/policy/pap/main/rest/depundep/TestProviderBase.java
main/src/test/java/org/onap/policy/pap/main/rest/depundep/TestSessionData.java
main/src/test/resources/simpleDeploy/getPolicyReqNullVersion.json [deleted file]

index cb2d1e3..3d44a0c 100644 (file)
@@ -351,7 +351,7 @@ public class PdpGroupDeployProvider extends ProviderBase<PdpGroupDeployResponse>
         BeanValidationResult result = new BeanValidationResult(subgrp.getPdpType(), subgrp);
 
         for (ToscaPolicyIdentifier ident : subgrp.getPolicies()) {
-            ToscaPolicy policy = data.getPolicy(ident);
+            ToscaPolicy policy = data.getPolicy(new ToscaPolicyIdentifierOptVersion(ident));
 
             if (!subgrp.getSupportedPolicyTypes().contains(policy.getTypeIdentifier())) {
                 result.addResult(new ObjectValidationResult("policy", ident, ValidationStatus.INVALID,
index 5e0fb71..b7575df 100644 (file)
@@ -37,7 +37,6 @@ import org.onap.policy.models.pdp.concepts.PdpSubGroup;
 import org.onap.policy.models.pdp.concepts.PdpUpdate;
 import org.onap.policy.models.provider.PolicyModelsProvider;
 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.ToscaPolicyIdentifierOptVersion;
 import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyTypeIdentifier;
 import org.onap.policy.pap.main.PapConstants;
@@ -155,12 +154,7 @@ public abstract class ProviderBase<R extends SimpleResponse> {
     private ToscaPolicy getPolicy(SessionData data, ToscaPolicyIdentifierOptVersion desiredPolicy)
                     throws PfModelException {
 
-        if (desiredPolicy.isNullVersion()) {
-            return data.getPolicyMaxVersion(desiredPolicy.getName());
-
-        } else {
-            return data.getPolicy(new ToscaPolicyIdentifier(desiredPolicy.getName(), desiredPolicy.getVersion()));
-        }
+        return data.getPolicy(desiredPolicy);
     }
 
     /**
@@ -276,7 +270,8 @@ public abstract class ProviderBase<R extends SimpleResponse> {
         update.setDescription(group.getDescription());
         update.setPdpGroup(group.getName());
         update.setPdpSubgroup(subgroup.getPdpType());
-        update.setPolicies(subgroup.getPolicies().stream().map(data::getPolicy).collect(Collectors.toList()));
+        update.setPolicies(subgroup.getPolicies().stream().map(ToscaPolicyIdentifierOptVersion::new)
+                        .map(data::getPolicy).collect(Collectors.toList()));
 
         return update;
     }
index 0537c80..b7aff76 100644 (file)
@@ -25,6 +25,7 @@ import java.util.Collections;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.regex.Pattern;
 import java.util.stream.Collectors;
 import org.apache.commons.lang3.tuple.Pair;
 import org.onap.policy.models.base.PfModelException;
@@ -36,7 +37,8 @@ import org.onap.policy.models.pdp.enums.PdpState;
 import org.onap.policy.models.provider.PolicyModelsProvider;
 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.ToscaPolicyIdentifier;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyFilter.ToscaPolicyFilterBuilder;
+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;
 
@@ -44,6 +46,14 @@ import org.onap.policy.pap.main.PolicyPapRuntimeException;
  * Data used during a single REST call when updating PDP policies.
  */
 public class SessionData {
+    /**
+     * If a version string matches this, then it is just a prefix (i.e., major or major.minor).
+     */
+    private static final Pattern VERSION_PREFIX_PAT = Pattern.compile("[^.]+(?:[.][^.]*)?");
+
+    /**
+     * DB provider.
+     */
     private final PolicyModelsProvider dao;
 
     /**
@@ -66,13 +76,7 @@ public class SessionData {
     /**
      * Maps a policy's identifier to the policy.
      */
-    private final Map<ToscaPolicyIdentifier, ToscaPolicy> policyCache = new HashMap<>();
-
-    /**
-     * Maps a policy name to its latest policy. Every policy appearing within this map has
-     * a corresponding entry in {@link #policyCache}.
-     */
-    private final Map<String, ToscaPolicy> latestPolicy = new HashMap<>();
+    private final Map<ToscaPolicyIdentifierOptVersion, ToscaPolicy> policyCache = new HashMap<>();
 
 
     /**
@@ -88,28 +92,50 @@ public class SessionData {
      * Gets the policy, referenced by an identifier. Loads it from the cache, if possible.
      * Otherwise, gets it from the DB.
      *
-     * @param ident policy identifier
+     * @param desiredPolicy policy identifier
      * @return the specified policy
      * @throws PolicyPapRuntimeException if an error occurs
      */
-    public ToscaPolicy getPolicy(ToscaPolicyIdentifier ident) {
+    public ToscaPolicy getPolicy(ToscaPolicyIdentifierOptVersion desiredPolicy) {
 
-        return policyCache.computeIfAbsent(ident, key -> {
+        ToscaPolicy policy = policyCache.computeIfAbsent(desiredPolicy, key -> {
 
             try {
-                List<ToscaPolicy> lst = dao.getPolicyList(ident.getName(), ident.getVersion());
+                ToscaPolicyFilterBuilder filterBuilder = ToscaPolicyFilter.builder().name(desiredPolicy.getName());
+
+                String version = desiredPolicy.getVersion();
+                if (version == null) {
+                    // no version specified - get the latest
+                    filterBuilder.version(ToscaPolicyFilter.LATEST_VERSION);
+
+                } else if (VERSION_PREFIX_PAT.matcher(version).matches()) {
+                    // version prefix provided - match the prefix and then pick the latest
+                    filterBuilder.versionPrefix(version + ".").version(ToscaPolicyFilter.LATEST_VERSION);
+
+                } else {
+                    // must be an exact match
+                    filterBuilder.version(version);
+                }
+
+
+                List<ToscaPolicy> lst = dao.getFilteredPolicyList(filterBuilder.build());
                 if (lst.isEmpty()) {
-                    throw new PolicyPapRuntimeException(
-                                    "cannot find policy: " + ident.getName() + " " + ident.getVersion());
+                    throw new PolicyPapRuntimeException("cannot find policy: " + desiredPolicy.getName() + " "
+                                    + desiredPolicy.getVersion());
                 }
 
                 return lst.get(0);
 
             } catch (PfModelException e) {
-                throw new PolicyPapRuntimeException("cannot get policy: " + ident.getName() + " " + ident.getVersion(),
-                                e);
+                throw new PolicyPapRuntimeException(
+                                "cannot get policy: " + desiredPolicy.getName() + " " + desiredPolicy.getVersion(), e);
             }
         });
+
+        // desired version may have only been a prefix - cache with full identifier, too
+        policyCache.putIfAbsent(new ToscaPolicyIdentifierOptVersion(policy.getIdentifier()), policy);
+
+        return policy;
     }
 
     /**
@@ -176,33 +202,6 @@ public class SessionData {
                         .collect(Collectors.toList());
     }
 
-    /**
-     * Gets the policy having the given name and the maximum version.
-     *
-     * @param name name of the desired policy
-     * @return the desired policy, or {@code null} if there is no policy with given name
-     * @throws PfModelException if an error occurs
-     */
-    public ToscaPolicy getPolicyMaxVersion(String name) throws PfModelException {
-        ToscaPolicy policy = latestPolicy.get(name);
-        if (policy != null) {
-            return policy;
-        }
-
-        ToscaPolicyFilter filter =
-                        ToscaPolicyFilter.builder().name(name).version(ToscaPolicyFilter.LATEST_VERSION).build();
-        List<ToscaPolicy> policies = dao.getFilteredPolicyList(filter);
-        if (policies.isEmpty()) {
-            throw new PolicyPapRuntimeException("cannot find policy: " + name);
-        }
-
-        policy = policies.get(0);
-        policyCache.putIfAbsent(policy.getIdentifier(), policy);
-        latestPolicy.put(name, policy);
-
-        return policy;
-    }
-
     /**
      * Creates a group.
      *
index 458ca9e..f739055 100644 (file)
@@ -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());
index c0b0864..5824b4b 100644 (file)
@@ -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());
index cad73d9..12c2ada 100644 (file)
@@ -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());
index 01b29b1..bec93e2 100644 (file)
@@ -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");
index 2eac432..e74f9f8 100644 (file)
@@ -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);
     }
@@ -249,26 +280,6 @@ public class TestSessionData extends ProviderSuper {
         return policy;
     }
 
-    @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);
@@ -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 (file)
index 5f9f8c9..0000000
+++ /dev/null
@@ -1,7 +0,0 @@
-{
-    "policies": [
-        {
-            "policy-id": "policyA"
-        }
-    ]
-}