This is an automated email from the ASF dual-hosted git repository. rombert pushed a commit to annotated tag org.apache.sling.testing.sling-mock-2.1.0 in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-testing-sling-mock.git
commit 256b173f3c649cb60d8becd6991c5864650c7851 Author: Stefan Seifert <[email protected]> AuthorDate: Mon Sep 12 14:19:06 2016 +0000 SLING-6049 sling-mock ContentBuilder: Support creating resources with object vararg parameter git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/testing/mocks/sling-mock@1760378 13f79535-47bb-0310-9956-ffa450edef68 --- .../testing/mock/sling/builder/ContentBuilder.java | 21 +++++++++++++++++++++ .../testing/mock/sling/builder/package-info.java | 2 +- .../mock/sling/builder/ContentBuilderTest.java | 22 +++++++++++++++++----- 3 files changed, 39 insertions(+), 6 deletions(-) diff --git a/src/main/java/org/apache/sling/testing/mock/sling/builder/ContentBuilder.java b/src/main/java/org/apache/sling/testing/mock/sling/builder/ContentBuilder.java index b6bf6d4..6b41a30 100644 --- a/src/main/java/org/apache/sling/testing/mock/sling/builder/ContentBuilder.java +++ b/src/main/java/org/apache/sling/testing/mock/sling/builder/ContentBuilder.java @@ -27,6 +27,7 @@ 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.api.resource.ValueMap; +import org.apache.sling.resourcebuilder.impl.MapArgsConverter; import com.google.common.collect.ImmutableMap; @@ -76,6 +77,26 @@ public class ContentBuilder { } /** + * Create resource. If parent resource(s) do not exist they are created + * automatically using <code>nt:unstructured</code> nodes. + * @param path Page path + * @param properties Properties for resource. + * @return Resource object + */ + @SuppressWarnings("unchecked") + public final Resource resource(String path, Object... properties) { + if (properties == null || properties.length == 0) { + return resource(path); + } + else if (properties.length == 1 && properties[0] instanceof Map) { + return resource(path, (Map<String,Object>)properties[0]); + } + else { + return resource(path, MapArgsConverter.toMap(properties)); + } + } + + /** * Ensure that a resource exists at the given path. If not, it is created * using <code>nt:unstructured</code> node type. * @param path Resource path diff --git a/src/main/java/org/apache/sling/testing/mock/sling/builder/package-info.java b/src/main/java/org/apache/sling/testing/mock/sling/builder/package-info.java index 942005f..e8a9066 100644 --- a/src/main/java/org/apache/sling/testing/mock/sling/builder/package-info.java +++ b/src/main/java/org/apache/sling/testing/mock/sling/builder/package-info.java @@ -19,5 +19,5 @@ /** * Content builder for creating test content. */ [email protected]("1.0") [email protected]("1.1") package org.apache.sling.testing.mock.sling.builder; diff --git a/src/test/java/org/apache/sling/testing/mock/sling/builder/ContentBuilderTest.java b/src/test/java/org/apache/sling/testing/mock/sling/builder/ContentBuilderTest.java index fc4ab4e..7e8ecb5 100644 --- a/src/test/java/org/apache/sling/testing/mock/sling/builder/ContentBuilderTest.java +++ b/src/test/java/org/apache/sling/testing/mock/sling/builder/ContentBuilderTest.java @@ -46,11 +46,23 @@ public class ContentBuilderTest { } @Test - public void testResourceWithProperties() { - Resource resource = context.create().resource( - "/content/test1/resource2", - ImmutableMap.<String, Object> builder().put("jcr:title", "Test Title").put("stringProp", "value1") - .build()); + public void testResourceWithProperties_Map() { + Resource resource = context.create().resource("/content/test1/resource2", ImmutableMap.<String,Object>builder() + .put("jcr:title", "Test Title") + .put("stringProp", "value1") + .build()); + assertNotNull(resource); + assertEquals("resource2", resource.getName()); + ValueMap props = ResourceUtil.getValueMap(resource); + assertEquals("Test Title", props.get("jcr:title", String.class)); + assertEquals("value1", props.get("stringProp", String.class)); + } + + @Test + public void testResourceWithProperties_ObjectArray() { + Resource resource = context.create().resource("/content/test1/resource2", + "jcr:title", "Test Title", + "stringProp", "value1"); assertNotNull(resource); assertEquals("resource2", resource.getName()); ValueMap props = ResourceUtil.getValueMap(resource); -- To stop receiving notification emails like this one, please contact "[email protected]" <[email protected]>.
