Package io.wcm.testing.mock.aem.context
Class AemContextImpl
- java.lang.Object
-
- org.apache.sling.testing.mock.osgi.context.OsgiContextImpl
-
- org.apache.sling.testing.mock.sling.context.SlingContextImpl
-
- io.wcm.testing.mock.aem.context.AemContextImpl
-
@ConsumerType public class AemContextImpl extends org.apache.sling.testing.mock.sling.context.SlingContextImplDefines AEM context objects with lazy initialization. Should not be used directly but via the JUnit 4 rule or JUnit 5 extension.
-
-
Constructor Summary
Constructors Constructor Description AemContextImpl()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description @NotNull com.day.cq.dam.api.AssetManagerassetManager()@NotNull com.day.cq.wcm.api.policies.ContentPolicyMappingcontentPolicyMapping(@NotNull java.lang.String resourceType, @NotNull java.lang.Object @NotNull ... properties)Creates a mocked content policy with the given properties and maps it to all content resources with the given resource type.@NotNull com.day.cq.wcm.api.policies.ContentPolicyMappingcontentPolicyMapping(@NotNull java.lang.String resourceType, java.util.Map<java.lang.String,java.lang.Object> properties)Creates a mocked content policy with the given properties and maps it to all content resources with the given resource type.@NotNull ContentBuildercreate()@Nullable com.day.cq.wcm.api.PagecurrentPage()@Nullable com.day.cq.wcm.api.PagecurrentPage(@Nullable com.day.cq.wcm.api.Page page)Set current Page in request (viaComponentContext).@Nullable com.day.cq.wcm.api.PagecurrentPage(@Nullable java.lang.String pagePath)Set current Page in request (viaComponentContext).@Nullable org.apache.sling.api.resource.ResourcecurrentResource(@Nullable org.apache.sling.api.resource.Resource resource)protected @NotNull org.apache.sling.api.resource.ResourceResolverFactorynewResourceResolverFactory()@NotNull com.day.cq.wcm.api.PageManagerpageManager()protected voidregisterDefaultServices()protected @Nullable java.lang.ObjectresolveSlingBindingProperty(@NotNull java.lang.String property, @NotNull org.apache.sling.api.SlingHttpServletRequest bindingsContextRequest)protected java.util.Map<java.lang.String,java.lang.Object>resourceResolverFactoryActivatorPropsMergeWithAemDefault(@Nullable java.util.Map<java.lang.String,java.lang.Object> customProps)Merges the given custom Resource Resolver Factory Activator OSGi configuration with the default configuration applied in AEM 6.protected voidsetResourceResolverType(@Nullable org.apache.sling.testing.mock.sling.ResourceResolverType resourceResolverType)protected voidsetUp()protected voidtearDown()@NotNull UniqueRootuniqueRoot()Create unique root paths for unit tests (and clean them up after the test run automatically).-
Methods inherited from class org.apache.sling.testing.mock.sling.context.SlingContextImpl
addModelsForClasses, addModelsForClasses, addModelsForPackage, addModelsForPackage, build, currentResource, currentResource, load, load, registerAdapter, registerAdapter, request, requestPathInfo, resolveSlingBindingProperty, resourceResolver, resourceResolverType, response, runMode, setRegisterSlingModelsFromClassPath, setResourceResolverFactoryActivatorProps, slingScriptHelper
-
Methods inherited from class org.apache.sling.testing.mock.osgi.context.OsgiContextImpl
bundleContext, componentContext, getService, getServices, registerInjectActivateService, registerInjectActivateService, registerInjectActivateService, registerInjectActivateService, registerInjectActivateService, registerInjectActivateService, registerService, registerService, registerService, registerService
-
-
-
-
Method Detail
-
registerDefaultServices
protected void registerDefaultServices()
- Overrides:
registerDefaultServicesin classorg.apache.sling.testing.mock.sling.context.SlingContextImpl
-
setResourceResolverType
protected void setResourceResolverType(@Nullable @Nullable org.apache.sling.testing.mock.sling.ResourceResolverType resourceResolverType)- Overrides:
setResourceResolverTypein classorg.apache.sling.testing.mock.sling.context.SlingContextImpl
-
newResourceResolverFactory
@NotNull protected @NotNull org.apache.sling.api.resource.ResourceResolverFactory newResourceResolverFactory()
- Overrides:
newResourceResolverFactoryin classorg.apache.sling.testing.mock.sling.context.SlingContextImpl
-
setUp
protected void setUp()
- Overrides:
setUpin classorg.apache.sling.testing.mock.sling.context.SlingContextImpl
-
tearDown
protected void tearDown()
- Overrides:
tearDownin classorg.apache.sling.testing.mock.sling.context.SlingContextImpl
-
resourceResolverFactoryActivatorPropsMergeWithAemDefault
protected final java.util.Map<java.lang.String,java.lang.Object> resourceResolverFactoryActivatorPropsMergeWithAemDefault(@Nullable @Nullable java.util.Map<java.lang.String,java.lang.Object> customProps)Merges the given custom Resource Resolver Factory Activator OSGi configuration with the default configuration applied in AEM 6. The custom configuration has higher precedence.- Parameters:
customProps- Custom config- Returns:
- Merged config
-
pageManager
@NotNull public @NotNull com.day.cq.wcm.api.PageManager pageManager()
- Returns:
- Page manager
-
assetManager
@NotNull public @NotNull com.day.cq.dam.api.AssetManager assetManager()
- Returns:
- Asset manager
-
create
@NotNull public @NotNull ContentBuilder create()
- Overrides:
createin classorg.apache.sling.testing.mock.sling.context.SlingContextImpl- Returns:
- Content builder for building test content
-
currentResource
@Nullable public @Nullable org.apache.sling.api.resource.Resource currentResource(@Nullable @Nullable org.apache.sling.api.resource.Resource resource)- Overrides:
currentResourcein classorg.apache.sling.testing.mock.sling.context.SlingContextImpl
-
currentPage
@Nullable public @Nullable com.day.cq.wcm.api.Page currentPage()
- Returns:
- Current page from
ComponentContext. If none is set the page containing the current resource. Null if no containing page exists.
-
currentPage
@Nullable public @Nullable com.day.cq.wcm.api.Page currentPage(@Nullable @Nullable java.lang.String pagePath)Set current Page in request (viaComponentContext). This also sets the current resource to the content resource of the page. You can set it to a different resources afterwards if required.- Parameters:
pagePath- Page path- Returns:
- currentPage
-
currentPage
@Nullable public @Nullable com.day.cq.wcm.api.Page currentPage(@Nullable @Nullable com.day.cq.wcm.api.Page page)Set current Page in request (viaComponentContext). This also sets the current resource to the content resource of the page. You can set it to a different resources afterwards if required.- Parameters:
page- Page- Returns:
- currentPage
-
uniqueRoot
@NotNull public @NotNull UniqueRoot uniqueRoot()
Create unique root paths for unit tests (and clean them up after the test run automatically).- Overrides:
uniqueRootin classorg.apache.sling.testing.mock.sling.context.SlingContextImpl- Returns:
- Unique root path helper
-
contentPolicyMapping
@NotNull public @NotNull com.day.cq.wcm.api.policies.ContentPolicyMapping contentPolicyMapping(@NotNull @NotNull java.lang.String resourceType, java.util.Map<java.lang.String,java.lang.Object> properties)Creates a mocked content policy with the given properties and maps it to all content resources with the given resource type. This is a shortcut to easily test your components with a content policy.- Parameters:
resourceType- Resource type that should be mapped to the content policyproperties- Properties for the content policy- Returns:
- New content policy mapping
-
contentPolicyMapping
@NotNull public @NotNull com.day.cq.wcm.api.policies.ContentPolicyMapping contentPolicyMapping(@NotNull @NotNull java.lang.String resourceType, @NotNull @NotNull java.lang.Object @NotNull ... properties)Creates a mocked content policy with the given properties and maps it to all content resources with the given resource type. This is a shortcut to easily test your components with a content policy.- Parameters:
resourceType- Resource type that should be mapped to the content policyproperties- Properties for the content policy- Returns:
- New content policy mapping
-
resolveSlingBindingProperty
@Nullable protected @Nullable java.lang.Object resolveSlingBindingProperty(@NotNull @NotNull java.lang.String property, @NotNull @NotNull org.apache.sling.api.SlingHttpServletRequest bindingsContextRequest)- Overrides:
resolveSlingBindingPropertyin classorg.apache.sling.testing.mock.sling.context.SlingContextImpl
-
-