@ConsumerType
public class SlingContextImpl
extends org.apache.sling.testing.mock.osgi.context.OsgiContextImpl
Modifier and Type | Field and Description |
---|---|
protected ContentBuilder |
contentBuilder |
protected ContentLoader |
contentLoader |
protected ContentLoader |
contentLoaderAutoCommit |
protected MockSlingHttpServletRequest |
request |
protected org.apache.sling.resourcebuilder.api.ResourceBuilder |
resourceBuilder |
protected org.apache.sling.api.resource.ResourceResolver |
resourceResolver |
protected org.apache.sling.api.resource.ResourceResolverFactory |
resourceResolverFactory |
protected ResourceResolverType |
resourceResolverType |
protected MockSlingHttpServletResponse |
response |
protected org.apache.sling.api.scripting.SlingScriptHelper |
slingScriptHelper |
protected UniqueRoot |
uniqueRoot |
Constructor and Description |
---|
SlingContextImpl() |
Modifier and Type | Method and Description |
---|---|
void |
addModelsForClasses(Class... classes)
Search classpath for given class names to scan for and register all classes with @Model annotation.
|
void |
addModelsForClasses(String... classNames)
Search classpath for given class names to scan for and register all classes with @Model annotation.
|
void |
addModelsForPackage(String... packageNames)
Search classpath for given java package names (and sub packages) to scan for and
register all classes with @Model annotation.
|
void |
addModelsForPackage(@NotNull String packageName)
Search classpath for given java package names (and sub packages) to scan for and
register all classes with @Model annotation.
|
@NotNull org.apache.sling.resourcebuilder.api.ResourceBuilder |
build()
Creates a
ResourceBuilder object for easily creating test content. |
@NotNull ContentBuilder |
create()
Creates a
ContentBuilder object for easily creating test content. |
@Nullable org.apache.sling.api.resource.Resource |
currentResource() |
@Nullable org.apache.sling.api.resource.Resource |
currentResource(@Nullable org.apache.sling.api.resource.Resource resource)
Set current resource in request.
|
@Nullable org.apache.sling.api.resource.Resource |
currentResource(@Nullable String resourcePath)
Set current resource in request.
|
@NotNull ContentLoader |
load() |
@NotNull ContentLoader |
load(boolean autoCommit) |
protected @NotNull org.apache.sling.api.resource.ResourceResolverFactory |
newResourceResolverFactory()
Initialize mocked resource resolver factory.
|
<T1,T2> void |
registerAdapter(@NotNull Class<T1> adaptableClass,
@NotNull Class<T2> adapterClass,
@NotNull com.google.common.base.Function<T1,T2> adaptHandler)
Create a Sling AdapterFactory on the fly which can adapt from
adaptableClass
to adapterClass and delegates the adapter mapping to the given adaptHandler function. |
<T1,T2> void |
registerAdapter(@NotNull Class<T1> adaptableClass,
@NotNull Class<T2> adapterClass,
T2 adapter)
Create a Sling AdapterFactory on the fly which can adapt from
adaptableClass
to adapterClass and just returns the given value as result. |
protected void |
registerDefaultServices()
Default services that should be available for every unit test
|
@NotNull MockSlingHttpServletRequest |
request() |
@NotNull MockRequestPathInfo |
requestPathInfo() |
protected @Nullable Object |
resolveSlingBindingProperty(@NotNull String property)
Dynamically resolve property request for current request
SlingBindings . |
@NotNull org.apache.sling.api.resource.ResourceResolver |
resourceResolver()
Returns the singleton resource resolver bound to this context.
|
@NotNull ResourceResolverType |
resourceResolverType() |
@NotNull MockSlingHttpServletResponse |
response() |
void |
runMode(String... runModes)
Set current run mode(s).
|
protected void |
setRegisterSlingModelsFromClassPath(boolean registerSlingModelsFromClassPath) |
protected void |
setResourceResolverFactoryActivatorProps(@Nullable Map<String,Object> props) |
protected void |
setResourceResolverType(@Nullable ResourceResolverType resourceResolverType) |
protected void |
setUp()
Setup actions before test method execution
|
@NotNull org.apache.sling.api.scripting.SlingScriptHelper |
slingScriptHelper() |
protected void |
tearDown()
Teardown actions after test method execution
|
@NotNull UniqueRoot |
uniqueRoot()
Create unique root paths for unit tests (and clean them up after the test run automatically).
|
bundleContext, componentContext, getService, getServices, registerInjectActivateService, registerInjectActivateService, registerInjectActivateService, registerService, registerService, registerService, registerService
protected org.apache.sling.api.resource.ResourceResolverFactory resourceResolverFactory
protected ResourceResolverType resourceResolverType
protected org.apache.sling.api.resource.ResourceResolver resourceResolver
protected MockSlingHttpServletRequest request
protected MockSlingHttpServletResponse response
protected org.apache.sling.api.scripting.SlingScriptHelper slingScriptHelper
protected ContentLoader contentLoader
protected ContentLoader contentLoaderAutoCommit
protected ContentBuilder contentBuilder
protected org.apache.sling.resourcebuilder.api.ResourceBuilder resourceBuilder
protected UniqueRoot uniqueRoot
protected void setResourceResolverType(@Nullable @Nullable ResourceResolverType resourceResolverType)
resourceResolverType
- Resource resolver typeprotected void setResourceResolverFactoryActivatorProps(@Nullable @Nullable Map<String,Object> props)
protected void setRegisterSlingModelsFromClassPath(boolean registerSlingModelsFromClassPath)
protected void setUp()
setUp
in class org.apache.sling.testing.mock.osgi.context.OsgiContextImpl
@NotNull protected @NotNull org.apache.sling.api.resource.ResourceResolverFactory newResourceResolverFactory()
protected void registerDefaultServices()
protected void tearDown()
tearDown
in class org.apache.sling.testing.mock.osgi.context.OsgiContextImpl
@NotNull public final @NotNull ResourceResolverType resourceResolverType()
@NotNull public final @NotNull org.apache.sling.api.resource.ResourceResolver resourceResolver()
@NotNull public final @NotNull MockSlingHttpServletRequest request()
@Nullable protected @Nullable Object resolveSlingBindingProperty(@NotNull @NotNull String property)
SlingBindings
.property
- Property key@NotNull public final @NotNull MockRequestPathInfo requestPathInfo()
@NotNull public final @NotNull MockSlingHttpServletResponse response()
@NotNull public final @NotNull org.apache.sling.api.scripting.SlingScriptHelper slingScriptHelper()
@NotNull public @NotNull ContentLoader load()
@NotNull public @NotNull ContentLoader load(boolean autoCommit)
autoCommit
- Automatically commit changes after loading content (default: true)@NotNull public @NotNull ContentBuilder create()
ContentBuilder
object for easily creating test content.
This API was part of Sling Mocks since version 1.x.
You can use alternatively the build()
method and use the ResourceBuilder
API.@NotNull public @NotNull org.apache.sling.resourcebuilder.api.ResourceBuilder build()
ResourceBuilder
object for easily creating test content.
This is a separate API which can be used inside sling mocks or in a running instance.
You can use alternatively the create()
method to use the ContentBuilder
API.@Nullable public final @Nullable org.apache.sling.api.resource.Resource currentResource()
@Nullable public final @Nullable org.apache.sling.api.resource.Resource currentResource(@Nullable @Nullable String resourcePath)
resourcePath
- Resource path@Nullable public @Nullable org.apache.sling.api.resource.Resource currentResource(@Nullable @Nullable org.apache.sling.api.resource.Resource resource)
resource
- Resourcepublic final void addModelsForPackage(@NotNull @NotNull String packageName)
packageName
- Java package namepublic final void addModelsForPackage(@NotNull String... packageNames)
packageNames
- Java package namespublic final void addModelsForClasses(@NotNull String... classNames)
classNames
- Java class namespublic final void addModelsForClasses(@NotNull Class... classes)
classes
- Java classespublic final void runMode(@NotNull String... runModes)
runModes
- Run mode(s).@NotNull public @NotNull UniqueRoot uniqueRoot()
public final <T1,T2> void registerAdapter(@NotNull @NotNull Class<T1> adaptableClass, @NotNull @NotNull Class<T2> adapterClass, @NotNull T2 adapter)
adaptableClass
to adapterClass
and just returns the given value as result.T1
- Adaptable typeT2
- Adapter typeadaptableClass
- Class to adapt fromadapterClass
- Class to adapt toadapter
- Object which is always returned for this adaption.public final <T1,T2> void registerAdapter(@NotNull @NotNull Class<T1> adaptableClass, @NotNull @NotNull Class<T2> adapterClass, @NotNull @NotNull com.google.common.base.Function<T1,T2> adaptHandler)
adaptableClass
to adapterClass
and delegates the adapter mapping to the given adaptHandler
function.T1
- Adaptable typeT2
- Adapter typeadaptableClass
- Class to adapt fromadapterClass
- Class to adapt toadaptHandler
- Function to handle the adaptionCopyright © 2007–2019 The Apache Software Foundation. All rights reserved.