Author: scottbw
Date: Thu Mar 1 15:40:02 2012
New Revision: 1295625
URL: http://svn.apache.org/viewvc?rev=1295625&view=rev
Log:
Fixed a problem with the Policies API when trying to delete a non-existant
policy.
Modified:
incubator/wookie/trunk/src-tests/org/apache/wookie/tests/functional/PoliciesControllerTest.java
incubator/wookie/trunk/src/org/apache/wookie/controller/PoliciesController.java
incubator/wookie/trunk/src/org/apache/wookie/proxy/Policies.java
Modified:
incubator/wookie/trunk/src-tests/org/apache/wookie/tests/functional/PoliciesControllerTest.java
URL:
http://svn.apache.org/viewvc/incubator/wookie/trunk/src-tests/org/apache/wookie/tests/functional/PoliciesControllerTest.java?rev=1295625&r1=1295624&r2=1295625&view=diff
==============================================================================
---
incubator/wookie/trunk/src-tests/org/apache/wookie/tests/functional/PoliciesControllerTest.java
(original)
+++
incubator/wookie/trunk/src-tests/org/apache/wookie/tests/functional/PoliciesControllerTest.java
Thu Mar 1 15:40:02 2012
@@ -196,7 +196,7 @@ public class PoliciesControllerTest exte
setAuthenticationCredentials(client);
DeleteMethod delete = new
DeleteMethod(TEST_POLICIES_SERVICE_URL_VALID+"/http%3A%2F%2Fno.such.scope%20http%3A%2F%2Fpolicies.test.origin%20ALLOW");
client.executeMethod(delete);
- assertEquals(200, delete.getStatusCode());
+ assertEquals(404, delete.getStatusCode());
}
@Test
Modified:
incubator/wookie/trunk/src/org/apache/wookie/controller/PoliciesController.java
URL:
http://svn.apache.org/viewvc/incubator/wookie/trunk/src/org/apache/wookie/controller/PoliciesController.java?rev=1295625&r1=1295624&r2=1295625&view=diff
==============================================================================
---
incubator/wookie/trunk/src/org/apache/wookie/controller/PoliciesController.java
(original)
+++
incubator/wookie/trunk/src/org/apache/wookie/controller/PoliciesController.java
Thu Mar 1 15:40:02 2012
@@ -160,6 +160,14 @@ public class PoliciesController extends
//
Policy policy;
policy = new Policy(resourceId);
+
+ //
+ // Policy doesn't exist so return 404
+ //
+ if (!Policies.getInstance().exists(policy)){
+ throw new ResourceNotFoundException();
+ }
+
Policies.getInstance().removePolicy(policy);
return true;
Modified: incubator/wookie/trunk/src/org/apache/wookie/proxy/Policies.java
URL:
http://svn.apache.org/viewvc/incubator/wookie/trunk/src/org/apache/wookie/proxy/Policies.java?rev=1295625&r1=1295624&r2=1295625&view=diff
==============================================================================
--- incubator/wookie/trunk/src/org/apache/wookie/proxy/Policies.java (original)
+++ incubator/wookie/trunk/src/org/apache/wookie/proxy/Policies.java Thu Mar 1
15:40:02 2012
@@ -319,4 +319,17 @@ public class Policies {
}
return allPolicies.toArray(new Policy[allPolicies.size()]);
}
+
+ /**
+ * Check whether a policy already exists
+ * @param policy the policy to check
+ * @return true if the policy exists, otherwise false
+ */
+ public boolean exists(Policy policy){
+ @SuppressWarnings("unchecked")
+ Collection<Policy> existingPolicies = (Collection<Policy>)
policies.get(policy.getScope());
+ if (existingPolicies == null) return false;
+ if (!existingPolicies.contains(policy)) return false;
+ return true;
+ }
}