public class FunctionalTestComponent extends org.mule.runtime.api.meta.AbstractAnnotatedObject implements Callable, org.mule.runtime.api.lifecycle.Initialisable, org.mule.runtime.api.lifecycle.Disposable, MuleContextAware, FlowConstructAware, Receiveable, org.mule.runtime.api.lifecycle.Startable, org.mule.runtime.api.lifecycle.Stoppable
FunctionalTestComponent 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 |
FunctionalTestComponent.LifecycleCallback |
| Modifier and Type | Field and Description |
|---|---|
protected org.slf4j.Logger |
logger |
static int |
STREAM_BUFFER_SIZE |
static int |
STREAM_SAMPLE_SIZE |
| Constructor and Description |
|---|
FunctionalTestComponent() |
| Modifier and Type | Method and Description |
|---|---|
static void |
addLifecycleCallback(FunctionalTestComponent.LifecycleCallback callback) |
protected String |
append(String contents,
Event event)
Will append the value of
getAppendString() to the contents of the message. |
void |
dispose() |
String |
getAppendString() |
EventCallback |
getEventCallback()
An event callback is called when a message is received by the service.
|
String |
getExceptionText() |
Class<? extends Throwable> |
getExceptionToThrow() |
Object |
getLastReceivedMessage()
If enableMessageHistory = true, returns the last message received by the service in chronological order.
|
Object |
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 |
isDoInboundTransform() |
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.
|
Object |
onCall(MuleEventContext context) |
Object |
onReceive(Object data)
This method is used by some WebServices tests where you don' want to be introducing the
MuleEventContext as a complex type. |
protected Object |
process(Object data,
MuleEventContext context)
The service method that implements the test component logic.
|
static void |
removeLifecycleCallback(FunctionalTestComponent.LifecycleCallback callback) |
void |
setAppendString(String appendString) |
void |
setDoInboundTransform(boolean doInboundTransform) |
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. |
protected transient org.slf4j.Logger logger
public static final int STREAM_SAMPLE_SIZE
public static final int STREAM_BUFFER_SIZE
public 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.Disposablepublic Object onCall(MuleEventContext context) throws Exception
public Object onReceive(Object data) throws Exception
MuleEventContext as a complex type.onReceive in interface Receiveabledata - the event data receivedExceptionprotected 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 Object process(Object data, MuleEventContext context) throws Exception
onCall(org.mule.runtime.core.api.MuleEventContext) or onReceive(Object)data - The message payloadcontext - the current MuleEventContextException - 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()
returnData 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 returnData 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 Object getReceivedMessage(int number)
public Object 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 isDoInboundTransform()
public void setDoInboundTransform(boolean doInboundTransform)
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(FunctionalTestComponent.LifecycleCallback callback)
public static void removeLifecycleCallback(FunctionalTestComponent.LifecycleCallback callback)
Copyright © 2003–2017 MuleSoft, Inc.. All rights reserved.