@ConsumerType public class SlingContextImpl extends OsgiContextImpl
Modifier and Type | Field and Description |
---|---|
protected ContentBuilder |
contentBuilder |
protected ContentLoader |
contentLoader |
protected ContentLoader |
contentLoaderAutoCommit |
protected MockSlingHttpServletRequest |
request |
protected 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 |
componentContext
Constructor and Description |
---|
SlingContextImpl() |
Modifier and Type | Method and Description |
---|---|
void |
addModelsForClasses(java.lang.Class... classes)
Search classpath for given class names to scan for and register all classes with @Model annotation.
|
void |
addModelsForClasses(java.lang.String... classNames)
Search classpath for given class names to scan for and register all classes with @Model annotation.
|
void |
addModelsForPackage(java.lang.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 java.lang.String packageName)
Search classpath for given java package names (and sub packages) to scan for and
register all classes with @Model annotation.
|
@NotNull 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 java.lang.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 java.lang.Class<T1> adaptableClass,
@NotNull java.lang.Class<T2> adapterClass,
@NotNull java.util.function.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 java.lang.Class<T1> adaptableClass,
@NotNull java.lang.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 java.lang.Object |
resolveSlingBindingProperty(@NotNull java.lang.String property)
Deprecated.
|
protected @Nullable java.lang.Object |
resolveSlingBindingProperty(@NotNull java.lang.String property,
@NotNull org.apache.sling.api.SlingHttpServletRequest request)
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(java.lang.String... runModes)
Set current run mode(s).
|
protected void |
setRegisterSlingModelsFromClassPath(boolean registerSlingModelsFromClassPath) |
protected void |
setResourceResolverFactoryActivatorProps(@Nullable java.util.Map<java.lang.String,java.lang.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, 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 ResourceBuilder resourceBuilder
protected UniqueRoot uniqueRoot
protected void setResourceResolverType(@Nullable @Nullable ResourceResolverType resourceResolverType)
resourceResolverType
- Resource resolver typeprotected void setResourceResolverFactoryActivatorProps(@Nullable @Nullable java.util.Map<java.lang.String,java.lang.Object> props)
protected void setRegisterSlingModelsFromClassPath(boolean registerSlingModelsFromClassPath)
protected void setUp()
setUp
in class OsgiContextImpl
@NotNull protected @NotNull org.apache.sling.api.resource.ResourceResolverFactory newResourceResolverFactory()
protected void registerDefaultServices()
protected void tearDown()
tearDown
in class 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 java.lang.Object resolveSlingBindingProperty(@NotNull @NotNull java.lang.String property, @NotNull @NotNull org.apache.sling.api.SlingHttpServletRequest request)
SlingBindings
.property
- Property keyrequest
- Context request@Deprecated @Nullable protected @Nullable java.lang.Object resolveSlingBindingProperty(@NotNull @NotNull java.lang.String property)
resolveSlingBindingProperty(String, SlingHttpServletRequest)
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 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 java.lang.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 java.lang.String packageName)
packageName
- Java package namepublic final void addModelsForPackage(@NotNull java.lang.String... packageNames)
packageNames
- Java package namespublic final void addModelsForClasses(@NotNull java.lang.String... classNames)
classNames
- Java class namespublic final void addModelsForClasses(@NotNull java.lang.Class... classes)
classes
- Java classespublic final void runMode(@NotNull java.lang.String... runModes)
runModes
- Run mode(s).@NotNull public @NotNull UniqueRoot uniqueRoot()
public final <T1,T2> void registerAdapter(@NotNull @NotNull java.lang.Class<T1> adaptableClass, @NotNull @NotNull java.lang.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 java.lang.Class<T1> adaptableClass, @NotNull @NotNull java.lang.Class<T2> adapterClass, @NotNull @NotNull java.util.function.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 © 2014–2021 wcm.io. All rights reserved.