incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r1479668 - in /sling/trunk/contrib/extensions/collection: pom.xml src/test/java/org/apache/sling/resource/collection/impl/ResourceCollectionImplTest.java src/test/java/org/apache/sling/resource/collection/test/
Date Mon, 06 May 2013 18:35:44 GMT
Author: cziegeler
Date: Mon May  6 18:35:43 2013
New Revision: 1479668

URL: http://svn.apache.org/r1479668
Log:
SLING-2853 :  Add ResourceCollection to Sling  - use resource resolver mock

Removed:
    sling/trunk/contrib/extensions/collection/src/test/java/org/apache/sling/resource/collection/test/
Modified:
    sling/trunk/contrib/extensions/collection/pom.xml
    sling/trunk/contrib/extensions/collection/src/test/java/org/apache/sling/resource/collection/impl/ResourceCollectionImplTest.java

Modified: sling/trunk/contrib/extensions/collection/pom.xml
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/collection/pom.xml?rev=1479668&r1=1479667&r2=1479668&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/collection/pom.xml (original)
+++ sling/trunk/contrib/extensions/collection/pom.xml Mon May  6 18:35:43 2013
@@ -143,5 +143,11 @@
             <artifactId>servlet-api</artifactId>
             <scope>test</scope>
         </dependency>
+         <dependency>
+            <groupId>org.apache.sling</groupId>
+            <artifactId>org.apache.sling.testing.resourceresolver-mock</artifactId>
+            <version>0.1.0</version>
+            <scope>test</scope>
+        </dependency>
     </dependencies>
 </project>

Modified: sling/trunk/contrib/extensions/collection/src/test/java/org/apache/sling/resource/collection/impl/ResourceCollectionImplTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/collection/src/test/java/org/apache/sling/resource/collection/impl/ResourceCollectionImplTest.java?rev=1479668&r1=1479667&r2=1479668&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/collection/src/test/java/org/apache/sling/resource/collection/impl/ResourceCollectionImplTest.java
(original)
+++ sling/trunk/contrib/extensions/collection/src/test/java/org/apache/sling/resource/collection/impl/ResourceCollectionImplTest.java
Mon May  6 18:35:43 2013
@@ -18,6 +18,7 @@
  */
 package org.apache.sling.resource.collection.impl;
 
+import java.util.Collections;
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.Map;
@@ -30,8 +31,7 @@ import org.apache.sling.api.resource.Val
 import org.apache.sling.jcr.resource.JcrResourceConstants;
 import org.apache.sling.resource.collection.ResourceCollection;
 import org.apache.sling.resource.collection.ResourceCollectionManager;
-import org.apache.sling.resource.collection.test.MockResource;
-import org.apache.sling.resource.collection.test.MockResourceResolver;
+import org.apache.sling.testing.resourceresolver.MockResourceResolverFactory;
 import org.junit.Before;
 import org.junit.Test;
 
@@ -41,151 +41,165 @@ public class ResourceCollectionImplTest 
 
 	@Before
 	public void setUp() throws Exception {
-		resResolver = new MockResourceResolver();
+		resResolver = new MockResourceResolverFactory().getAdministrativeResourceResolver(null);
 		rcm = new ResourceCollectionManagerImpl(resResolver);
-		// need a root resource
-		new MockResource(resResolver, "/", "type");
 	}
-	
+
 	@Test
 	public void testAddResource() throws Exception {
-		        
+
         final ResourceCollection collection = rcm.createCollection(resResolver.getResource("/"),
"test1");
-        collection.add(new MockResource(resResolver, "/res1", "type"));
-        final Resource resource = new MockResource(resResolver, "/res2", "type");
+        final Resource res1 = resResolver.create(resResolver.getResource("/"), "res1",
+                Collections.singletonMap(ResourceResolver.PROPERTY_RESOURCE_TYPE, (Object)"type"));
+        collection.add(res1);
+        final Resource resource = resResolver.create(resResolver.getResource("/"), "res2",
+                Collections.singletonMap(ResourceResolver.PROPERTY_RESOURCE_TYPE, (Object)"type"));
         collection.add(resource);
-        
+
         Assert.assertEquals(true, collection.contains(resource));
         Assert.assertEquals(true, collection.contains(resource));
         Assert.assertNotNull(resResolver.getResource("/test1"));
         Assert.assertEquals(ResourceCollection.RESOURCE_TYPE, resResolver.getResource("/test1").getResourceType());
 	}
