public class SlingContextImpl
extends org.apache.sling.testing.mock.osgi.context.OsgiContextImpl
SlingContext
JUnit
rule.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(String packageName)
Search classpath for given java package names (and sub packages) to scan for and
register all classes with @Model annotation.
|
org.apache.sling.resourcebuilder.api.ResourceBuilder |
build()
Creates a
ResourceBuilder object for easily creating test content. |
ContentBuilder |
create() |
org.apache.sling.api.resource.Resource |
currentResource() |
org.apache.sling.api.resource.Resource |
currentResource(org.apache.sling.api.resource.Resource resource)
Set current resource in request.
|
org.apache.sling.api.resource.Resource |
currentResource(String resourcePath)
Set current resource in request.
|
ContentLoader |
load() |
ContentLoader |
load(boolean autoCommit) |
protected org.apache.sling.api.resource.ResourceResolverFactory |
newResourceResolverFactory()
Initialize mocked resource resolver factory.
|
<T1,T2> void |
registerAdapter(Class<T1> adaptableClass,
Class<T2> adapterClass,
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(Class<T1> adaptableClass,
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
|
MockSlingHttpServletRequest |
request() |
MockRequestPathInfo |
requestPathInfo() |
org.apache.sling.api.resource.ResourceResolver |
resourceResolver() |
ResourceResolverType |
resourceResolverType() |
MockSlingHttpServletResponse |
response() |
void |
runMode(String... runModes)
Set current run mode(s).
|
protected void |
setResourceResolverFactoryActivatorProps(Map<String,Object> props) |
protected void |
setResourceResolverType(ResourceResolverType resourceResolverType) |
protected void |
setUp()
Setup actions before test method execution
|
org.apache.sling.api.scripting.SlingScriptHelper |
slingScriptHelper() |
protected void |
tearDown()
Teardown actions after test method execution
|
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(ResourceResolverType resourceResolverType)
resourceResolverType
- Resource resolver typeprotected void setResourceResolverFactoryActivatorProps(Map<String,Object> props)
protected void setUp()
setUp
in class org.apache.sling.testing.mock.osgi.context.OsgiContextImpl
protected org.apache.sling.api.resource.ResourceResolverFactory newResourceResolverFactory()
protected void registerDefaultServices()
protected void tearDown()
tearDown
in class org.apache.sling.testing.mock.osgi.context.OsgiContextImpl
public final ResourceResolverType resourceResolverType()
public final org.apache.sling.api.resource.ResourceResolver resourceResolver()
public final MockSlingHttpServletRequest request()
public final MockRequestPathInfo requestPathInfo()
public final MockSlingHttpServletResponse response()
public final org.apache.sling.api.scripting.SlingScriptHelper slingScriptHelper()
public ContentLoader load()
public ContentLoader load(boolean autoCommit)
autoCommit
- Automatically commit changes after loading content (default: true)public ContentBuilder create()
public 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.public final org.apache.sling.api.resource.Resource currentResource()
public final org.apache.sling.api.resource.Resource currentResource(String resourcePath)
resourcePath
- Resource pathpublic final org.apache.sling.api.resource.Resource currentResource(org.apache.sling.api.resource.Resource resource)
resource
- Resourcepublic final void addModelsForPackage(String packageName)
packageName
- Java package namepublic final void addModelsForPackage(String... packageNames)
packageNames
- Java package namespublic final void addModelsForClasses(String... classNames)
classNames
- Java class namespublic final void addModelsForClasses(Class... classes)
classes
- Java classespublic final void runMode(String... runModes)
runModes
- Run mode(s).public UniqueRoot uniqueRoot()
public final <T1,T2> void registerAdapter(Class<T1> adaptableClass, Class<T2> adapterClass, 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(Class<T1> adaptableClass, Class<T2> adapterClass, 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–2018 The Apache Software Foundation. All rights reserved.