sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sseif...@apache.org
Subject svn commit: r1759511 - in /sling: branches/testing/mocks/sling-mock-1.x/ branches/testing/mocks/sling-mock-1.x/src/main/java/org/apache/sling/testing/mock/sling/context/ branches/testing/mocks/sling-mock-1.x/src/main/java/org/apache/sling/testing/mock/...
Date Tue, 06 Sep 2016 21:03:07 GMT
Author: sseifert
Date: Tue Sep  6 21:03:07 2016
New Revision: 1759511

URL: http://svn.apache.org/viewvc?rev=1759511&view=rev
Log:
SLING-6040 add ResourceBuilder support to SlingContext
This closes #167

Modified:
    sling/branches/testing/mocks/sling-mock-1.x/pom.xml
    sling/branches/testing/mocks/sling-mock-1.x/src/main/java/org/apache/sling/testing/mock/sling/context/SlingContextImpl.java
    sling/branches/testing/mocks/sling-mock-1.x/src/main/java/org/apache/sling/testing/mock/sling/context/package-info.java
    sling/branches/testing/mocks/sling-mock-1.x/src/main/java/org/apache/sling/testing/mock/sling/junit/package-info.java
    sling/branches/testing/mocks/sling-mock-1.x/src/test/java/org/apache/sling/testing/mock/sling/junit/SlingContextTest.java
    sling/trunk/testing/mocks/sling-mock/pom.xml
    sling/trunk/testing/mocks/sling-mock/src/main/java/org/apache/sling/testing/mock/sling/context/SlingContextImpl.java
    sling/trunk/testing/mocks/sling-mock/src/main/java/org/apache/sling/testing/mock/sling/context/package-info.java
    sling/trunk/testing/mocks/sling-mock/src/main/java/org/apache/sling/testing/mock/sling/junit/package-info.java
    sling/trunk/testing/mocks/sling-mock/src/test/java/org/apache/sling/testing/mock/sling/junit/SlingContextTest.java

Modified: sling/branches/testing/mocks/sling-mock-1.x/pom.xml
URL: http://svn.apache.org/viewvc/sling/branches/testing/mocks/sling-mock-1.x/pom.xml?rev=1759511&r1=1759510&r2=1759511&view=diff
==============================================================================
--- sling/branches/testing/mocks/sling-mock-1.x/pom.xml (original)
+++ sling/branches/testing/mocks/sling-mock-1.x/pom.xml Tue Sep  6 21:03:07 2016
@@ -140,6 +140,12 @@
             <version>2.2.4</version>
             <scope>compile</scope>
         </dependency>
+        <dependency>
+            <groupId>org.apache.sling</groupId>
+            <artifactId>org.apache.sling.resourcebuilder</artifactId>
+            <version>0.0.1-SNAPSHOT</version>
+            <scope>compile</scope>
+        </dependency>
 
         <dependency>
             <groupId>commons-collections</groupId>

Modified: sling/branches/testing/mocks/sling-mock-1.x/src/main/java/org/apache/sling/testing/mock/sling/context/SlingContextImpl.java
URL: http://svn.apache.org/viewvc/sling/branches/testing/mocks/sling-mock-1.x/src/main/java/org/apache/sling/testing/mock/sling/context/SlingContextImpl.java?rev=1759511&r1=1759510&r2=1759511&view=diff
==============================================================================
--- sling/branches/testing/mocks/sling-mock-1.x/src/main/java/org/apache/sling/testing/mock/sling/context/SlingContextImpl.java
(original)
+++ sling/branches/testing/mocks/sling-mock-1.x/src/main/java/org/apache/sling/testing/mock/sling/context/SlingContextImpl.java
Tue Sep  6 21:03:07 2016
@@ -46,6 +46,9 @@ import org.apache.sling.models.impl.inje
 import org.apache.sling.models.impl.injectors.SlingObjectInjector;
 import org.apache.sling.models.impl.injectors.ValueMapInjector;
 import org.apache.sling.models.spi.ImplementationPicker;
+import org.apache.sling.resourcebuilder.api.ResourceBuilder;
+import org.apache.sling.resourcebuilder.api.ResourceBuilderFactory;
+import org.apache.sling.resourcebuilder.impl.ResourceBuilderFactoryService;
 import org.apache.sling.settings.SlingSettingsService;
 import org.apache.sling.testing.mock.osgi.context.OsgiContextImpl;
 import org.apache.sling.testing.mock.sling.MockSling;
@@ -92,6 +95,7 @@ public class SlingContextImpl extends Os
     protected SlingScriptHelper slingScriptHelper;
     protected ContentLoader contentLoader;
     protected ContentBuilder contentBuilder;