-	
+
 	@Test
 	public void testCreateCollection() throws Exception {
         final ResourceCollection collection = rcm.createCollection(resResolver.getResource("/"),
"test1");
-        collection.add(new MockResource(resResolver, "/res1", "type"), null);
-        final Resource resource = new MockResource(resResolver, "/res2", "type");
+        final Resource res1 = resResolver.create(resResolver.getResource("/"), "res1",
+                Collections.singletonMap(ResourceResolver.PROPERTY_RESOURCE_TYPE, (Object)"type"));
+        collection.add(res1, null);
+        final Resource resource = resResolver.create(resResolver.getResource("/"), "res2",
+                Collections.singletonMap(ResourceResolver.PROPERTY_RESOURCE_TYPE, (Object)"type"));
         collection.add(resource, null);
-        
+
         Assert.assertEquals(true, collection.contains(resource));
         Assert.assertNotNull(resResolver.getResource("/test1"));
         Assert.assertEquals(ResourceCollection.RESOURCE_TYPE, resResolver.getResource("/test1").getResourceType());
 	}
-	
+
 	@Test
 	public void testGetCollection() throws Exception {
         ResourceCollection collection = rcm.createCollection(resResolver.getResource("/"),
"test1");
-        collection.add(new MockResource(resResolver, "/res1", "type"), null);
-        final Resource resource = new MockResource(resResolver, "/res2", "type");
+        final Resource res1 = resResolver.create(resResolver.getResource("/"), "res1",
+                Collections.singletonMap(ResourceResolver.PROPERTY_RESOURCE_TYPE, (Object)"type"));
+        collection.add(res1, null);
+        final Resource resource = resResolver.create(resResolver.getResource("/"), "res2",
+                Collections.singletonMap(ResourceResolver.PROPERTY_RESOURCE_TYPE, (Object)"type"));
         collection.add(resource, null);
-        
+
         collection = rcm.getCollection(resResolver.getResource(collection.getPath()));
-        
+
         Assert.assertEquals(true, collection.contains(resource));
         Assert.assertNotNull(resResolver.getResource("/test1"));
         Assert.assertEquals(ResourceCollection.RESOURCE_TYPE, resResolver.getResource("/test1").getResourceType());
 	}
-	
+
 	@Test
 	public void testListCollection() throws Exception {
         final ResourceCollection collection = rcm.createCollection(resResolver.getResource("/"),
"collection1");
-        collection.add(new MockResource(resResolver, "/res1", "type"), null);
-        final Resource resource = new MockResource(resResolver, "/res2", "type");
-        
+        final Resource res1 = resResolver.create(resResolver.getResource("/"), "res1",
+                Collections.singletonMap(ResourceResolver.PROPERTY_RESOURCE_TYPE, (Object)"type"));
+        collection.add(res1, null);
+        final Resource resource = resResolver.create(resResolver.getResource("/"), "res2",
+                Collections.singletonMap(ResourceResolver.PROPERTY_RESOURCE_TYPE, (Object)"type"));
+
         collection.add(resource, null);
         Assert.assertEquals(true, collection.contains(resource));
-        
+
         final Iterator<Resource> resources = collection.getResources();
         int numOfRes = 0;
         while (resources.hasNext()) {
         	resources.next();
         	numOfRes ++;
         }
-        
+
         Assert.assertEquals(2, numOfRes);
 	}
