Record Class MatchRunEvent

java.lang.Object
java.lang.Record
io.karatelabs.core.MatchRunEvent
All Implemented Interfaces:
RunEvent

public record MatchRunEvent(RunEventType type, Match.Type matchType, String actualExpr, String expectedExpr, Object actual, Object expected, Result result, ScenarioRuntime scenarioRuntime, long timeStamp) extends Record implements RunEvent
Assertion-level events (MATCH_EXIT).

Enables commercial extensions to capture what a test actually asserted — the expression strings as written, the evaluated values and the match outcome — for reports like assertion evidence or assertion-strength grading.

Fired by the match keyword, the karate.match("...") JS API (both route through StepExecutor.evalMatchString) and the assert keyword. An assert carries no Match.Type: its actualExpr() is the asserted expression, actual() the evaluated boolean, and expected is absent.

Usage with pattern matching:

 listener = event -> switch (event) {
     case MatchRunEvent e when e.type() == MATCH_EXIT -> {
         Step step = e.getCurrentStep();
         boolean pass = e.result().pass;
         // Process assertion data
         yield true;
     }
     default -> true;
 };
 

The return value of a listener is ignored — the assertion has already been evaluated.

  • Constructor Details

    • MatchRunEvent

      public MatchRunEvent(RunEventType type, Match.Type matchType, String actualExpr, String expectedExpr, Object actual, Object expected, Result result, ScenarioRuntime scenarioRuntime, long timeStamp)
      Creates an instance of a MatchRunEvent record class.
      Parameters:
      type - the value for the type record component
      matchType - the value for the matchType record component
      actualExpr - the value for the actualExpr record component
      expectedExpr - the value for the expectedExpr record component
      actual - the value for the actual record component
      expected - the value for the expected record component
      result - the value for the result record component
      scenarioRuntime - the value for the scenarioRuntime record component
      timeStamp - the value for the timeStamp record component
  • Method Details

    • exit

      public static MatchRunEvent exit(Match.Type matchType, String actualExpr, String expectedExpr, Object actual, Object expected, Result result, ScenarioRuntime sr)
      Creates a MATCH_EXIT event fired after the match is evaluated. Fires for a failed match too, before the keyword path throws.
    • getType

      public RunEventType getType()
      Description copied from interface: RunEvent
      Returns the event type.
      Specified by:
      getType in interface RunEvent
    • getTimeStamp

      public long getTimeStamp()
      Description copied from interface: RunEvent
      Returns the timestamp when this event occurred (epoch milliseconds).
      Specified by:
      getTimeStamp in interface RunEvent
    • toJson

      public Map<String,Object> toJson()
      Description copied from interface: RunEvent
      Serializes this event to a map for JSONL output.
      Specified by:
      toJson in interface RunEvent
    • getCurrentStep

      public Step getCurrentStep()
      Convenience method to get the currently executing step. Use this to correlate an assertion to the step that made it.
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. Reference components are compared with Objects::equals(Object,Object); primitive components are compared with '=='.
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • type

      public RunEventType type()
      Returns the value of the type record component.
      Returns:
      the value of the type record component
    • matchType

      public Match.Type matchType()
      Returns the value of the matchType record component.
      Returns:
      the value of the matchType record component
    • actualExpr

      public String actualExpr()
      Returns the value of the actualExpr record component.
      Returns:
      the value of the actualExpr record component
    • expectedExpr

      public String expectedExpr()
      Returns the value of the expectedExpr record component.
      Returns:
      the value of the expectedExpr record component
    • actual

      public Object actual()
      Returns the value of the actual record component.
      Returns:
      the value of the actual record component
    • expected

      public Object expected()
      Returns the value of the expected record component.
      Returns:
      the value of the expected record component
    • result

      public Result result()
      Returns the value of the result record component.
      Returns:
      the value of the result record component
    • scenarioRuntime

      public ScenarioRuntime scenarioRuntime()
      Returns the value of the scenarioRuntime record component.
      Returns:
      the value of the scenarioRuntime record component
    • timeStamp

      public long timeStamp()
      Returns the value of the timeStamp record component.
      Returns:
      the value of the timeStamp record component