You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@wookie.apache.org by sc...@apache.org on 2011/10/28 15:58:40 UTC
svn commit: r1190330 - in /incubator/wookie/trunk:
src-tests/org/apache/wookie/tests/functional/ src-tests/testdata/
src/org/apache/wookie/helpers/
Author: scottbw
Date: Fri Oct 28 13:58:40 2011
New Revision: 1190330
URL: http://svn.apache.org/viewvc?rev=1190330&view=rev
Log:
Fixed issue with duplicate access policies when updating widgets (see WOOKIE-273) and added a test case.
Added:
incubator/wookie/trunk/src-tests/testdata/access-test.wgt (with props)
Modified:
incubator/wookie/trunk/src-tests/org/apache/wookie/tests/functional/WidgetAccessRequestPolicyControllerTest.java
incubator/wookie/trunk/src-tests/org/apache/wookie/tests/functional/WidgetsControllerTest.java
incubator/wookie/trunk/src/org/apache/wookie/helpers/WidgetFactory.java
Modified: incubator/wookie/trunk/src-tests/org/apache/wookie/tests/functional/WidgetAccessRequestPolicyControllerTest.java
URL: http://svn.apache.org/viewvc/incubator/wookie/trunk/src-tests/org/apache/wookie/tests/functional/WidgetAccessRequestPolicyControllerTest.java?rev=1190330&r1=1190329&r2=1190330&view=diff
==============================================================================
--- incubator/wookie/trunk/src-tests/org/apache/wookie/tests/functional/WidgetAccessRequestPolicyControllerTest.java (original)
+++ incubator/wookie/trunk/src-tests/org/apache/wookie/tests/functional/WidgetAccessRequestPolicyControllerTest.java Fri Oct 28 13:58:40 2011
@@ -246,7 +246,7 @@ public class WidgetAccessRequestPolicyCo
* @throws IOException
* @throws HttpException
*/
- private static Element[] getPolicies() throws HttpException, IOException {
+ public static Element[] getPolicies() throws HttpException, IOException {
HttpClient client = new HttpClient();
setAuthenticationCredentials(client);
GetMethod get = new GetMethod(TEST_WARP_SERVICE_URL_VALID);
Modified: incubator/wookie/trunk/src-tests/org/apache/wookie/tests/functional/WidgetsControllerTest.java
URL: http://svn.apache.org/viewvc/incubator/wookie/trunk/src-tests/org/apache/wookie/tests/functional/WidgetsControllerTest.java?rev=1190330&r1=1190329&r2=1190330&view=diff
==============================================================================
--- incubator/wookie/trunk/src-tests/org/apache/wookie/tests/functional/WidgetsControllerTest.java (original)
+++ incubator/wookie/trunk/src-tests/org/apache/wookie/tests/functional/WidgetsControllerTest.java Fri Oct 28 13:58:40 2011
@@ -17,6 +17,7 @@ package org.apache.wookie.tests.function
import static org.junit.Assert.*;
import java.io.File;
+import java.io.FileNotFoundException;
import java.io.IOException;
import org.apache.commons.httpclient.HttpClient;
@@ -28,6 +29,7 @@ import org.apache.commons.httpclient.met
import org.apache.commons.httpclient.methods.multipart.FilePart;
import org.apache.commons.httpclient.methods.multipart.MultipartRequestEntity;
import org.apache.commons.httpclient.methods.multipart.Part;
+import org.jdom.Element;
import org.junit.Test;
/**
@@ -214,4 +216,70 @@ public class WidgetsControllerTest exten
post.releaseConnection();
}
+ /**
+ * Check that when we update a widget, we don't duplicate access policies. See WOOKIE-273.
+ * @throws HttpException
+ * @throws IOException
+ * @throws InterruptedException
+ */
+ @Test
+ public void checkForDuplicateAccessRequests() throws HttpException, IOException, InterruptedException{
+
+ //
+ // Add the test widget, and update it a few times
+ //
+ for (int i=0;i<4;i++){
+
+ HttpClient client = new HttpClient();
+ //
+ // Use admin credentials
+ //
+ client.getState().setCredentials(
+ new AuthScope("localhost", 8080, "wookie"),
+ new UsernamePasswordCredentials("java", "java")
+ );
+
+ PostMethod post = new PostMethod(TEST_WIDGETS_SERVICE_URL_VALID);
+
+ //
+ // Add the access test widget. This just has a single access request
+ // for the origin "http://accesstest.incubator.apache.org"
+ //
+ File file = new File("src-tests/testdata/access-test.wgt");
+ assertTrue(file.exists());
+
+ //
+ // Add test wgt file to POST
+ //
+ Part[] parts = { new FilePart(file.getName(), file) };
+ post.setRequestEntity(new MultipartRequestEntity(parts, post
+ .getParams()));
+
+ //
+ // POST the file to /widgets
+ //
+ client.executeMethod(post);
+ post.releaseConnection();
+
+ //
+ // Wait a few seconds for Wookie to finish updating
+ //
+ Thread.sleep(5000);
+ }
+
+ //
+ // Check that we only have one copy of the access request, not two
+ //
+ int policies = 0;
+ final String POLICY_ORIGIN = "http://accesstest.incubator.apache.org:80";
+ Element[] policyElements = WidgetAccessRequestPolicyControllerTest.getPolicies();
+ for (Element policy: policyElements){
+ if (policy.getAttribute("origin").getValue().equals(POLICY_ORIGIN)) {
+ policies ++;
+ }
+ }
+ assertEquals(1, policies);
+
+ }
+
}
Added: incubator/wookie/trunk/src-tests/testdata/access-test.wgt
URL: http://svn.apache.org/viewvc/incubator/wookie/trunk/src-tests/testdata/access-test.wgt?rev=1190330&view=auto
==============================================================================
Binary file - no diff available.
Propchange: incubator/wookie/trunk/src-tests/testdata/access-test.wgt
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
Modified: incubator/wookie/trunk/src/org/apache/wookie/helpers/WidgetFactory.java
URL: http://svn.apache.org/viewvc/incubator/wookie/trunk/src/org/apache/wookie/helpers/WidgetFactory.java?rev=1190330&r1=1190329&r2=1190330&view=diff
==============================================================================
--- incubator/wookie/trunk/src/org/apache/wookie/helpers/WidgetFactory.java (original)
+++ incubator/wookie/trunk/src/org/apache/wookie/helpers/WidgetFactory.java Fri Oct 28 13:58:40 2011
@@ -236,7 +236,22 @@ public class WidgetFactory {
}
}
+ /**
+ * Create or update the access policies associated with a widget
+ * @param persistenceManager the persistence manager
+ * @param model the W3C model of the widget
+ * @param widget the Wookie widget object
+ * @param grantAccessRequests whether access requests are granted by default
+ */
private static void createAccessRequests(IPersistenceManager persistenceManager, W3CWidget model, IWidget widget, boolean grantAccessRequests){
+ //
+ // Remove any existing access policies
+ //
+ persistenceManager.delete(persistenceManager.findApplicableAccessRequests(widget));
+
+ //
+ // Create access policies for each access request in the widget model
+ //
for(IAccessEntity accessEntity:model.getAccessList()){
IAccessRequest acc = persistenceManager.newInstance(IAccessRequest.class);
acc.setOrigin(accessEntity.getOrigin());