incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bdelacre...@apache.org
Subject svn commit: r1479496 - in /sling/trunk/contrib/extensions/collection/src/test/java/org/apache/sling/resource/collection: impl/ResourceCollectionImplTest.java test/MockResource.java test/MockResourceResolver.java
Date Mon, 06 May 2013 08:44:50 GMT
Author: bdelacretaz
Date: Mon May  6 08:44:43 2013
New Revision: 1479496

URL: http://svn.apache.org/r1479496
Log:
SLING-2853 - simplify tests

Modified:
    sling/trunk/contrib/extensions/collection/src/test/java/org/apache/sling/resource/collection/impl/ResourceCollectionImplTest.java
    sling/trunk/contrib/extensions/collection/src/test/java/org/apache/sling/resource/collection/test/MockResource.java
    sling/trunk/contrib/extensions/collection/src/test/java/org/apache/sling/resource/collection/test/MockResourceResolver.java

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=1479496&r1=1479495&r2=1479496&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 08:44:43 2013
@@ -1,6 +1,5 @@
 package org.apache.sling.resource.collection.impl;
 
-
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.Map;
@@ -20,33 +19,25 @@ import org.junit.Test;
 
 public class ResourceCollectionImplTest {
 	private ResourceResolver resResolver;
+    private ResourceCollectionManager rcm;
 
 	@Before
 	public void setUp() throws Exception {
 		resResolver = new MockResourceResolver();
-		//create some root resource
-		Resource resource = new MockResource(resResolver, "/", "type");
-		
-		((MockResourceResolver) resResolver).addResource(resource);
+		rcm = new ResourceCollectionManagerImpl(resResolver);
+		// need a root resource
+		new MockResource(resResolver, "/", "type");
 	}
 	
 	@Test
 	public void testAddResource() throws Exception {
-		ResourceCollectionManager rcm = new ResourceCollectionManagerImpl(resResolver);
 		        
-        ResourceCollection collection = rcm.createCollection(resResolver.getResource("/"),
"test1");
-        
-        Resource resource = new MockResource(resResolver, "/res1", "type");
-        ((MockResourceResolver) resResolver).addResource(resource);
-        
-        collection.add(resource);
-        resource = new MockResource(resResolver, "/res2", "type");
-        ((MockResourceResolver) resResolver).addResource(resource);
-        
+        final ResourceCollection collection = rcm.createCollection(resResolver.getResource("/"),
"test1");
+        collection.add(new MockResource(resResolver, "/res1", "type"));
+        final Resource resource = new MockResource(resResolver, "/res2", "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());
@@ -54,17 +45,9 @@ public class ResourceCollectionImplTest 
 	
 	@Test
 	public void testCreateCollection() throws Exception {
-		ResourceCollectionManager rcm = new ResourceCollectionManagerImpl(resResolver);
-		        
-        ResourceCollection collection = rcm.createCollection(resResolver.getResource("/"),
"test1");
-        
-        Resource resource = new MockResource(resResolver, "/res1", "type");
-        ((MockResourceResolver) resResolver).addResource(resource);
-        
-        collection.add(resource, null);
-        resource = new MockResource(resResolver, "/res2", "type");
-        ((MockResourceResolver) resResolver).addResource(resource);
-        
+        final ResourceCollection collection = rcm.createCollection(resResolver.getResource("/"),
"test1");
+        collection.add(new MockResource(resResolver, "/res1", "type"), null);
+        final Resource resource = new MockResource(resResolver, "/res2", "type");
         collection.add(resource, null);
         
         Assert.assertEquals(true, collection.contains(resource));
@@ -74,17 +57,9 @@ public class ResourceCollectionImplTest 
 	
 	@Test
 	public void testGetCollection() throws Exception {
-		ResourceCollectionManager rcm = new ResourceCollectionManagerImpl(resResolver);
-		        
         ResourceCollection collection = rcm.createCollection(resResolver.getResource("/"),
"test1");
-        
-        Resource resource = new MockResource(resResolver, "/res1", "type");
-        ((MockResourceResolver) resResolver).addResource(resource);
-        
-        collection.add(resource, null);
-        resource = new MockResource(resResolver, "/res2", "type");
-        ((MockResourceResolver) resResolver).addResource(resource);
-        
+        collection.add(new MockResource(resResolver, "/res1", "type"), null);
+        final Resource resource = new MockResource(resResolver, "/res2", "type");
         collection.add(resource, null);
         
         collection = rcm.getCollection(resResolver.getResource(collection.getPath()));
@@ -96,23 +71,14 @@ public class ResourceCollectionImplTest 
 	
 	@Test
 	public void testListCollection() throws Exception {
-		ResourceCollectionManager rcm = new ResourceCollectionManagerImpl(resResolver);
-        
-        ResourceCollection collection = rcm.createCollection(resResolver.getResource("/"),
"collection1");
-        
-        Resource resource = new MockResource(resResolver, "/res1", "type");
-        ((MockResourceResolver) resResolver).addResource(resource);
-        
-        collection.add(resource, null);
-        resource = new MockResource(resResolver, "/res2", "type");
-        ((MockResourceResolver) resResolver).addResource(resource);
+        final ResourceCollection collection = rcm.createCollection(resResolver.getResource("/"),
"collection1");
+        collection.add(new MockResource(resResolver, "/res1", "type"), null);
+        final Resource resource = new MockResource(resResolver, "/res2", "type");
         
         collection.add(resource, null);
-        
         Assert.assertEquals(true, collection.contains(resource));
         
-        Iterator<Resource> resources = collection.getResources();
-        
+        final Iterator<Resource> resources = collection.getResources();
         int numOfRes = 0;
         while (resources.hasNext()) {
         	resources.next();
@@ -124,20 +90,15 @@ public class ResourceCollectionImplTest 
 	
 	@Test
 	public void testCreateCollectionWithProperties() throws Exception {
-		ResourceCollectionManager rcm = new ResourceCollectionManagerImpl(resResolver);
-		Map<String, Object> props = new HashMap<String, Object>();
+		final Map<String, Object> props = new HashMap<String, Object>();
 		props.put(JcrResourceConstants.SLING_RESOURCE_TYPE_PROPERTY, "some/type");
 		props.put("creator", "slingdev");
         
-        ResourceCollection collection = rcm.createCollection(resResolver.getResource("/"),
"collection3", props);
-        
-        Resource resource = new MockResource(resResolver, "/res1", "type");
-        ((MockResourceResolver) resResolver).addResource(resource);
-        
+        final ResourceCollection collection = rcm.createCollection(resResolver.getResource("/"),
"collection3", props);
+        final Resource resource = new MockResource(resResolver, "/res1", "type");
         collection.add(resource, null);
         
-        
-        Resource collectionRes = resResolver.getResource("/collection3");
+        final Resource collectionRes = resResolver.getResource("/collection3");
         Assert.assertNotNull(collectionRes);
         
         Assert.assertEquals(true, collection.contains(resource));
@@ -150,19 +111,15 @@ public class ResourceCollectionImplTest 
 	
 	@Test
 	public void testAddResourceWithProperties() throws Exception {
-		ResourceCollectionManager rcm = new ResourceCollectionManagerImpl(resResolver);
-		Map<String, Object> props = new HashMap<String, Object>();
+		final Map<String, Object> props = new HashMap<String, Object>();
 		props.put("creator", "slingdev");
         
-        ResourceCollection collection = rcm.createCollection(resResolver.getResource("/"),
"collection3");
-        
-        Resource resource = new MockResource(resResolver, "/res1", "type");
-        ((MockResourceResolver) resResolver).addResource(resource);
+        final ResourceCollection collection = rcm.createCollection(resResolver.getResource("/"),
"collection3");
         
+        final Resource resource = new MockResource(resResolver, "/res1", "type");
         collection.add(resource, props);
         
-        
-        Resource collectionRes = resResolver.getResource("/collection3");
+        final Resource collectionRes = resResolver.getResource("/collection3");
         Assert.assertNotNull(collectionRes);
         
         Assert.assertEquals(true, collection.contains(resource));
@@ -178,17 +135,12 @@ public class ResourceCollectionImplTest 
 	
 	@Test
 	public void testOrdering() throws Exception {
-		ResourceCollectionManager rcm = new ResourceCollectionManagerImpl(resResolver);
-        
-        ResourceCollection collection = rcm.createCollection(resResolver.getResource("/"),
"test1");
+        final ResourceCollection collection = rcm.createCollection(resResolver.getResource("/"),
"test1");
         String[] resPaths = {"/res1", "/res2"};
-        Resource resource = new MockResource(resResolver, resPaths[0], "type");
-        ((MockResourceResolver) resResolver).addResource(resource);
+        final Resource resource = new MockResource(resResolver, resPaths[0], "type");
         
         collection.add(resource, null);
-        Resource resource2 = new MockResource(resResolver, resPaths[1], "type");
-        ((MockResourceResolver) resResolver).addResource(resource2);
-        
+        final Resource resource2 = new MockResource(resResolver, resPaths[1], "type");
         collection.add(resource2, null);
         
         Assert.assertEquals(true, collection.contains(resource2));
@@ -218,4 +170,4 @@ public class ResourceCollectionImplTest 
         
         Assert.assertEquals(0, numOfRes);
 	}
-}
+}
\ No newline at end of file

Modified: sling/trunk/contrib/extensions/collection/src/test/java/org/apache/sling/resource/collection/test/MockResource.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/collection/src/test/java/org/apache/sling/resource/collection/test/MockResource.java?rev=1479496&r1=1479495&r2=1479496&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/collection/src/test/java/org/apache/sling/resource/collection/test/MockResource.java
(original)
+++ sling/trunk/contrib/extensions/collection/src/test/java/org/apache/sling/resource/collection/test/MockResource.java
Mon May  6 08:44:43 2013
@@ -43,6 +43,7 @@ public class MockResource extends Synthe
             String resourceType, String resourceSuperType) {
         super(resourceResolver, path, resourceType);
 
+        ((MockResourceResolver)resourceResolver).addResource(this);
         setResourceType(resourceType);
         setResourceSuperType(resourceSuperType);
     }

Modified: sling/trunk/contrib/extensions/collection/src/test/java/org/apache/sling/resource/collection/test/MockResourceResolver.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/collection/src/test/java/org/apache/sling/resource/collection/test/MockResourceResolver.java?rev=1479496&r1=1479495&r2=1479496&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/collection/src/test/java/org/apache/sling/resource/collection/test/MockResourceResolver.java
(original)
+++ sling/trunk/contrib/extensions/collection/src/test/java/org/apache/sling/resource/collection/test/MockResourceResolver.java
Mon May  6 08:44:43 2013
@@ -40,7 +40,7 @@ public class MockResourceResolver implem
 
     private Map<String, Collection<Resource>> children = new LinkedHashMap<String,
Collection<Resource>>();
 
-    public void addResource(Resource resource) {
+    void addResource(Resource resource) {
         this.resources.put(resource.getPath(), resource);
     }
 



Mime
View raw message