incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r1565585 - in /sling/trunk/contrib/extensions/resourcemerger: pom.xml src/test/java/org/apache/sling/resourcemerger/impl/MergedResourceProviderTest.java
Date Fri, 07 Feb 2014 08:53:58 GMT
Author: cziegeler
Date: Fri Feb  7 08:53:57 2014
New Revision: 1565585

URL: http://svn.apache.org/r1565585
Log:
Use new resource resolver mock testing lib

Modified:
    sling/trunk/contrib/extensions/resourcemerger/pom.xml
    sling/trunk/contrib/extensions/resourcemerger/src/test/java/org/apache/sling/resourcemerger/impl/MergedResourceProviderTest.java

Modified: sling/trunk/contrib/extensions/resourcemerger/pom.xml
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/resourcemerger/pom.xml?rev=1565585&r1=1565584&r2=1565585&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/resourcemerger/pom.xml (original)
+++ sling/trunk/contrib/extensions/resourcemerger/pom.xml Fri Feb  7 08:53:57 2014
@@ -91,7 +91,7 @@
         <dependency>
             <groupId>org.apache.sling</groupId>
             <artifactId>org.apache.sling.testing.resourceresolver-mock</artifactId>
-            <version>0.1.0</version>
+            <version>0.2.0</version>
             <scope>test</scope>
         </dependency>
     </dependencies>

Modified: sling/trunk/contrib/extensions/resourcemerger/src/test/java/org/apache/sling/resourcemerger/impl/MergedResourceProviderTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/resourcemerger/src/test/java/org/apache/sling/resourcemerger/impl/MergedResourceProviderTest.java?rev=1565585&r1=1565584&r2=1565585&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/resourcemerger/src/test/java/org/apache/sling/resourcemerger/impl/MergedResourceProviderTest.java
(original)
+++ sling/trunk/contrib/extensions/resourcemerger/src/test/java/org/apache/sling/resourcemerger/impl/MergedResourceProviderTest.java
Fri Feb  7 08:53:57 2014
@@ -23,19 +23,14 @@ import static org.junit.Assert.assertNot
 import static org.junit.Assert.assertTrue;
 
 import java.util.ArrayList;
-import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;
-import java.util.Map;
 
-import javax.servlet.http.HttpServletRequest;
-
-import org.apache.sling.api.resource.LoginException;
-import org.apache.sling.api.resource.PersistenceException;
 import org.apache.sling.api.resource.Resource;
 import org.apache.sling.api.resource.ResourceResolver;
 import org.apache.sling.api.resource.ResourceResolverFactory;
 import org.apache.sling.api.resource.ValueMap;
+import org.apache.sling.testing.resourceresolver.MockHelper;
 import org.apache.sling.testing.resourceresolver.MockResourceResolverFactory;
 import org.junit.Before;
 import org.junit.Test;
@@ -48,22 +43,18 @@ public class MergedResourceProviderTest 
 
     @Before public void setup() throws Exception {
         final ResourceResolverFactory factory = new MockResourceResolverFactory();
-        this.resolver = new ResourceResolverWrapper(factory.getAdministrativeResourceResolver(null));
-        final Resource root = this.resolver.getResource("/");
-        final Resource apps = this.resolver.create(root, "apps", null);
-        final Resource libs = this.resolver.create(root, "libs", null);
-
-        final Resource appsA = this.resolver.create(apps, "a", null);
-        final Resource libsA = this.resolver.create(libs, "a", null);
-
-        this.resolver.create(appsA, "1", new map().p("a", "1").p("b", "2"));
-        this.resolver.create(libsA, "1", new map().p("a", "5").p("c", "2"));
-        this.resolver.create(appsA, "2", new map().p(ResourceResolver.PROPERTY_RESOURCE_TYPE,
"apps"));
-        this.resolver.create(libsA, "2", new map().p(ResourceResolver.PROPERTY_RESOURCE_TYPE,
"libs"));
-        this.resolver.create(appsA, "X", null);
-        this.resolver.create(libsA, "Y", null);
-
-        this.resolver.commit();
+        this.resolver = factory.getAdministrativeResourceResolver(null);
+        MockHelper.create(this.resolver).resource("/apps")
+                                          .resource("a")
+                                            .resource("1").p("a", "1").p("b", "2")
+                                            .resource("./2").p(ResourceResolver.PROPERTY_RESOURCE_TYPE,
"apps")
+                                            .resource("./X")
+                                        .resource("/libs")
+                                          .resource("a")
+                                            .resource("1").p("a", "5").p("c", "2")
+                                            .resource("./2").p(ResourceResolver.PROPERTY_RESOURCE_TYPE,
"libs")
+                                            .resource("./Y")
+                                        .commit();
 
         this.provider = new MergedResourceProvider("/merged");
     }
