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/10/21 18:03:19 UTC

svn commit: r1534257 - in /sling/trunk/launchpad/base: pom.xml src/test/java/org/apache/sling/launchpad/base/impl/ClassLoaderResourceProviderChildrenTest.java

Author: bdelacretaz
Date: Mon Oct 21 16:03:19 2013
New Revision: 1534257

URL: http://svn.apache.org/r1534257
Log:
SLING-3196 - test that demonstrates the issue, @Ignored for now

Added:
    sling/trunk/launchpad/base/src/test/java/org/apache/sling/launchpad/base/impl/ClassLoaderResourceProviderChildrenTest.java   (with props)
Modified:
    sling/trunk/launchpad/base/pom.xml

Modified: sling/trunk/launchpad/base/pom.xml
URL: http://svn.apache.org/viewvc/sling/trunk/launchpad/base/pom.xml?rev=1534257&r1=1534256&r2=1534257&view=diff
==============================================================================
--- sling/trunk/launchpad/base/pom.xml (original)
+++ sling/trunk/launchpad/base/pom.xml Mon Oct 21 16:03:19 2013
@@ -303,7 +303,12 @@
             <artifactId>jmock-junit4</artifactId>
             <scope>test</scope>
         </dependency>
+        <dependency>
+            <groupId>org.mockito</groupId>
+            <artifactId>mockito-core</artifactId>
+            <version>1.9.5</version>
+            <scope>test</scope>
+        </dependency>
     </dependencies>
-
 </project>
 

Added: sling/trunk/launchpad/base/src/test/java/org/apache/sling/launchpad/base/impl/ClassLoaderResourceProviderChildrenTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/launchpad/base/src/test/java/org/apache/sling/launchpad/base/impl/ClassLoaderResourceProviderChildrenTest.java?rev=1534257&view=auto
==============================================================================
--- sling/trunk/launchpad/base/src/test/java/org/apache/sling/launchpad/base/impl/ClassLoaderResourceProviderChildrenTest.java (added)
+++ sling/trunk/launchpad/base/src/test/java/org/apache/sling/launchpad/base/impl/ClassLoaderResourceProviderChildrenTest.java Mon Oct 21 16:03:19 2013
@@ -0,0 +1,129 @@
+/*
+ * 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.assertEquals;
+import static org.junit.Assert.fail;
+import static org.mockito.Mockito.when;
+
+import java.io.IOException;
+import java.net.JarURLConnection;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.net.URLConnection;
+import java.net.URLStreamHandler;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Vector;
+import java.util.jar.JarEntry;
+import java.util.jar.JarFile;
+
+import org.junit.Before;
+import org.junit.Ignore;
+import org.junit.Test;
+import org.mockito.Matchers;
+import org.mockito.Mockito;
+
+@Ignore("SLING-3196")
+public class ClassLoaderResourceProviderChildrenTest {
+    
+    private ClassLoader classLoader;
+    private ClassLoaderResourceProvider provider;
+    
+    private static final String [] TEST_PATHS = {
+        "resources/install",
+        "resources/install/one.jar",
+        "resources/install/sub/two.jar",
+        "resources/install/sub/six.jar",
+        "resources/install.jackrabbit/three.jar",
+        "resources/install.oak/four.jar",
+        "resources/install.oak/sub/five.jar"
+    };
+    
+    private ClassLoader mockClassLoader(String ... paths) throws MalformedURLException, IOException {
+        final ClassLoader cl = Mockito.mock(ClassLoader.class);
+        final JarURLConnection conn = Mockito.mock(JarURLConnection.class);
+        final URLStreamHandler handler = new URLStreamHandler() {
+            @Override
+            protected URLConnection openConnection(final URL url) throws IOException {
+                return conn;
+            }
+        };
+        final JarFile f = Mockito.mock(JarFile.class);
+        final URL url = new URL("jar://some.jar", "localhost", 1234, "some.jar", handler);
+        
+        final Vector<JarEntry> entries = new Vector<JarEntry>();
+        for(String path : paths) {
+            entries.add(new JarEntry(path));
+        }
+        
+        when(cl.getResource(Matchers.any(String.class))).thenReturn(url);
+        when(conn.getJarFile()).thenReturn(f);
+        when(f.entries()).thenReturn(entries.elements());
+        
+        return cl;
+    }
+    
+    private void assertChildren(ClassLoaderResourceProvider p, String path, String ... expected) {
+        final List<String> result = new ArrayList<String>();
+        final Iterator<String> it = p.getChildren(path);
+        while(it.hasNext()) {
+            result.add(it.next());
+        }
+        for(String exp : expected) {
+            if(!result.contains(exp)) {
+                fail(path + ": expected child is not present in result: " + exp + ", result=" + result);
+            }
+        }
+        assertEquals(path + ": expecting " + expected.length + " children, result=" + result, expected.length, result.size());
+    }
+    
+    @Before
+    public void setup() throws MalformedURLException, IOException {
+        classLoader = mockClassLoader(TEST_PATHS);
+        provider = new ClassLoaderResourceProvider(classLoader);
+    }
+    
+    @Test
+    public void testInstall() {
+        assertChildren(provider, "resources/install", "resources/install/one.jar");
+    }
+    
+    @Test
+    public void testInstallSub() {
+        assertChildren(provider, 
+                "resources/install/sub", 
+                "resources/install/sub/two.jar",
+                "resources/install/sub/six.jar");
+    }
+    
+    @Test
+    public void testInstallJackrabbit() {
+        assertChildren(provider, 
+                "resources/install.jackrabbit", 
+                "resources/install.jackrabbit/three.jar");
+    }
+    
+    @Test
+    public void testInstallOak() {
+        assertChildren(provider, 
+                "resources/install.oak/four.jar");
+    }
+}

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

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