Class 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.
    • Field Detail

      • 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
    • Constructor Detail

      • ServerSetup

        public ServerSetup()
    • 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.
      • getPhasesToRun

        public List<String> getPhasesToRun()
        Return the IDs of phases that should run