@@ -104,147 +95,4 @@ public class MergedResourceProviderTest 
         assertEquals("a/1", rsrcA1.getResourceType());
 
     }
-
-    protected static final class map extends HashMap<String, Object> {
-
-        private static final long serialVersionUID = 1L;
-
-        public map p(final String name, final String value) {
-            this.put(name, value);
-            return this;
-        }
-    }
-
-    /**
-     *  We have to use a wrapper until Sling testing resource resolver mock 0.2.0 is out
-     *  Fixing SLING-3354
-     */
-    public static class ResourceResolverWrapper implements ResourceResolver {
-
-        private final ResourceResolver resolver;
-
-        public ResourceResolverWrapper(final ResourceResolver r) {
-            this.resolver = r;
-        }
-
-        public <AdapterType> AdapterType adaptTo(Class<AdapterType> type) {
-            return resolver.adaptTo(type);
-        }
-
-        public Resource resolve(HttpServletRequest request, String absPath) {
-            return resolver.resolve(request, absPath);
-        }
-
-        public Resource resolve(String absPath) {
-            return resolver.resolve(absPath);
-        }
-
-        public Resource resolve(HttpServletRequest request) {
-            return resolver.resolve(request);
-        }
-
-        public String map(String resourcePath) {
-            return resolver.map(resourcePath);
-        }
-
-        public String map(HttpServletRequest request, String resourcePath) {
-            return resolver.map(request, resourcePath);
-        }
-
-        public Resource getResource(String path) {
-            return resolver.getResource(path);
-        }
-
-        public Resource getResource(Resource base, String path) {
-            return resolver.getResource(base, path);
-        }
-
-        public String[] getSearchPath() {
-            return new String[] {"/apps", "/libs"};
-        }
-
-        public Iterator<Resource> listChildren(Resource parent) {
-            return resolver.listChildren(parent);
-        }
-
-        public Iterable<Resource> getChildren(Resource parent) {
-            return resolver.getChildren(parent);
-        }
-
-        public Iterator<Resource> findResources(String query, String language) {
-            return resolver.findResources(query, language);
-        }
-
-        public Iterator<Map<String, Object>> queryResources(String query,
-                String language) {
-            return resolver.queryResources(query, language);
-        }
-
-        public boolean hasChildren(Resource resource) {
-            return resolver.hasChildren(resource);
-        }
-
-        public ResourceResolver clone(Map<String, Object> authenticationInfo)
-                throws LoginException {
-            return resolver.clone(authenticationInfo);
-        }
-
-        public boolean isLive() {
-            return resolver.isLive();
-        }
-
-        public void close() {
-            resolver.close();
-        }
-
-        public String getUserID() {
-            return resolver.getUserID();
-        }
-
-        public Iterator<String> getAttributeNames() {
-            return resolver.getAttributeNames();
-        }
-
-        public Object getAttribute(String name) {
-            return resolver.getAttribute(name);
-        }
-
-        public void delete(Resource resource) throws PersistenceException {
-            resolver.delete(resource);
-        }
-
-        public Resource create(Resource parent, String name,
-                Map<String, Object> properties) throws PersistenceException {
-            return resolver.create(parent, name, properties);
-        }
-
-        public void revert() {
-            resolver.revert();
-        }
-
-        public void commit() throws PersistenceException {
-            resolver.commit();
-        }
-
-        public boolean hasChanges() {
-            return resolver.hasChanges();
-        }
-
-        public String getParentResourceType(Resource resource) {
-            return resolver.getParentResourceType(resource);
-        }
-
-        public String getParentResourceType(String resourceType) {
-            return resolver.getParentResourceType(resourceType);
-        }
-
-        public boolean isResourceType(Resource resource, String resourceType) {
-            return resolver.isResourceType(resource, resourceType);
-        }
-
-        public void refresh() {
-            resolver.refresh();
-        }
-
-    }
 }



Mime
View raw message