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 2013/08/16 12:08:27 UTC

svn commit: r1514637 - in /sling/trunk/launchpad/base/src: main/java/org/apache/sling/launchpad/base/impl/ClassLoaderResourceProvider.java test/java/org/apache/sling/launchpad/base/impl/ClassLoaderResourceProviderTest.java

Author: bdelacretaz
Date: Fri Aug 16 10:08:27 2013
New Revision: 1514637

URL: http://svn.apache.org/r1514637
Log:
SLING-3022 - tests added to demonstrate the problem

Added:
    sling/trunk/launchpad/base/src/test/java/org/apache/sling/launchpad/base/impl/ClassLoaderResourceProviderTest.java   (with props)
Modified:
    sling/trunk/launchpad/base/src/main/java/org/apache/sling/launchpad/base/impl/ClassLoaderResourceProvider.java

Modified: sling/trunk/launchpad/base/src/main/java/org/apache/sling/launchpad/base/impl/ClassLoaderResourceProvider.java
URL: http://svn.apache.org/viewvc/sling/trunk/launchpad/base/src/main/java/org/apache/sling/launchpad/base/impl/ClassLoaderResourceProvider.java?rev=1514637&r1=1514636&r2=1514637&view=diff
==============================================================================
--- sling/trunk/launchpad/base/src/main/java/org/apache/sling/launchpad/base/impl/ClassLoaderResourceProvider.java (original)
+++ sling/trunk/launchpad/base/src/main/java/org/apache/sling/launchpad/base/impl/ClassLoaderResourceProvider.java Fri Aug 16 10:08:27 2013
@@ -44,14 +44,17 @@ public class ClassLoaderResourceProvider
                 ? classLoader
                 : this.getClass().getClassLoader();
     }
+    
+    static Pattern getResourcePathPattern(String forPath) {
+        return Pattern.compile("^" + forPath + "/[^/]+/?$");
+    }
 
     public Iterator<String> getChildren(String path) {
         List<String> children;
 
         URL url = this.classLoader.getResource(path);
         if (url != null) {
-            Pattern pathPattern = Pattern.compile("^" + path + "/[^/]+/?$");
-
+            final Pattern pathPattern = getResourcePathPattern(path);
             children = new ArrayList<String>();
             try {
                 URLConnection conn = url.openConnection();

Added: sling/trunk/launchpad/base/src/test/java/org/apache/sling/launchpad/base/impl/ClassLoaderResourceProviderTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/launchpad/base/src/test/java/org/apache/sling/launchpad/base/impl/ClassLoaderResourceProviderTest.java?rev=1514637&view=auto
==============================================================================
--- sling/trunk/launchpad/base/src/test/java/org/apache/sling/launchpad/base/impl/ClassLoaderResourceProviderTest.java (added)
+++ sling/trunk/launchpad/base/src/test/java/org/apache/sling/launchpad/base/impl/ClassLoaderResourceProviderTest.java Fri Aug 16 10:08:27 2013
@@ -0,0 +1,64 @@
+/*
+ * 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.base.impl;
+
+import static org.junit.Assert.fail;
+
+import java.util.regex.Pattern;
+
+import org.junit.Test;
+
+public class ClassLoaderResourceProviderTest {
+    
+    private final Pattern pattern = ClassLoaderResourceProvider.getResourcePathPattern("resources/bundles");
+    
+    private void assertMatch(String path, boolean expectMatch) {
+        if(expectMatch != pattern.matcher(path).matches()) {
+            fail("Expected match=" + expectMatch + " for path '" + path + "', got " + !expectMatch);
+        }
+    }
+    
+    @Test
+    public void testResourcePathPatterns() {
+        assertMatch("resources/bundles/", false);
+        
+        assertMatch("resources/bundles/0/", true);
+        assertMatch("resources/bundles/0", true);
+        
+        assertMatch("resources/bundles/1234/", true);
+        assertMatch("resources/bundles/1234", true);
+        
+        assertMatch("resources/bundles/12/42", false);
+        assertMatch("resources/bundles/12/42", false);
+        
+        assertMatch("something/else/0/", false);
+        assertMatch("something/else/0", false);
+        
+        /* these fail due to SLING-3022
+        assertMatch("resources/bundles.someRunMode/", true);
+        assertMatch("resources/bundles.someRunMode/14/", true);
+        assertMatch("resources/bundles.someRunMode/15", false);
+        
+        assertMatch("resources/bundles.runModeA.runModeB/", false);
+        assertMatch("resources/bundles.runModeA.runModeB/14/", true);
+        assertMatch("resources/bundles.runModeA.runModeB/14", true);
+        assertMatch("resources/bundles.runModeA.runModeB/15/16", false);
+        */
+    }
+}

Propchange: sling/trunk/launchpad/base/src/test/java/org/apache/sling/launchpad/base/impl/ClassLoaderResourceProviderTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sling/trunk/launchpad/base/src/test/java/org/apache/sling/launchpad/base/impl/ClassLoaderResourceProviderTest.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev URL