sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From vram...@apache.org
Subject svn commit: r1239587 [9/9] - in /sling/whiteboard/resourceresolverfactory/jcr-resource: ./ src/ src/main/ src/main/appended-resources/ src/main/appended-resources/META-INF/ src/main/java/ src/main/java/org/ src/main/java/org/apache/ src/main/java/org/a...
Date Thu, 02 Feb 2012 12:47:01 GMT
Added: sling/whiteboard/resourceresolverfactory/jcr-resource/src/test/java/org/apache/sling/jcr/resource/internal/SynchronousJcrResourceListener.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/resourceresolverfactory/jcr-resource/src/test/java/org/apache/sling/jcr/resource/internal/SynchronousJcrResourceListener.java?rev=1239587&view=auto
==============================================================================
--- sling/whiteboard/resourceresolverfactory/jcr-resource/src/test/java/org/apache/sling/jcr/resource/internal/SynchronousJcrResourceListener.java (added)
+++ sling/whiteboard/resourceresolverfactory/jcr-resource/src/test/java/org/apache/sling/jcr/resource/internal/SynchronousJcrResourceListener.java Thu Feb  2 12:46:58 2012
@@ -0,0 +1,41 @@
+/*
+ * 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.jcr.resource.internal;
+
+import javax.jcr.RepositoryException;
+
+import org.apache.jackrabbit.core.observation.SynchronousEventListener;
+import org.apache.sling.api.resource.LoginException;
+import org.apache.sling.api.resource.ResourceResolverFactory;
+import org.osgi.util.tracker.ServiceTracker;
+
+/**
+ * This class is used to ensure that events are handled during the test.
+ *
+ * TODO - Ideally, this wouldn't be necessary, but EventHelper doesn't seem
+ * to be working 100% of the time.
+ *
+ */
+public class SynchronousJcrResourceListener extends JcrResourceListener implements SynchronousEventListener {
+
+    public SynchronousJcrResourceListener(String workspaceName,
+            ResourceResolverFactory factory, String startPath, String mountPrefix, ServiceTracker eventAdminTracker)
+            throws LoginException, RepositoryException {
+        super(workspaceName, factory, startPath, mountPrefix, eventAdminTracker);
+    }
+
+}

