Class MockOperations

java.lang.Object
org.mule.munit.tools.mock.MockOperations

@Stereotype(org.mule.munit.common.api.model.stereotype.MUnitMockStereotype.class) public class MockOperations extends Object

Operations to perform mocking

Since:
2.0.0
Author:
Mulesoft Inc.
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static class 
    Definition of the attribute list metadata.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    mockWhen(String processor, List<org.mule.munit.common.api.model.Attribute> withAttributes, org.mule.munit.common.api.model.Answer answer, org.mule.runtime.extension.api.runtime.streaming.StreamingHelper streamingHelper)
    Mocks the processor that has the given withAttributes, replacing it with the given answer.
    protected void
    setMockModule(org.mule.munit.mock.MockModule mockModule)
     
    protected void
    setRegistry(org.mule.runtime.api.artifact.Registry registry)
     
    void
    spy(String processor, List<org.mule.munit.common.api.model.Attribute> withAttributes, BeforeCall beforeCall, AfterCall afterCall, org.mule.runtime.extension.api.runtime.process.RouterCompletionCallback callback)
    Spies the processor that has the given withAttributes, executing logic before and after its execution.
    void
    verifyCall(String processor, List<org.mule.munit.common.api.model.Attribute> withAttributes, Integer times, Integer atLeast, Integer atMost)
    Verifies that the processor that has the given withAttributes has been executed.

    Methods inherited from class java.lang.Object

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

    • MockOperations

      public MockOperations()
  • Method Details

    • mockWhen

      @Summary("Mock the Processor when it matches processor name and attributes") public void mockWhen(@Example("http:request") String processor, @TypeResolver(AttributeListTypeResolver.class) @Optional @Expression(NOT_SUPPORTED) List<org.mule.munit.common.api.model.Attribute> withAttributes, @ParameterGroup(name="Answer") org.mule.munit.common.api.model.Answer answer, org.mule.runtime.extension.api.runtime.streaming.StreamingHelper streamingHelper)
      Mocks the processor that has the given withAttributes, replacing it with the given answer.

      During the test execution, if any processor tries to be executed, and it matches the processor name and the withAttributes, its execution its not performed, and instead the answer is used. If thenReturn is specified, then that event is returned, or if thenCall is specified, the given flow is invoked, and the resulting event is returned. If no Answer is specified, the incoming event is returned.

      Parameters:
      processor - identifier of the processor to mock
      withAttributes - additional attributes to identify the processor
      answer - Answer to be used when mocking the processor
    • verifyCall

      @Summary("Verify that a processor is called") public void verifyCall(@Example("mule:logger") String processor, @TypeResolver(AttributeListTypeResolver.class) @Optional @Expression(NOT_SUPPORTED) List<org.mule.munit.common.api.model.Attribute> withAttributes, @Optional Integer times, @Optional Integer atLeast, @Optional Integer atMost)
      Verifies that the processor that has the given withAttributes has been executed.

      During the test execution, if any processor is executed, and it matches the processor name and the withAttributes it will be counted as called.

      If the processor was not called the specified number of times, it will throw an AssertionError

      Parameters:
      processor - identifier of the processor to mock
      withAttributes - additional attributes to identify the processor
      times - exact number of times the processor should have been executed
      atLeast - minimum number of times the processor should have been executed
      atMost - maximum number of times the processor should have been executed
    • spy

      @Summary("Allows to take actions over the event before and after the execution of a processor") public void spy(String processor, @TypeResolver(AttributeListTypeResolver.class) @Optional @NullSafe @Expression(NOT_SUPPORTED) List<org.mule.munit.common.api.model.Attribute> withAttributes, @Optional BeforeCall beforeCall, @Optional AfterCall afterCall, org.mule.runtime.extension.api.runtime.process.RouterCompletionCallback callback)
      Spies the processor that has the given withAttributes, executing logic before and after its execution.

      During the test execution, if any processor tries to be executed, and it matches the processor name and the withAttributes, the beforeCall will be executed before the processor, and the afterCall will be executed after

      Parameters:
      processor - identifier of the processor to mock
      withAttributes - additional attributes to identify the processor
      beforeCall - processors to be executed before the spied processor
      afterCall - processors to be executed after the spied processor
    • setRegistry

      protected void setRegistry(org.mule.runtime.api.artifact.Registry registry)
    • setMockModule

      protected void setMockModule(org.mule.munit.mock.MockModule mockModule)