Class 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.
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static interface  TeleporterRule.Customizer
      Customizer is used client-side to setup the server URL and other parameters
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static java.lang.String CLIENT_CLASS
      Name of the implementation class to use when running on the client side
      static java.lang.String CUSTOMIZER_PATTERN
      Class name pattern for Customizers
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      static TeleporterRule forClass​(java.lang.Class<?> classUnderTest)
      Build a TeleporterRule for the given class, with no client setup options
      static TeleporterRule forClass​(java.lang.Class<?> classUnderTest, java.lang.String clientSetupOptions)
      Build a TeleporterRule for the given class, with optional clientSetupOptions.
      <T> T getService​(java.lang.Class<T> serviceClass)
      If running on the server side, get an OSGi service
      <T> T getService​(java.lang.Class<T> serviceClass, java.lang.String ldapFilter)
      If running on the server side, get an OSGi service specified by an LDAP service filter
      static boolean isServerSide()
      True if running on the server-side.
      TeleporterRule withResources​(java.lang.String... paths)
      Tell the concrete teleporter to embed resources, based on their path, in the test bundle.
      • Methods inherited from class org.junit.rules.ExternalResource

        apply
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • CLIENT_CLASS

        public static final java.lang.String CLIENT_CLASS
        Name of the implementation class to use when running on the client side
        See Also:
        Constant Field Values
      • CUSTOMIZER_PATTERN

        public static final java.lang.String CUSTOMIZER_PATTERN
        Class name pattern for Customizers
        See Also:
        Constant Field Values
    • Method Detail

      • isServerSide

        public static boolean isServerSide()
        True if running on the server-side.
      • forClass

        public static TeleporterRule forClass​(java.lang.Class<?> classUnderTest)
        Build a TeleporterRule for the given class, with no client setup options
      • forClass

        public static TeleporterRule forClass​(java.lang.Class<?> classUnderTest,
                                              java.lang.String clientSetupOptions)
        Build a TeleporterRule for the given class, with optional clientSetupOptions.
        Parameters:
        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)
      • getService

        public final <T> T getService​(java.lang.Class<T> serviceClass)
        If running on the server side, get an OSGi service
      • getService

        public <T> T getService​(java.lang.Class<T> serviceClass,
                                java.lang.String ldapFilter)
        If running on the server side, get an OSGi service specified by an LDAP service filter
      • withResources

        public TeleporterRule withResources​(java.lang.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.