public class FunctionalTestProcessor extends AbstractComponent implements Processor, Lifecycle
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
LOCATION_KEY, ROOT_CONTAINER_NAME_KEY
PHASE_NAME
PHASE_NAME
PHASE_NAME
PHASE_NAME
ANNOTATIONS_PROPERTY_NAME
Constructor and Description |
---|
FunctionalTestProcessor() |
Modifier and Type | Method and Description |
---|---|
static void |
addLifecycleCallback(FunctionalTestProcessor.LifecycleCallback callback) |
protected String |
append(String contents,
CoreEvent event)
Will append the value of
getAppendString() to the contents of the message. |
void |
dispose()
A lifecycle method where implementor should free up any resources.
|
protected CoreEvent |
doProcess(CoreEvent 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(ConfigurationComponentLocator locator,
String flowName) |
CoreEvent |
getLastReceivedMessage()
If enableMessageHistory = true, returns the last message received by the service in chronological order.
|
ReactiveProcessor.ProcessingType |
getProcessingType()
In order for Mule to determine the best way to execute different processors based on the chosen
ProcessingStrategy it
needs to know the type of work the message processor will be performing and if it is ReactiveProcessor.ProcessingType.BLOCKING ,
ReactiveProcessor.ProcessingType.CPU_INTENSIVE intensive or neither (ReactiveProcessor.ProcessingType.CPU_LITE ). |
CoreEvent |
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()
Method used to perform any initialisation work.
|
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.
|
CoreEvent |
process(CoreEvent event)
Invokes the MessageProcessor.
|
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 |
setId(String id) |
void |
setLogMessageDetails(boolean logMessageDetails) |
void |
setProcessingType(ReactiveProcessor.ProcessingType processingType) |
void |
setProcessorClass(String processorClass) |
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, getRootContainerLocation, setAnnotations
public void initialise() throws InitialisationException
Initialisable
InitialisationException
should be thrown.
In case that the Initialisable.initialise()
method execution fails then mule will call the Disposable.dispose()
method if
the class also implements Disposable
allowing the object to dispose any allocated resource during
Initialisable.initialise()
initialise
in interface Initialisable
InitialisationException
- if a fatal error occurs causing the Mule instance to shutdownDisposable
public void start() throws MuleException
start
in interface Startable
MuleException
public void stop() throws MuleException
stop
in interface Stoppable
MuleException
public void dispose()
Disposable
dispose
in interface Disposable
public CoreEvent process(CoreEvent event) throws MuleException
Processor
process
in interface Processor
event
- MuleEvent to be processedMuleException
protected void throwException() throws Exception
FunctionalTestException
. This methodis only called if isThrowException()
is true.FunctionalTestException
- or the exception specified in 'exceptionTypeException
protected String append(String contents, CoreEvent 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 CoreEvent doProcess(CoreEvent event) throws Exception
event
- the current CoreEvent
Exception
- 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
,
FunctionalTestNotificationListener
public 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
,
FunctionalTestNotificationListener
public 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 CoreEvent getReceivedMessage(int number)
public CoreEvent 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(ConfigurationComponentLocator locator, String flowName) throws Exception
test:processor
from a flow with the provided name.Exception
public void setProcessorClass(String processorClass)
public ReactiveProcessor.ProcessingType getProcessingType()
ReactiveProcessor
ProcessingStrategy
it
needs to know the type of work the message processor will be performing and if it is ReactiveProcessor.ProcessingType.BLOCKING
,
ReactiveProcessor.ProcessingType.CPU_INTENSIVE
intensive or neither (ReactiveProcessor.ProcessingType.CPU_LITE
).
This method must return the same value for the same processor every time.
getProcessingType
in interface ReactiveProcessor
public void setProcessingType(ReactiveProcessor.ProcessingType processingType)
Copyright © 2018. All rights reserved.