This is an automated email from the ASF dual-hosted git repository.

rombert pushed a commit to annotated tag org.apache.sling.resourcebuilder-1.0.0
in repository 
https://gitbox.apache.org/repos/asf/sling-org-apache-sling-resourcebuilder.git

commit e6427c6783ca4bbe9b3d63b0f01b14925be29bbd
Author: Bertrand Delacretaz <[email protected]>
AuthorDate: Fri Dec 11 11:44:59 2015 +0000

    SLING-5356 - basic server-side tests added
    
    git-svn-id: 
https://svn.apache.org/repos/asf/sling/trunk/bundles/commons/resourcebuilder@1719353
 13f79535-47bb-0310-9956-ffa450edef68
---
 pom.xml                                            | 25 +++++++++-
 .../impl/ResourceBuilderProviderImpl.java}         | 39 +++++++--------
 .../customizers/RBIT_TeleporterCustomizer.java     |  5 +-
 .../impl/ResourceBuilderImplTest.java              | 20 ++++----
 .../resourcebuilder/it/ResourceBuilderIT.java      | 58 +++++++++++++++++++---
 .../resourcebuilder/test/ResourceAssertions.java   | 15 +++++-
 src/test/resources/{ => files}/models.js           |  0
 src/test/resources/{ => files}/myapp.json          |  0
 src/test/resources/{ => files}/text.html           |  0
 9 files changed, 119 insertions(+), 43 deletions(-)

diff --git a/pom.xml b/pom.xml
index 93a9251..d4f7e86 100644
--- a/pom.xml
+++ b/pom.xml
@@ -42,7 +42,13 @@
         <!-- Set this to run tests against an existing server instance -->
         <keepJarRunning>false</keepJarRunning>
         
-        <!-- Options for the jar to execute. $JAREXEC_SERVER_PORT$ is replaced 
by the
+        <!-- 
+            Options for the VM that executes our runnable jar. 
+            Set debugging options here to debug teleported tests.  
+        -->
+        <jar.executor.vm.options>-Xmx512m</jar.executor.vm.options>
+        
+         <!-- Options for the jar to execute. $JAREXEC_SERVER_PORT$ is 
replaced by the
             selected port number -->
         <jar.executor.jar.options>-p 
$JAREXEC_SERVER_PORT$</jar.executor.jar.options>
     </properties>
@@ -93,6 +99,20 @@
                 </executions>
             </plugin>
             <plugin>
