org.mule.tck.functional
Class FunctionalTestComponent

java.lang.Object
  extended by org.mule.tck.functional.FunctionalTestComponent
All Implemented Interfaces:
Callable, Disposable, EventListener, Initialisable
Direct Known Subclasses:
TestServiceComponent, TransactionalFunctionalTestComponent

public class FunctionalTestComponent
extends Object
implements Callable, Initialisable, Disposable

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.

See Also:
EventCallback, FunctionalTestNotification, FunctionalTestNotificationListener

Field Summary
protected  Log logger
           
static int STREAM_BUFFER_SIZE
           
static int STREAM_SAMPLE_SIZE
           
 
Fields inherited from interface org.mule.api.lifecycle.Initialisable
PHASE_NAME
 
Fields inherited from interface org.mule.api.lifecycle.Disposable
PHASE_NAME
 
Constructor Summary
FunctionalTestComponent()
           
 
Method Summary
protected  String append(String contents, MuleMessage message)
          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.
 Class 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 getReceivedMessages()
          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 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.
 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 setExceptionToThrow(Class exceptionToThrow)
           
 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)
           
protected  void throwException()
          Always throws a FunctionalTestException.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logger

protected transient Log logger

STREAM_SAMPLE_SIZE

public static final int STREAM_SAMPLE_SIZE
See Also:
Constant Field Values

STREAM_BUFFER_SIZE

public static final int STREAM_BUFFER_SIZE
See Also:
Constant Field Values
Constructor Detail

FunctionalTestComponent

public FunctionalTestComponent()
Method Detail

initialise

public void initialise()
Specified by:
initialise in interface Initialisable

dispose

public void dispose()
Specified by:
dispose in interface Disposable

onCall

public Object onCall(MuleEventContext context)
              throws Exception

Specified by:
onCall in interface Callable
Throws:
Exception

onReceive

public Object onReceive(Object data)
                 throws Exception
This method is used by some WebServices tests where you don' want to be introducing the MuleEventContext as a complex type.

Parameters:
data - the event data received
Returns:
the processed message
Throws:
Exception

throwException

protected void throwException()
                       throws Exception
Always throws a FunctionalTestException. This methodis only called if isThrowException() is true.

Throws:
FunctionalTestException - or the exception specified in 'exceptionType
Exception

append

protected String append(String contents,
                        MuleMessage message)
Will append the value of 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.

Parameters:
contents - the string vlaue of the current message payload
message - the current message
Returns:
a concatenated string of the current payload and the appendString

process

protected Object process(Object data,
                         MuleEventContext context)
                  throws Exception
The service method that implements the test component logic. This method can be called publically through either onCall(org.mule.api.MuleEventContext) or onReceive(Object)

Parameters:
data - The message payload
context - the current MuleEventContext
Returns:
a new message payload according to the configuration of the component
Throws:
Exception - if there is a general failure or if isThrowException() is true.

getEventCallback

public EventCallback getEventCallback()
An event callback is called when a message is received by the service. An MuleEvent callback isn't strictly required but it is usfal for performing assertions on the current message being received. Note that the FunctionalTestComponent should be made a singleton UMODescriptor when using MuleEvent callbacks

Another option is to register a FunctionalTestNotificationListener with Mule and this will deleiver a FunctionalTestNotification for every message received by this service

Returns:
the callback to call when a message is received
See Also:
UMODescriptor, FunctionalTestNotification, FunctionalTestNotificationListener

setEventCallback

public void setEventCallback(EventCallback eventCallback)
An event callback is called when a message is received by the service. An MuleEvent callback isn't strictly required but it is usfal for performing assertions on the current message being received. Note that the FunctionalTestComponent should be made a singleton UMODescriptor when using MuleEvent callbacks

Another option is to register a FunctionalTestNotificationListener with Mule and this will deleiver a FunctionalTestNotification for every message received by this service

Parameters:
eventCallback - the callback to call when a message is received
See Also:
UMODescriptor, FunctionalTestNotification, FunctionalTestNotificationListener

getReturnData

public Object getReturnData()
Often you will may want to return a fixed message payload to simulate and external system call. This can be done using the 'returnData' property. Note that you can return complex objects by using the element in the Xml configuration.

Returns:
the message payload to always return from this service instance

setReturnData

public void setReturnData(Object returnData)
Often you will may want to return a fixed message payload to simulate and external system call. This can be done using the 'returnData' property. Note that you can return complex objects by using the element in the Xml configuration.

Parameters:
returnData - the message payload to always return from this service instance

isThrowException

public 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.

Returns:
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.

setThrowException

public 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.

Parameters:
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.

isEnableMessageHistory

public boolean isEnableMessageHistory()

setEnableMessageHistory

public void setEnableMessageHistory(boolean enableMessageHistory)

getReceivedMessages

public int getReceivedMessages()
If enableMessageHistory = true, returns the number of messages received by this service.


getReceivedMessage

public Object getReceivedMessage(int number)
If enableMessageHistory = true, returns a message received by the service in chronological order. For example, getReceivedMessage(1) returns the first message received by the service, getReceivedMessage(2) returns the second message received by the service, etc.


getLastReceivedMessage

public Object getLastReceivedMessage()
If enableMessageHistory = true, returns the last message received by the service in chronological order.


getAppendString

public String getAppendString()

setAppendString

public void setAppendString(String appendString)

isEnableNotifications

public boolean isEnableNotifications()

setEnableNotifications

public void setEnableNotifications(boolean enableNotifications)

getExceptionToThrow

public Class getExceptionToThrow()

setExceptionToThrow

public void setExceptionToThrow(Class exceptionToThrow)

getWaitTime

public long getWaitTime()

setWaitTime

public void setWaitTime(long waitTime)

isDoInboundTransform

public boolean isDoInboundTransform()

setDoInboundTransform

public void setDoInboundTransform(boolean doInboundTransform)


Copyright © 2003-2008 MuleSource, Inc.. All Rights Reserved.