[ 
https://issues.apache.org/jira/browse/SLING-5356?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15458657#comment-15458657
 ] 

Stefan Seifert commented on SLING-5356:
---------------------------------------

after playing around with the ResourceBuilder in integration tests i've some 
questions about the API usage/current implementation:

A) why not supporting absolute paths for resource creation?
example 1:
{noformat}
resourceBuilder = 
getService(ResourceBuilder.class).forResolver(resourceResolver);
resourceBuilder.resource("content/page1", "sling:config-ref", 
"/conf/content/page1");
{noformat}
it would be clearer/cleaner to just write /content/page1 to make sure this 
resource starts at the root, and not at an perhaps unknown parent location.
currently it's completely forbidden to use absoulte paths.

B) reusing resourcebuilder instances
example 2:
{noformat}
resourceBuilder = 
getService(ResourceBuilder.class).forResolver(resourceResolver);
resourceBuilder.resource("content/page1");
resourceBuilder.resource("content/page2");
{noformat}
this produces not the expected result - it produces
/content/page1
/content/page1/content/page2
instead of 
/content/page1
/content/page2

it would be useful if the resourcebuilder returned by a resource method has a 
new parent set, but not the builder instance initially applyed the resource 
method on.
currently the only way to get the expected result is something like:

example 3:
{noformat}
resourceBuilder = 
getService(ResourceBuilder.class).forResolver(resourceResolver);
resourceBuilder.resource("content/page1")
.atParent()
resource("content/page2");
{noformat}

but if creating bigger content structures it makes sense to not use one 
gigantic fluent line, but split if up in smaller parts.

[~bdelacretaz] what do you think?


> New ResourceBuilder module - fluent API to create content structures
> --------------------------------------------------------------------
>
>                 Key: SLING-5356
>                 URL: https://issues.apache.org/jira/browse/SLING-5356
>             Project: Sling
>          Issue Type: New Feature
>          Components: General
>            Reporter: Bertrand Delacretaz
>            Assignee: Bertrand Delacretaz
>            Priority: Minor
>
> As discussed recently on our dev list the {{ContentBuilder}} currently 
> provided by the Sling Mocks library [1] can be very useful in testing.  
> _(edit: while implementing I have diverged from that idea and created a new, 
> more powerful {{ResourceBuilder}} API, for now that {{ContentBuilder}} stays 
> unchanged)_.
> In order to make it usable for both client-side and server-side testing (as 
> well as in server-side code) I'm planning to
> * Extract it into its own module
> * Define an API that allows for creating nodes and properties, importing JSON 
> and other files via the Sling ContentLoader and providing a simple a way to 
> cleanup the test content
> * Implement (first) a server-side version of that API
> * Implement (as a second priority) a client-side version that can be used in 
> test run via HTTP
> This shouldn't affect the existing Sling Mocks library users, except maybe 
> forcing them to rebuild their tests to use the new API.
> [1] 
> https://sling.apache.org/documentation/development/sling-mock.html#building-content



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to