Added: sling/whiteboard/resourceresolverfactory/jcr-resource/src/test/java/org/apache/sling/jcr/resource/internal/helper/JcrNodeResourceIteratorTest.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/resourceresolverfactory/jcr-resource/src/test/java/org/apache/sling/jcr/resource/internal/helper/JcrNodeResourceIteratorTest.java?rev=1239587&view=auto
==============================================================================
--- sling/whiteboard/resourceresolverfactory/jcr-resource/src/test/java/org/apache/sling/jcr/resource/internal/helper/JcrNodeResourceIteratorTest.java (added)
+++ sling/whiteboard/resourceresolverfactory/jcr-resource/src/test/java/org/apache/sling/jcr/resource/internal/helper/JcrNodeResourceIteratorTest.java Thu Feb  2 12:46:58 2012
@@ -0,0 +1,98 @@
+/*
+ * 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.jcr.resource.internal.helper;
+
+import java.util.NoSuchElementException;
+
+import javax.jcr.Node;
+import javax.jcr.NodeIterator;
+import javax.jcr.RepositoryException;
+
+import junit.framework.TestCase;
+
+import org.apache.sling.api.resource.Resource;
+import org.apache.sling.commons.testing.jcr.MockNode;
+import org.apache.sling.commons.testing.jcr.MockNodeIterator;
+import org.apache.sling.jcr.resource.internal.helper.jcr.JcrNodeResourceIterator;
+
+public class JcrNodeResourceIteratorTest extends TestCase {
+
+    public void testEmpty() {
+        NodeIterator ni = new MockNodeIterator(null);
+        JcrNodeResourceIterator ri = new JcrNodeResourceIterator(null, ni, null);
+
+        assertFalse(ri.hasNext());
+
+        try {
+            ri.next();
+            fail("Expected no element in the iterator");
+        } catch (NoSuchElementException nsee) {
+            // expected
+        }
+    }
+
+    public void testSingle() throws RepositoryException {
+        String path = "/parent/path/node";
+        Node node = new MockNode(path);
+        NodeIterator ni = new MockNodeIterator(new Node[] { node });
+        JcrNodeResourceIterator ri = new JcrNodeResourceIterator(null, ni, null);
+
+        assertTrue(ri.hasNext());
+        Resource res = ri.next();
+        assertEquals(path, res.getPath());
+        assertEquals(node.getPrimaryNodeType().getName(), res.getResourceType());
+
+        assertFalse(ri.hasNext());
+
+        try {
+            ri.next();
+            fail("Expected no element in the iterator");
+        } catch (NoSuchElementException nsee) {
+            // expected
+        }
+    }
+
+    public void testMulti() throws RepositoryException {
+        int numNodes = 10;
+        String pathBase = "/parent/path/node/";
+        Node[] nodes = new Node[numNodes];
+        for (int i=0; i < nodes.length; i++) {
+            nodes[i] = new MockNode(pathBase + i, "some:type" + i);
+        }
+        NodeIterator ni = new MockNodeIterator(nodes);
+        JcrNodeResourceIterator ri = new JcrNodeResourceIterator(null, ni, null);
+
+        for (int i=0; i < nodes.length; i++) {
+            assertTrue(ri.hasNext());
+            Resource res = ri.next();
+            assertEquals(pathBase + i, res.getPath());
+            assertEquals(nodes[i].getPrimaryNodeType().getName(), res.getResourceType());
+        }
+
+        assertFalse(ri.hasNext());
+
+        try {
+            ri.next();
+            fail("Expected no element in the iterator");
+        } catch (NoSuchElementException nsee) {
+            // expected
+        }
+    }
+
+}

Added: sling/whiteboard/resourceresolverfactory/jcr-resource/src/test/java/org/apache/sling/jcr/resource/internal/helper/MapEntryTest.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/resourceresolverfactory/jcr-resource/src/test/java/org/apache/sling/jcr/resource/internal/helper/MapEntryTest.java?rev=1239587&view=auto
==============================================================================
--- sling/whiteboard/resourceresolverfactory/jcr-resource/src/test/java/org/apache/sling/jcr/resource/internal/helper/MapEntryTest.java (added)
+++ sling/whiteboard/resourceresolverfactory/jcr-resource/src/test/java/org/apache/sling/jcr/resource/internal/helper/MapEntryTest.java Thu Feb  2 12:46:58 2012
@@ -0,0 +1,147 @@
+/*
+ * 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.jcr.resource.internal.helper;
+
+import java.net.URI;
+
+import junit.framework.TestCase;
+
+public class MapEntryTest extends TestCase {
+
+    public void test_to_url_http_80() {
+        assertEqualUri("http://sling.apache.org", "http/sling.apache.org.80");
+        assertEqualUri("http://sling.apache.org/", "http/sling.apache.org.80/");
+        assertEqualUri("http://sling.apache.org/site/index.html",
+            "http/sling.apache.org.80/site/index.html");
+    }
+
+    public void test_to_url_https_443() {
+        assertEqualUri("https://sling.apache.org", "https/sling.apache.org.443");
+        assertEqualUri("https://sling.apache.org/",
+            "https/sling.apache.org.443/");
+        assertEqualUri("https://sling.apache.org/site/index.html",
+            "https/sling.apache.org.443/site/index.html");
+    }
+
+    public void test_to_url_any_999() {
+        // http with arbitrary port
+        assertEqualUri("http://sling.apache.org:123",
+            "http/sling.apache.org.123");
+        assertEqualUri("http://sling.apache.org:456/",
+            "http/sling.apache.org.456/");
+        assertEqualUri("http://sling.apache.org:456/site/index.html",
+            "http/sling.apache.org.456/site/index.html");
+
+        // https with arbitrary port
+        assertEqualUri("https://sling.apache.org:987",
+            "https/sling.apache.org.987");
+        assertEqualUri("https://sling.apache.org:654/",
+            "https/sling.apache.org.654/");
+        assertEqualUri("https://sling.apache.org:321/site/index.html",
+            "https/sling.apache.org.321/site/index.html");
+
+        // any scheme with arbitrary port
+        assertEqualUri("gurk://sling.apache.org:987",
+            "gurk/sling.apache.org.987");
+        assertEqualUri("gurk://sling.apache.org:654/",
+            "gurk/sling.apache.org.654/");
+        assertEqualUri("gurk://sling.apache.org:321/site/index.html",
+            "gurk/sling.apache.org.321/site/index.html");
+    }
+
+    public void test_to_url_any() {
+        // http without port
+        assertEqualUri("http://sling.apache.org", "http/sling.apache.org");
+        assertEqualUri("http://sling.apache.org/", "http/sling.apache.org/");
+        assertEqualUri("http://sling.apache.org/site/index.html",
+            "http/sling.apache.org/site/index.html");
+
+        // https without port
+        assertEqualUri("https://sling.apache.org", "https/sling.apache.org");
+        assertEqualUri("https://sling.apache.org/", "https/sling.apache.org/");
+        assertEqualUri("https://sling.apache.org/site/index.html",
+            "https/sling.apache.org/site/index.html");
+
+        // any scheme without port
+        assertEqualUri("gurk://sling.apache.org", "gurk/sling.apache.org");
+        assertEqualUri("gurk://sling.apache.org/", "gurk/sling.apache.org/");
+        assertEqualUri("gurk://sling.apache.org/site/index.html",
+            "gurk/sling.apache.org/site/index.html");
+    }
+
+    public void test_fixUriPath() {
+        // http without port
+        assertEqualUriPath("http/sling.apache.org.80", "http/sling.apache.org");
+        assertEqualUriPath("http/sling.apache.org.80/",
+            "http/sling.apache.org/");
+        assertEqualUriPath("http/sling.apache.org.80/site/index.html",
+            "http/sling.apache.org/site/index.html");
+
+        // http with port
+        assertEqualUriPath("http/sling.apache.org.80",
+            "http/sling.apache.org.80");
+        assertEqualUriPath("http/sling.apache.org.80/",
+            "http/sling.apache.org.80/");
+        assertEqualUriPath("http/sling.apache.org.80/site/index.html",
+            "http/sling.apache.org.80/site/index.html");
+
+        // https without port
+        assertEqualUriPath("https/sling.apache.org.443",
+            "https/sling.apache.org");
+        assertEqualUriPath("https/sling.apache.org.443/",
+            "https/sling.apache.org/");
+        assertEqualUriPath("https/sling.apache.org.443/site/index.html",
+            "https/sling.apache.org/site/index.html");
+
+        // https with port
+        assertEqualUriPath("https/sling.apache.org.443",
+            "https/sling.apache.org.443");
+        assertEqualUriPath("https/sling.apache.org.443/",
+            "https/sling.apache.org.443/");
+        assertEqualUriPath("https/sling.apache.org.443/site/index.html",
+            "https/sling.apache.org.443/site/index.html");
+
+        // anything without port
+        assertEqualUriPath("gurk/sling.apache.org", "gurk/sling.apache.org");
+        assertEqualUriPath("gurk/sling.apache.org/", "gurk/sling.apache.org/");
+        assertEqualUriPath("gurk/sling.apache.org/site/index.html",
+            "gurk/sling.apache.org/site/index.html");
+
+        // http with port
+        assertEqualUriPath("gurk/sling.apache.org.123",
+            "gurk/sling.apache.org.123");
+        assertEqualUriPath("gurk/sling.apache.org.456/",
+            "gurk/sling.apache.org.456/");
+        assertEqualUriPath("gurk/sling.apache.org.789/site/index.html",
+            "gurk/sling.apache.org.789/site/index.html");
+
+    }
+
+    private void assertEqualUri(String expected, String uriPath) {
+        URI uri = MapEntry.toURI(uriPath);
+        assertNotNull("Failed converting " + uriPath, uri);
+        assertEquals(expected, uri.toString());
+    }
+
+    private void assertEqualUriPath(String expected, String uriPath) {
+        String fixed = MapEntry.fixUriPath(uriPath);
+        assertNotNull(fixed);
+        assertEquals(expected, fixed);
+    }
+}

Added: sling/whiteboard/resourceresolverfactory/jcr-resource/src/test/java/org/apache/sling/jcr/resource/internal/helper/RedirectResourceTest.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/resourceresolverfactory/jcr-resource/src/test/java/org/apache/sling/jcr/resource/internal/helper/RedirectResourceTest.java?rev=1239587&view=auto
==============================================================================
--- sling/whiteboard/resourceresolverfactory/jcr-resource/src/test/java/org/apache/sling/jcr/resource/internal/helper/RedirectResourceTest.java (added)
+++ sling/whiteboard/resourceresolverfactory/jcr-resource/src/test/java/org/apache/sling/jcr/resource/internal/helper/RedirectResourceTest.java Thu Feb  2 12:46:58 2012
@@ -0,0 +1,56 @@
+/*
+ * 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.jcr.resource.internal.helper;
+
+import java.util.Map;
+
+import org.apache.sling.api.resource.PersistableValueMap;
+import org.apache.sling.api.resource.ValueMap;
+
+import junit.framework.TestCase;
+
+public class RedirectResourceTest extends TestCase {
+
+    public void testRedirectResource() {
+
+        final String path = "/redir/path";
+        final String target = "/redir/target";
+        final int status = 999;
+        final RedirectResource res = new RedirectResource(null, path, target,
+            status);
+
+        assertEquals(path, res.getPath());
+        assertEquals(RedirectResource.RT_SLING_REDIRECT, res.getResourceType());
+
+        final Map<?, ?> map = res.adaptTo(Map.class);
+        assertNotNull("Expected Map adapter", map);
+        assertEquals(target, map.get(RedirectResource.PROP_SLING_TARGET));
+        assertEquals(status, ((Integer) map.get(RedirectResource.PROP_SLING_STATUS)).intValue());
+
+        final ValueMap valueMap = res.adaptTo(ValueMap.class);
+        assertNotNull("Expected ValueMap adapter", valueMap);
+        assertEquals(target, valueMap.get(RedirectResource.PROP_SLING_TARGET));
+        assertEquals(status, ((Integer) valueMap.get(RedirectResource.PROP_SLING_STATUS)).intValue());
+        assertEquals(status, valueMap.get(RedirectResource.PROP_SLING_STATUS, Integer.class).intValue());
+
+        final PersistableValueMap persistableValueMap = res.adaptTo(PersistableValueMap.class);
+        assertNull("Unexpected PersistableValueMap adapter",
+            persistableValueMap);
+    }
+}

Added: sling/whiteboard/resourceresolverfactory/jcr-resource/src/test/java/org/apache/sling/jcr/resource/internal/helper/ResourcePathIteratorTest.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/resourceresolverfactory/jcr-resource/src/test/java/org/apache/sling/jcr/resource/internal/helper/ResourcePathIteratorTest.java?rev=1239587&view=auto
==============================================================================
--- sling/whiteboard/resourceresolverfactory/jcr-resource/src/test/java/org/apache/sling/jcr/resource/internal/helper/ResourcePathIteratorTest.java (added)
+++ sling/whiteboard/resourceresolverfactory/jcr-resource/src/test/java/org/apache/sling/jcr/resource/internal/helper/ResourcePathIteratorTest.java Thu Feb  2 12:46:58 2012
@@ -0,0 +1,150 @@
+/*
+ * 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.jcr.resource.internal.helper;
+
+import java.util.Iterator;
+import java.util.NoSuchElementException;
+
+import junit.framework.TestCase;
+
+public class ResourcePathIteratorTest extends TestCase {
+
+    public void testNull() {
+        ResourcePathIterator rpi = new ResourcePathIterator(null);
+        assertFinished(rpi);
+    }
+
+    public void testEmpty() {
+        ResourcePathIterator rpi = new ResourcePathIterator("");
+        assertFinished(rpi);
+    }
+
+    public void testRoot() {
+        ResourcePathIterator rpi = new ResourcePathIterator("/");
+        assertNext("/", rpi);
+        assertFinished(rpi);
+    }
+
+    public void testSlashed() {
+        ResourcePathIterator rpi = new ResourcePathIterator("/root/child");
+        assertNext("/root/child", rpi);
+        assertFinished(rpi);
+    }
+
+    public void testSlashedTrailingSlash1() {
+        ResourcePathIterator rpi = new ResourcePathIterator("/root/child/");
+        assertNext("/root/child", rpi);
+        assertFinished(rpi);
+    }
+
+    public void testSlashedTrailingSlash2() {
+        ResourcePathIterator rpi = new ResourcePathIterator("/root/child//");
+        assertNext("/root/child", rpi);
+        assertFinished(rpi);
+    }
+
+    public void testDotted() {
+        ResourcePathIterator rpi = new ResourcePathIterator("/root.child");
+        assertNext("/root.child", rpi);
+        assertNext("/root", rpi);
+        assertFinished(rpi);
+    }
+
+    public void testMixed() {
+        ResourcePathIterator rpi = new ResourcePathIterator(
+            "/root/child.print.a4.html/with/suffix");
+        assertNext("/root/child.print.a4.html/with/suffix", rpi);
+        assertNext("/root/child.print.a4", rpi);
+        assertNext("/root/child.print", rpi);
+        assertNext("/root/child", rpi);
+        assertFinished(rpi);
+    }
+
+    public void testNoSeparators() {
+        final Iterator<String> rpi = new ResourcePathIterator(
+            "MickeyMouseWasHere");
+        assertNext("MickeyMouseWasHere", rpi);
+        assertFinished(rpi);
+    }
+
+    public void testGetA() {
+        final Iterator<String> rpi = new ResourcePathIterator(
+            "/some/stuff/more.a4.html");
+        assertNext("/some/stuff/more.a4.html", rpi);
+        assertNext("/some/stuff/more.a4", rpi);
+        assertNext("/some/stuff/more", rpi);
+        assertFinished(rpi);
+    }
+
+    public void testGetB() {
+        final Iterator<String> rpi = new ResourcePathIterator(
+            "/some/stuff/more.html");
+        assertNext("/some/stuff/more.html", rpi);
+        assertNext("/some/stuff/more", rpi);
+        assertFinished(rpi);
+    }
+
+    public void testHeadB() {
+        final Iterator<String> rpi = new ResourcePathIterator(
+            "/some/stuff/more.html");
+        assertNext("/some/stuff/more.html", rpi);
+        assertNext("/some/stuff/more", rpi);
+        assertFinished(rpi);
+    }
+
+    public void testGetC() {
+        final Iterator<String> it = new ResourcePathIterator("/some/stuff/more");
+        assertNext("/some/stuff/more", it);
+        assertFinished(it);
+    }
+
+    public void testGetD() {
+        final Iterator<String> it = new ResourcePathIterator(
+            "/some/stuff.print/more.html");
+        assertNext("/some/stuff.print/more.html", it);
+        assertNext("/some/stuff.print/more", it);
+        assertNext("/some/stuff", it);
+        assertFinished(it);
+    }
+
+    public void testRelativePathGet() {
+        final Iterator<String> it = new ResourcePathIterator("some/stuff.print");
+        assertNext("some/stuff.print", it);
+        assertNext("some/stuff", it);
+        assertFinished(it);
+    }
+    
+    private void assertNext(String expected, Iterator<String> iterator) {
+        assertTrue("Iterator must have next", iterator.hasNext());
+        assertEquals("Incorrect next value", expected, iterator.next());
+    }
+    
+    private void assertFinished(Iterator<String> iterator) {
+        
+        assertFalse("Iterator must not have next", iterator.hasNext());
+
+        try {
+            iterator.next();
+            fail("Iterator should throw NoSuchElementException");
+        } catch (NoSuchElementException nsee) {
+            // expected
+        }
+
+    }
+}
\ No newline at end of file

Added: sling/whiteboard/resourceresolverfactory/jcr-resource/src/test/java/org/apache/sling/jcr/resource/internal/helper/ResourceProviderEntryTest.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/resourceresolverfactory/jcr-resource/src/test/java/org/apache/sling/jcr/resource/internal/helper/ResourceProviderEntryTest.java?rev=1239587&view=auto
==============================================================================
--- sling/whiteboard/resourceresolverfactory/jcr-resource/src/test/java/org/apache/sling/jcr/resource/internal/helper/ResourceProviderEntryTest.java (added)
+++ sling/whiteboard/resourceresolverfactory/jcr-resource/src/test/java/org/apache/sling/jcr/resource/internal/helper/ResourceProviderEntryTest.java Thu Feb  2 12:46:58 2012
@@ -0,0 +1,320 @@
+/*
+ * 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.jcr.resource.internal.helper;
+
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.Map;
+
+import javax.servlet.http.HttpServletRequest;
+
+import junit.framework.TestCase;
+
+import org.apache.sling.api.resource.AbstractResource;
+import org.apache.sling.api.resource.Resource;
+import org.apache.sling.api.resource.ResourceMetadata;
+import org.apache.sling.api.resource.ResourceProvider;
+import org.apache.sling.api.resource.ResourceResolver;
+
+public class ResourceProviderEntryTest extends TestCase {
+
+    private ResourceProvider rootProvider;
+
+    private ResourceProviderEntry root;
+
+    @Override
+    protected void setUp() throws Exception {
+        super.setUp();
+
+        rootProvider = new TestResourceProvider("/");
+        root = new ResourceProviderEntry("/", new ResourceProvider[]{ rootProvider});
+    }
+
+    @Override
+    protected void tearDown() throws Exception {
+        super.tearDown();
+    }
+
+    public void testRootProvider() {
+        assertNull(root.getResource(null, "relpath"));
+        assertEquals(root, root.getResource(null, "/"));
+        assertEquals(root, root.getResource(null, "/rootel"));
+        assertEquals(root, root.getResource(null, "/rootel/child"));
+        assertEquals(root, root.getResource(null, "/apps/sling/sample/html.js"));
+        assertEquals(root, root.getResource(null,
+            "/apps/sling/microsling/html.js"));
+    }
+
+    public void testAdd1Provider() {
+        String firstPath = "/rootel";
+        ResourceProvider first = new TestResourceProvider(firstPath);
+        root.addResourceProvider(firstPath, first, null);
+
+
+        assertEquals(root, root.getResource(null, "/"));
+        assertEquals(first, root.getResource(null, "/rootel"));
+        assertEquals(first, root.getResource(null, "/rootel/html.js"));
+        assertEquals(first, root.getResource(null, "/rootel/child"));
+        assertEquals(first, root.getResource(null, "/rootel/child/html.js"));
+        assertEquals(rootProvider, root.getResource(null,
+            "/apps/sling/sample/html.js"));
+        assertEquals(rootProvider, root.getResource(null,
+            "/apps/sling/microsling/html.js"));
+    }
+
+    public void testAdd3Providers() {
+        String firstPath = "/rootel";
+        String thirdPath = "/apps/sling/sample";
+        String secondPath = firstPath + "/child";
+
+        ResourceProvider first = new TestResourceProvider(firstPath);
+        ResourceProvider second = new TestResourceProvider(secondPath);
+        ResourceProvider third = new TestResourceProvider(thirdPath);
+
+        root.addResourceProvider(firstPath, first, null);
+        root.addResourceProvider(secondPath, second, null);
+        root.addResourceProvider(thirdPath, third, null);
+
+
+
+        assertEquals(rootProvider, root.getResource(null, "/"));
+        assertEquals(first, root.getResource(null, "/rootel"));
+        assertEquals(first, root.getResource(null, "/rootel/html.js"));
+        assertEquals(second, root.getResource(null, "/rootel/child"));
+        assertEquals(second, root.getResource(null, "/rootel/child/html.js"));
+        assertEquals(third,
+            root.getResource(null, "/apps/sling/sample/html.js"));
+        Resource resource = root.getResource(null,
+            "/apps/sling/microsling/html.js");
+            assertEquals(rootProvider, resource);
+    }
+
+    public void testAdd3ProvidersReverse() {
+        String firstPath = "/rootel";
+        String thirdPath = "/apps/sling/sample";
+        String secondPath = firstPath + "/child";
+
+        ResourceProvider first = new TestResourceProvider(firstPath);
+        ResourceProvider second = new TestResourceProvider(secondPath);
+        ResourceProvider third = new TestResourceProvider(thirdPath);
+
+        root.addResourceProvider(thirdPath, third, null);
+        root.addResourceProvider(secondPath, second, null);
+        root.addResourceProvider(firstPath, first, null);
+
+        assertEquals(rootProvider, root.getResource(null, "/"));
+        assertEquals(first, root.getResource(null, "/rootel"));
+        assertEquals(first, root.getResource(null, "/rootel/html.js"));
+        assertEquals(second, root.getResource(null, "/rootel/child"));
+        assertEquals(second, root.getResource(null, "/rootel/child/html.js"));
+        assertEquals(third,
+           root.getResource(null, "/apps/sling/sample/html.js"));
+        Resource resource = root.getResource(null,
+              "/apps/sling/microsling/html.js");
+        assertEquals(rootProvider, resource);
+    }
+
+    public void testRemoveProviders() {
+        String firstPath = "/rootel";
+        String thirdPath = "/apps/sling/sample";
+        String secondPath = firstPath + "/child";
+
+        ResourceProvider first = new TestResourceProvider(firstPath);
+        ResourceProvider second = new TestResourceProvider(secondPath);
+        ResourceProvider third = new TestResourceProvider(thirdPath);
+
+        root.addResourceProvider(firstPath, first, null);
+        root.addResourceProvider(secondPath, second, null);
+        root.addResourceProvider(thirdPath, third, null);
+
+        assertEquals(rootProvider, root.getResource(null, "/"));
+        assertEquals(first, root.getResource(null, "/rootel/html.js"));
+        assertEquals(second, root.getResource(null, "/rootel/child/html.js"));
+
+        root.removeResourceProvider(firstPath, first, null);
+
+        assertEquals(rootProvider, root.getResource(null, "/"));
+        assertEquals(rootProvider, root.getResource(null, "/rootel/sddsf/sdfsdf/html.js"));
+        assertEquals(rootProvider, root.getResource(null, "/rootel/html.js"));
+        assertEquals(second, root.getResource(null, "/rootel/child/html.js"));
+
+        root.addResourceProvider(firstPath, first, null);
+
+        assertEquals(rootProvider, root.getResource(null, "/"));
+        assertEquals(first, root.getResource(null, "/rootel/html.js"));
+        assertEquals(second, root.getResource(null, "/rootel/child/html.js"));
+    }
+
+    protected void assertEquals(ResourceProvider resProvider, Resource res) {
+        assertEquals(resProvider, res.getResourceResolver());
+    }
+
+    protected void assertEquals(ResourceProviderEntry resProviderEntry,
+            Resource res) {
+        ResourceProvider[] resourceProviders = resProviderEntry.getResourceProviders();
+        for ( ResourceProvider rp : resourceProviders ) {
+            if ( rp.equals(res.getResourceResolver())) {
+                return;
+            }
+        }
+        fail();
+    }
+
+    // The test provider implements the ResourceResolver interface and sets
+    // itself on the returned resource. This way the assertEquals methods above
+    // may identify whether a resource has been returned from the expected
+    // ResourceProvider
+    private static class TestResourceProvider implements ResourceProvider, ResourceResolver {
+
+        private final String[] roots;
+
+        TestResourceProvider(String root) {
+            roots = new String[] { root };
+        }
+
+        public ResourceResolver clone(Map<String, Object> authenticationInfo) {
+            throw new UnsupportedOperationException("copy");
+        }
+
+        public Resource getResource(ResourceResolver resolver,
+                HttpServletRequest request, String path) {
+            return getResource(resolver, path);
+        }
+
+        public Resource getResource(ResourceResolver resolver, String path) {
+            return new TestResource(path, this);
+        }
+
+        public Iterator<Resource> listChildren(Resource parent) {
+            return null;
+        }
+
+        // just dummy implementation to mark our resources for the tests
+        public Iterator<Resource> findResources(String query, String language) {
+            return null;
+        }
+
+        public Resource getResource(String path) {
+            return null;
+        }
+
+        public Resource getResource(Resource base, String path) {
+            return null;
+        }
+
+        public String[] getSearchPath() {
+            return null;
+        }
+
+        public String map(HttpServletRequest request, String resourcePath) {
+            return null;
+        }
+
+        public String map(String resourcePath) {
+            return null;
+        }
+
+        public Iterator<Map<String, Object>> queryResources(String query,
+                String language) {
+            return null;
+        }
+
+        public Resource resolve(HttpServletRequest request, String absPath) {
+            return null;
+        }
+
+        public Resource resolve(HttpServletRequest request) {
+            return null;
+        }
+
+        public Resource resolve(String absPath) {
+            return null;
+        }
+
+        public <AdapterType> AdapterType adaptTo(Class<AdapterType> type) {
+            return null;
+        }
+
+        /**
+         * {@inheritDoc}
+         * @see java.lang.Object#toString()
+         */
+        @Override
+        public String toString() {
+            return Arrays.toString(roots);
+        }
+
+        public boolean isLive() {
+            return true;
+        }
+
+        public void close() {
+            // nothing to do
+        }
+
+        public String getUserID() {
+            return null;
+        }
+
+        public Object getAttribute(String name) {
+            return null;
+        }
+
+        public Iterator<String> getAttributeNames() {
+            return Collections.<String> emptyList().iterator();
+        }
+    }
+
+    private static class TestResource extends AbstractResource {
+
+        private final String path;
+
+        private final ResourceResolver resourceResolver;
+
+        public TestResource(String path, ResourceResolver resourceResolver) {
+            this.path = path;
+            this.resourceResolver = resourceResolver;
+        }
+
+        public String getPath() {
+            return path;
+        }
+
+        public ResourceMetadata getResourceMetadata() {
+            return null;
+        }
+
+        public ResourceResolver getResourceResolver() {
+            return resourceResolver;
+        }
+
+        public String getResourceType() {
+            return null;
+        }
+
+        public String getResourceSuperType() {
+            return null;
+        }
+
+        public <AdapterType> AdapterType adaptTo(Class<AdapterType> type) {
+            return null;
+        }
+    }
+}

