You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by bd...@apache.org on 2011/02/24 16:04:54 UTC

svn commit: r1074181 - in /sling/trunk/testing/junit/core/src: main/java/org/apache/sling/junit/ test/ test/java/ test/java/org/ test/java/org/apache/ test/java/org/apache/sling/ test/java/org/apache/sling/junit/

Author: bdelacretaz
Date: Thu Feb 24 15:04:53 2011
New Revision: 1074181

URL: http://svn.apache.org/viewvc?rev=1074181&view=rev
Log:
SLING-1981 - prepare for test method selection support

Added:
    sling/trunk/testing/junit/core/src/test/
    sling/trunk/testing/junit/core/src/test/java/
    sling/trunk/testing/junit/core/src/test/java/org/
    sling/trunk/testing/junit/core/src/test/java/org/apache/
    sling/trunk/testing/junit/core/src/test/java/org/apache/sling/
    sling/trunk/testing/junit/core/src/test/java/org/apache/sling/junit/
    sling/trunk/testing/junit/core/src/test/java/org/apache/sling/junit/RequestParserTest.java   (with props)
Modified:
    sling/trunk/testing/junit/core/src/main/java/org/apache/sling/junit/RequestParser.java

Modified: sling/trunk/testing/junit/core/src/main/java/org/apache/sling/junit/RequestParser.java
URL: http://svn.apache.org/viewvc/sling/trunk/testing/junit/core/src/main/java/org/apache/sling/junit/RequestParser.java?rev=1074181&r1=1074180&r2=1074181&view=diff
==============================================================================
--- sling/trunk/testing/junit/core/src/main/java/org/apache/sling/junit/RequestParser.java (original)
+++ sling/trunk/testing/junit/core/src/main/java/org/apache/sling/junit/RequestParser.java Thu Feb 24 15:04:53 2011
@@ -29,24 +29,39 @@ public class RequestParser {
     private final String testSelector;
     private final String extension;
     private final HttpServletRequest request;
+    private static final String EMPTY_STRING = "";
 
     public RequestParser(HttpServletRequest request) {
         this.request = request;
-        String pathinfo = request.getPathInfo();
-        if (pathinfo == null) {
-            pathinfo = "";
-        } else if (pathinfo.startsWith("/")) {
-            pathinfo = pathinfo.substring(1);
+        final String [] s = parsePathInfo(request.getPathInfo());
+        testSelector = s[0];
+        extension = s[1];
+    }
+    
+    static String [] parsePathInfo(String pathInfo) {
+        final String [] result = new String[3];
+        
+        if (pathInfo != null) {
+            if (pathInfo.startsWith("/")) {
+                pathInfo = pathInfo.substring(1);
+            }
+            
+            final int pos = pathInfo.lastIndexOf('.');
+            if (pos >= 0) {
+                result[0] = pathInfo.substring(0, pos);
+                result[1] = pathInfo.substring(pos+1);
+            } else {
+                result[0] = pathInfo;
+            }
         }
-
-        final int pos = pathinfo.lastIndexOf('.');
-        if (pos >= 0) {
-            testSelector = pathinfo.substring(0, pos);
-            extension = pathinfo.substring(pos+1);
-        } else {
-            testSelector = pathinfo;
-            extension = "";
+        
+        for(int i=0; i < result.length; i++) {
+            if(result[i] == null) {
+                result[i] = EMPTY_STRING;
+            }
         }
+        
+        return result;
     }
 
     public String toString() {

Added: sling/trunk/testing/junit/core/src/test/java/org/apache/sling/junit/RequestParserTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/testing/junit/core/src/test/java/org/apache/sling/junit/RequestParserTest.java?rev=1074181&view=auto
==============================================================================
--- sling/trunk/testing/junit/core/src/test/java/org/apache/sling/junit/RequestParserTest.java (added)
+++ sling/trunk/testing/junit/core/src/test/java/org/apache/sling/junit/RequestParserTest.java Thu Feb 24 15:04:53 2011
@@ -0,0 +1,80 @@
+/*
+ * 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.junit;
+
+import java.util.Arrays;
+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(value=Parameterized.class)
+public class RequestParserTest {
+    final String pathInfo;
+    final String expectedTestSelector;
+    final String expectedExtension;
+    final String expectedMethodSelector;
+    final String [] parseResult;
+    
+    public RequestParserTest(String pathInfo, String expectedTestSelector, String expectedExtension, String expectedMethodSelector) {
+        this.pathInfo = pathInfo;
+        this.expectedTestSelector = expectedTestSelector;
+        this.expectedExtension = expectedExtension;
+        this.expectedMethodSelector = expectedMethodSelector;
+        this.parseResult = RequestParser.parsePathInfo(pathInfo);
+        
+        assertEquals(3, parseResult.length);
+    }
+
+    @Override
+    public String toString() {
+        return getClass().getSimpleName() + ", pathInfo=" + pathInfo;
+    }
+    
+    @Test
+    public void testSelector() {
+        assertEquals(toString(), expectedTestSelector, parseResult[0]);
+    }
+    
+    @Test
+    public void testExtension() {
+        assertEquals(toString(), expectedExtension, parseResult[1]);
+    }
+    
+    @Test
+    public void testMethodSelector() {
+        assertEquals(toString(), expectedMethodSelector, parseResult[2]);
+    }
+    
+    @Parameters
+    public static Collection<Object[]> configs() {
+        final String EMPTY= "";
+        final Object[][] data = new Object[][] {
+                { EMPTY, EMPTY, EMPTY, EMPTY },
+                { "/", EMPTY, EMPTY, EMPTY },
+                { "/.html", EMPTY, "html", EMPTY },
+                { "/someTests.here.html", "someTests.here", "html", EMPTY },
+                { "someTests.here.html", "someTests.here", "html", EMPTY },
+                { "someTests.here.html.json", "someTests.here.html", "json", EMPTY },
+        };
+        
+        return Arrays.asList(data);
+     }
+}
\ No newline at end of file

Propchange: sling/trunk/testing/junit/core/src/test/java/org/apache/sling/junit/RequestParserTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

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