Package rife.test

Class MockEvent

java.lang.Object
rife.test.MockEvent

public class MockEvent extends Object
A MockEvent instance corresponds to a single event that was parsed from a server-sent events (SSE) response, as it is provided by MockResponse.getEvents().

This makes it possible to assert on the individual fields of the events that an element streamed, without having to parse the raw response text yourself.

Since:
1.10
See Also:
  • Method Details

    • getName

      public String getName()
      Retrieves the name of this event, which was transmitted as the event field.
      Returns:
      this event's name; or

      null when it was an unnamed event

      Since:
      1.10
      See Also:
    • getId

      public String getId()
      Retrieves the ID of this event, which was transmitted as the id field.
      Returns:
      this event's ID; or

      null when no ID was provided

      Since:
      1.10
      See Also:
    • getRetry

      public int getRetry()
      Retrieves the reconnection time in milliseconds, which was transmitted as the retry field.
      Returns:
      this event's reconnection time; or

      -1 when none was provided

      Since:
      1.10
    • getComments

      public List<String> getComments()
      Retrieves the comments of this event.
      Returns:
      this event's comments; or

      an empty list when there were none

      Since:
      1.10
    • getData

      public String getData()
      Retrieves the data of this event, with multiple data fields joined by line feeds, in the same way that browsers assemble the event data.
      Returns:
      this event's data; or

      null when the event carried no data

      Since:
      1.10
      See Also:
    • getDataAsJsonObject

      public JsonObject getDataAsJsonObject()
      Parses the data of this event as a JSON object.
      Returns:
      this event's data as a JSON object
      Throws:
      JsonParseException - when the data isn't a valid JSON object
      Since:
      1.10
      See Also:
    • getDataAsBean

      public <T> T getDataAsBean(Class<T> beanClass)
      Parses the data of this event as a JSON object and fills a new bean instance with its members, like Json.toBean(rife.json.JsonObject, java.lang.Class<T>) does.
      Type Parameters:
      T - the type of the bean
      Parameters:
      beanClass - the class of the bean to instantiate
      Returns:
      the new bean instance with this event's data filled in
      Throws:
      JsonParseException - when the data isn't a valid JSON object
      Since:
      1.10
      See Also:
    • getTemplate

      public Template getTemplate()
      Retrieves the template instance that provided the data of this event.

      The template is captured with the value assignments that were active at the moment the event was sent, which makes it possible to assert on the values of streamed fragments without having to parse the event data.

      Returns:
      the template that provided this event's data; or

      null when the event's data didn't come from a template

      Since:
      1.10
      See Also: