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.SlingContextImpl
Defines AEM context objects with lazy initialization.
Should not be used directly but via the JUnit 4 rule or JUnit 5 extension.
-
Field Summary
Fields inherited from class org.apache.sling.testing.mock.sling.context.SlingContextImpl
contentBuilder, contentLoader, contentLoaderAutoCommit, request, resourceBuilder, resourceResolver, resourceResolverFactory, resourceResolverType, response, slingScriptHelper, uniqueRootFields inherited from class org.apache.sling.testing.mock.osgi.context.OsgiContextImpl
componentContext -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription@NotNull com.day.cq.dam.api.AssetManager@NotNull com.day.cq.wcm.api.policies.ContentPolicyMappingcontentPolicyMapping(@NotNull String resourceType, @NotNull 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 String resourceType, Map<String, 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.Page@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 String pagePath) Set current Page in request (viaComponentContext).@Nullable org.apache.sling.api.resource.ResourcecurrentResource(@Nullable org.apache.sling.api.resource.Resource resource) com.adobe.granite.asset.api.AssetManagerprotected @NotNull org.apache.sling.api.resource.ResourceResolverFactory@NotNull com.day.cq.wcm.api.PageManagerprotected voidprotected @Nullable ObjectresolveSlingBindingProperty(@NotNull String property, @NotNull org.apache.sling.api.SlingHttpServletRequest bindingsContextRequest) resourceResolverFactoryActivatorPropsMergeWithAemDefault(@Nullable Map<String, 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 UniqueRootCreate 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, slingScriptHelperMethods 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
-
Constructor Details
-
AemContextImpl
public AemContextImpl()
-
-
Method Details
-
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 Map<String,Object> resourceResolverFactoryActivatorPropsMergeWithAemDefault(@Nullable @Nullable Map<String, 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
-
graniteAssetManager
@NotNull public com.adobe.granite.asset.api.AssetManager graniteAssetManager()- Returns:
- Adobe Granite Asset manager
-
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
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
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 String resourceType, Map<String, 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 String resourceType, @NotNull @NotNull 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 Object resolveSlingBindingProperty(@NotNull @NotNull String property, @NotNull @NotNull org.apache.sling.api.SlingHttpServletRequest bindingsContextRequest) - Overrides:
resolveSlingBindingPropertyin classorg.apache.sling.testing.mock.sling.context.SlingContextImpl
-