incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bdelacre...@apache.org
Subject svn commit: r1080625 - in /sling/trunk/testing/tools/src: main/java/org/apache/sling/testing/tools/sling/ test/ test/java/ test/java/org/ test/java/org/apache/ test/java/org/apache/sling/ test/java/org/apache/sling/testing/ test/java/org/apache/sling/t...
Date Fri, 11 Mar 2011 15:50:39 GMT
Author: bdelacretaz
Date: Fri Mar 11 15:50:39 2011
New Revision: 1080625

URL: http://svn.apache.org/viewvc?rev=1080625&view=rev
Log:
SLING-2028 - fix conversion of Location header value

Added:
    sling/trunk/testing/tools/src/test/
    sling/trunk/testing/tools/src/test/java/
    sling/trunk/testing/tools/src/test/java/org/
    sling/trunk/testing/tools/src/test/java/org/apache/
    sling/trunk/testing/tools/src/test/java/org/apache/sling/
    sling/trunk/testing/tools/src/test/java/org/apache/sling/testing/
    sling/trunk/testing/tools/src/test/java/org/apache/sling/testing/tools/
    sling/trunk/testing/tools/src/test/java/org/apache/sling/testing/tools/sling/
    sling/trunk/testing/tools/src/test/java/org/apache/sling/testing/tools/sling/SlingClientTest.java
  (with props)
Modified:
    sling/trunk/testing/tools/src/main/java/org/apache/sling/testing/tools/sling/SlingClient.java

Modified: sling/trunk/testing/tools/src/main/java/org/apache/sling/testing/tools/sling/SlingClient.java
URL: http://svn.apache.org/viewvc/sling/trunk/testing/tools/src/main/java/org/apache/sling/testing/tools/sling/SlingClient.java?rev=1080625&r1=1080624&r2=1080625&view=diff
==============================================================================
--- sling/trunk/testing/tools/src/main/java/org/apache/sling/testing/tools/sling/SlingClient.java
(original)
+++ sling/trunk/testing/tools/src/main/java/org/apache/sling/testing/tools/sling/SlingClient.java
Fri Mar 11 15:50:39 2011
@@ -43,6 +43,7 @@ import org.apache.sling.testing.tools.ht
  *  tests but should be general purpose */
 public class SlingClient {
     public static final String LOCATION_HEADER = "Location";
+    public static final String HTTP_PREFIX = "http://";
     private final RequestExecutor executor;
     private final RequestBuilder builder;
     private final String slingServerUrl;
@@ -127,10 +128,24 @@ public class SlingClient {
         
         final Header location = response.getFirstHeader(LOCATION_HEADER);
         assertNotNull("Expecting " + LOCATION_HEADER + " in response", location);
-        actualPath = location.getValue().substring(slingServerUrl.length());
+        actualPath = locationToPath(location.getValue());
         return actualPath;
     }
     
+    /** Convert a Location value to the corresponding node path */
+    String locationToPath(String locationHeaderValue) {
+        if(locationHeaderValue.startsWith(slingServerUrl)) {
+            return locationHeaderValue.substring(slingServerUrl.length());
+        } else if(locationHeaderValue.startsWith(HTTP_PREFIX)){
+            throw new IllegalArgumentException(
+                    "Unexpected Location header value [" + locationHeaderValue 
+                    + "], should start with [" + slingServerUrl + "] if starting with " 
+                    + HTTP_PREFIX);
+        } else {
+            return locationHeaderValue;
+        }
+    }
+    
     /** Delete supplied path */
     public void delete(String path) throws IOException {
         executor.execute(

Added: sling/trunk/testing/tools/src/test/java/org/apache/sling/testing/tools/sling/SlingClientTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/testing/tools/src/test/java/org/apache/sling/testing/tools/sling/SlingClientTest.java?rev=1080625&view=auto
==============================================================================
--- sling/trunk/testing/tools/src/test/java/org/apache/sling/testing/tools/sling/SlingClientTest.java
(added)
+++ sling/trunk/testing/tools/src/test/java/org/apache/sling/testing/tools/sling/SlingClientTest.java
Fri Mar 11 15:50:39 2011
@@ -0,0 +1,61 @@
+/*
+ * 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.testing.tools.sling;
+
+import java.util.ArrayList;
+import java.util.Collection;
+
+import static org.junit.Assert.assertEquals;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import org.junit.runners.Parameterized.Parameters;
+
+@RunWith(Parameterized.class)
+public class SlingClientTest {
+    public final static String SLING_SERVER_URL = "http://localhost:1234";
+    private final String locationHeaderValue;
+    private final String expectedPath;
+    
+    public SlingClientTest(String locationHeaderValue, String expectedPath) {
+        this.locationHeaderValue = locationHeaderValue;
+        this.expectedPath = expectedPath;
+    }
+    
+    @Test
+    public void testPath() {
+        final SlingClient c = new SlingClient(SLING_SERVER_URL, null, null);
+        assertEquals(expectedPath, c.locationToPath(locationHeaderValue));
+    }
+
+    @Test(expected = IllegalArgumentException.class)
+    public void testBadPrefix() {
+        final SlingClient c = new SlingClient(SLING_SERVER_URL, null, null);
+        c.locationToPath("http://example.com/foo");
+    }
+    
+    @Parameters
+    public static Collection<Object[]> data() {
+        final Collection<Object[]> data = new ArrayList<Object[]>();
+        data.add(new Object[] { SLING_SERVER_URL + "/one", "/one" });
+        data.add(new Object[] { SLING_SERVER_URL + "/one/foo", "/one/foo" });
+        data.add(new Object[] { "/two", "/two" });
+        data.add(new Object[] { "/two/bar", "/two/bar" });
+        data.add(new Object[] { SLING_SERVER_URL, "" });
+        return data;
+    }
+}

Propchange: sling/trunk/testing/tools/src/test/java/org/apache/sling/testing/tools/sling/SlingClientTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sling/trunk/testing/tools/src/test/java/org/apache/sling/testing/tools/sling/SlingClientTest.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev URL



Mime
View raw message