Package org.apache.sling.junit.rules
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.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interface
Customizer is used client-side to setup the server URL and other parameters -
Field Summary
Fields -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
Meant to be instantiated viaforClass(java.lang.Class<?>)
-
Method Summary
Modifier and TypeMethodDescriptionprotected static <T> T
createInstance
(Class<T> objectClass, String className) protected void
Use a Customizer, if one was defined, to customize this Rulestatic TeleporterRule
Build a TeleporterRule for the given class, with no client setup options.static TeleporterRule
Build a TeleporterRule for the given class, with optional clientSetupOptions.final <T> T
getService
(Class<T> serviceClass) If running on the server side, get an OSGi service<T> T
getService
(Class<T> serviceClass, String ldapFilter) If running on the server side, get an OSGi service specified by an LDAP service filterstatic boolean
True if running on the server-side.protected void
setClassUnderTest
(Class<?> c) withResources
(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
after, apply, before
-
Field Details
-
classUnderTest
-
CLIENT_CLASS
Name of the implementation class to use when running on the client side- See Also:
-
CUSTOMIZER_PATTERN
Class name pattern for Customizers- See Also:
-
embeddedResourcePaths
-
-
Constructor Details
-
TeleporterRule
protected TeleporterRule()Meant to be instantiated viaforClass(java.lang.Class<?>)
-
-
Method Details
-
setClassUnderTest
-
isServerSide
public static boolean isServerSide()True if running on the server-side.- Returns:
true
if running server-side,false
otherwise
-
forClass
Build a TeleporterRule for the given class, with no client setup options.- Parameters:
classUnderTest
- the class under test- Returns:
- the teleporter rule
-
forClass
Build a TeleporterRule for the given class, with optional clientSetupOptions.- Parameters:
classUnderTest
- the class under testclientSetupOptions
- 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
-
getService
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
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 classldapFilter
- a filter to select the service- Returns:
- the service instance, if one was found, or
null
-
withResources
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
-