Class ServerSetup
- java.lang.Object
-
- org.apache.sling.testing.serversetup.ServerSetup
-
public class ServerSetup extends Object
This is an evolution of the SlingTestBase/JarExecutor combination that we had at revision 1201491, used to control the server side of integration tests. This class allows a number of startup and shutdown phases to be defined, and executes some or all of them in a specified order, according to a property which lists their names. Flexibility in those startup/shutdown phases allows for creating test scenarios like automated testing of system upgrades, where you would for example:1. Start the old runnable jar 2. Wait for it to be ready 3. Install some bundles and wait for them to be ready 4. Create some content in that version 5. Stop that jar 6. Start the new runnable jar 7. Wait for it to be ready 8. Run tests against that new jar to verify the upgrade
Running the whole thing might take a long time, so when debugging the upgrade or the tests you might want to restart from a state saved at step 5, and only run steps 6 to 8, for example. Those steps are SetupPhase objects identified by their name, and specifying a partial list of names allows you to run only some of them in a given test run, speeding up development and troubleshooting as much as possible. TODO: the companion samples/integration-tests module should be updated to use this class to setup the Sling server that it tests, instead of the SlingTestBase class that it currently uses.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
ServerSetup.SetupException
-
Field Summary
Fields Modifier and Type Field Description static String
PHASES_TO_RUN_PROP
Config property name: comma-separated list of phases to runstatic String
PROP_NAME_PREFIX
Prefix used for our property namesstatic String
SERVER_BASE_URL
Context attribute: server access URLstatic String
SHUTDOWN_ID_SUFFIX
Standard suffix for shutdown tasks IDs
-
Constructor Summary
Constructors Constructor Description ServerSetup()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addSetupPhase(SetupPhase p)
Add a SetupPhase to our list.Properties
getConfig()
Return the configuration Properties that were set bysetConfig(java.util.Properties)
Map<String,Object>
getContext()
Return a context that can use to communicate among them and with the outside.List<String>
getPhasesToRun()
Return the IDs of phases that should runvoid
setConfig(Properties props)
Set configuration and reset our lists of phases that already ran or failed.void
setupTestServer()
Runs all startup phases that have not run yet, and throws an Exception or call Junit's fail() method if one of them fails or failed in a previous call of this method.void
shutdown()
Called by a shutdown hook to run all shutdown phases, but can also be called explicitly, each shutdown phase only runs once anyway.
-
-
-
Field Detail
-
PROP_NAME_PREFIX
public static final String PROP_NAME_PREFIX
Prefix used for our property names- See Also:
- Constant Field Values
-
PHASES_TO_RUN_PROP
public static final String PHASES_TO_RUN_PROP
Config property name: comma-separated list of phases to run- See Also:
- Constant Field Values
-
SHUTDOWN_ID_SUFFIX
public static final String SHUTDOWN_ID_SUFFIX
Standard suffix for shutdown tasks IDs- See Also:
- Constant Field Values
-
SERVER_BASE_URL
public static final String SERVER_BASE_URL
Context attribute: server access URL- See Also:
- Constant Field Values
-
-
Method Detail
-
setupTestServer
public void setupTestServer() throws Exception
Runs all startup phases that have not run yet, and throws an Exception or call Junit's fail() method if one of them fails or failed in a previous call of this method. This can be called several times, will only run setup phases that have not run yet.- Throws:
Exception
-
shutdown
public void shutdown() throws Exception
Called by a shutdown hook to run all shutdown phases, but can also be called explicitly, each shutdown phase only runs once anyway.- Throws:
Exception
-
getContext
public Map<String,Object> getContext()
Return a context that can use to communicate among them and with the outside.
-
setConfig
public void setConfig(Properties props)
Set configuration and reset our lists of phases that already ran or failed.
-
getConfig
public Properties getConfig()
Return the configuration Properties that were set bysetConfig(java.util.Properties)
-
addSetupPhase
public void addSetupPhase(SetupPhase p) throws ServerSetup.SetupException
Add a SetupPhase to our list. Its ID must be unique in that list.- Throws:
ServerSetup.SetupException
-
-