org.mule.tck.functional
Class FunctionalTestComponent

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

public class FunctionalTestComponent
extends Object
implements Callable, Initialisable, Disposable, MuleContextAware, Receiveable, Startable, 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.

See Also:
EventCallback, FunctionalTestNotification, FunctionalTestNotificationListener

Nested Class Summary
static interface FunctionalTestComponent.LifecycleCallback
           
 
Field Summary
protected  org.apache.commons.logging.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
 
Fields inherited from interface org.mule.api.lifecycle.Startable
PHASE_NAME
 
Fields inherited from interface org.mule.api.lifecycle.Stoppable
PHASE_NAME
 
Constructor Summary
FunctionalTestComponent()
           
 
Method Summary
static void addLifecycleCallback(FunctionalTestComponent.LifecycleCallback callback)
           
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.
 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 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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logger

protected transient org.apache.commons.logging.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

start

public void start()
           throws MuleException
Specified by:
start in interface Startable
Throws:
MuleException

setMuleContext

public void setMuleContext(MuleContext context)
Specified by:
setMuleContext in interface MuleContextAware

stop

public void stop()
          throws MuleException
Specified by:
stop in interface Stoppable
Throws:
MuleException

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.

Specified by:
onReceive in interface Receiveable
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 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:
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 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:
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)

getReceivedMessagesCount

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

Returns:
-1 if no message history, otherwise the history size

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<? extends Throwable> getExceptionToThrow()

setExceptionToThrow

public void setExceptionToThrow(Class<? extends Throwable> exceptionToThrow)

getWaitTime

public long getWaitTime()

setWaitTime

public void setWaitTime(long waitTime)

isDoInboundTransform

public boolean isDoInboundTransform()

setDoInboundTransform

public void setDoInboundTransform(boolean doInboundTransform)

isLogMessageDetails

public boolean isLogMessageDetails()

setLogMessageDetails

public void setLogMessageDetails(boolean logMessageDetails)

getExceptionText

public String getExceptionText()

setExceptionText

public void setExceptionText(String text)

setId

public void setId(String id)

addLifecycleCallback

public static void addLifecycleCallback(FunctionalTestComponent.LifecycleCallback callback)

removeLifecycleCallback

public static void removeLifecycleCallback(FunctionalTestComponent.LifecycleCallback callback)


Copyright © 2003–2014 MuleSoft, Inc.. All rights reserved.