Class StubServer

java.lang.Object
com.xebialabs.restito.server.StubServer

public class StubServer extends Object
The HttpServer wrapper which is responsible for operations like starting and stopping and holding objects that describe server behavior.
  • Field Details

    • DEFAULT_PORT

      public static final int DEFAULT_PORT
      See Also:
    • secured

      public boolean secured
      Whether the server should run in HTTPS mode.
  • Constructor Details

    • StubServer

      public StubServer(Stub... stubs)
      Creates a server based on stubs that are used to determine behavior.
    • StubServer

      public StubServer(int portRangeStart, int portRangeEnd, Stub... stubs)
      This constructor allows to specify the port range beside stubs. Grizzly will select the first available port.
    • StubServer

      public StubServer(int port, Stub... stubs)
      This constructor allows to specify the port beside stubs. If the port is busy, Restito won't try to pick different one and java.net.BindException will be thrown.
  • Method Details

    • addStub

      public StubServer addStub(Stub s)
      It is possible to add a stub even after the server is started
    • clearStubs

      public StubServer clearStubs()
      Removes any previously registered stubs.
    • clearCalls

      public StubServer clearCalls()
      Removes any registered stubs calls.
    • clear

      public StubServer clear()
      Clears the server state.
    • isRegisterCalls

      public boolean isRegisterCalls()
      Defines whether stubs calls will be registered or not.
      Returns:
      current flag value
    • setRegisterCalls

      public void setRegisterCalls(boolean registerCalls)
      Defines whether stubs calls will be registered or not.
      Parameters:
      registerCalls - new flag value
    • run

      public StubServer run()
      Starts the server
    • start

      public void start()
      Alias for StubServer.run()
    • stop

      public StubServer stop()
      Stops the server
    • secured

      public StubServer secured()
      Sets the Server in Secure mode. If it is already running, ignores the call.
    • clientAuth

      public StubServer clientAuth(byte[] trustStore, String trustStorePass)
      Sets the Server to require client authentication (implies Secure mode). If it is already running, ignores the call.
    • getPort

      public int getPort()
      Returns the port which the server is running at
    • getCalls

      public List<Call> getCalls()
      Returns calls performed to the server. Returned list is actually a copy of the original one. This is done to prevent concurrency issues. See #33.
    • getStubs

      public List<Stub> getStubs()
      Returns stubs associated with the server. Returned list is actually a copy of the original one. This is done to prevent concurrency issues. See #33.