Class MockHttpReceiver

java.lang.Object
jline.streaming.MockHttpReceiver

public class MockHttpReceiver extends Object
Mock HTTP receiver for testing streaming functionality. Uses Java's built-in HttpServer for maximum compatibility. Receives JSON metrics via HTTP POST and captures them for verification.
  • Constructor Details

    • MockHttpReceiver

      public MockHttpReceiver() throws IOException
      Creates a mock HTTP receiver on a random available port.
      Throws:
      IOException - if unable to find an available port or start the server
  • Method Details

    • start

      public void start()
      Starts the mock receiver.
    • stop

      public void stop()
      Stops the mock receiver gracefully.
    • getPort

      public int getPort()
      Gets the port this receiver is listening on.
      Returns:
      the port number
    • getEndpoint

      public String getEndpoint()
      Gets the endpoint string for this receiver.
      Returns:
      endpoint string (e.g., "http://localhost:12345/metrics")
    • getRequestCount

      public int getRequestCount()
      Gets the total number of POST requests received.
      Returns:
      number of requests
    • getTotalMetricCount

      public int getTotalMetricCount()
      Gets the total number of metrics received across all requests.
      Returns:
      total metric count
    • getReceivedMetricNames

      public List<String> getReceivedMetricNames()
      Gets all metric names received.
      Returns:
      list of metric names
    • getReceivedPayloads

      public List<String> getReceivedPayloads()
      Gets all received JSON payloads.
      Returns:
      list of JSON strings
    • hasReceivedMetric

      public boolean hasReceivedMetric(String metricName)
      Checks if a specific metric type was received.
      Parameters:
      metricName - the metric name to check
      Returns:
      true if at least one metric with that name was received
    • reset

      public void reset()
      Clears all received data.