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 MockSlingHttpServletRequest |
request |
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 |
addModelsForPackage(String packageName)
Scan classpaths for given package name (and sub packages) to scan for and
register all classes with @Model annotation.
|
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() |
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()
Returns the singleton resource resolver bound to this context.
|
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).
|
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 ContentBuilder contentBuilder
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.OsgiContextImplprotected org.apache.sling.api.resource.ResourceResolverFactory newResourceResolverFactory()
protected void registerDefaultServices()
protected void tearDown()
tearDown in class org.apache.sling.testing.mock.osgi.context.OsgiContextImplpublic 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 ContentBuilder create()
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 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–2016 The Apache Software Foundation. All rights reserved.