+    protected ResourceBuilder resourceBuilder;
     protected UniqueRoot uniqueRoot;
     
     private Map<String, Object> resourceResolverFactoryActivatorProps;
@@ -171,6 +175,7 @@ public class SlingContextImpl extends Os
         // other services
         registerService(SlingSettingsService.class, new MockSlingSettingService(DEFAULT_RUN_MODES));
         registerService(MimeTypeService.class, new MockMimeTypeService());
+        registerInjectActivateService(new ResourceBuilderFactoryService());
     }
 
     /**
@@ -208,6 +213,7 @@ public class SlingContextImpl extends Os
         this.slingScriptHelper = null;
         this.contentLoader = null;
         this.contentBuilder = null;
+        this.resourceBuilder = null;
         this.uniqueRoot = null;
         
         super.tearDown();
@@ -298,6 +304,19 @@ public class SlingContextImpl extends Os
         }
         return this.contentBuilder;
     }
+    
+    /**
+     * Creates a {@link ResourceBuilder} object for easily creating test content.
+     * This is a separate API which can be used inside sling mocks or in a running instance.
+     * You can use alternatively the {@link #create()} method to use the {@link ContentBuilder}
API.
+     * @return Resource builder for building test content.
+     */
+    public ResourceBuilder build() {
+        if (this.resourceBuilder == null) {
+            this.resourceBuilder = getService(ResourceBuilderFactory.class).forResolver(this.resourceResolver());
+        }
+        return this.resourceBuilder;
+    }
 
     /**
      * @return Current resource

Modified: sling/branches/testing/mocks/sling-mock-1.x/src/main/java/org/apache/sling/testing/mock/sling/context/package-info.java
URL: http://svn.apache.org/viewvc/sling/branches/testing/mocks/sling-mock-1.x/src/main/java/org/apache/sling/testing/mock/sling/context/package-info.java?rev=1759511&r1=1759510&r2=1759511&view=diff
==============================================================================
--- sling/branches/testing/mocks/sling-mock-1.x/src/main/java/org/apache/sling/testing/mock/sling/context/package-info.java
(original)
+++ sling/branches/testing/mocks/sling-mock-1.x/src/main/java/org/apache/sling/testing/mock/sling/context/package-info.java
Tue Sep  6 21:03:07 2016
@@ -19,5 +19,5 @@
 /**
  * Sling context implementation for unit tests.
  */
-@aQute.bnd.annotation.Version("3.2")
+@aQute.bnd.annotation.Version("3.3")
 package org.apache.sling.testing.mock.sling.context;

Modified: sling/branches/testing/mocks/sling-mock-1.x/src/main/java/org/apache/sling/testing/mock/sling/junit/package-info.java
URL: http://svn.apache.org/viewvc/sling/branches/testing/mocks/sling-mock-1.x/src/main/java/org/apache/sling/testing/mock/sling/junit/package-info.java?rev=1759511&r1=1759510&r2=1759511&view=diff
==============================================================================
--- sling/branches/testing/mocks/sling-mock-1.x/src/main/java/org/apache/sling/testing/mock/sling/junit/package-info.java
(original)
+++ sling/branches/testing/mocks/sling-mock-1.x/src/main/java/org/apache/sling/testing/mock/sling/junit/package-info.java
Tue Sep  6 21:03:07 2016
@@ -19,5 +19,5 @@
 /**
  * Rule for providing easy access to Sling context in JUnit tests.
  */
-@aQute.bnd.annotation.Version("3.2")
+@aQute.bnd.annotation.Version("3.3")
 package org.apache.sling.testing.mock.sling.junit;

Modified: sling/branches/testing/mocks/sling-mock-1.x/src/test/java/org/apache/sling/testing/mock/sling/junit/SlingContextTest.java
URL: http://svn.apache.org/viewvc/sling/branches/testing/mocks/sling-mock-1.x/src/test/java/org/apache/sling/testing/mock/sling/junit/SlingContextTest.java?rev=1759511&r1=1759510&r2=1759511&view=diff
==============================================================================
--- sling/branches/testing/mocks/sling-mock-1.x/src/test/java/org/apache/sling/testing/mock/sling/junit/SlingContextTest.java
(original)
+++ sling/branches/testing/mocks/sling-mock-1.x/src/test/java/org/apache/sling/testing/mock/sling/junit/SlingContextTest.java
Tue Sep  6 21:03:07 2016
@@ -27,7 +27,9 @@ import static org.mockito.Mockito.verify
 import java.io.IOException;
 
 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.ResourceUtil;
 import org.apache.sling.testing.mock.sling.ResourceResolverType;
 import org.junit.Before;
 import org.junit.Rule;
