Package org.apache.sling.testing.mock.sling.builder

# Class ContentBuilder

java.lang.Object
org.apache.sling.testing.mock.sling.builder.ContentBuilder

public class ContentBuilder extends Object
Helper class for building test content in the resource hierarchy with as less boilerplate code as possible.

## Field Summary

Fields
Modifier and Type
Field
Description
`protected final org.apache.sling.api.resource.ResourceResolver`
`resourceResolver`
Resource resolver

## Constructor Summary

Constructors
Constructor
Description
`ContentBuilder(@NotNull org.apache.sling.api.resource.ResourceResolver resourceResolver)`

## Method Summary

Modifier and Type
Method
Description
`protected final @NotNull org.apache.sling.api.resource.Resource`
`ensureResourceExists(@NotNull String path)`
Ensure that a resource exists at the given path.
`final @NotNull org.apache.sling.api.resource.Resource`
`resource(@NotNull String path)`
Create resource.
`final @NotNull org.apache.sling.api.resource.Resource`
`resource(@NotNull String path, @NotNull Object @NotNull ... properties)`
Create resource.
`final @NotNull org.apache.sling.api.resource.Resource`
`resource(@NotNull String path, @NotNull Map<String,Object> properties)`
Create resource.
`final @NotNull org.apache.sling.api.resource.Resource`
`resource(@NotNull org.apache.sling.api.resource.Resource resource, @NotNull String name)`
Create child resource below the given parent resource.
`final @NotNull org.apache.sling.api.resource.Resource`
`resource(@NotNull org.apache.sling.api.resource.Resource resource, @NotNull String name, @NotNull Object @NotNull ... properties)`
Create child resource below the given parent resource.
`final @NotNull org.apache.sling.api.resource.Resource`
`resource(@NotNull org.apache.sling.api.resource.Resource resource, @NotNull String name, @NotNull Map<String,Object> properties)`
Create child resource below the given parent resource.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Field Details

### resourceResolver

protected final org.apache.sling.api.resource.ResourceResolver resourceResolver
Resource resolver

## Constructor Details

### ContentBuilder

public ContentBuilder(@NotNull @NotNull org.apache.sling.api.resource.ResourceResolver resourceResolver)

Parameters:
  `resourceResolver` - Resource resolver

## Method Details

### resource

@NotNull public final @NotNull org.apache.sling.api.resource.Resource resource(@NotNull @NotNull String path)
Create resource. If parent resource(s) do not exist they are created automatically using `nt:unstructured` nodes.

Parameters:
  `path` - Page path
Returns:
  Resource object

### resource

@NotNull public final @NotNull org.apache.sling.api.resource.Resource resource(@NotNull @NotNull String path, @NotNull @NotNull Map<String,Object> properties)
Create resource. If parent resource(s) do not exist they are created automatically using `nt:unstructured` nodes.

Parameters:
  `path` - Page path
  `properties` - Properties for resource.
Returns:
  Resource object

### resource

@NotNull public final @NotNull org.apache.sling.api.resource.Resource resource(@NotNull @NotNull String path, @NotNull @NotNull Object @NotNull ... properties)
Create resource. If parent resource(s) do not exist they are created automatically using `nt:unstructured` nodes.

Parameters:
  `path` - Page path
  `properties` - Properties for resource.
Returns:
  Resource object

### resource

@NotNull public final @NotNull org.apache.sling.api.resource.Resource resource(@NotNull @NotNull org.apache.sling.api.resource.Resource resource, @NotNull @NotNull String name)
Create child resource below the given parent resource.

Parameters:
  `resource` - Parent resource
  `name` - Child resource name
Returns:
  Resource object

### resource

@NotNull public final @NotNull org.apache.sling.api.resource.Resource resource(@NotNull @NotNull org.apache.sling.api.resource.Resource resource, @NotNull @NotNull String name, @NotNull @NotNull Map<String,Object> properties)
Create child resource below the given parent resource.

Parameters:
  `resource` - Parent resource
  `name` - Child resource name
  `properties` - Properties for resource.
Returns:
  Resource object

### resource

@NotNull public final @NotNull org.apache.sling.api.resource.Resource resource(@NotNull @NotNull org.apache.sling.api.resource.Resource resource, @NotNull @NotNull String name, @NotNull @NotNull Object @NotNull ... properties)
Create child resource below the given parent resource.

Parameters:
  `resource` - Parent resource
  `name` - Child resource name
  `properties` - Properties for resource.
Returns:
  Resource object

### ensureResourceExists

@NotNull protected final @NotNull org.apache.sling.api.resource.Resource ensureResourceExists(@NotNull @NotNull String path)
Ensure that a resource exists at the given path. If not, it is created using `nt:unstructured` node type.

Parameters:
  `path` - Resource path
Returns:
  Resource at path (existing or newly created)