+                <artifactId>maven-clean-plugin</artifactId>
+                <configuration>
+                    <filesets>
+                        <fileset>
+                            <directory>${basedir}</directory>
+                            <includes>
+                                <!-- sling folder is the workdir of the 
executable jar that we test -->
+                                <include>sling/**</include>
+                            </includes>
+                        </fileset>
+                    </filesets>
+                </configuration>
+            </plugin>
+            <plugin>
                 <groupId>org.apache.maven.plugins</groupId>
                 <artifactId>maven-failsafe-plugin</artifactId>
                 <executions>
@@ -114,6 +134,7 @@
                         <!--  these are the minimal options required for the 
jar executor, see bundle-with-it module for more -->
                         <keepJarRunning>${keepJarRunning}</keepJarRunning>
                         
<jar.executor.jar.options>${jar.executor.jar.options}</jar.executor.jar.options>
+                        
<jar.executor.vm.options>${jar.executor.vm.options}</jar.executor.vm.options>
                         
<jar.executor.server.port>${http.port}</jar.executor.server.port>
                         
<additional.bundles.path>${project.build.directory}</additional.bundles.path>
                         <server.ready.path.1>/:script 
src="system/sling.js"</server.ready.path.1>
@@ -122,7 +143,7 @@
                         
                         <!-- Additional bundles to install for testing -->
                         
<sling.additional.bundle.1>org.apache.sling.junit.core</sling.additional.bundle.1>
-                        
<sling.additional.bundle.2>${maven.final.name}.jar</sling.additional.bundle.2>
+                        
<sling.additional.bundle.2>${project.artifactId}-${project.version}.jar</sling.additional.bundle.2>
                     </systemPropertyVariables>
                 </configuration>
             </plugin>
diff --git 
a/src/test/java/org/apache/sling/resourcebuilder/it/ResourceBuilderIT.java 
b/src/main/java/org/apache/sling/resourcebuilder/impl/ResourceBuilderProviderImpl.java
similarity index 50%
copy from 
src/test/java/org/apache/sling/resourcebuilder/it/ResourceBuilderIT.java
copy to 
src/main/java/org/apache/sling/resourcebuilder/impl/ResourceBuilderProviderImpl.java
index 3623f33..4832e4f 100644
--- a/src/test/java/org/apache/sling/resourcebuilder/it/ResourceBuilderIT.java
+++ 
b/src/main/java/org/apache/sling/resourcebuilder/impl/ResourceBuilderProviderImpl.java
@@ -16,29 +16,26 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-package org.apache.sling.resourcebuilder.it;
+package org.apache.sling.resourcebuilder.impl;
 
-import org.apache.sling.junit.rules.TeleporterRule;
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
-import org.osgi.service.cm.ConfigurationAdmin;
+import org.apache.felix.scr.annotations.Component;
+import org.apache.felix.scr.annotations.Reference;
+import org.apache.felix.scr.annotations.Service;
+import org.apache.sling.api.resource.Resource;
+import org.apache.sling.commons.mime.MimeTypeService;
+import org.apache.sling.resourcebuilder.api.ResourceBuilder;
+import org.apache.sling.resourcebuilder.api.ResourceBuilderProvider;
 
-/** Server-side integration test for the 
- *  ResourceBuilder, acquired via the ResourceBuilderProvider
- */
-public class ResourceBuilderIT {
+/** ResourceBuilderProvider implementation */
+@Component
+@Service(value=ResourceBuilderProvider.class)
+public class ResourceBuilderProviderImpl implements ResourceBuilderProvider {
     
-    @Rule
-    public final TeleporterRule teleporter = 
TeleporterRule.forClass(getClass(), "RBIT_Teleporter");
+    @Reference
+    private MimeTypeService mimeTypeService;
 
-    @Before
-    public void setup() {
-        teleporter.getService(ConfigurationAdmin.class);
-    }
-    
-    @Test
-    public void basicResource() {
+    @Override
+    public ResourceBuilder getResourceBuilder(Resource parent) {
+        return new ResourceBuilderImpl(parent, mimeTypeService);
     }
-    
-}
+}
\ No newline at end of file
diff --git 
a/src/test/java/org/apache/sling/junit/teleporter/customizers/RBIT_TeleporterCustomizer.java
 
b/src/test/java/org/apache/sling/junit/teleporter/customizers/RBIT_TeleporterCustomizer.java
index 6ba2f6f..a01f991 100644
--- 
a/src/test/java/org/apache/sling/junit/teleporter/customizers/RBIT_TeleporterCustomizer.java
+++ 
b/src/test/java/org/apache/sling/junit/teleporter/customizers/RBIT_TeleporterCustomizer.java
@@ -17,6 +17,7 @@
 package org.apache.sling.junit.teleporter.customizers;
 
 import org.apache.sling.junit.rules.TeleporterRule;
+import org.apache.sling.resourcebuilder.api.ResourceBuilderProvider;
 import org.apache.sling.testing.teleporter.client.ClientSideTeleporter;
 import org.apache.sling.testing.tools.sling.SlingTestBase;
 import org.apache.sling.testing.tools.sling.TimeoutsProvider;
@@ -37,8 +38,8 @@ public class RBIT_TeleporterCustomizer implements 
TeleporterRule.Customizer {
         
cst.setTestReadyTimeoutSeconds(TimeoutsProvider.getInstance().getTimeout(5));
         
         // Make sure our bundle API is imported instead of embedded
-        final String apiPackage = 
"org.apache.sling.testing.samples.bundlewit.api";
-        
cst.includeDependencyPrefix("org.apache.sling.testing.samples.bundlewit");
+        final String apiPackage = 
ResourceBuilderProvider.class.getPackage().getName();
+        cst.includeDependencyPrefix("org.apache.sling.resourcebuilder");
         cst.excludeDependencyPrefix(apiPackage);
         cst.getAdditionalBundleHeaders().put(Constants.IMPORT_PACKAGE, 
apiPackage);
     }
diff --git 
a/src/test/java/org/apache/sling/resourcebuilder/impl/ResourceBuilderImplTest.java
 
b/src/test/java/org/apache/sling/resourcebuilder/impl/ResourceBuilderImplTest.java
index 83d01c0..5758259 100644
--- 
a/src/test/java/org/apache/sling/resourcebuilder/impl/ResourceBuilderImplTest.java
+++ 
b/src/test/java/org/apache/sling/resourcebuilder/impl/ResourceBuilderImplTest.java
@@ -204,17 +204,17 @@ public class ResourceBuilderImplTest {
         getBuilder(testRootPath)
             .resource("apps/myapp/components/resource")
             .siblingsMode()
-            .file("models.js", getClass().getResourceAsStream("/models.js"), 
"MT1", 42)
-            .file("text.html", getClass().getResourceAsStream("/text.html"), 
"MT2", 43)
+            .file("models.js", 
getClass().getResourceAsStream("/files/models.js"), "MT1", 42)
+            .file("text.html", 
getClass().getResourceAsStream("/files/text.html"), "MT2", 43)
             .resetParent()
             .hierarchyMode()
             .resource("apps")
-            .file("myapp.json", getClass().getResourceAsStream("/myapp.json"), 
"MT3", 44)
+            .file("myapp.json", 
getClass().getResourceAsStream("/files/myapp.json"), "MT3", 44)
             .resetParent()
             .resource("apps/content/myapp/resource")
             .resetParent()
             .resource("apps/content", "title", "foo")
-            .file("myapp.json", getClass().getResourceAsStream("/myapp.json"), 
"MT4", 45)
+            .file("myapp.json", 
getClass().getResourceAsStream("/files/myapp.json"), "MT4", 45)
             .commit()
             ;
         
@@ -235,7 +235,7 @@ public class ResourceBuilderImplTest {
     @Test
     public void autoMimetype() throws Exception {
         getBuilder(testRootPath)
-            .file("models.js", getClass().getResourceAsStream("/models.js"), 
null, 42)
+            .file("models.js", 
getClass().getResourceAsStream("/files/models.js"), null, 42)
             .commit()
             ;
         A.assertFile("models.js", 
@@ -245,7 +245,7 @@ public class ResourceBuilderImplTest {
     @Test
     public void autoLastModified() throws Exception {
         getBuilder(testRootPath)
-            .file("models.js", getClass().getResourceAsStream("/models.js"), 
"MT1", -1)
+            .file("models.js", 
getClass().getResourceAsStream("/files/models.js"), "MT1", -1)
             .commit()
             ;
         A.assertFile("models.js", 
@@ -255,7 +255,7 @@ public class ResourceBuilderImplTest {
     @Test
     public void autoEverything() throws Exception {
         getBuilder(testRootPath)
-            .file("models.js", getClass().getResourceAsStream("/models.js"))
+            .file("models.js", 
getClass().getResourceAsStream("/files/models.js"))
             .commit()
             ;
         A.assertFile("models.js", 
@@ -266,15 +266,15 @@ public class ResourceBuilderImplTest {
     public void duplicatedFileFails() throws Exception {
         getBuilder(testRootPath)
             .siblingsMode()
-            .file("models.js", getClass().getResourceAsStream("/models.js"), 
null, 42)
-            .file("models.js", getClass().getResourceAsStream("/models.js"), 
null, 42)
+            .file("models.js", 
getClass().getResourceAsStream("/files/models.js"), null, 42)
+            .file("models.js", 
getClass().getResourceAsStream("/files/models.js"), null, 42)
             ;
     }
     
     @Test(expected=IllegalArgumentException.class)
     public void fileWithPathFails() throws Exception {
         getBuilder(testRootPath)
-            .file("somewhere/models.js", 
getClass().getResourceAsStream("/models.js"), null, 42)
+            .file("somewhere/files/models.js", 
getClass().getResourceAsStream("/files/models.js"), null, 42)
             ;
     }
     
diff --git 
a/src/test/java/org/apache/sling/resourcebuilder/it/ResourceBuilderIT.java 
b/src/test/java/org/apache/sling/resourcebuilder/it/ResourceBuilderIT.java
index 3623f33..e97d542 100644
--- a/src/test/java/org/apache/sling/resourcebuilder/it/ResourceBuilderIT.java
+++ b/src/test/java/org/apache/sling/resourcebuilder/it/ResourceBuilderIT.java
@@ -18,11 +18,22 @@
  */
 package org.apache.sling.resourcebuilder.it;
 
+import java.io.IOException;
+import java.util.UUID;
+
+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.junit.rules.TeleporterRule;
+import org.apache.sling.resourcebuilder.api.ResourceBuilder;
+import org.apache.sling.resourcebuilder.api.ResourceBuilderProvider;
+import org.apache.sling.resourcebuilder.test.ResourceAssertions;
+import org.junit.After;
 import org.junit.Before;
 import org.junit.Rule;
 import org.junit.Test;
-import org.osgi.service.cm.ConfigurationAdmin;
 
 /** Server-side integration test for the 
  *  ResourceBuilder, acquired via the ResourceBuilderProvider
@@ -30,15 +41,50 @@ import org.osgi.service.cm.ConfigurationAdmin;
 public class ResourceBuilderIT {
     
     @Rule
-    public final TeleporterRule teleporter = 
TeleporterRule.forClass(getClass(), "RBIT_Teleporter");
+    public final TeleporterRule teleporter = 
+        TeleporterRule
+        .forClass(getClass(), "RBIT_Teleporter")
+        .withResources("/files/");
+    
+    private ResourceBuilder builder;
+    private ResourceResolver resolver;
+    private String testRootPath;
+    private Resource parent;
+    private ResourceAssertions A;
 
     @Before
-    public void setup() {
-        teleporter.getService(ConfigurationAdmin.class);
+    public void setup() throws LoginException, PersistenceException {
+        testRootPath = getClass().getSimpleName() + "-" + 
UUID.randomUUID().toString(); 
+        resolver = 
teleporter.getService(ResourceResolverFactory.class).getAdministrativeResourceResolver(null);
+        final Resource root = resolver.getResource("/");
+        parent = resolver.create(root, testRootPath, null);
+        builder = 
teleporter.getService(ResourceBuilderProvider.class).getResourceBuilder(parent);
+        A = new ResourceAssertions(testRootPath, resolver);
+    }
+    
+    @After
+    public void cleanup() throws PersistenceException {
+        if(resolver != null && parent != null) {
+            resolver.delete(parent);
+            resolver.commit();
+        }
     }
     
     @Test
-    public void basicResource() {
+    public void simpleResource() {
+        builder
+            .resource("foo", "title", testRootPath)
+            .commit();
+        A.assertProperties("foo", "title", testRootPath);
     }
     
-}
+    @Test
+    public void smallTreeWithFile() throws IOException {
+        builder
+            .resource("somefolder")
+            .file("the-model.js", 
getClass().getResourceAsStream("/files/models.js"), "foo", 42L)
+            .commit();
+        
+        A.assertFile("somefolder/the-model.js", "foo", "yes, it worked", 42L);
+    }
+}
\ No newline at end of file
diff --git 
a/src/test/java/org/apache/sling/resourcebuilder/test/ResourceAssertions.java 
b/src/test/java/org/apache/sling/resourcebuilder/test/ResourceAssertions.java
index c0794e0..32db89e 100644
--- 
a/src/test/java/org/apache/sling/resourcebuilder/test/ResourceAssertions.java
+++ 
b/src/test/java/org/apache/sling/resourcebuilder/test/ResourceAssertions.java
@@ -25,6 +25,7 @@ import static org.junit.Assert.assertTrue;
 import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
+import java.util.Calendar;
 import java.util.Map;
 
 import org.apache.commons.io.IOUtils;
@@ -57,7 +58,7 @@ public class ResourceAssertions {
     
     /** Assert that a file exists and verify its properties. */
     public void assertFile(String path, String mimeType, String 
expectedContent, Long lastModified) throws IOException {
-        final Resource r = assertResource(fullPath(path));
+        final Resource r = assertResource(path);
         assertNotNull("Expecting resource to exist:" + path, r);
         
         // Files are stored according to the standard JCR structure
@@ -68,7 +69,7 @@ public class ResourceAssertions {
         assertEquals("Expecting nt:Resource type for " + jcrContent.getPath(), 
                 ResourceBuilderImpl.NT_RESOURCE, 
vm.get(ResourceBuilderImpl.JCR_PRIMARYTYPE));
         assertEquals("Expecting the correct mime-type", mimeType, 
vm.get(ResourceBuilderImpl.JCR_MIMETYPE));
-        assertEquals("Expecting the correct last modified", lastModified, 
vm.get(ResourceBuilderImpl.JCR_LASTMODIFIED));
+        assertEquals("Expecting the correct last modified", lastModified, 
getLastModified(vm));
         
         final ByteArrayOutputStream bos = new ByteArrayOutputStream();
         final InputStream is = vm.get(ResourceBuilderImpl.JCR_DATA, 
InputStream.class);
@@ -83,6 +84,16 @@ public class ResourceAssertions {
         }
     }
     
+    private Long getLastModified(ValueMap vm) {
+        final Object o = vm.get(ResourceBuilderImpl.JCR_LASTMODIFIED);
+        if(o instanceof Long) {
+            return (Long)o;
+        } else if(o instanceof Calendar) {
+            return ((Calendar)o).getTimeInMillis();
+        }
+        throw new IllegalArgumentException("Unexpected type " + 
o.getClass().getName());
+    }
+    
     public void assertProperties(String path, Object ...props) {
         final Map<String, Object> expected = MapArgsConverter.toMap(props);
         final Resource r = assertResource(path);
diff --git a/src/test/resources/models.js b/src/test/resources/files/models.js
similarity index 100%
rename from src/test/resources/models.js
rename to src/test/resources/files/models.js
diff --git a/src/test/resources/myapp.json b/src/test/resources/files/myapp.json
similarity index 100%
rename from src/test/resources/myapp.json
rename to src/test/resources/files/myapp.json
diff --git a/src/test/resources/text.html b/src/test/resources/files/text.html
similarity index 100%
rename from src/test/resources/text.html
rename to src/test/resources/files/text.html

-- 
To stop receiving notification emails like this one, please contact
"[email protected]" <[email protected]>.

Reply via email to