Class MockHttpReceiver

  • All Implemented Interfaces:

    
    public class MockHttpReceiver
    
                        

    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.

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
    • Field Summary

      Fields 
      Modifier and Type Field Description
      public final int port
    • Constructor Summary

      Constructors 
      Constructor Description
      MockHttpReceiver() Creates a mock HTTP receiver on a random available port.
    • Enum Constant Summary

      Enum Constants 
      Enum Constant Description
    • Method Summary

      Modifier and Type Method Description
      int getPort() Gets the port this receiver is listening on.
      void start() Starts the mock receiver.
      void stop() Stops the mock receiver gracefully.
      String getEndpoint() Gets the endpoint string for this receiver.
      int getRequestCount() Gets the total number of POST requests received.
      int getTotalMetricCount() Gets the total number of metrics received across all requests.
      List<String> getReceivedMetricNames() Gets all metric names received.
      List<String> getReceivedPayloads() Gets all received JSON payloads.
      boolean hasReceivedMetric(String metricName) Checks if a specific metric type was received.
      void reset() Clears all received data.
      • Methods inherited from class java.lang.Object

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

      • MockHttpReceiver

        MockHttpReceiver()
        Creates a mock HTTP receiver on a random available port.
    • Method Detail

      • getPort

         int getPort()

        Gets the port this receiver is listening on.

        Returns:

        the port number

      • start

         void start()

        Starts the mock receiver.

      • stop

         void stop()

        Stops the mock receiver gracefully.

      • getEndpoint

         String getEndpoint()

        Gets the endpoint string for this receiver.

        Returns:

        endpoint string (e.g., "http://localhost:12345/metrics")

      • getRequestCount

         int getRequestCount()

        Gets the total number of POST requests received.

        Returns:

        number of requests

      • getTotalMetricCount

         int getTotalMetricCount()

        Gets the total number of metrics received across all requests.

        Returns:

        total metric count

      • hasReceivedMetric

         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

         void reset()

        Clears all received data.