Class 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, uniqueRoot
      • Fields inherited from class org.apache.sling.testing.mock.osgi.context.OsgiContextImpl

        componentContext
    • 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.AssetManager assetManager()  
      @NotNull com.day.cq.wcm.api.policies.ContentPolicyMapping contentPolicyMapping​(@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.ContentPolicyMapping contentPolicyMapping​(@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 ContentBuilder create()  
      @Nullable com.day.cq.wcm.api.Page currentPage()  
      @Nullable com.day.cq.wcm.api.Page currentPage​(@Nullable com.day.cq.wcm.api.Page page)
      Set current Page in request (via ComponentContext).
      @Nullable com.day.cq.wcm.api.Page currentPage​(@Nullable String pagePath)
      Set current Page in request (via ComponentContext).
      @Nullable org.apache.sling.api.resource.Resource currentResource​(@Nullable org.apache.sling.api.resource.Resource resource)  
      protected @NotNull org.apache.sling.api.resource.ResourceResolverFactory newResourceResolverFactory()  
      @NotNull com.day.cq.wcm.api.PageManager pageManager()  
      protected void registerDefaultServices()  
      protected @Nullable Object resolveSlingBindingProperty​(@NotNull String property, @NotNull org.apache.sling.api.SlingHttpServletRequest bindingsContextRequest)  
      protected Map<String,​Object> 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 void setResourceResolverType​(@Nullable org.apache.sling.testing.mock.sling.ResourceResolverType resourceResolverType)  
      protected void setUp()  
      protected void tearDown()  
      @NotNull UniqueRoot uniqueRoot()
      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, registerService, registerService, registerService, registerService
    • Constructor Detail

      • AemContextImpl

        public AemContextImpl()
    • Method Detail

      • registerDefaultServices

        protected void registerDefaultServices()
        Overrides:
        registerDefaultServices in class org.apache.sling.testing.mock.sling.context.SlingContextImpl
      • setResourceResolverType

        protected void setResourceResolverType​(@Nullable
                                               @Nullable org.apache.sling.testing.mock.sling.ResourceResolverType resourceResolverType)
        Overrides:
        setResourceResolverType in class org.apache.sling.testing.mock.sling.context.SlingContextImpl
      • newResourceResolverFactory

        @NotNull
        protected @NotNull org.apache.sling.api.resource.ResourceResolverFactory newResourceResolverFactory()
        Overrides:
        newResourceResolverFactory in class org.apache.sling.testing.mock.sling.context.SlingContextImpl
      • setUp

        protected void setUp()
        Overrides:
        setUp in class org.apache.sling.testing.mock.sling.context.SlingContextImpl
      • tearDown

        protected void tearDown()
        Overrides:
        tearDown in class org.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
      • create

        @NotNull
        public @NotNull ContentBuilder create()
        Overrides:
        create in class org.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:
        currentResource in class org.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 String pagePath)
        Set current Page in request (via ComponentContext). 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 (via ComponentContext). 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:
        uniqueRoot in class org.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 policy
        properties - 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 policy
        properties - 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:
        resolveSlingBindingProperty in class org.apache.sling.testing.mock.sling.context.SlingContextImpl