You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by cz...@apache.org on 2008/02/12 19:41:41 UTC

svn commit: r624948 - in /incubator/sling/trunk/launchpad: launchpad-servlets/src/main/java/org/apache/sling/ujax/ launchpad-webapp/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/ launchpad-webapp/src/test/java/org/apache/sling/launchp...

Author: cziegeler
Date: Tue Feb 12 10:41:35 2008
New Revision: 624948

URL: http://svn.apache.org/viewvc?rev=624948&view=rev
Log:
SLING-239: Apply patch from Tobias Bocanegra to fix integration tests.

Added:
    incubator/sling/trunk/launchpad/launchpad-webapp/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/ujax/UjaxDateValuesTest.java   (with props)
Modified:
    incubator/sling/trunk/launchpad/launchpad-servlets/src/main/java/org/apache/sling/ujax/UjaxPostProcessor.java
    incubator/sling/trunk/launchpad/launchpad-webapp/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/HttpTestBase.java
    incubator/sling/trunk/launchpad/launchpad-webapp/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/ValueFromTest.java
    incubator/sling/trunk/launchpad/launchpad-webapp/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/helpers/UslingIntegrationTestClient.java

Modified: incubator/sling/trunk/launchpad/launchpad-servlets/src/main/java/org/apache/sling/ujax/UjaxPostProcessor.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/launchpad/launchpad-servlets/src/main/java/org/apache/sling/ujax/UjaxPostProcessor.java?rev=624948&r1=624947&r2=624948&view=diff
==============================================================================
--- incubator/sling/trunk/launchpad/launchpad-servlets/src/main/java/org/apache/sling/ujax/UjaxPostProcessor.java (original)
+++ incubator/sling/trunk/launchpad/launchpad-servlets/src/main/java/org/apache/sling/ujax/UjaxPostProcessor.java Tue Feb 12 10:41:35 2008
@@ -491,23 +491,23 @@
     private Node deepGetOrCreateNode(String parent, String path)
             throws RepositoryException {
         if(log.isDebugEnabled()) {
-            log.debug("Deep-creating Node '{}'", path);
+            log.debug("Deep-creating Node '{}/{}'", parent, path);
         }
         if (path.equals("")) {
-            return (Node) session.getItem(parent);
-        }
-
-        // prepend parent path if path is relative
-        if (path.charAt(0) != '/') {
             if (parent == null || !parent.startsWith("/")) {
                 throw new IllegalArgumentException("parent must be an absolute path for relative paths.");
             }
-
-            if (!parent.endsWith("/")) {
-                path = "/" + path;
+            path = parent;
+        } else if (path.charAt(0) != '/') {
+            // prepend parent path if path is relative
+            if (parent == null || !parent.startsWith("/")) {
+                throw new IllegalArgumentException("parent must be an absolute path for relative paths.");
+            }
+            if (parent.endsWith("/")) {
+                path = parent + path;
+            } else {
+                path = parent + "/" + path;
             }
-
-            path = parent + path;
         }
 
         String[] pathelems = path.substring(1).split("/");
@@ -554,7 +554,7 @@
     /**
      * If orderCode is ORDER_ZERO, move n so that it is the first child of its
      * parent
-     * @param n th node to order
+     * @param nodePath path to the node to order
      * @param orderCode code that specifies how to order
      * @throws RepositoryException if a repository error occurs
      */

Modified: incubator/sling/trunk/launchpad/launchpad-webapp/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/HttpTestBase.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/launchpad/launchpad-webapp/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/HttpTestBase.java?rev=624948&r1=624947&r2=624948&view=diff
==============================================================================
--- incubator/sling/trunk/launchpad/launchpad-webapp/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/HttpTestBase.java (original)
+++ incubator/sling/trunk/launchpad/launchpad-webapp/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/HttpTestBase.java Tue Feb 12 10:41:35 2008
@@ -66,9 +66,8 @@
     protected UslingIntegrationTestClient testClient;
     protected HttpClient httpClient;
     
-    private static boolean slingStartupOk; 
-    private static final long startupTime = System.currentTimeMillis();
-    
+    private static Boolean slingStartupOk;
+
     /** Class that creates a test node under the given parentPath, and 
      *  stores useful values for testing. Created for JspScriptingTest,
      *  older test classes do not use it, but it might simplify them.
@@ -120,7 +119,7 @@
         waitForSlingStartup();
     }
     
-    /** On the server side, initialization of Sling bundles is done 
+    /** On the server side, initialization of Sling bundles is done
      *  asynchronously once the webapp is started. This method checks
      *  that everything's ready on the server side, by calling an URL
      *  that requires the UjaxPostServlet and the JCR repository to
@@ -128,16 +127,23 @@
      */
     protected void waitForSlingStartup() throws Exception {
         // Use a static flag to make sure this runs only once in our test suite
-        if(slingStartupOk) {
-            return;
+        if (slingStartupOk != null) {
+            if(slingStartupOk) {
+                return;
+            } else {
+                fail("Sling services not available. Already checked in earlier tests.");
+            }
         }
+        slingStartupOk = false;
         
         System.err.println("Checking if the required Sling services are started...");
         System.err.println("(base URLs=" + HTTP_BASE_URL + " and " + WEBDAV_BASE_URL + ")");
-        
+
         // Try creating a node on server, every 500msec, until ok, with timeout
         final List<String> exceptionMessages = new LinkedList<String>();
         final long maxMsecToWait = 10000L;
+        final long startupTime = System.currentTimeMillis();
+
         while(!slingStartupOk && (System.currentTimeMillis() < startupTime + maxMsecToWait) ) {
             try {
                 slingStartupOk = slingServerReady();
@@ -146,29 +152,30 @@
                 Thread.sleep(500L);
             }
         }
-        
+
         if(!slingStartupOk) {
             StringBuffer msg = new StringBuffer("Server does not seem to be ready, after ");
-            msg.append(maxMsecToWait).append(" msec, got the following Exceptions:");
+            msg.append(maxMsecToWait).append(" msec, got the following ").append(exceptionMessages.size()).append(" Exceptions:");
             for (String e: exceptionMessages) {
                 msg.append(e).append("\n");
             }
+            System.err.println(msg);
             fail(msg.toString());
         }
-        
+
         System.err.println("Sling services seem to be started, continuing with integration tests.");
     }
-    
+
     /** Return true if able to create and retrieve a node on server */
     protected boolean slingServerReady() throws Exception {
         // create a node on the server
         final String time = String.valueOf(System.currentTimeMillis());
         final String url = HTTP_BASE_URL + "/WaitForSlingStartup_" + time;
-        
+
         // add some properties to the node
         final Map<String,String> props = new HashMap<String,String>();
         props.put("time", time);
-        
+
         // POST, get URL of created node and get content
         {
             final String urlOfNewNode = testClient.createNode(url, props, null, true);
@@ -177,19 +184,19 @@
             if(status!=200) {
                 throw new IOException("Expected status 200 but got " + status + " for URL=" + urlOfNewNode);
             }
-            
+
             final Header h = get.getResponseHeader("Content-Type");
             final String contentType = h==null ? "" : h.getValue();
             if(!contentType.startsWith("text/plain")) {
                 throw new IOException("Expected Content-Type=text/plain but got '" + contentType + "' for URL=" + urlOfNewNode);
             }
-            
+
             final String content = get.getResponseBodyAsString();
             if(!content.contains(time)) {
                 throw new IOException("Content does not contain '" + time + "' (" + content + ") at URL=" + urlOfNewNode);
             }
         }
-        
+
         // Also check that the WebDAV root is ready
         {
             final HttpAnyMethod options = new HttpAnyMethod("OPTIONS",WEBDAV_BASE_URL);
@@ -197,7 +204,7 @@
             if(status!=200) {
                 throw new IOException("Expected status 200 but got " + status + " for OPTIONS at URL=" + WEBDAV_BASE_URL);
             }
-            
+
             // The Allow header tells us that we're talking to a WebDAV server
             final Header h = options.getResponseHeader("Allow");
             if(h == null) {
@@ -208,12 +215,12 @@
                 throw new IOException("Allow header (" + h.getValue() + " does not contain PROPFIND, at URL=" + WEBDAV_BASE_URL);
             }
         }
-        
-        
+
+
         return true;
     }
 
-    /** Verify that given URL returns expectedStatusCode 
+    /** Verify that given URL returns expectedStatusCode
      * @throws IOException */
     protected void assertHttpStatus(String urlString, int expectedStatusCode, String assertMessage) throws IOException {
         final int status = httpClient.executeMethod(new GetMethod(urlString));

Modified: incubator/sling/trunk/launchpad/launchpad-webapp/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/ValueFromTest.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/launchpad/launchpad-webapp/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/ValueFromTest.java?rev=624948&r1=624947&r2=624948&view=diff
==============================================================================
--- incubator/sling/trunk/launchpad/launchpad-webapp/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/ValueFromTest.java (original)
+++ incubator/sling/trunk/launchpad/launchpad-webapp/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/ValueFromTest.java Tue Feb 12 10:41:35 2008
@@ -63,7 +63,9 @@
     
     public void testWithValueFromAndMissingField() throws IOException {
         final Map<String,String> props = new HashMap<String,String>();
+        props.put("./jcr:created", "");
         props.put("./text@ValueFrom", "fulltext");
+
         // no fulltext field on purpose, field must be ignored
         
         final String jsonUrl = testClient.createNode(postUrl, props) + ".json";

Modified: incubator/sling/trunk/launchpad/launchpad-webapp/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/helpers/UslingIntegrationTestClient.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/launchpad/launchpad-webapp/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/helpers/UslingIntegrationTestClient.java?rev=624948&r1=624947&r2=624948&view=diff
==============================================================================
--- incubator/sling/trunk/launchpad/launchpad-webapp/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/helpers/UslingIntegrationTestClient.java (original)
+++ incubator/sling/trunk/launchpad/launchpad-webapp/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/helpers/UslingIntegrationTestClient.java Tue Feb 12 10:41:35 2008
@@ -122,6 +122,9 @@
         // take over any client provided properties
         if (clientNodeProperties != null) {
             nodeProperties.putAll(clientNodeProperties);
+        } else {
+            // add fake property - otherwise the node is not created
+            nodeProperties.put("jcr:created", "");
         }
         
         

Added: incubator/sling/trunk/launchpad/launchpad-webapp/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/ujax/UjaxDateValuesTest.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/launchpad/launchpad-webapp/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/ujax/UjaxDateValuesTest.java?rev=624948&view=auto
==============================================================================
--- incubator/sling/trunk/launchpad/launchpad-webapp/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/ujax/UjaxDateValuesTest.java (added)
+++ incubator/sling/trunk/launchpad/launchpad-webapp/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/ujax/UjaxDateValuesTest.java Tue Feb 12 10:41:35 2008
@@ -0,0 +1,78 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sling.launchpad.webapp.integrationtest.ujax;
+
+import java.io.IOException;
+import java.util.Map;
+import java.util.HashMap;
+import java.util.Locale;
+import java.util.Date;
+import java.text.SimpleDateFormat;
+
+import org.apache.sling.launchpad.webapp.integrationtest.HttpTestBase;
+import org.apache.sling.ujax.UjaxPostServlet;
+
+/**
+ *  checks if the date parsing for non jcr-dates works.
+ */
+
+public class UjaxDateValuesTest extends HttpTestBase {
+
+    public static final String TEST_BASE_PATH = "/ujax-tests";
+
+    // TODO: the commented formats do not work beacuse of SLING-242
+    //       the + of the timezone offset is stripped by sling
+
+    private final SimpleDateFormat[] testFormats = new SimpleDateFormat[]{
+        new SimpleDateFormat("EEE MMM dd yyyy HH:mm:ss 'GMT'Z", Locale.US),
+        new SimpleDateFormat("dd.MM.yyyy HH:mm:ss", Locale.US),
+        new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ", Locale.US),
+        new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss", Locale.US)
+    };
+
+    private String postUrl;
+
+    @Override
+    protected void setUp() throws Exception {
+        super.setUp();
+        postUrl = HTTP_BASE_URL + TEST_BASE_PATH + "/" + System.currentTimeMillis();
+    }
+
+    private void doDateTest(String expected, String input)
+            throws IOException {
+        final Map<String, String> props = new HashMap<String, String>();
+        props.put("someDate", input);
+        props.put("someDate@TypeHint", "Date");
+
+        final String createdNodeUrl = testClient.createNode(postUrl + UjaxPostServlet.DEFAULT_CREATE_SUFFIX, props);
+        String content = getContent(createdNodeUrl + ".json", CONTENT_TYPE_JSON);
+
+        // default behaviour writes empty string
+        assertJavascript(expected, content, "out.println(data.someDate)");
+    }
+
+    public void testDateValues() throws IOException {
+        SimpleDateFormat ecmaFmt = new SimpleDateFormat("EEE MMM dd yyyy HH:mm:ss 'GMT'Z", Locale.US);
+        Date now = new Date();
+        String nowStr = ecmaFmt.format(now);
+        for (SimpleDateFormat fmt: testFormats) {
+            String testStr = fmt.format(now);
+            doDateTest(nowStr, testStr);
+        }
+    }
+
+}
\ No newline at end of file

Propchange: incubator/sling/trunk/launchpad/launchpad-webapp/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/ujax/UjaxDateValuesTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/sling/trunk/launchpad/launchpad-webapp/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/ujax/UjaxDateValuesTest.java
------------------------------------------------------------------------------
    svn:keywords = author date id revision url