@@ -109,4 +111,19 @@ public class SlingContextTest {
         assertNull(context.resourceResolver().adaptTo(Double.class));
     }
 
+    @Test
+    public void testResourceBuilder() {
+        
+        context.build().resource("/test1", "prop1", "value1")
+            .siblingsMode()
+            .resource("a")
+            .resource("b");
+        
+        Resource test1 = context.resourceResolver().getResource("/test1");
+        assertNotNull(test1);
+        assertEquals("value1", ResourceUtil.getValueMap(test1).get("prop1", String.class));
+        assertNotNull(test1.getChild("a"));
+        assertNotNull(test1.getChild("b"));
+    }
+        
 }

Modified: sling/trunk/testing/mocks/sling-mock/pom.xml
URL: http://svn.apache.org/viewvc/sling/trunk/testing/mocks/sling-mock/pom.xml?rev=1759511&r1=1759510&r2=1759511&view=diff
==============================================================================
--- sling/trunk/testing/mocks/sling-mock/pom.xml (original)
+++ sling/trunk/testing/mocks/sling-mock/pom.xml Tue Sep  6 21:03:07 2016
@@ -148,6 +148,12 @@
             <scope>compile</scope>
         </dependency>
         <dependency>
+            <groupId>org.apache.sling</groupId>
+            <artifactId>org.apache.sling.resourcebuilder</artifactId>
+            <version>0.0.1-SNAPSHOT</version>
+            <scope>compile</scope>
+        </dependency>
+        <dependency>
             <groupId>org.apache.jackrabbit</groupId>
             <artifactId>jackrabbit-api</artifactId>
             <version>2.11.3</version>

Modified: sling/trunk/testing/mocks/sling-mock/src/main/java/org/apache/sling/testing/mock/sling/context/SlingContextImpl.java
URL: http://svn.apache.org/viewvc/sling/trunk/testing/mocks/sling-mock/src/main/java/org/apache/sling/testing/mock/sling/context/SlingContextImpl.java?rev=1759511&r1=1759510&r2=1759511&view=diff
==============================================================================
--- sling/trunk/testing/mocks/sling-mock/src/main/java/org/apache/sling/testing/mock/sling/context/SlingContextImpl.java
(original)
+++ sling/trunk/testing/mocks/sling-mock/src/main/java/org/apache/sling/testing/mock/sling/context/SlingContextImpl.java
Tue Sep  6 21:03:07 2016
@@ -46,6 +46,9 @@ import org.apache.sling.models.impl.inje
 import org.apache.sling.models.impl.injectors.SlingObjectInjector;
 import org.apache.sling.models.impl.injectors.ValueMapInjector;
 import org.apache.sling.models.spi.ImplementationPicker;
+import org.apache.sling.resourcebuilder.api.ResourceBuilder;
+import org.apache.sling.resourcebuilder.api.ResourceBuilderFactory;
+import org.apache.sling.resourcebuilder.impl.ResourceBuilderFactoryService;
 import org.apache.sling.settings.SlingSettingsService;
 import org.apache.sling.testing.mock.osgi.context.OsgiContextImpl;
 import org.apache.sling.testing.mock.sling.MockSling;
@@ -92,6 +95,7 @@ public class SlingContextImpl extends Os
     protected SlingScriptHelper slingScriptHelper;
     protected ContentLoader contentLoader;
     protected ContentBuilder contentBuilder;
+    protected ResourceBuilder resourceBuilder;
     protected UniqueRoot uniqueRoot;
     
     private Map<String, Object> resourceResolverFactoryActivatorProps;
@@ -171,6 +175,7 @@ public class SlingContextImpl extends Os
         // other services
         registerService(SlingSettingsService.class, new MockSlingSettingService(DEFAULT_RUN_MODES));
         registerService(MimeTypeService.class, new MockMimeTypeService());
+        registerInjectActivateService(new ResourceBuilderFactoryService());
     }
 
     /**
@@ -208,6 +213,7 @@ public class SlingContextImpl extends Os
         this.slingScriptHelper = null;
         this.contentLoader = null;
         this.contentBuilder = null;
+        this.resourceBuilder = null;
         this.uniqueRoot = null;
         
         super.tearDown();
@@ -292,6 +298,9 @@ public class SlingContextImpl extends Os
     }
 
     /**
+     * Creates a {@link ContentBuilder} object for easily creating test content.
+     * This API was part of Sling Mocks since version 1.x.
+     * You can use alternatively the {@link #build()} method and use the {@link ResourceBuilder}
API.
      * @return Content builder for building test content
      */
     public ContentBuilder create() {
@@ -300,6 +309,19 @@ public class SlingContextImpl extends Os
         }
         return this.contentBuilder;
     }
