Package rife.test
Class MockEvent
java.lang.Object
rife.test.MockEvent
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 Summary
Modifier and TypeMethodDescriptionRetrieves the comments of this event.getData()Retrieves the data of this event, with multipledatafields joined by line feeds, in the same way that browsers assemble the event data.<T> TgetDataAsBean(Class<T> beanClass) Parses the data of this event as a JSON object and fills a new bean instance with its members, likeJson.toBean(rife.json.JsonObject, java.lang.Class<T>)does.Parses the data of this event as a JSON object.getId()Retrieves the ID of this event, which was transmitted as theidfield.getName()Retrieves the name of this event, which was transmitted as theeventfield.intgetRetry()Retrieves the reconnection time in milliseconds, which was transmitted as theretryfield.Retrieves the template instance that provided the data of this event.
-
Method Details
-
getName
Retrieves the name of this event, which was transmitted as theeventfield.- Returns:
- this event's name; or
nullwhen it was an unnamed event - Since:
- 1.10
- See Also:
-
getId
Retrieves the ID of this event, which was transmitted as theidfield.- Returns:
- this event's ID; or
nullwhen no ID was provided - Since:
- 1.10
- See Also:
-
getRetry
public int getRetry()Retrieves the reconnection time in milliseconds, which was transmitted as theretryfield.- Returns:
- this event's reconnection time; or
-1when none was provided - Since:
- 1.10
-
getComments
Retrieves the comments of this event.- Returns:
- this event's comments; or
an empty list when there were none
- Since:
- 1.10
-
getData
Retrieves the data of this event, with multipledatafields joined by line feeds, in the same way that browsers assemble the event data.- Returns:
- this event's data; or
nullwhen the event carried no data - Since:
- 1.10
- See Also:
-
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
Parses the data of this event as a JSON object and fills a new bean instance with its members, likeJson.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
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
nullwhen the event's data didn't come from a template - Since:
- 1.10
- See Also:
-