Class AbstractEmbeddedServer<S,T extends AbstractConfiguration>

java.lang.Object
com.github.mjeanroy.junit.servers.servers.AbstractEmbeddedServer<S,T>
All Implemented Interfaces:
EmbeddedServer<T>

public abstract class AbstractEmbeddedServer<S,T extends AbstractConfiguration> extends Object implements EmbeddedServer<T>
Partial implementation of an embedded server.

Subclasses should implement doStart() and doStop() methods and synchronization is already managed by this abstract implementation.

  • Field Details

  • Constructor Details

    • AbstractEmbeddedServer

      protected AbstractEmbeddedServer(T configuration)
      Build default embedded server.
      Parameters:
      configuration - Server configuration.
  • Method Details

    • start

      public void start()
      Description copied from interface: EmbeddedServer
      Start embedded server. If server is already started, this method should do nothing.
      Specified by:
      start in interface EmbeddedServer<S>
    • stop

      public void stop()
      Description copied from interface: EmbeddedServer
      Stop embedded server. If server is already stopped, this method should do nothing.
      Specified by:
      stop in interface EmbeddedServer<S>
    • isStarted

      public boolean isStarted()
      Description copied from interface: EmbeddedServer
      Check if embedded server is started.
      Specified by:
      isStarted in interface EmbeddedServer<S>
      Returns:
      true if embedded server is started, false otherwise.
    • restart

      public void restart()
      Description copied from interface: EmbeddedServer
      Restart embedded server.
      Specified by:
      restart in interface EmbeddedServer<S>
    • getPort

      public int getPort()
      Description copied from interface: EmbeddedServer
      Get port used by embedded server.

      Note that:

      • If the server is not started, the returned port should be the one set in the configuration.
      • Otherwise, the "real" port should be returned (the port used by the embedded server)
      Specified by:
      getPort in interface EmbeddedServer<S>
      Returns:
      Port.
    • getPath

      public String getPath()
      Description copied from interface: EmbeddedServer
      Get server context path.
      Specified by:
      getPath in interface EmbeddedServer<S>
      Returns:
      Server context path.
    • getScheme

      public String getScheme()
      Description copied from interface: EmbeddedServer
      Get the protocol scheme ("http", "https").
      Specified by:
      getScheme in interface EmbeddedServer<S>
      Returns:
      Protocol scheme.
    • getHost

      public String getHost()
      Description copied from interface: EmbeddedServer
      Get the host, should be "localhost", unless specific configuration.
      Specified by:
      getHost in interface EmbeddedServer<S>
      Returns:
      The server hostname.
    • getUrl

      public String getUrl()
      Description copied from interface: EmbeddedServer
      Get URL to query embedded server.
      Specified by:
      getUrl in interface EmbeddedServer<S>
      Returns:
      URL.
    • getConfiguration

      public T getConfiguration()
      Description copied from interface: EmbeddedServer
      Return server configuration.
      Specified by:
      getConfiguration in interface EmbeddedServer<S>
      Returns:
      Configuration.
    • getDelegate

      public abstract S getDelegate()
      Get internal server implementation. Note that this method should not be used to start or stop internal server, use dedicated method instead. This method can be used to do some custom configuration on original implementation.
      Returns:
      Original server implementation.
    • doStart

      protected abstract void doStart()
      Start embedded server. Must block until server is fully started.
    • doStop

      protected abstract void doStop()
      Stop embedded server. Must block until server is fully stopped.
    • doGetPort

      protected abstract int doGetPort()
      Get port once server is started.
      Returns:
      The port.