Class MockServer

java.lang.Object
io.karatelabs.core.MockServer
All Implemented Interfaces:
io.karatelabs.js.ObjectLike, io.karatelabs.js.SimpleObject

public class MockServer extends Object implements io.karatelabs.js.SimpleObject
Public API for creating mock servers from feature files.

Usage:

 MockServer server = MockServer.feature("api.feature")
     .port(8080)
     .arg(Map.of("key", "value"))
     .start();

 // ... use server ...

 server.stopAsync();     // non-blocking
 server.stopAndWait();   // blocking
 
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static class 
    Builder for creating MockServer instances.
  • Field Summary

    Fields inherited from interface io.karatelabs.js.SimpleObject

    TO_STRING
  • Method Summary

    Modifier and Type
    Method
    Description
    feature(io.karatelabs.common.Resource resource)
    Create a builder for a mock server from a Resource.
    feature(Feature feature)
    Create a builder for a mock server from a parsed Feature.
    Create a builder for a mock server from a feature file path.
    featureString(String featureContent)
    Create a builder for a mock server from a feature string.
    Get the underlying MockHandler.
    int
    Get the port the server is listening on.
    Get the base URL for the server (e.g., http://localhost:8080 or https://localhost:8443).
    Get a variable from the mock handler's global context.
    boolean
    Check if the server is using SSL/TLS.
     
    void
    Stop the mock server and wait for shutdown to complete (blocking).
    void
    Stop the mock server asynchronously (non-blocking).
    void
    Wait for the server to be stopped (blocking).

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface io.karatelabs.js.ObjectLike

    getMember, getPrototype, isExtensible, isFrozen, isOwnProperty, isSealed, putMember, removeMember, setExtensible, setFrozen, setSealed

    Methods inherited from interface io.karatelabs.js.SimpleObject

    getMember, jsKeys, jsToString, putMember, removeMember, toMap
  • Method Details

    • feature

      public static MockServer.Builder feature(String path)
      Create a builder for a mock server from a feature file path.
    • feature

      public static MockServer.Builder feature(Feature feature)
      Create a builder for a mock server from a parsed Feature.
    • feature

      public static MockServer.Builder feature(io.karatelabs.common.Resource resource)
      Create a builder for a mock server from a Resource.
    • featureString

      public static MockServer.Builder featureString(String featureContent)
      Create a builder for a mock server from a feature string. Useful for inline feature definitions in tests.
    • getPort

      public int getPort()
      Get the port the server is listening on.
    • isSsl

      public boolean isSsl()
      Check if the server is using SSL/TLS.
    • getUrl

      public String getUrl()
      Get the base URL for the server (e.g., http://localhost:8080 or https://localhost:8443).
    • stopAndWait

      public void stopAndWait()
      Stop the mock server and wait for shutdown to complete (blocking).
      See Also:
    • stopAsync

      public void stopAsync()
      Stop the mock server asynchronously (non-blocking).
      See Also:
    • waitSync

      public void waitSync()
      Wait for the server to be stopped (blocking).
    • getVariable

      public Object getVariable(String name)
      Get a variable from the mock handler's global context.
    • getHandler

      public MockHandler getHandler()
      Get the underlying MockHandler.
    • jsGet

      public Object jsGet(String key)
      Specified by:
      jsGet in interface io.karatelabs.js.SimpleObject