You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by fm...@apache.org on 2010/10/03 09:45:54 UTC

svn commit: r1003926 - /sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/servlets/post/PostServletVersionableTest.java

Author: fmeschbe
Date: Sun Oct  3 07:45:53 2010
New Revision: 1003926

URL: http://svn.apache.org/viewvc?rev=1003926&view=rev
Log:
SLING-1796 Ensure autoCheckout is enabled for versioning support integration tests by supplying configuration

Modified:
    sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/servlets/post/PostServletVersionableTest.java

Modified: sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/servlets/post/PostServletVersionableTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/servlets/post/PostServletVersionableTest.java?rev=1003926&r1=1003925&r2=1003926&view=diff
==============================================================================
--- sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/servlets/post/PostServletVersionableTest.java (original)
+++ sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/servlets/post/PostServletVersionableTest.java Sun Oct  3 07:45:53 2010
@@ -17,6 +17,7 @@
 package org.apache.sling.launchpad.webapp.integrationtest.servlets.post;
 
 import java.io.IOException;
+import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.HashMap;
 import java.util.List;
@@ -30,16 +31,41 @@ import org.apache.sling.servlets.post.Sl
 
 /** Test node creation via the PostServlet and versionable nodes */
 public class PostServletVersionableTest extends HttpTestBase {
+
+    // the URL to configure the POST servlet with
+    private static final String CFG_URL = HTTP_BASE_URL + "/system/console/configMgr/org.apache.sling.servlets.post.impl.SlingPostServlet";
+
     public static final String TEST_BASE_PATH = "/sling-tests";
     private String postUrl;
     private Map<String,String> params;
 
+
     @Override
     protected void setUp() throws Exception {
         super.setUp();
         postUrl = HTTP_BASE_URL + TEST_BASE_PATH + "/" + System.currentTimeMillis();
         params = new HashMap<String,String>();
         params.put("jcr:mixinTypes", "mix:versionable");
+
+        // enable autoCheckout for the tests
+        ArrayList<NameValuePair> config = new ArrayList<NameValuePair>();
+        config.add(new NameValuePair("apply", "true"));
+        config.add(new NameValuePair("propertylist",
+            "servlet.post.autoCheckout"));
+        config.add(new NameValuePair("servlet.post.autoCheckout", "true"));
+        assertPostStatus(CFG_URL, 302, config, null);
+        Thread.sleep(500); // give async config update some time
+    }
+
+    @Override
+    protected void tearDown() throws Exception {
+        // remove configuration after test
+        ArrayList<NameValuePair> config = new ArrayList<NameValuePair>();
+        config.add(new NameValuePair("apply", "true"));
+        config.add(new NameValuePair("delete", "true"));
+        assertPostStatus(CFG_URL, 200, config, null);
+
+        super.tearDown();
     }
 
    public void testPostPathIsUnique() throws IOException {
@@ -422,14 +448,14 @@ public class PostServletVersionableTest 
                 content.contains("jcr:isCheckedOut: false"));
         assertTrue("Node (" + location + ") has a test property.",
                 content.contains("testprop: testvalue"));
-        
+
         List<NameValuePair> testParams = Arrays.asList(new NameValuePair(":autoCheckout", "false"),
                 new NameValuePair("testprop@Delete", ""));
-        
+
         assertPostStatus(location, 500, testParams, "Attempted modification with :autoCheckout=false should fail.");
 
     }
-    
+
     public void testMovingAPropertyOfACheckedInNodeToANewVersionableNode() throws IOException {
         params.put(":checkinNewVersionableNodes", "true");
         params.put("text", "Hello");
@@ -458,7 +484,7 @@ public class PostServletVersionableTest 
         assertJavascript("undefined", oldContent, "out.println(typeof(data.text))");
         assertJavascript("false", oldContent, "out.println(data['jcr:isCheckedOut'])");
     }
-    
+
     public void testMovingAPropertyOfACheckedInNodeToACheckedInNode() throws IOException {
         params.put(":checkinNewVersionableNodes", "true");
         params.put("text", "Hello");
@@ -475,7 +501,7 @@ public class PostServletVersionableTest 
         params.put("jcr:mixinTypes", "mix:versionable");
         params.put(":checkinNewVersionableNodes", "true");
         testClient.createNode(HTTP_BASE_URL + testPath + "/dest", params);
-        
+
         // assert content at new location
         String content = getContent(HTTP_BASE_URL + testPath + "/dest.json", CONTENT_TYPE_JSON);
         assertJavascript("false", oldContent, "out.println(data['jcr:isCheckedOut'])");
@@ -495,7 +521,7 @@ public class PostServletVersionableTest 
         assertJavascript("false", oldContent, "out.println(data['jcr:isCheckedOut'])");
 
     }