+    
+    /**
+     * Creates a {@link ResourceBuilder} object for easily creating test content.
+     * This is a separate API which can be used inside sling mocks or in a running instance.
+     * You can use alternatively the {@link #create()} method to use the {@link ContentBuilder}
API.
+     * @return Resource builder for building test content.
+     */
+    public ResourceBuilder build() {
+        if (this.resourceBuilder == null) {
+            this.resourceBuilder = getService(ResourceBuilderFactory.class).forResolver(this.resourceResolver());
+        }
+        return this.resourceBuilder;
+    }
 
     /**
      * @return Current resource

Modified: sling/trunk/testing/mocks/sling-mock/src/main/java/org/apache/sling/testing/mock/sling/context/package-info.java
URL: http://svn.apache.org/viewvc/sling/trunk/testing/mocks/sling-mock/src/main/java/org/apache/sling/testing/mock/sling/context/package-info.java?rev=1759511&r1=1759510&r2=1759511&view=diff
==============================================================================
--- sling/trunk/testing/mocks/sling-mock/src/main/java/org/apache/sling/testing/mock/sling/context/package-info.java
(original)
+++ sling/trunk/testing/mocks/sling-mock/src/main/java/org/apache/sling/testing/mock/sling/context/package-info.java
Tue Sep  6 21:03:07 2016
@@ -19,5 +19,5 @@
 /**
  * Sling context implementation for unit tests.
  */
-@org.osgi.annotation.versioning.Version("3.2.1")
+@org.osgi.annotation.versioning.Version("3.3")
 package org.apache.sling.testing.mock.sling.context;

Modified: sling/trunk/testing/mocks/sling-mock/src/main/java/org/apache/sling/testing/mock/sling/junit/package-info.java
URL: http://svn.apache.org/viewvc/sling/trunk/testing/mocks/sling-mock/src/main/java/org/apache/sling/testing/mock/sling/junit/package-info.java?rev=1759511&r1=1759510&r2=1759511&view=diff
==============================================================================
--- sling/trunk/testing/mocks/sling-mock/src/main/java/org/apache/sling/testing/mock/sling/junit/package-info.java
(original)
+++ sling/trunk/testing/mocks/sling-mock/src/main/java/org/apache/sling/testing/mock/sling/junit/package-info.java
Tue Sep  6 21:03:07 2016
@@ -19,5 +19,5 @@
 /**
  * Rule for providing easy access to Sling context in JUnit tests.
  */
-@org.osgi.annotation.versioning.Version("3.2")
+@org.osgi.annotation.versioning.Version("3.3")
 package org.apache.sling.testing.mock.sling.junit;

Modified: sling/trunk/testing/mocks/sling-mock/src/test/java/org/apache/sling/testing/mock/sling/junit/SlingContextTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/testing/mocks/sling-mock/src/test/java/org/apache/sling/testing/mock/sling/junit/SlingContextTest.java?rev=1759511&r1=1759510&r2=1759511&view=diff
==============================================================================
--- sling/trunk/testing/mocks/sling-mock/src/test/java/org/apache/sling/testing/mock/sling/junit/SlingContextTest.java
(original)
+++ sling/trunk/testing/mocks/sling-mock/src/test/java/org/apache/sling/testing/mock/sling/junit/SlingContextTest.java
Tue Sep  6 21:03:07 2016
@@ -29,6 +29,7 @@ import java.io.IOException;
 import org.apache.sling.api.adapter.AdapterFactory;
 import org.apache.sling.api.adapter.SlingAdaptable;
 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.testing.mock.sling.ResourceResolverType;
 import org.junit.Before;
@@ -138,6 +139,22 @@ public class SlingContextTest {
         assertEquals("testMessage3-dynamic", new TestAdaptable("testMessage3").adaptTo(String.class));
     }
     
+    @Test
+    public void testResourceBuilder() {
+        
+        context.build().resource("/test1", "prop1", "value1")
+            .siblingsMode()
+            .resource("a")
+            .resource("b");
+        
+        Resource test1 = context.resourceResolver().getResource("/test1");
+        assertNotNull(test1);
+        assertEquals("value1", test1.getValueMap().get("prop1", String.class));
+        assertNotNull(test1.getChild("a"));
+        assertNotNull(test1.getChild("b"));
+    }
+    
+    
     private void prepareInitialAdapterFactory() {
         // register "traditional" adapter factory without specific service ranking
         AdapterFactory adapterFactory = new AdapterFactory() {



Mime
View raw message