Class MockOperations
Operations to perform mocking
- Since:
- 2.0.0
- Author:
- Mulesoft Inc.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidmockWhen(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 theprocessorthat has the givenwithAttributes, replacing it with the givenanswer.protected voidsetMockModule(org.mule.munit.mock.MockModule mockModule)protected voidsetRegistry(org.mule.runtime.api.artifact.Registry registry)voidspy(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 theprocessorthat has the givenwithAttributes, executing logic before and after its execution.voidverifyCall(String processor, List<org.mule.munit.common.api.model.Attribute> withAttributes, Integer times, Integer atLeast, Integer atMost)Verifies that theprocessorthat has the givenwithAttributeshas been executed.
-
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, @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 theprocessorthat has the givenwithAttributes, replacing it with the givenanswer.During the test execution, if any processor tries to be executed, and it matches the
processorname and thewithAttributes, its execution its not performed, and instead theansweris used. IfthenReturnis specified, then that event is returned, or ifthenCallis specified, the given flow is invoked, and the resulting event is returned. If noAnsweris specified, the incoming event is returned.- Parameters:
processor- identifier of the processor to mockwithAttributes- additional attributes to identify the processoranswer-Answerto be used when mocking the processor
-
verifyCall
@Summary("Verify that a processor is called") public void verifyCall(@Example("mule:logger") String processor, @Optional @Expression(NOT_SUPPORTED) List<org.mule.munit.common.api.model.Attribute> withAttributes, @Optional Integer times, @Optional Integer atLeast, @Optional Integer atMost)Verifies that theprocessorthat has the givenwithAttributeshas been executed.During the test execution, if any processor is executed, and it matches the
processorname and thewithAttributesit 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 mockwithAttributes- additional attributes to identify the processortimes- exact number of times the processor should have been executedatLeast- minimum number of times the processor should have been executedatMost- 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, @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 theprocessorthat has the givenwithAttributes, executing logic before and after its execution.During the test execution, if any processor tries to be executed, and it matches the
processorname and thewithAttributes, thebeforeCallwill be executed before the processor, and theafterCallwill be executed after- Parameters:
processor- identifier of the processor to mockwithAttributes- additional attributes to identify the processorbeforeCall- processors to be executed before the spied processorafterCall- 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)
-