public class FunctionalTestProcessor extends org.mule.runtime.api.meta.AbstractAnnotatedObject implements Processor, org.mule.runtime.api.lifecycle.Lifecycle, MuleContextAware, FlowConstructAware
FunctionalTestProcessor is a service that can be used by functional tests. This service accepts an EventCallback
that can be used to assert the state of the current event.
Also, this service fires FunctionalTestNotification via Mule for every message received. Tests can register with Mule
to receive these events by implementing FunctionalTestNotificationListener.| Modifier and Type | Class and Description |
|---|---|
static interface |
FunctionalTestProcessor.LifecycleCallback |
ReactiveProcessor.ProcessingType| Constructor and Description |
|---|
FunctionalTestProcessor() |
| Modifier and Type | Method and Description |
|---|---|
static void |
addLifecycleCallback(FunctionalTestProcessor.LifecycleCallback callback) |
protected String |
append(String contents,
Event event)
Will append the value of
getAppendString() to the contents of the message. |
void |
dispose() |
protected Event |
doProcess(Event event)
The service method that implements the test component logic.
|
String |
getAppendString() |
EventCallback |
getEventCallback()
An event callback is called when a message is received by the service.
|
String |
getExceptionText() |
Class<? extends Throwable> |
getExceptionToThrow() |
static FunctionalTestProcessor |
getFromFlow(MuleContext muleContext,
String flowName) |
Event |
getLastReceivedMessage()
If enableMessageHistory = true, returns the last message received by the service in chronological order.
|
Event |
getReceivedMessage(int number)
If enableMessageHistory = true, returns a message received by the service in chronological order.
|
int |
getReceivedMessagesCount()
If enableMessageHistory = true, returns the number of messages received by this service.
|
Object |
getReturnData()
Often you will may want to return a fixed message payload to simulate and external system call.
|
long |
getWaitTime() |
void |
initialise() |
boolean |
isEnableMessageHistory() |
boolean |
isEnableNotifications() |
boolean |
isLogMessageDetails() |
boolean |
isThrowException()
Sometimes you will want the service to always throw an exception, if this is the case you can set the 'throwException'
property to true.
|
Event |
process(Event event) |
static void |
removeLifecycleCallback(FunctionalTestProcessor.LifecycleCallback callback) |
void |
setAppendString(String appendString) |
void |
setEnableMessageHistory(boolean enableMessageHistory) |
void |
setEnableNotifications(boolean enableNotifications) |
void |
setEventCallback(EventCallback eventCallback)
An event callback is called when a message is received by the service.
|
void |
setExceptionText(String text) |
void |
setExceptionToThrow(Class<? extends Throwable> exceptionToThrow) |
void |
setFlowConstruct(FlowConstruct flowConstruct) |
void |
setId(String id) |
void |
setLogMessageDetails(boolean logMessageDetails) |
void |
setMuleContext(MuleContext context) |
void |
setReturnData(Object returnData)
Often you will may want to return a fixed message payload to simulate and external system call.
|
void |
setThrowException(boolean throwException)
Sometimes you will want the service to always throw an exception, if this is the case you can set the 'throwException'
property to true.
|
void |
setWaitTime(long waitTime) |
void |
start() |
void |
stop() |
protected void |
throwException()
Always throws a
FunctionalTestException. |
getAnnotation, getAnnotations, getLocation, setAnnotationsclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitgetProcessingTypepublic void initialise()
initialise in interface org.mule.runtime.api.lifecycle.Initialisablepublic void start()
throws org.mule.runtime.api.exception.MuleException
start in interface org.mule.runtime.api.lifecycle.Startableorg.mule.runtime.api.exception.MuleExceptionpublic void setMuleContext(MuleContext context)
setMuleContext in interface MuleContextAwarepublic void setFlowConstruct(FlowConstruct flowConstruct)
setFlowConstruct in interface FlowConstructAwarepublic void stop()
throws org.mule.runtime.api.exception.MuleException
stop in interface org.mule.runtime.api.lifecycle.Stoppableorg.mule.runtime.api.exception.MuleExceptionpublic void dispose()
dispose in interface org.mule.runtime.api.lifecycle.Disposableprotected void throwException()
throws Exception
FunctionalTestException. This methodis only called if isThrowException() is true.FunctionalTestException - or the exception specified in 'exceptionTypeExceptionprotected String append(String contents, Event event)
getAppendString() to the contents of the message. This has a side affect that the inbound
message will be converted to a string and the return payload will be a string. Note that the value of
getAppendString() can contain expressions.contents - the string vlaue of the current message payloadevent - the current eventprotected Event doProcess(Event event) throws Exception
event - the current EventException - if there is a general failure or if isThrowException() is true.public EventCallback getEventCallback()
FunctionalTestNotificationListener with Mule and this will deleiver a
FunctionalTestNotification for every message received by this serviceFunctionalTestNotification,
FunctionalTestNotificationListenerpublic void setEventCallback(EventCallback eventCallback)
FunctionalTestNotificationListener with Mule and this will deleiver a
FunctionalTestNotification for every message received by this serviceeventCallback - the callback to call when a message is receivedFunctionalTestNotification,
FunctionalTestNotificationListenerpublic Object getReturnData()
public void setReturnData(Object returnData)
returnData - the message payload to always return from this service instancepublic boolean isThrowException()
getReturnData()
property is set and is of type java.lang.Exception, that exception will be thrown.public void setThrowException(boolean throwException)
throwException - true if an exception should always be thrown from this instance. If the getReturnData()
property is set and is of type java.lang.Exception, that exception will be thrown.public boolean isEnableMessageHistory()
public void setEnableMessageHistory(boolean enableMessageHistory)
public int getReceivedMessagesCount()
public Event getReceivedMessage(int number)
public Event getLastReceivedMessage()
public String getAppendString()
public void setAppendString(String appendString)
public boolean isEnableNotifications()
public void setEnableNotifications(boolean enableNotifications)
public long getWaitTime()
public void setWaitTime(long waitTime)
public boolean isLogMessageDetails()
public void setLogMessageDetails(boolean logMessageDetails)
public String getExceptionText()
public void setExceptionText(String text)
public void setId(String id)
public static void addLifecycleCallback(FunctionalTestProcessor.LifecycleCallback callback)
public static void removeLifecycleCallback(FunctionalTestProcessor.LifecycleCallback callback)
public static FunctionalTestProcessor getFromFlow(MuleContext muleContext, String flowName) throws Exception
test:processor from a flow with the provided name.ExceptionCopyright © 2003–2017 MuleSoft, Inc.. All rights reserved.