Class TeleporterRule

java.lang.Object
org.junit.rules.ExternalResource
org.apache.sling.junit.rules.TeleporterRule
All Implemented Interfaces:
org.junit.rules.TestRule

public abstract class TeleporterRule extends org.junit.rules.ExternalResource
JUnit Rule used to teleport a server-side test to a Sling instance to execute it there. See the launchpad/integration-tests module for usage examples (coming soon). A concrete TeleporterRule class is selected to match the different required behaviors of the server-side and client-side variants of this rule. The junit.core module only contains the server-side code, to minimize its dependencies, and the client-side part is in the sling testing.teleporter module.
  • Field Details

    • classUnderTest

      protected Class<?> classUnderTest
    • CLIENT_CLASS

      public static final String CLIENT_CLASS
      Name of the implementation class to use when running on the client side
      See Also:
    • CUSTOMIZER_PATTERN

      public static final String CUSTOMIZER_PATTERN
      Class name pattern for Customizers
      See Also:
    • embeddedResourcePaths

      protected List<String> embeddedResourcePaths
  • Constructor Details

  • Method Details

    • setClassUnderTest

      protected void setClassUnderTest(Class<?> c)
    • isServerSide

      public static boolean isServerSide()
      True if running on the server-side.
      Returns:
      true if running server-side, false otherwise
    • forClass

      public static TeleporterRule forClass(Class<?> classUnderTest)
      Build a TeleporterRule for the given class, with no client setup options.
      Parameters:
      classUnderTest - the class under test
      Returns:
      the teleporter rule
    • forClass

      public static TeleporterRule forClass(Class<?> classUnderTest, String clientSetupOptions)
      Build a TeleporterRule for the given class, with optional clientSetupOptions.
      Parameters:
      classUnderTest - the class under test
      clientSetupOptions - If supplied, the part of that string before the first colon is used as the class name of a Customizer (or shorthand for that if it contains no dots). The rest of the string is then passed to the Customizer so that it can be used to define options (which server to run the test on, etc)
      Returns:
      the teleporter rule
    • customize

      protected void customize()
      Use a Customizer, if one was defined, to customize this Rule
    • createInstance

      protected static <T> T createInstance(Class<T> objectClass, String className)
    • getService

      public final <T> T getService(Class<T> serviceClass)
      If running on the server side, get an OSGi service
      Type Parameters:
      T - the service type
      Parameters:
      serviceClass - the class
      Returns:
      the service instance, if one was found, or null
    • getService

      public <T> T getService(Class<T> serviceClass, String ldapFilter)
      If running on the server side, get an OSGi service specified by an LDAP service filter
      Type Parameters:
      T - the service type
      Parameters:
      serviceClass - the class
      ldapFilter - a filter to select the service
      Returns:
      the service instance, if one was found, or null
    • withResources

      public TeleporterRule withResources(String... paths)
      Tell the concrete teleporter to embed resources, based on their path, in the test bundle.
      Parameters:
      paths - 0..N resource paths to add to the current rule. A path that ends with a / causes all resources found under it to be recursively embedded as well.
      Returns:
      this enhanced rule