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.ExternalResourceJUnit 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 interfaceTeleporterRule.CustomizerCustomizer is used client-side to setup the server URL and other parameters
-
Field Summary
Fields Modifier and Type Field Description protected Class<?>classUnderTeststatic StringCLIENT_CLASSName of the implementation class to use when running on the client sidestatic StringCUSTOMIZER_PATTERNClass name pattern for Customizersprotected List<String>embeddedResourcePaths
-
Constructor Summary
Constructors Modifier Constructor Description protectedTeleporterRule()Meant to be instantiated viaforClass(java.lang.Class<?>)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected static <T> TcreateInstance(Class<T> objectClass, String className)protected voidcustomize()Use a Customizer, if one was defined, to customize this Rulestatic TeleporterRuleforClass(Class<?> classUnderTest)Build a TeleporterRule for the given class, with no client setup options.static TeleporterRuleforClass(Class<?> classUnderTest, String clientSetupOptions)Build a TeleporterRule for the given class, with optional clientSetupOptions.<T> TgetService(Class<T> serviceClass)If running on the server side, get an OSGi service<T> TgetService(Class<T> serviceClass, String ldapFilter)If running on the server side, get an OSGi service specified by an LDAP service filterstatic booleanisServerSide()True if running on the server-side.protected voidsetClassUnderTest(Class<?> c)TeleporterRulewithResources(String... paths)Tell the concrete teleporter to embed resources, based on their path, in the test bundle.
-
-
-
Field Detail
-
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:
- Constant Field Values
-
CUSTOMIZER_PATTERN
public static final String CUSTOMIZER_PATTERN
Class name pattern for Customizers- See Also:
- Constant Field Values
-
-
Constructor Detail
-
TeleporterRule
protected TeleporterRule()
Meant to be instantiated viaforClass(java.lang.Class<?>)
-
-
Method Detail
-
setClassUnderTest
protected void setClassUnderTest(Class<?> c)
-
isServerSide
public static boolean isServerSide()
True if running on the server-side.- Returns:
trueif running server-side,falseotherwise
-
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 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
-
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 classldapFilter- 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
-
-