-	
+
 	@Test
 	public void testCreateCollectionWithProperties() throws Exception {
 		final Map<String, Object> props = new HashMap<String, Object>();
 		props.put(JcrResourceConstants.SLING_RESOURCE_TYPE_PROPERTY, "some/type");
 		props.put("creator", "slingdev");
-        
+
         final ResourceCollection collection = rcm.createCollection(resResolver.getResource("/"),
"collection3", props);
-        final Resource resource = new MockResource(resResolver, "/res1", "type");
+        final Resource resource = resResolver.create(resResolver.getResource("/"), "res1",
+                Collections.singletonMap(ResourceResolver.PROPERTY_RESOURCE_TYPE, (Object)"type"));
         collection.add(resource, null);
-        
+
         final Resource collectionRes = resResolver.getResource("/collection3");
         Assert.assertNotNull(collectionRes);
-        
+
         Assert.assertEquals(true, collection.contains(resource));
         Assert.assertEquals(ResourceCollection.RESOURCE_TYPE, collectionRes.getResourceSuperType());
-        
+
         ValueMap vm = collectionRes.adaptTo(ValueMap.class);
-        
+
         Assert.assertEquals("slingdev", vm.get("creator", ""));
 	}
-	
+
 	@Test
 	public void testAddResourceWithProperties() throws Exception {
 		final Map<String, Object> props = new HashMap<String, Object>();
 		props.put("creator", "slingdev");
-        
+
         final ResourceCollection collection = rcm.createCollection(resResolver.getResource("/"),
"collection3");
-        
-        final Resource resource = new MockResource(resResolver, "/res1", "type");
+
+        final Resource resource = resResolver.create(resResolver.getResource("/"), "res1",
+                Collections.singletonMap(ResourceResolver.PROPERTY_RESOURCE_TYPE, (Object)"type"));
         collection.add(resource, props);
-        
+
         final Resource collectionRes = resResolver.getResource("/collection3");
         Assert.assertNotNull(collectionRes);
-        
+
         Assert.assertEquals(true, collection.contains(resource));
-        
+
         ValueMap vm = collection.getProperties(resource);
-        
+
         if (vm != null) {
         	Assert.assertEquals("slingdev", vm.get("creator", ""));
         } else {
         	Assert.fail("no resource entry in collection");
         }
 	}
-	
+
 	@Test
 	public void testOrdering() throws Exception {
         final ResourceCollection collection = rcm.createCollection(resResolver.getResource("/"),
"test1");
         String[] resPaths = {"/res1", "/res2"};
-        final Resource resource = new MockResource(resResolver, resPaths[0], "type");
-        
+        final Resource resource = resResolver.create(resResolver.getResource("/"), resPaths[0].substring(1),
+                Collections.singletonMap(ResourceResolver.PROPERTY_RESOURCE_TYPE, (Object)"type"));
+
         collection.add(resource, null);
-        final Resource resource2 = new MockResource(resResolver, resPaths[1], "type");
+        final Resource resource2 = resResolver.create(resResolver.getResource("/"), resPaths[1].substring(1),
+                Collections.singletonMap(ResourceResolver.PROPERTY_RESOURCE_TYPE, (Object)"type"));
         collection.add(resource2, null);
-        
+
         Assert.assertEquals(true, collection.contains(resource2));
         Assert.assertNotNull(resResolver.getResource("/test1"));
         Assert.assertEquals(ResourceCollection.RESOURCE_TYPE, resResolver.getResource("/test1").getResourceType());
-        
+
         Iterator<Resource> resources = collection.getResources();
-        
+
         int numOfRes = 0;
         while (resources.hasNext()) {
         	Resource entry = resources.next();
         	Assert.assertEquals(resPaths[numOfRes], entry.getPath());
         	numOfRes ++;
         }
-        
+
         //change the order
         collection.orderBefore(resource2, resource);
-        
+
         resources = collection.getResources();
-        
+
         numOfRes = 2;
         while (resources.hasNext()) {
         	numOfRes --;
         	Resource entry = resources.next();
         	Assert.assertEquals(resPaths[numOfRes], entry.getPath());
         }
-        
+
         Assert.assertEquals(0, numOfRes);
 	}
 }
\ No newline at end of file



Mime
View raw message