Added: sling/whiteboard/resourceresolverfactory/jcr-resource/src/test/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrItemResourceTestBase.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/resourceresolverfactory/jcr-resource/src/test/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrItemResourceTestBase.java?rev=1239587&view=auto
==============================================================================
--- sling/whiteboard/resourceresolverfactory/jcr-resource/src/test/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrItemResourceTestBase.java (added)
+++ sling/whiteboard/resourceresolverfactory/jcr-resource/src/test/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrItemResourceTestBase.java Thu Feb  2 12:46:58 2012
@@ -0,0 +1,95 @@
+/*
+ * 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.jcr.resource.internal.helper.jcr;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+import javax.jcr.NamespaceRegistry;
+import javax.jcr.Node;
+
+import org.apache.sling.api.SlingConstants;
+import org.apache.sling.api.resource.ResourceResolver;
+import org.apache.sling.commons.testing.jcr.RepositoryTestBase;
+import org.apache.sling.jcr.resource.JcrResourceConstants;
+
+public class JcrItemResourceTestBase extends RepositoryTestBase {
+
+    protected static final long TEST_MODIFIED = System.currentTimeMillis();
+
+    protected static final String TEST_TYPE = "text/gurk";
+
+    protected static final String TEST_ENCODING = "ISO-8859-1";
+
+    protected static final byte[] TEST_DATA = { 'S', 'o', 'm', 'e', ' ', 'T',
+        'e', 's', 't' };
+
+    protected ResourceResolver resourceResolver;
+
+    protected String rootPath;
+
+    protected Node rootNode;
+
+    protected void setUp() throws Exception {
+        super.setUp();
+
+        resourceResolver = new MockResourceResolver(getSession());
+
+        try {
+            NamespaceRegistry nsr = session.getWorkspace().getNamespaceRegistry();
+            nsr.registerNamespace(SlingConstants.NAMESPACE_PREFIX,
+                JcrResourceConstants.SLING_NAMESPACE_URI);
+        } catch (Exception e) {
+            // don't care for now
+        }
+
+        rootPath = "/test" + System.currentTimeMillis();
+        rootNode = getSession().getRootNode().addNode(rootPath.substring(1),
+            "nt:unstructured");
+        getSession().save();
+    }
+
+    @Override
+    protected void tearDown() throws Exception {
+        if (rootNode != null) {
+            rootNode.remove();
+            getSession().save();
+        }
+        
+        super.tearDown();
+    }
+
+    protected void assertEquals(byte[] expected, InputStream actual)
+            throws IOException {
+        if (actual == null) {
+            fail("Resource stream is null");
+        } else {
+            try {
+                for (byte b : expected) {
+                    assertEquals(b, (byte)actual.read());
+                }
+            } finally {
+                try {
+                    actual.close();
+                } catch (IOException grok) {
+                }
+            }
+        }
+    }
+}

Added: sling/whiteboard/resourceresolverfactory/jcr-resource/src/test/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrNodeResourceTest.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/resourceresolverfactory/jcr-resource/src/test/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrNodeResourceTest.java?rev=1239587&view=auto
==============================================================================
--- sling/whiteboard/resourceresolverfactory/jcr-resource/src/test/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrNodeResourceTest.java (added)
+++ sling/whiteboard/resourceresolverfactory/jcr-resource/src/test/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrNodeResourceTest.java Thu Feb  2 12:46:58 2012
@@ -0,0 +1,260 @@
+/*
+ * 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.jcr.resource.internal.helper.jcr;
+
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+import javax.jcr.Node;
+import javax.jcr.RepositoryException;
+
+import org.apache.jackrabbit.JcrConstants;
+import org.apache.sling.api.resource.Resource;
+import org.apache.sling.api.resource.ResourceMetadata;
+import org.apache.sling.api.resource.ResourceUtil;
+import org.apache.sling.jcr.resource.JcrResourceConstants;
+
+public class JcrNodeResourceTest extends JcrItemResourceTestBase {
+
+    public void testNtFileNtResource() throws Exception {
+
+        String name = "file";
+        Node file = rootNode.addNode(name, JcrConstants.NT_FILE);
+        Node res = file.addNode(JcrConstants.JCR_CONTENT,
+            JcrConstants.NT_RESOURCE);
+        setupResource(res);
+        getSession().save();
+
+        file = rootNode.getNode(name);
+        JcrNodeResource jnr = new JcrNodeResource(null, file, null);
+
+        assertEquals(file.getPath(), jnr.getPath());
+
+        assertResourceMetaData(jnr.getResourceMetadata());
+        assertEquals(TEST_DATA, jnr.adaptTo(InputStream.class));
+    }
+
+    public void testNtFileNtUnstructured() throws Exception {
+
+        String name = "fileunstructured";
+        Node file = rootNode.addNode(name, JcrConstants.NT_FILE);
+        Node res = file.addNode(JcrConstants.JCR_CONTENT,
+            JcrConstants.NT_UNSTRUCTURED);
+        setupResource(res);
+        getSession().save();
+
+        file = rootNode.getNode(name);
+        JcrNodeResource jnr = new JcrNodeResource(null, file, null);
+
+        assertEquals(file.getPath(), jnr.getPath());
+
+        assertResourceMetaData(jnr.getResourceMetadata());
+        assertEquals(TEST_DATA, jnr.adaptTo(InputStream.class));
+    }
+
+    public void testNtResource() throws Exception {
+
+        String name = "resource";
+        Node res = rootNode.addNode(name, JcrConstants.NT_RESOURCE);
+        setupResource(res);
+        getSession().save();
+
+        res = rootNode.getNode(name);
+        JcrNodeResource jnr = new JcrNodeResource(null, res, null);
+
+        assertEquals(res.getPath(), jnr.getPath());
+
+        assertResourceMetaData(jnr.getResourceMetadata());
+        assertEquals(TEST_DATA, jnr.adaptTo(InputStream.class));
+    }
+
+    public void testNtUnstructured() throws Exception {
+
+        String name = "unstructured";
+        Node res = rootNode.addNode(name, JcrConstants.NT_UNSTRUCTURED);
+        setupResource(res);
+        getSession().save();
+
+        res = rootNode.getNode(name);
+        JcrNodeResource jnr = new JcrNodeResource(null, res, null);
+
+        assertEquals(res.getPath(), jnr.getPath());
+
+        assertResourceMetaData(jnr.getResourceMetadata());
+        assertEquals(TEST_DATA, jnr.adaptTo(InputStream.class));
+    }
+
+    public void testResourceType() throws Exception {
+        String name = "resourceType";
+        Node node = rootNode.addNode(name, JcrConstants.NT_UNSTRUCTURED);
+        getSession().save();
+
+        JcrNodeResource jnr = new JcrNodeResource(null, node, null);
+        assertEquals(JcrConstants.NT_UNSTRUCTURED, jnr.getResourceType());
+
+        String typeName = "some/resource/type";
+        node.setProperty(JcrResourceConstants.SLING_RESOURCE_TYPE_PROPERTY, typeName);
+        getSession().save();
+
+        jnr = new JcrNodeResource(null, node, null);
+        assertEquals(typeName, jnr.getResourceType());
+    }
+
+    public void testResourceSuperType() throws Exception {
+        String name = "resourceSuperType";
+        String typeNodeName = "some_resource_type";
+        String typeName = rootPath + "/" + typeNodeName;
+        Node node = rootNode.addNode(name, JcrConstants.NT_UNSTRUCTURED);
+        node.setProperty(JcrResourceConstants.SLING_RESOURCE_TYPE_PROPERTY, typeName);
+        getSession().save();
+
+        Resource jnr = new JcrNodeResource(resourceResolver, node, null);
+        assertEquals(typeName, jnr.getResourceType());
+
+        // default super type is null
+        assertNull(jnr.getResourceSuperType());
+
+        String superTypeName = "supertype";
+        Node typeNode = rootNode.addNode(typeNodeName, JcrConstants.NT_UNSTRUCTURED);
+        typeNode.setProperty(JcrResourceConstants.SLING_RESOURCE_SUPER_TYPE_PROPERTY, superTypeName);
+        getSession().save();
+
+        jnr = new JcrNodeResource(resourceResolver, node, null);
+        assertEquals(typeName, jnr.getResourceType());
+        assertEquals(superTypeName, ResourceUtil.findResourceSuperType(jnr));
+
+        // overwrite super type with direct property
+        String otherSuperTypeName = "othersupertype";
+        node.setProperty(JcrResourceConstants.SLING_RESOURCE_SUPER_TYPE_PROPERTY, otherSuperTypeName);
+        getSession().save();
+
+        jnr = new JcrNodeResource(resourceResolver, node, null);
+        assertEquals(typeName, jnr.getResourceType());
+        assertEquals(otherSuperTypeName, jnr.getResourceSuperType());
+
+        // remove direct property to get supertype again
+        node.getProperty(JcrResourceConstants.SLING_RESOURCE_SUPER_TYPE_PROPERTY).remove();
+        getSession().save();
+
+        jnr = new JcrNodeResource(resourceResolver, node, null);
+        assertEquals(typeName, jnr.getResourceType());
+        assertNull(jnr.getResourceSuperType());
+    }
+
+    public void testAdaptToMap() throws Exception {
+
+        String name = "adaptable";
+        Node res = rootNode.addNode(name, JcrConstants.NT_UNSTRUCTURED);
+        setupResource(res);
+        getSession().save();
+
+        res = rootNode.getNode(name);
+        JcrNodeResource jnr = new JcrNodeResource(null, res, null);
+
+        final Map<?, ?> props = jnr.adaptTo(Map.class);
+
+        // assert we have properties at all, only fails if property
+        // retrieval fails for any reason
+        assertNotNull(props);
+        assertFalse(props.isEmpty());
+
+        // assert all properties set up
+        assertEquals(TEST_MODIFIED, props.get(JcrConstants.JCR_LASTMODIFIED));
+        assertEquals(TEST_TYPE, props.get(JcrConstants.JCR_MIMETYPE));
+        assertEquals(TEST_ENCODING, props.get(JcrConstants.JCR_ENCODING));
+        assertEquals(TEST_DATA, (InputStream) props.get(JcrConstants.JCR_DATA));
+
+        // assert JCR managed properties
+        assertEquals(JcrConstants.NT_UNSTRUCTURED, props.get(JcrConstants.JCR_PRIMARYTYPE));
+
+        // assert we have nothing else left
+        final Set<String> existingKeys = new HashSet<String>();
+        existingKeys.add(JcrConstants.JCR_LASTMODIFIED);
+        existingKeys.add(JcrConstants.JCR_MIMETYPE);
+        existingKeys.add(JcrConstants.JCR_ENCODING);
+        existingKeys.add(JcrConstants.JCR_DATA);
+        existingKeys.add(JcrConstants.JCR_PRIMARYTYPE);
+        final Set<Object> crossCheck = new HashSet<Object>(props.keySet());
+        crossCheck.removeAll(existingKeys);
+        assertTrue(crossCheck.isEmpty());
+
+        // call a second time, ensure the map contains the same data again
+        final Map<?, ?> propsSecond = jnr.adaptTo(Map.class);
+
+        // assert we have properties at all, only fails if property
+        // retrieval fails for any reason
+        assertNotNull(propsSecond);
+        assertFalse(propsSecond.isEmpty());
+
+        // assert all properties set up
+        assertEquals(TEST_MODIFIED, propsSecond.get(JcrConstants.JCR_LASTMODIFIED));
+        assertEquals(TEST_TYPE, propsSecond.get(JcrConstants.JCR_MIMETYPE));
+        assertEquals(TEST_ENCODING, propsSecond.get(JcrConstants.JCR_ENCODING));
+        assertEquals(TEST_DATA, (InputStream) propsSecond.get(JcrConstants.JCR_DATA));
+
+        // assert JCR managed properties
+        assertEquals(JcrConstants.NT_UNSTRUCTURED, propsSecond.get(JcrConstants.JCR_PRIMARYTYPE));
+
+        // assert we have nothing else left
+        final Set<Object> crossCheck2 = new HashSet<Object>(propsSecond.keySet());
+        crossCheck2.removeAll(existingKeys);
+        assertTrue(crossCheck2.isEmpty());
+    }
+
+    public void testCorrectUTF8ByteLength() throws Exception {
+        byte[] utf8bytes = "Übersättigung".getBytes("UTF-8");
+        String name = "utf8file";
+        Node file = rootNode.addNode(name, JcrConstants.NT_FILE);
+        Node res = file.addNode(JcrConstants.JCR_CONTENT,
+            JcrConstants.NT_RESOURCE);
+
+        res.setProperty(JcrConstants.JCR_LASTMODIFIED, TEST_MODIFIED);
+        res.setProperty(JcrConstants.JCR_MIMETYPE, TEST_TYPE);
+        res.setProperty(JcrConstants.JCR_ENCODING, "UTF-8");
+        res.setProperty(JcrConstants.JCR_DATA, new ByteArrayInputStream(utf8bytes));
+
+        getSession().save();
+
+        file = rootNode.getNode(name);
+        JcrNodeResource jnr = new JcrNodeResource(null, file, null);
+
+        assertEquals(utf8bytes, jnr.adaptTo(InputStream.class));
+        assertEquals(utf8bytes.length, jnr.getResourceMetadata().getContentLength());
+    }
+
+
+    private void setupResource(Node res) throws RepositoryException {
+        res.setProperty(JcrConstants.JCR_LASTMODIFIED, TEST_MODIFIED);
+        res.setProperty(JcrConstants.JCR_MIMETYPE, TEST_TYPE);
+        res.setProperty(JcrConstants.JCR_ENCODING, TEST_ENCODING);
+        res.setProperty(JcrConstants.JCR_DATA, new ByteArrayInputStream(
+            TEST_DATA));
+    }
+
+    private void assertResourceMetaData(ResourceMetadata rm) {
+        assertNotNull(rm);
+
+        assertEquals(TEST_MODIFIED, rm.getModificationTime());
+        assertEquals(TEST_TYPE, rm.getContentType());
+        assertEquals(TEST_ENCODING, rm.getCharacterEncoding());
+    }
+}

Added: sling/whiteboard/resourceresolverfactory/jcr-resource/src/test/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrPropertyResourceTest.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/resourceresolverfactory/jcr-resource/src/test/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrPropertyResourceTest.java?rev=1239587&view=auto
==============================================================================
--- sling/whiteboard/resourceresolverfactory/jcr-resource/src/test/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrPropertyResourceTest.java (added)
+++ sling/whiteboard/resourceresolverfactory/jcr-resource/src/test/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrPropertyResourceTest.java Thu Feb  2 12:46:58 2012
@@ -0,0 +1,77 @@
+/*
+ * 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.jcr.resource.internal.helper.jcr;
+
+import static org.junit.Assert.assertEquals;
+
+import java.io.UnsupportedEncodingException;
+import java.util.HashMap;
+import java.util.Map.Entry;
+
+import javax.jcr.Property;
+import javax.jcr.PropertyType;
+import javax.jcr.RepositoryException;
+
+import org.apache.sling.api.resource.ResourceResolver;
+import org.jmock.Expectations;
+import org.jmock.Mockery;
+import org.jmock.integration.junit4.JMock;
+import org.jmock.integration.junit4.JUnit4Mockery;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+/**
+ * JcrPropertyResourceTest ...
+ */
+@RunWith(JMock.class)
+public class JcrPropertyResourceTest {
+
+    protected final Mockery context = new JUnit4Mockery();
+
+    @Test
+    public void testCorrectUTF8ByteLength() throws RepositoryException, UnsupportedEncodingException {
+        final HashMap<Object, Integer> testData = new HashMap<Object, Integer>() {{
+            put("some random ascii string", PropertyType.STRING);
+            put("русский язык", PropertyType.STRING);
+            put("贛語", PropertyType.STRING);
+            put("string with ümlaut", PropertyType.STRING);
+            put(true, PropertyType.BOOLEAN);
+            put(1000L, PropertyType.LONG);
+        }};
+
+        final ResourceResolver resolver = this.context.mock(ResourceResolver.class);
+        for (final Entry<Object, Integer> data : testData.entrySet()) {
+            final String stringValue = data.getKey().toString();
+            final long stringByteLength =  stringValue.getBytes("UTF-8").length;
+            final Property property = this.context.mock(Property.class, stringValue);
+            this.context.checking(new Expectations() {{
+                ignoring(resolver);
+                allowing(property).getParent();
+                allowing(property).getName();
+                allowing(property).isMultiple(); will(returnValue(false));
+                allowing(property).getLength(); will(returnValue((long) stringValue.length()));
+
+                allowing(property).getType(); will(returnValue(data.getValue()));
+                allowing(property).getString(); will(returnValue(stringValue));
+            }});
+            final JcrPropertyResource propResource = new JcrPropertyResource(resolver, "/path/to/string-property", property);
+            assertEquals("Byte length of " +  stringValue, stringByteLength, propResource.getResourceMetadata().getContentLength());
+        }
+    }
+}

