You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by ro...@apache.org on 2017/11/07 10:20:04 UTC
[sling-org-apache-sling-testing-resourceresolver-mock] 09/12:
SLING-3355 : Add helper methods for creating resources
This is an automated email from the ASF dual-hosted git repository.
rombert pushed a commit to annotated tag org.apache.sling.testing.resourceresolver-mock-0.2.0
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-testing-resourceresolver-mock.git
commit 518a6e2b79e8ee58e8a02e8ecb89d60c0af6bf7e
Author: Carsten Ziegeler <cz...@apache.org>
AuthorDate: Thu Jan 30 12:59:26 2014 +0000
SLING-3355 : Add helper methods for creating resources
git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/testing/resourceresolver-mock@1562804 13f79535-47bb-0310-9956-ffa450edef68
---
.../sling/testing/resourceresolver/MockHelper.java | 31 +++++++++++++++++++---
1 file changed, 28 insertions(+), 3 deletions(-)
diff --git a/src/main/java/org/apache/sling/testing/resourceresolver/MockHelper.java b/src/main/java/org/apache/sling/testing/resourceresolver/MockHelper.java
index c899b52..c4995ff 100644
--- a/src/main/java/org/apache/sling/testing/resourceresolver/MockHelper.java
+++ b/src/main/java/org/apache/sling/testing/resourceresolver/MockHelper.java
@@ -32,6 +32,7 @@ import org.apache.sling.api.resource.ResourceUtil;
*
* MockHelper.create(resolver).resource("/libs").p("prop", "value")
* .resource("sub").p("sub", "hello")
+ * .resource(".sameLevel")
* .resource("/apps").p("foo", "baa").commit()
*
*/
@@ -45,17 +46,30 @@ public class MockHelper {
this.resolver = r;
}
+
+ /**
+ * Create a new helper
+ */
public static MockHelper create(final ResourceResolver resolver) {
return new MockHelper(resolver);
}
+ /**
+ * Add a new resource
+ * If the path is relative, this resource is added as a child to the previous resource.
+ * If the path is relative and starts with a dot, this resource is added as a peer to
+ * the previous resource.
+ */
public MockHelper resource(final String path) {
final String fullPath;
- if ( !path.startsWith("/") ) {
+ if ( path.startsWith("/") ) {
+ fullPath = path;
+ } else if ( path.startsWith(".") ) {
final Description d = this.stack.peek();
- fullPath = d.path + "/" + path;
+ fullPath = ResourceUtil.normalize(d.path + "/../" + path.substring(1));
} else {
- fullPath = path;
+ final Description d = this.stack.peek();
+ fullPath = d.path + "/" + path;
}
final Description d = new Description();
d.path = fullPath;
@@ -64,6 +78,9 @@ public class MockHelper {
return this;
}
+ /**
+ * Add a property to the current resource
+ */
public MockHelper p(final String name, final Object value) {
final Description d = this.stack.peek();
d.properties.put(name, value);
@@ -71,6 +88,9 @@ public class MockHelper {
return this;
}
+ /**
+ * Finish building and add all resources to the resource tree.
+ */
public void add() throws PersistenceException {
for(int i=0; i<this.stack.size(); i++) {
final Description d = this.stack.get(i);
@@ -79,6 +99,11 @@ public class MockHelper {
this.stack.clear();
}
+ /**
+ * Finish building, add all resources to the resource tree and commit
+ * changes.
+ * @throws PersistenceException
+ */
public void commit() throws PersistenceException {
this.add();
this.resolver.commit();
--
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.