Object MockSiteLauncher

  • All Implemented Interfaces:
    java.io.Closeable , java.lang.AutoCloseable

    
    public class MockSiteLauncher
     implements Closeable
                        

    Utility launcher to programmatically start / stop the MockSiteApplication.

    Improvements:

    • Honors the explicit port argument by using a command-line arg --server.port= (highest precedence)

    • If already running on a different port, can optionally restart to match the requested port

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
    • Constructor Summary

      Constructors 
      Constructor Description
    • Enum Constant Summary

      Enum Constants 
      Enum Constant Description
    • Method Summary

      Modifier and Type Method Description
      final Boolean isRunning() Whether the mock site is currently running.
      final Integer port() The port the server actually bound to (null if not started).
      final String baseUrl() Base URL (null if not started).
      final ConfigurableApplicationContext start(Integer port, Map<String, Object> properties, Array<String> profiles, Boolean headless, Boolean enforcePort) Start the mock site if not already started or restart if running on a different port and enforcePort is true.
      final ConfigurableApplicationContext restart(Integer port, Map<String, Object> properties) Restart the server: stops if running, then starts again.
      final Boolean awaitReady(Duration timeout, Duration interval, String healthPath) Wait until the health endpoint (default "/actuator/health") responds with a 2xx/3xx status or timeout reached.
      final Unit stop() Stop the server if running.
      Unit close()
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

    • Method Detail

      • isRunning

         final Boolean isRunning()

        Whether the mock site is currently running.

      • port

         final Integer port()

        The port the server actually bound to (null if not started).

      • start

        @Synchronized() final ConfigurableApplicationContext start(Integer port, Map<String, Object> properties, Array<String> profiles, Boolean headless, Boolean enforcePort)

        Start the mock site if not already started or restart if running on a different port and enforcePort is true.

        Parameters:
        port - Desired port (0 for random).
        enforcePort - If true and already running on a different port, the server is restarted on the requested port.
      • awaitReady

         final Boolean awaitReady(Duration timeout, Duration interval, String healthPath)

        Wait until the health endpoint (default "/actuator/health") responds with a 2xx/3xx status or timeout reached. Falls back to root "/" if health path not available.

        Returns:

        true if ready, false if timed out.