-    
+
     public void testCopyingAPropertyToACheckedInNode() throws IOException {
         params.put(":checkinNewVersionableNodes", "true");
         params.put("text", "Hello");
@@ -511,10 +537,10 @@ public class PostServletVersionableTest 
         params.put("jcr:mixinTypes", "mix:versionable");
         params.put(":checkinNewVersionableNodes", "true");
         testClient.createNode(HTTP_BASE_URL + testPath + "/dest", params);
-        
+
         String content = getContent(HTTP_BASE_URL + testPath + "/dest.json", CONTENT_TYPE_JSON);
         assertJavascript("false", content, "out.println(data['jcr:isCheckedOut'])");
-        
+
         // copy text from src/text
         params.clear();
         params.put("text@CopyFrom", testPath + "/src/text");
@@ -530,12 +556,12 @@ public class PostServletVersionableTest 
         assertJavascript("Hello", oldContent, "out.println(data.text)");
         assertJavascript("false", oldContent, "out.println(data['jcr:isCheckedOut'])");
     }
-    
+
     public void testMovingAChildNodeOfACheckedInNodeToANewVersionableNode() throws IOException {
         params.put(":checkinNewVersionableNodes", "true");
         final String testPath = TEST_BASE_PATH + "/abs/" + System.currentTimeMillis();
         testClient.createNode(HTTP_BASE_URL + testPath + "/src", params);
-        
+
         params.clear();
         params.put("text", "Hello");
         testClient.createNode(HTTP_BASE_URL + testPath + "/src/child", params);
@@ -563,12 +589,12 @@ public class PostServletVersionableTest 
         oldContent = getContent(HTTP_BASE_URL + testPath + "/src.-1.json", CONTENT_TYPE_JSON);
         assertJavascript("false", oldContent, "out.println(data['jcr:isCheckedOut'])");
     }
-    
+
     public void testMovingAChildNodeOfACheckedInNodeToACheckedInNode() throws IOException {
         params.put(":checkinNewVersionableNodes", "true");
         final String testPath = TEST_BASE_PATH + "/abs/" + System.currentTimeMillis();
         testClient.createNode(HTTP_BASE_URL + testPath + "/src", params);
-        
+
         params.clear();
         params.put("text", "Hello");
         testClient.createNode(HTTP_BASE_URL + testPath + "/src/child", params);
@@ -583,10 +609,10 @@ public class PostServletVersionableTest 
         params.put("jcr:mixinTypes", "mix:versionable");
         params.put(":checkinNewVersionableNodes", "true");
         testClient.createNode(HTTP_BASE_URL + testPath + "/dest", params);
-        
+
         String content = getContent(HTTP_BASE_URL + testPath + "/dest.json", CONTENT_TYPE_JSON);
         assertJavascript("false", content, "out.println(data['jcr:isCheckedOut'])");
-        
+
         // move src child
         params.clear();
         params.put("src@MoveFrom", testPath + "/src/child");
@@ -603,12 +629,12 @@ public class PostServletVersionableTest 
         oldContent = getContent(HTTP_BASE_URL + testPath + "/src.-1.json", CONTENT_TYPE_JSON);
         assertJavascript("false", oldContent, "out.println(data['jcr:isCheckedOut'])");
     }
-    
+
     public void testCopyingANodeToACheckedInNode() throws IOException {
         params.put(":checkinNewVersionableNodes", "true");
         final String testPath = TEST_BASE_PATH + "/abs/" + System.currentTimeMillis();
         testClient.createNode(HTTP_BASE_URL + testPath + "/src", params);
-        
+
         params.clear();
         params.put("text", "Hello");
         testClient.createNode(HTTP_BASE_URL + testPath + "/src/child", params);
@@ -617,15 +643,15 @@ public class PostServletVersionableTest 
         String oldContent = getContent(HTTP_BASE_URL + testPath + "/src.-1.json", CONTENT_TYPE_JSON);
         assertJavascript("false", oldContent, "out.println(data['jcr:isCheckedOut'])");
         assertJavascript("Hello", oldContent, "out.println(data.child.text)");
-        
+
         // create dest as empty
         params.put("jcr:mixinTypes", "mix:versionable");
         params.put(":checkinNewVersionableNodes", "true");
         testClient.createNode(HTTP_BASE_URL + testPath + "/dest", params);
-        
+
         String content = getContent(HTTP_BASE_URL + testPath + "/dest.json", CONTENT_TYPE_JSON);
         assertJavascript("false", oldContent, "out.println(data['jcr:isCheckedOut'])");
-        
+
         // copy text from src/text
         params.clear();
         params.put("src@CopyFrom", testPath + "/src/child");
@@ -641,12 +667,12 @@ public class PostServletVersionableTest 
         assertJavascript("Hello", oldContent, "out.println(data.child.text)");
         assertJavascript("false", oldContent, "out.println(data['jcr:isCheckedOut'])");
     }
