Class SlingContext

  • All Implemented Interfaces:
    org.junit.rules.TestRule

    @ProviderType
    public final class SlingContext
    extends SlingContextImpl
    implements org.junit.rules.TestRule
    JUnit rule for setting up and tearing down Sling context objects for unit tests. You can use SlingContextBuilder alternatively to the constructors on this class - it offers more options and fine-grained control about setting up the test context.
    • Constructor Detail

      • SlingContext

        public SlingContext​(@NotNull
                            @NotNull ResourceResolverType resourceResolverType)
        Initialize Sling context with resource resolver type.
        Parameters:
        resourceResolverType - Resource resolver type.
      • SlingContext

        public SlingContext​(@NotNull
                            @NotNull org.apache.sling.testing.mock.osgi.context.ContextCallback<T> afterSetUpCallback)
        Initialize Sling context with default resource resolver type: MockSling.DEFAULT_RESOURCERESOLVER_TYPE.
        Type Parameters:
        T - context type
        Parameters:
        afterSetUpCallback - Allows the application to register an own callback function that is called after the built-in setup rules are executed.
      • SlingContext

        public SlingContext​(@NotNull
                            @NotNull org.apache.sling.testing.mock.osgi.context.ContextCallback<T> afterSetUpCallback,
                            @NotNull
                            @NotNull ResourceResolverType resourceResolverType)
        Initialize Sling context with resource resolver type.
        Type Parameters:
        T - context type
        Parameters:
        afterSetUpCallback - Allows the application to register an own callback function that is called after the built-in setup rules are executed.
        resourceResolverType - Resource resolver type.
      • SlingContext

        public SlingContext​(@NotNull
                            @NotNull org.apache.sling.testing.mock.osgi.context.ContextCallback<U> afterSetUpCallback,
                            @NotNull
                            @NotNull org.apache.sling.testing.mock.osgi.context.ContextCallback<V> beforeTearDownCallback)
        Initialize Sling context with default resource resolver type: MockSling.DEFAULT_RESOURCERESOLVER_TYPE.
        Type Parameters:
        U - context type
        V - context type
        Parameters:
        afterSetUpCallback - Allows the application to register an own callback function that is called after the built-in setup rules are executed.
        beforeTearDownCallback - Allows the application to register an own callback function that is called before the built-in teardown rules are executed.
      • SlingContext

        public SlingContext​(@NotNull
                            @NotNull org.apache.sling.testing.mock.osgi.context.ContextCallback<U> afterSetUpCallback,
                            @NotNull
                            @NotNull org.apache.sling.testing.mock.osgi.context.ContextCallback<V> beforeTearDownCallback,
                            @NotNull
                            @NotNull ResourceResolverType resourceResolverType)
        Initialize Sling context with resource resolver type.
        Type Parameters:
        U - context type
        V - context type
        Parameters:
        afterSetUpCallback - Allows the application to register an own callback function that is called after the built-in setup rules are executed.
        beforeTearDownCallback - Allows the application to register an own callback function that is called before the built-in teardown rules are executed.
        resourceResolverType - Resource resolver type.
    • Method Detail

      • apply

        public org.junit.runners.model.Statement apply​(org.junit.runners.model.Statement base,
                                                       org.junit.runner.Description description)
        Specified by:
        apply in interface org.junit.rules.TestRule