sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sseif...@apache.org
Subject svn commit: r1761462 - /sling/site/trunk/content/documentation/development/sling-mock.mdtext
Date Mon, 19 Sep 2016 14:48:57 GMT
Author: sseifert
Date: Mon Sep 19 14:48:57 2016
New Revision: 1761462

URL: http://svn.apache.org/viewvc?rev=1761462&view=rev
Log:
add ResourceBuilder usage

Modified:
    sling/site/trunk/content/documentation/development/sling-mock.mdtext

Modified: sling/site/trunk/content/documentation/development/sling-mock.mdtext
URL: http://svn.apache.org/viewvc/sling/site/trunk/content/documentation/development/sling-mock.mdtext?rev=1761462&r1=1761461&r2=1761462&view=diff
==============================================================================
--- sling/site/trunk/content/documentation/development/sling-mock.mdtext (original)
+++ sling/site/trunk/content/documentation/development/sling-mock.mdtext Mon Sep 19 14:48:57
2016
@@ -53,7 +53,7 @@ Additional features provided:
 * `ContentLoader` supports importing JSON data and binary data into the mock resource hierarchy
to easily 
   prepare a test fixture consisting of a hierarchy of resources and properties.
     * The same JSON format can be used that is provided by the Sling GET servlet for output
-* `ContentBuilder` makes it easier to create resources and properties as test fixture
+* `ContentBuilder` and `ResourceBuilder` make it easier to create resources and properties
as test fixture
 
 
 ## Usage
@@ -96,7 +96,7 @@ Additionally it supports:
 
 * Registering OSGi services
 * Registering adapter factories
-* Accessing Content Loader and Content Builder
+* Accessing ContentLoader, and ContentBuilder and ResourceBuilder
 
 
 ### Choosing Resource Resolver Mock Type
@@ -348,14 +348,11 @@ Example JSON data:
 Example code to import the JSON data:
 
     #!java
-    ContentLoader contentLoader = new ContentLoader(resolver);
-    contentLoader.json("/sample-data.json", "/content/sample/en");
+    context.load().json("/sample-data.json", "/content/sample/en");
 
 This codes creates a new resource at `/content/sample/en` (and - if not existent - the parent
resources) and
 imports the JSON data to this node. It can be accessed using the Sling Resource or JCR API
afterwards.
 
-If you use the `SlingContext` JUnit rule you case just use `context.load()`.
-
 
 ### Import binary data from file in classpath
 
@@ -365,31 +362,60 @@ The data is stored using a nt:file/nt:re
 Example code to import a binary file:
 
     #!java
-    ContentLoader contentLoader = new ContentLoader(resolver);
-    contentLoader.binaryFile("/sample-file.gif", "/content/binary/sample-file.gif");
+    context.load().binaryFile("/sample-file.gif", "/content/binary/sample-file.gif");
 
 This codes creates a new resource at `/content/binary/sample-file.gif` (and - if not existent
- the parent 
 resources) and imports the binary data to a jcr:content subnode.
 
-If you use the `SlingContext` JUnit rule you case just use `context.load()`.
-
 
 ### Building content
 
-For easily building resources a `ContentBuilder` provides convenience methods.
+Sling Mocks provides two alterantives for quickly building test content in the repository
with as few code as possible. Sling Mocks provides two alternatives. Both are quite similar
in their results, but follow different API concepts. You can choose whatever matches your
needs and mix them as well.
+
+* `ContentBuilder`: Part of Sling Mocks since its first release. If you need a references
to each created resource this is the easiest way.
+* `ResourceBuilder`: Separate bundle that can also be used in integration tests or live instances.
Supports a "fluent" API to create a bunch of resources in hierarchy at once.
+
+
+### Building content using `ContentBuilder`
+
+The entry point for the `ContentBuilder` is the `create()` method on the Sling context.
 
 Example:
 
     #!java
-    ContentBuilder contentBuilder = new ContentBuilder(resolver);
-    contentBuilder.resource("/content/test1", ImmutableMap.<String, Object>builder()
+    context.create().resource("/content/test1", ImmutableMap.<String, Object>builder()
             .put("prop1", "value1")
             .put("prop2", "value2")
             .build());
 
+Simplified syntax without using a map:
+
+    #!java
+    context.create().resource("/content/test1",
+            "prop1", "value1",
+            "prop2", "value2");
+
+
 If you use the `SlingContext` JUnit rule you case just use `context.create()`.
 
 
+### Building content using `ResourceBuilder`
+
+The entry point for the `ResourceBuilder` is the `build()` method on the Sling context.
+
+Example:
+
+    #!java
+    context.build().resource("/content/test1")
+            .siblingsMode()
+            .resource("test1.1", "stringParam", "configValue1.1")
+            .resource("test1.2", "stringParam", "configValue1.2")
+            .resource("test1.2", "stringParam", "configValue1.3");
+
+See JavaDocs of the class `org.apache.sling.resourcebuilder.api.ResourceBuilder` for a detailed
documentation.
+
+
+
 [osgi-mock]: {{ refs.osgi-mock.path }}
 [jcr-mock]: {{ refs.jcr-mock.path }}
 [resourceresolver-mock]: {{ refs.resourceresolver-mock.path }}



Mime
View raw message