-    
+
     public void testMovingAChildNodeOfACheckedInNodeToACheckedInNodeByOp() throws IOException {
         params.put(":checkinNewVersionableNodes", "true");
         final String testPath = TEST_BASE_PATH + "/abs/" + System.currentTimeMillis();
         testClient.createNode(HTTP_BASE_URL + testPath + "/src", params);
-        
+
         params.clear();
         params.put("text", "Hello");
         testClient.createNode(HTTP_BASE_URL + testPath + "/src/child", params);
@@ -661,10 +687,10 @@ public class PostServletVersionableTest 
         params.put("jcr:mixinTypes", "mix:versionable");
         params.put(":checkinNewVersionableNodes", "true");
         testClient.createNode(HTTP_BASE_URL + testPath + "/dest", params);
-        
+
         String content = getContent(HTTP_BASE_URL + testPath + "/dest.json", CONTENT_TYPE_JSON);
         assertJavascript("false", content, "out.println(data['jcr:isCheckedOut'])");
-        
+
         // move src child
         params.clear();
         params.put(SlingPostConstants.RP_OPERATION, SlingPostConstants.OPERATION_MOVE);
@@ -682,12 +708,12 @@ public class PostServletVersionableTest 
         oldContent = getContent(HTTP_BASE_URL + testPath + "/src.-1.json", CONTENT_TYPE_JSON);
         assertJavascript("false", oldContent, "out.println(data['jcr:isCheckedOut'])");
     }
-    
+
     public void testCopyingANodeToACheckedInNodeByOp() throws IOException {
         params.put(":checkinNewVersionableNodes", "true");
         final String testPath = TEST_BASE_PATH + "/abs/" + System.currentTimeMillis();
         testClient.createNode(HTTP_BASE_URL + testPath + "/src", params);
-        
+
         params.clear();
         params.put("text", "Hello");
         testClient.createNode(HTTP_BASE_URL + testPath + "/src/child", params);
@@ -696,15 +722,15 @@ public class PostServletVersionableTest 
         String oldContent = getContent(HTTP_BASE_URL + testPath + "/src.-1.json", CONTENT_TYPE_JSON);
         assertJavascript("false", oldContent, "out.println(data['jcr:isCheckedOut'])");
         assertJavascript("Hello", oldContent, "out.println(data.child.text)");
-        
+
         // create dest as empty
         params.put("jcr:mixinTypes", "mix:versionable");
         params.put(":checkinNewVersionableNodes", "true");
         testClient.createNode(HTTP_BASE_URL + testPath + "/dest", params);
-        
+
         String content = getContent(HTTP_BASE_URL + testPath + "/dest.json", CONTENT_TYPE_JSON);
         assertJavascript("false", oldContent, "out.println(data['jcr:isCheckedOut'])");
-        
+
         // copy child from src
         params.clear();
         params.put(SlingPostConstants.RP_OPERATION, SlingPostConstants.OPERATION_COPY);
@@ -721,6 +747,6 @@ public class PostServletVersionableTest 
         assertJavascript("Hello", oldContent, "out.println(data.child.text)");
         assertJavascript("false", oldContent, "out.println(data['jcr:isCheckedOut'])");
     }
-    
-    
+
+
  }
\ No newline at end of file



Re: svn commit: r1003926 - /sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/servlets/post/PostServletVersionableTest.java

Posted by Justin Edelson <ju...@gmail.com>.
Just committed r1004649 which uses the :autoCheckout parameter instead
of setting the default value via ConfigAdmin.

I think we probably need some better ConfigAdmin integration with our
tests, but in this context it seems like overkill.

Justin

