org.mule.munit

mock

1.0.1
Namespacehttp://www.mulesoft.org/schema/mule/mock
Schema Locationhttp://www.mulesoft.org/schema/mule/mock/1.0/mule-mock.xsd
Version1.0
Minimum Mule Version3.2

Module Overview

Module for Mocking devkit Modules.

With this module you can mock using mockito framework all the modules that are written with Mule Devkit.

In order to be able to mock a module it has to be declare with a reference name. For example:

Otherwise the module/connector will not be accessible by a reference name and will not be able to be mocked.

Summary

Configuration
<mock:config>
Configure an instance of this module
Message Processors
<mock:expect>

Define what the mock must return on a message processor call.

<mock:expect-fail>

Expect to throw an exception when message processor is called.

<mock:fail-on-connect>
Throw an Exception when a connector tries to connect.
<mock:reset>
Reset mock behaviour

<mock:verify-call>
Check that the message processor was called with some specified parameters

Configuration

To use the this module within a flow the namespace to the module must be included. The resulting flow will look similar to the following:

<mule xmlns="http://www.mulesoft.org/schema/mule/core"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xmlns:mock="http://www.mulesoft.org/schema/mule/mock"
      xsi:schemaLocation="
               http://www.mulesoft.org/schema/mule/core
               http://www.mulesoft.org/schema/mule/core/current/mule.xsd
               http://www.mulesoft.org/schema/mule/mock
               http://www.mulesoft.org/schema/mule/mock/1.0/mule-mock.xsd">

      <!-- here goes your flows and configuration elements -->

</mule>

This module is configured using the config element. This element must be placed outside of your flows and at the root of your Mule application. You can create as many configurations as you deem necesary as long as each carries its own name.

Each message processor, message source or transformer carries a config-ref attribute that allows the invoker to specify which configuration to use.

Attributes
TypeNameDefault ValueDescription
xs:string name Optional. Give a name to this configuration so it can be later referenced.
xs:string of

Component that we want to mock.

Message Processors

<mock:expect>

Define what the mock must return on a message processor call.

If the message processor doesn't return any value then there is no need to define an expect.

You can define the message processor parameters in the same order they appear in the API documentation. In order to define the behaviour on that particular case.

XML Sample
INCLUDE_ERROR

Attributes
NameDefault ValueDescription
config-ref Optional. Specify which configuration to use.
when Message processor name.
mustReturn Optional. Expected return value.
mustReturnResponseFrom Optional. The flow name that creates the expected result
Child Elements
<mock:parameters>
Optional. Message processor parameters.

<mock:expect-fail>

Expect to throw an exception when message processor is called.

XML Sample
INCLUDE_ERROR

Attributes
NameDefault ValueDescription
config-ref Optional. Specify which configuration to use.
when Message processor name.
throwA Java Exception full qualified name.
Child Elements

<mock:fail-on-connect>

Throw an Exception when a connector tries to connect.

XML Sample
INCLUDE_ERROR

Attributes
NameDefault ValueDescription
config-ref Optional. Specify which configuration to use.
Child Elements

<mock:reset>

Reset mock behaviour

XML Sample
INCLUDE_ERROR

Attributes
NameDefault ValueDescription
config-ref Optional. Specify which configuration to use.
Child Elements

<mock:verify-call>

Check that the message processor was called with some specified parameters

XML Sample
INCLUDE_ERROR

Attributes
NameDefault ValueDescription
config-ref Optional. Specify which configuration to use.
messageProcessor Message processor Id
times Optional. Number of times the message processor has to be called
atLeast Optional. Number of time the message processor has to be called at least.
atMost Optional. Number of times the message processor has to be called at most.
Child Elements
<mock:parameters>
Message processor parameters.