Class AssertOperations

java.lang.Object
org.mule.munit.tools.assertion.AssertOperations

public class AssertOperations extends Object

Operations to perform assertions

Since:
2.0.0
Author:
Mulesoft Inc.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    org.mule.runtime.core.api.el.ExpressionManager
     
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    assertEquals(org.mule.runtime.api.metadata.TypedValue<Object> actual, org.mule.runtime.api.metadata.TypedValue<Object> expected, String message, org.mule.runtime.api.component.location.ComponentLocation location)
    Checks if the given actual value is equal to the expected value.
    void
    assertExpression(org.mule.runtime.extension.api.runtime.parameter.ParameterResolver<org.mule.munit.assertion.api.expression.MatcherResult> that, String message, org.mule.runtime.api.component.location.ComponentLocation location)
    Evaluates if the given that assertion expression is successful.
    void
    assertThat(org.mule.runtime.api.metadata.TypedValue<Object> expression, org.mule.munit.assertion.api.matchers.Matcher is, String message, org.mule.runtime.api.component.location.ComponentLocation location)
    Checks if the expression matches the given is Matcher.
    void
    fail(String message)
    Fails with a AssertionError with the given message
    void
    runCustom(String assertion, org.mule.runtime.api.metadata.TypedValue<Object> expression, Object params)
    Runs a custom assertion over the given expression with the parameters params
    protected void
    setAssertModule(org.mule.munit.assertion.internal.AssertModule assertModule)
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • expressionManager

      @Inject public org.mule.runtime.core.api.el.ExpressionManager expressionManager
  • Constructor Details

    • AssertOperations

      public AssertOperations()
  • Method Details

    • assertThat

      @Summary("Perform an assertion over an expression") public void assertThat(@Example("#[payload]") org.mule.runtime.api.metadata.TypedValue<Object> expression, @Expression(REQUIRED) @Example("#[MunitTools::notNullValue()]") org.mule.munit.assertion.api.matchers.Matcher is, @Optional(defaultValue="") String message, org.mule.runtime.api.component.location.ComponentLocation location)
      Checks if the expression matches the given is Matcher. If the assertion fails, it throws an AssertionError
      Parameters:
      expression - value to be asserted
      is - matcher to validate against the expression
      message - message in case the assertion fails
    • assertExpression

      @Summary("Asserts that an expression is successful") @DisplayName("Assert expression") @Alias("assert") @Throws(AssertionErrorProvider.class) public void assertExpression(@DisplayName("Expression") @Optional(defaultValue="#[import * from dw::test::Asserts \n ---\npayload must notBeNull()]") @Content org.mule.runtime.extension.api.runtime.parameter.ParameterResolver<org.mule.munit.assertion.api.expression.MatcherResult> that, @Optional(defaultValue="Assertion failed") String message, org.mule.runtime.api.component.location.ComponentLocation location)
      Evaluates if the given that assertion expression is successful. If the assertion fails, it throws an AssertionError
      Parameters:
      that - result of the assertion expression
      message - message in case the assertion fails
    • assertEquals

      @Summary("Check if an expression is equal to a value") public void assertEquals(@Example("#[payload]") org.mule.runtime.api.metadata.TypedValue<Object> actual, @ParameterDsl(allowReferences=false) @Example("#[\'EXAMPLE\']") org.mule.runtime.api.metadata.TypedValue<Object> expected, @Optional(defaultValue="") String message, org.mule.runtime.api.component.location.ComponentLocation location)
      Checks if the given actual value is equal to the expected value. If they differ, an AssertionError is thrown.
      Parameters:
      actual - actual value to be asserted
      expected - expected value of the assertion
      message - message in case the assertion fails
    • fail

      @Summary("Fail with an assertion") public void fail(@Optional(defaultValue="") String message)
      Fails with a AssertionError with the given message
      Parameters:
      message - message for the assertion failure
    • runCustom

      @Summary("Run a custom assertion") public void runCustom(@Example("com.example.CustomAssertion") @ClassValue(extendsOrImplements="org.mule.munit.assertion.api.MunitAssertion") String assertion, @Example("#[payload]") org.mule.runtime.api.metadata.TypedValue<Object> expression, @Optional Object params)
      Runs a custom assertion over the given expression with the parameters params

      The assertion must implement MunitAssertion

      Parameters:
      assertion - full qualified name of the custom assertion class
      expression - value to be asserted
      params - parameters of the custom assertion
    • setAssertModule

      protected void setAssertModule(org.mule.munit.assertion.internal.AssertModule assertModule)