On 10/5/10 9:16 AM, Felix Meschberger wrote:
> Hi,
> 
> On 05.10.2010 14:46, Bertrand Delacretaz wrote:
>> Hi,
>>
>> On Tue, Oct 5, 2010 at 2:39 PM, Felix Meschberger <fm...@gmail.com> wrote:
>> ...
>>>>>    sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/servlets/post/PostServletVersionableTest.java
>>>>> ...
>>>>>     @Override
>>>>>     protected void setUp() throws Exception {
>>>>> +        // enable autoCheckout for the tests
>>>>> ...
>>>>> +        assertPostStatus(CFG_URL, 302, config, null);
>>>>> ...
>>>>> +        Thread.sleep(500); // give async config update some time
>>>>
>>> ...We have to wait for the configuration to propagate to the Sling Post
>>> Servlet and for the Sling Post Servlet to restart. This is asynchronous.
>>> AFAICT there is no good (non-intrusive) way to find out whether the
>>> Sling Post Servlet has been updated with the correct configuration....
>>
>> Checking for the service in the OSGi console might help? But I'm not
>> sure how to find out that the service has been restarted.
> 
> There's always the timeing incertainty involved with asynchronous calls.
> 
>>
>>>
>>> As a workaround, we could update the configuration in the test methods
>>> depending on this configuration instead of doing it in the setUp method
>>> for all tests (even though setUp is definitely the right place for this)...
>>
>> I'm not following, not sure what differences this would make.
> 
> Not all tests in the PostServletVersionableTest class really depend on
> the configuration. By moving the configuration setup to the respective
> methods we could reduce the time it takes to execute all tests of the class.



> 
>>
>>>
>>> Or is there a way to push the configuration before any of the
>>> PostServletVersionableTest tests run and to remove the configuration
>>> again after the PostServletVersionableTest tests have run ?...
>>
>> We might need to create a utility that does that, and talks to the
>> OSGi console (or to a specific test helper service) to find out when
>> those config changes have actually been executed.
> 
> I think more of a @BeforeClass/@AfterClass setup. This would still
> create configuration and add a delay, but only once instead of before
> each test method execution.
> 
>>
>> In short: no worries if this is the only test where we need this, a
>> delay is probably good enough, but if we need more of this I'd rather
>> create a config manipulation utility.
> 
> 
> I don't worry about this delay ;-)
> 
> Regards
> Felix
> 
>>
>> -Bertrand
>>


Re: svn commit: r1003926 - /sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/servlets/post/PostServletVersionableTest.java

Posted by Felix Meschberger <fm...@gmail.com>.
Hi,

On 05.10.2010 14:46, Bertrand Delacretaz wrote:
> Hi,
> 
> On Tue, Oct 5, 2010 at 2:39 PM, Felix Meschberger <fm...@gmail.com> wrote:
> ...
>>>>    sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/servlets/post/PostServletVersionableTest.java
>>>> ...
>>>>     @Override
>>>>     protected void setUp() throws Exception {
>>>> +        // enable autoCheckout for the tests
>>>> ...
>>>> +        assertPostStatus(CFG_URL, 302, config, null);
>>>> ...
>>>> +        Thread.sleep(500); // give async config update some time
>>>
>> ...We have to wait for the configuration to propagate to the Sling Post
>> Servlet and for the Sling Post Servlet to restart. This is asynchronous.
>> AFAICT there is no good (non-intrusive) way to find out whether the
>> Sling Post Servlet has been updated with the correct configuration....
> 
> Checking for the service in the OSGi console might help? But I'm not
> sure how to find out that the service has been restarted.

There's always the timeing incertainty involved with asynchronous calls.

> 
>>
>> As a workaround, we could update the configuration in the test methods
>> depending on this configuration instead of doing it in the setUp method
>> for all tests (even though setUp is definitely the right place for this)...
> 
> I'm not following, not sure what differences this would make.

Not all tests in the PostServletVersionableTest class really depend on
the configuration. By moving the configuration setup to the respective
methods we could reduce the time it takes to execute all tests of the class.

> 
>>
>> Or is there a way to push the configuration before any of the
>> PostServletVersionableTest tests run and to remove the configuration
>> again after the PostServletVersionableTest tests have run ?...
> 
> We might need to create a utility that does that, and talks to the
> OSGi console (or to a specific test helper service) to find out when
> those config changes have actually been executed.

I think more of a @BeforeClass/@AfterClass setup. This would still
create configuration and add a delay, but only once instead of before
each test method execution.

> 
> In short: no worries if this is the only test where we need this, a
> delay is probably good enough, but if we need more of this I'd rather
> create a config manipulation utility.


I don't worry about this delay ;-)

Regards
Felix

> 
> -Bertrand
> 

Re: svn commit: r1003926 - /sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/servlets/post/PostServletVersionableTest.java

Posted by Bertrand Delacretaz <bd...@apache.org>.
Hi,

On Tue, Oct 5, 2010 at 2:39 PM, Felix Meschberger <fm...@gmail.com> wrote:
...
>>>    sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/servlets/post/PostServletVersionableTest.java
>>> ...
>>>     @Override
>>>     protected void setUp() throws Exception {
>>> +        // enable autoCheckout for the tests
>>> ...
>>> +        assertPostStatus(CFG_URL, 302, config, null);
>>> ...
>>> +        Thread.sleep(500); // give async config update some time
>>
> ...We have to wait for the configuration to propagate to the Sling Post
> Servlet and for the Sling Post Servlet to restart. This is asynchronous.
> AFAICT there is no good (non-intrusive) way to find out whether the
> Sling Post Servlet has been updated with the correct configuration....

Checking for the service in the OSGi console might help? But I'm not
sure how to find out that the service has been restarted.

>
> As a workaround, we could update the configuration in the test methods
> depending on this configuration instead of doing it in the setUp method
> for all tests (even though setUp is definitely the right place for this)...

I'm not following, not sure what differences this would make.

>
> Or is there a way to push the configuration before any of the
> PostServletVersionableTest tests run and to remove the configuration
> again after the PostServletVersionableTest tests have run ?...

We might need to create a utility that does that, and talks to the
OSGi console (or to a specific test helper service) to find out when
those config changes have actually been executed.

In short: no worries if this is the only test where we need this, a
delay is probably good enough, but if we need more of this I'd rather
create a config manipulation utility.

-Bertrand

Re: svn commit: r1003926 - /sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/servlets/post/PostServletVersionableTest.java

Posted by Felix Meschberger <fm...@gmail.com>.
Hi,

On 05.10.2010 10:37, Bertrand Delacretaz wrote:
> On Sun, Oct 3, 2010 at 9:45 AM,  <fm...@apache.org> wrote:
>> Author: fmeschbe
>> Date: Sun Oct  3 07:45:53 2010
>> New Revision: 1003926
>> ...
>> Modified:
>>    sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/servlets/post/PostServletVersionableTest.java
>> ...
>>     @Override
>>     protected void setUp() throws Exception {
>> +        // enable autoCheckout for the tests
>> ...
>> +        assertPostStatus(CFG_URL, 302, config, null);
>> ...
>> +        Thread.sleep(500); // give async config update some time
> 
> Isn't there a better way, like rereading the config to make sure it's
> been updated?
> 
> This looks fragile, and will slow down the tests.

Yes, it will certainly slow down. But the point is not writing the
config back to persistence which is synchronous.

We have to wait for the configuration to propagate to the Sling Post
Servlet and for the Sling Post Servlet to restart. This is asynchronous.
AFAICT there is no good (non-intrusive) way to find out whether the
Sling Post Servlet has been updated with the correct configuration.

As a workaround, we could update the configuration in the test methods
depending on this configuration instead of doing it in the setUp method
for all tests (even though setUp is definitely the right place for this).

Or is there a way to push the configuration before any of the
PostServletVersionableTest tests run and to remove the configuration
again after the PostServletVersionableTest tests have run ?

Regards
Felix

> 
> -Bertrand
> 

Re: svn commit: r1003926 - /sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/servlets/post/PostServletVersionableTest.java

Posted by Bertrand Delacretaz <bd...@apache.org>.
On Sun, Oct 3, 2010 at 9:45 AM,  <fm...@apache.org> wrote:
> Author: fmeschbe
> Date: Sun Oct  3 07:45:53 2010
> New Revision: 1003926
>...
> Modified:
>    sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/servlets/post/PostServletVersionableTest.java
>...
>     @Override
>     protected void setUp() throws Exception {
> +        // enable autoCheckout for the tests
>...
> +        assertPostStatus(CFG_URL, 302, config, null);
>...
> +        Thread.sleep(500); // give async config update some time

Isn't there a better way, like rereading the config to make sure it's
been updated?

This looks fragile, and will slow down the tests.

-Bertrand