You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by cz...@apache.org on 2012/06/14 11:52:09 UTC
svn commit: r1350169 [5/5] - in /sling/trunk/bundles/resourceresolver/src:
main/java/org/apache/sling/resourceresolver/impl/
main/java/org/apache/sling/resourceresolver/impl/console/
main/java/org/apache/sling/resourceresolver/impl/helper/ main/java/or...
Added: sling/trunk/bundles/resourceresolver/src/test/java/org/apache/sling/resourceresolver/impl/mapping/MapEntryTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/resourceresolver/src/test/java/org/apache/sling/resourceresolver/impl/mapping/MapEntryTest.java?rev=1350169&view=auto
==============================================================================
--- sling/trunk/bundles/resourceresolver/src/test/java/org/apache/sling/resourceresolver/impl/mapping/MapEntryTest.java (added)
+++ sling/trunk/bundles/resourceresolver/src/test/java/org/apache/sling/resourceresolver/impl/mapping/MapEntryTest.java Thu Jun 14 09:52:08 2012
@@ -0,0 +1,174 @@
+/*
+ * 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.resourceresolver.impl.mapping;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.fail;
+
+import java.lang.reflect.Method;
+import java.net.URI;
+
+import junit.framework.TestCase;
+
+import org.apache.sling.resourceresolver.impl.mapping.MapEntry;
+import org.junit.Test;
+
+public class MapEntryTest {
+
+ @Test 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");
+ }
+
+ @Test 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");
+ }
+
+ @Test 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");
+ }
+
+ @Test 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");
+ }
+
+ @Test 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");
+
+ }
+
+ @Test public void test_isRegExp() {
+ TestCase.assertFalse(isRegExp("http/www.example.com.8080/bla"));
+ TestCase.assertTrue(isRegExp("http/.+\\.www.example.com.8080/bla"));
+ TestCase.assertTrue(isRegExp("http/(.+)\\.www.example.com.8080/bla"));
+ TestCase.assertTrue(isRegExp("http/(.+)\\.www.example.com.8080/bla"));
+ TestCase.assertTrue(isRegExp("http/[^.]+.www.example.com.8080/bla"));
+ }
+
+ 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);
+ }
+
+ private boolean isRegExp(final String string) {
+ try {
+ Method m = MapEntry.class.getDeclaredMethod("isRegExp", String.class);
+ m.setAccessible(true);
+ return (Boolean) m.invoke(null, string);
+ } catch (Exception e) {
+ fail(e.toString());
+ return false; // quiesc compiler
+ }
+ }
+}
Propchange: sling/trunk/bundles/resourceresolver/src/test/java/org/apache/sling/resourceresolver/impl/mapping/MapEntryTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: sling/trunk/bundles/resourceresolver/src/test/java/org/apache/sling/resourceresolver/impl/mapping/MapEntryTest.java
------------------------------------------------------------------------------
svn:keywords = author date id revision rev url
Added: sling/trunk/bundles/resourceresolver/src/test/java/org/apache/sling/resourceresolver/impl/tree/ProviderHandlerTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/resourceresolver/src/test/java/org/apache/sling/resourceresolver/impl/tree/ProviderHandlerTest.java?rev=1350169&view=auto
==============================================================================
--- sling/trunk/bundles/resourceresolver/src/test/java/org/apache/sling/resourceresolver/impl/tree/ProviderHandlerTest.java (added)
+++ sling/trunk/bundles/resourceresolver/src/test/java/org/apache/sling/resourceresolver/impl/tree/ProviderHandlerTest.java Thu Jun 14 09:52:08 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.resourceresolver.impl.tree;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
+import org.apache.sling.api.resource.Resource;
+import org.apache.sling.api.resource.ResourceProvider;
+import org.apache.sling.api.resource.ResourceResolver;
+import org.apache.sling.resourceresolver.impl.helper.ResourceResolverContext;
+import org.junit.Test;
+import org.osgi.framework.Constants;
+
+public class ProviderHandlerTest {
+
+ @Test public void testRoots() {
+ // service id = 1, no roots
+ final Map<String, Object> props1 = new HashMap<String, Object>();
+ props1.put(Constants.SERVICE_ID, 1L);
+ final ProviderHandler ph1 = new MyProviderHandler(props1);
+ assertNull(ph1.getRoots());
+ assertEquals(1, (long)ph1.getServiceId());
+
+ // service id = 2, empty roots
+ final Map<String, Object> props2 = new HashMap<String, Object>();
+ props2.put(Constants.SERVICE_ID, 2L);
+ props2.put(ResourceProvider.ROOTS, new String[0]);
+ final ProviderHandler ph2 = new MyProviderHandler(props2);
+ assertNull(ph2.getRoots());
+ assertEquals(2, (long)ph2.getServiceId());
+
+ // service id = 3, empty string
+ final Map<String, Object> props3 = new HashMap<String, Object>();
+ props3.put(Constants.SERVICE_ID, 3L);
+ props3.put(ResourceProvider.ROOTS, new String[] {""});
+ final ProviderHandler ph3 = new MyProviderHandler(props3);
+ assertNull(ph3.getRoots());
+ assertEquals(3, (long)ph3.getServiceId());
+
+ // service id = 4, empty string and real string mixed
+ final Map<String, Object> props4 = new HashMap<String, Object>();
+ props4.put(Constants.SERVICE_ID, 4L);
+ props4.put(ResourceProvider.ROOTS, new String[] {"", "/a", " ", "/a", "/b", "/c ", " /d ", ""});
+ final ProviderHandler ph4 = new MyProviderHandler(props4);
+ assertNotNull(ph4.getRoots());
+ assertEquals(4, (long)ph4.getServiceId());
+ assertEquals(new String[] {"/a", "/b", "/c", "/d"}, ph4.getRoots());
+
+ // service id = 5, trailing slash string
+ final Map<String, Object> props5 = new HashMap<String, Object>();
+ props5.put(Constants.SERVICE_ID, 5L);
+ props5.put(ResourceProvider.ROOTS, new String[] {"", " /", "/b/ ", " /c/", " /d/ ", ""});
+ final ProviderHandler ph5 = new MyProviderHandler(props5);
+ assertNotNull(ph5.getRoots());
+ assertEquals(5, (long)ph5.getServiceId());
+ assertEquals(new String[] {"/", "/b", "/c", "/d"}, ph5.getRoots());
+ }
+
+ private static final class MyProviderHandler extends ProviderHandler {
+
+ public MyProviderHandler(Map<String, Object> properties) {
+ super(properties);
+ }
+
+ @Override
+ public Resource getResource(ResourceResolverContext ctx, ResourceResolver resourceResolver, String path) {
+ return null;
+ }
+
+ @Override
+ public Iterator<Resource> listChildren(ResourceResolverContext ctx, Resource parent) { // TODO Auto-generated method stub
+ return null;
+ }
+
+ }
+}
Propchange: sling/trunk/bundles/resourceresolver/src/test/java/org/apache/sling/resourceresolver/impl/tree/ProviderHandlerTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: sling/trunk/bundles/resourceresolver/src/test/java/org/apache/sling/resourceresolver/impl/tree/ProviderHandlerTest.java
------------------------------------------------------------------------------
svn:keywords = author date id revision rev url
Added: sling/trunk/bundles/resourceresolver/src/test/java/org/apache/sling/resourceresolver/impl/tree/ResourceProviderEntryTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/resourceresolver/src/test/java/org/apache/sling/resourceresolver/impl/tree/ResourceProviderEntryTest.java?rev=1350169&view=auto
==============================================================================
--- sling/trunk/bundles/resourceresolver/src/test/java/org/apache/sling/resourceresolver/impl/tree/ResourceProviderEntryTest.java (added)
+++ sling/trunk/bundles/resourceresolver/src/test/java/org/apache/sling/resourceresolver/impl/tree/ResourceProviderEntryTest.java Thu Jun 14 09:52:08 2012
@@ -0,0 +1,341 @@
+/*
+ * 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.resourceresolver.impl.tree;
+
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.fail;
+
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
+import javax.servlet.http.HttpServletRequest;
+
+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;
+import org.apache.sling.resourceresolver.impl.tree.ProviderHandler;
+import org.apache.sling.resourceresolver.impl.tree.ResourceProviderEntry;
+import org.apache.sling.resourceresolver.impl.tree.ResourceProviderHandler;
+import org.junit.Before;
+import org.junit.Test;
+import org.osgi.framework.Constants;
+
+public class ResourceProviderEntryTest {
+
+ private ResourceProvider rootProvider;
+
+ private ResourceProviderEntry root;
+
+ @Before public void setUp() throws Exception {
+ rootProvider = new TestResourceProvider("/");
+ final Map<String, Object> props = new HashMap<String, Object>();
+ props.put(Constants.SERVICE_ID, (long)0);
+ root = new ResourceProviderEntry("/", new ResourceProviderHandler[]{ new ResourceProviderHandler(rootProvider, props)});
+ }
+
+ @Test public void testRootProvider() {
+ assertNull(root.getResource(null, null, "relpath"));
+ assertEquals(root, root.getResource(null, null, "/"));
+ assertEquals(root, root.getResource(null, null, "/rootel"));
+ assertEquals(root, root.getResource(null, null, "/rootel/child"));
+ assertEquals(root, root.getResource(null, null, "/apps/sling/sample/html.js"));
+ assertEquals(root, root.getResource(null, null,
+ "/apps/sling/microsling/html.js"));
+ }
+
+ @Test public void testAdd1Provider() {
+ String firstPath = "/rootel";
+ ResourceProvider first = new TestResourceProvider(firstPath);
+ final Map<String, Object> firstProps = new HashMap<String, Object>();
+ firstProps.put(Constants.SERVICE_ID, (long)1);
+ root.addResourceProvider(firstPath, new ResourceProviderHandler(first, firstProps));
+
+
+ assertEquals(root, root.getResource(null, null, "/"));
+ assertEquals(first, root.getResource(null, null, "/rootel"));
+ assertEquals(first, root.getResource(null, null, "/rootel/html.js"));
+ assertEquals(first, root.getResource(null, null, "/rootel/child"));
+ assertEquals(first, root.getResource(null, null, "/rootel/child/html.js"));
+ assertEquals(rootProvider, root.getResource(null, null,
+ "/apps/sling/sample/html.js"));
+ assertEquals(rootProvider, root.getResource(null, null,
+ "/apps/sling/microsling/html.js"));
+ }
+
+ @Test 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);
+ final Map<String, Object> firstProps = new HashMap<String, Object>();
+ firstProps.put(Constants.SERVICE_ID, (long)1);
+ final Map<String, Object> secondProps = new HashMap<String, Object>();
+ secondProps.put(Constants.SERVICE_ID, (long)2);
+ final Map<String, Object> thirdProps = new HashMap<String, Object>();
+ thirdProps.put(Constants.SERVICE_ID, (long)3);
+
+ root.addResourceProvider(firstPath, new ResourceProviderHandler(first, firstProps));
+ root.addResourceProvider(secondPath, new ResourceProviderHandler(second, secondProps));
+ root.addResourceProvider(thirdPath, new ResourceProviderHandler(third, thirdProps));
+
+
+ assertEquals(rootProvider, root.getResource(null, null, "/"));
+ assertEquals(first, root.getResource(null, null, "/rootel"));
+ assertEquals(first, root.getResource(null, null, "/rootel/html.js"));
+ assertEquals(second, root.getResource(null, null, "/rootel/child"));
+ assertEquals(second, root.getResource(null, null, "/rootel/child/html.js"));
+ assertEquals(third,
+ root.getResource(null, null, "/apps/sling/sample/html.js"));
+ Resource resource = root.getResource(null, null,
+ "/apps/sling/microsling/html.js");
+ assertEquals(rootProvider, resource);
+ }
+
+ @Test 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);
+ final Map<String, Object> firstProps = new HashMap<String, Object>();
+ firstProps.put(Constants.SERVICE_ID, (long)1);
+ final Map<String, Object> secondProps = new HashMap<String, Object>();
+ secondProps.put(Constants.SERVICE_ID, (long)2);
+ final Map<String, Object> thirdProps = new HashMap<String, Object>();
+ thirdProps.put(Constants.SERVICE_ID, (long)3);
+
+ root.addResourceProvider(firstPath, new ResourceProviderHandler(first, firstProps));
+ root.addResourceProvider(secondPath, new ResourceProviderHandler(second, secondProps));
+ root.addResourceProvider(thirdPath, new ResourceProviderHandler(third, thirdProps));
+
+ assertEquals(rootProvider, root.getResource(null, null, "/"));
+ assertEquals(first, root.getResource(null, null, "/rootel"));
+ assertEquals(first, root.getResource(null, null, "/rootel/html.js"));
+ assertEquals(second, root.getResource(null, null, "/rootel/child"));
+ assertEquals(second, root.getResource(null, null, "/rootel/child/html.js"));
+ assertEquals(third,
+ root.getResource(null, null, "/apps/sling/sample/html.js"));
+ Resource resource = root.getResource(null, null,
+ "/apps/sling/microsling/html.js");
+ assertEquals(rootProvider, resource);
+ }
+
+ @Test 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);
+ final Map<String, Object> firstProps = new HashMap<String, Object>();
+ firstProps.put(Constants.SERVICE_ID, (long)1);
+ final Map<String, Object> secondProps = new HashMap<String, Object>();
+ secondProps.put(Constants.SERVICE_ID, (long)2);
+ final Map<String, Object> thirdProps = new HashMap<String, Object>();
+ thirdProps.put(Constants.SERVICE_ID, (long)3);
+
+ root.addResourceProvider(firstPath, new ResourceProviderHandler(first, firstProps));
+ root.addResourceProvider(secondPath, new ResourceProviderHandler(second, secondProps));
+ root.addResourceProvider(thirdPath, new ResourceProviderHandler(third, thirdProps));
+
+ assertEquals(rootProvider, root.getResource(null, null, "/"));
+ assertEquals(first, root.getResource(null, null, "/rootel/html.js"));
+ assertEquals(second, root.getResource(null, null, "/rootel/child/html.js"));
+
+ root.removeResourceProvider(firstPath, new ResourceProviderHandler(first, firstProps));
+
+ assertEquals(rootProvider, root.getResource(null, null, "/"));
+ assertEquals(rootProvider, root.getResource(null, null, "/rootel/sddsf/sdfsdf/html.js"));
+ assertEquals(rootProvider, root.getResource(null, null, "/rootel/html.js"));
+ assertEquals(second, root.getResource(null, null, "/rootel/child/html.js"));
+
+ root.addResourceProvider(firstPath, new ResourceProviderHandler(first, firstProps));
+
+ assertEquals(rootProvider, root.getResource(null, null, "/"));
+ assertEquals(first, root.getResource(null, null, "/rootel/html.js"));
+ assertEquals(second, root.getResource(null, null, "/rootel/child/html.js"));
+ }
+
+ protected void assertEquals(ResourceProvider resProvider, Resource res) {
+ org.junit.Assert.assertEquals(resProvider, res.getResourceResolver());
+ }
+
+ protected void assertEquals(ResourceProviderEntry resProviderEntry,
+ Resource res) {
+ ProviderHandler[] resourceProviders = resProviderEntry.getResourceProviders();
+ for ( ProviderHandler 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;
+ }
+ }
+}
Propchange: sling/trunk/bundles/resourceresolver/src/test/java/org/apache/sling/resourceresolver/impl/tree/ResourceProviderEntryTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: sling/trunk/bundles/resourceresolver/src/test/java/org/apache/sling/resourceresolver/impl/tree/ResourceProviderEntryTest.java
------------------------------------------------------------------------------
svn:keywords = author date id revision rev url