Added: sling/whiteboard/resourceresolverfactory/jcr-resource/src/test/java/org/apache/sling/jcr/resource/internal/helper/jcr/MockResourceResolver.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/resourceresolverfactory/jcr-resource/src/test/java/org/apache/sling/jcr/resource/internal/helper/jcr/MockResourceResolver.java?rev=1239587&view=auto
==============================================================================
--- sling/whiteboard/resourceresolverfactory/jcr-resource/src/test/java/org/apache/sling/jcr/resource/internal/helper/jcr/MockResourceResolver.java (added)
+++ sling/whiteboard/resourceresolverfactory/jcr-resource/src/test/java/org/apache/sling/jcr/resource/internal/helper/jcr/MockResourceResolver.java Thu Feb  2 12:46:58 2012
@@ -0,0 +1,128 @@
+/*
+ * 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.jcr.resource.internal.helper.jcr;
+
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.Map;
+
+import javax.jcr.Item;
+import javax.jcr.Node;
+import javax.jcr.Property;
+import javax.jcr.Session;
+import javax.servlet.http.HttpServletRequest;
+
+import org.apache.sling.api.resource.Resource;
+import org.apache.sling.api.resource.ResourceResolver;
+
+public class MockResourceResolver implements ResourceResolver {
+
+    private final Session session;
+
+    MockResourceResolver(Session session) {
+        this.session = session;
+    }
+
+    public ResourceResolver clone(Map<String, Object> authenticationInfo) {
+        throw new UnsupportedOperationException("copy");
+    }
+
+    public Iterator<Resource> findResources(String query, String language) {
+        return null;
+    }
+
+    public Resource getResource(String path) {
+        // assume path is absolute for testing purposes
+        try {
+            Item item = session.getItem(path);
+
+            if (item.isNode()) {
+                return new JcrNodeResource(this, (Node) item, null);
+            }
+
+            return new JcrPropertyResource(this, path, (Property) item);
+        } catch (Exception e) {
+            // don't care
+        }
+
+        return null;
+    }
+
+    public Resource getResource(Resource base, String path) {
+        return getResource(base.getPath() + "/" + path);
+    }
+
+    public String[] getSearchPath() {
+        return new String[0];
+    }
+
+    public Iterator<Resource> listChildren(Resource parent) {
+        return null;
+    }
+
+    public String map(String resourcePath) {
+        return null;
+    }
+
+    public String map(HttpServletRequest request, String resourcePath) {
+        return null;
+    }
+
+    public Iterator<Map<String, Object>> queryResources(String query,
+            String language) {
+        return null;
+    }
+
+    public Resource resolve(HttpServletRequest request, String absPath) {
+        return null;
+    }
+
+    public Resource resolve(HttpServletRequest request) {
+        return null;
+    }
+
+    public Resource resolve(String absPath) {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    public <AdapterType> AdapterType adaptTo(Class<AdapterType> type) {
+        return null;
+    }
+
+    public boolean isLive() {
+        return session.isLive();
+    }
+
+    public void close() {
+        // nothing to do
+    }
+
+    public String getUserID() {
+        return session.getUserID();
+    }
+
+    public Object getAttribute(String name) {
+        return null;
+    }
+
+    public Iterator<String> getAttributeNames() {
+        return Collections.<String> emptyList().iterator();
+    }
+}

Added: sling/whiteboard/resourceresolverfactory/jcr-resource/src/test/java/org/apache/sling/jcr/resource/internal/helper/starresource/StarResourceTest.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/resourceresolverfactory/jcr-resource/src/test/java/org/apache/sling/jcr/resource/internal/helper/starresource/StarResourceTest.java?rev=1239587&view=auto
==============================================================================
--- sling/whiteboard/resourceresolverfactory/jcr-resource/src/test/java/org/apache/sling/jcr/resource/internal/helper/starresource/StarResourceTest.java (added)
+++ sling/whiteboard/resourceresolverfactory/jcr-resource/src/test/java/org/apache/sling/jcr/resource/internal/helper/starresource/StarResourceTest.java Thu Feb  2 12:46:58 2012
@@ -0,0 +1,48 @@
+/*
+ * 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.jcr.resource.internal.helper.starresource;
+
+import junit.framework.TestCase;
+
+import org.apache.sling.api.resource.ResourceMetadata;
+
+/** Test the StarResource */
+public class StarResourceTest extends TestCase {
+	private void assertSplit(String requestPath, String path, String pathInfo) {
+		final ResourceMetadata rm = StarResource.getResourceMetadata(requestPath);
+		assertEquals("For requestPath=" + requestPath + ", path matches", path, rm.getResolutionPath());
+		assertEquals("For requestPath=" + requestPath + ", pathInfo matches", pathInfo, rm.getResolutionPathInfo());
+	}
+	
+	public void testSimplePath() {
+		assertSplit("/foo/*.html", "/foo/*", ".html");
+	}
+	
+	public void testNoExtension() {
+		assertSplit("/foo/*", "/foo/*", "");
+	}
+	
+	public void testNoStar() {
+		assertSplit("/foo/bar.html", "/foo/bar.html", null);
+	}
+	
+	public void testTwoStars() {
+		assertSplit("/foo/*.html/*.txt", "/foo/*", ".html/*.txt");
+	}
+}



Mime
View raw message