com.mockrunner.connector
Class GenericFailureInteraction

java.lang.Object
  extended by com.mockrunner.connector.GenericFailureInteraction
All Implemented Interfaces:
InteractionImplementor

public class GenericFailureInteraction
extends java.lang.Object
implements InteractionImplementor

This interaction implementor can be used to simulate failures. By default it simply accepts every request and throws a ResourceException for all execute calls. It can be disabled and it can be configured to return false for execute(InteractionSpec, Record, Record) and null for execute(InteractionSpec, Record) instead of throwing an exception.


Constructor Summary
GenericFailureInteraction()
          Sets the default values, i.e. throwing a ResourceException.
GenericFailureInteraction(boolean throwException)
          Sets if failure values should be returned instead of throwing a ResourceException.
GenericFailureInteraction(boolean throwException, javax.resource.ResourceException exception)
          Sets if failure values should be returned instead of throwing a ResourceException and allows to set the exception that will be thrown if exceptions are enabled.
 
Method Summary
 boolean canHandle(javax.resource.cci.InteractionSpec interactionSpec, javax.resource.cci.Record actualRequest, javax.resource.cci.Record actualResponse)
          Returns true if this implementor is enabled and false otherwise.
 void disable()
          Disables this implementor.
 void enable()
          Enables this implementor.
 javax.resource.cci.Record execute(javax.resource.cci.InteractionSpec interactionSpec, javax.resource.cci.Record actualRequest)
          Throws a ResourceException or returns null.
 boolean execute(javax.resource.cci.InteractionSpec interactionSpec, javax.resource.cci.Record actualRequest, javax.resource.cci.Record actualResponse)
          Throws a ResourceException or returns false.
 void setException(javax.resource.ResourceException exception)
          Sets the exception that will be thrown if exceptions are enabled.
 void setThrowException(boolean throwException)
          Sets if failure values should be returned instead of throwing a ResourceException.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

GenericFailureInteraction

public GenericFailureInteraction()
Sets the default values, i.e. throwing a ResourceException.


GenericFailureInteraction

public GenericFailureInteraction(boolean throwException)
Sets if failure values should be returned instead of throwing a ResourceException.

Parameters:
throwException - true thrown an exception, false return failure values for execute

GenericFailureInteraction

public GenericFailureInteraction(boolean throwException,
                                 javax.resource.ResourceException exception)
Sets if failure values should be returned instead of throwing a ResourceException and allows to set the exception that will be thrown if exceptions are enabled.

Parameters:
throwException - true thrown an exception, false return failure values for execute
exception - the exception to be thrown
Method Detail

enable

public void enable()
Enables this implementor. canHandle(InteractionSpec, Record, Record) returns true, if this implementor is enabled.


disable

public void disable()
Disables this implementor. canHandle(InteractionSpec, Record, Record) returns false, if this implementor is disabled.


setThrowException

public void setThrowException(boolean throwException)
Sets if failure values should be returned instead of throwing a ResourceException.

Parameters:
throwException - true thrown an exception, false return failure values for execute

setException

public void setException(javax.resource.ResourceException exception)
Sets the exception that will be thrown if exceptions are enabled.

Parameters:
exception - the exception to be thrown

canHandle

public boolean canHandle(javax.resource.cci.InteractionSpec interactionSpec,
                         javax.resource.cci.Record actualRequest,
                         javax.resource.cci.Record actualResponse)
Returns true if this implementor is enabled and false otherwise.

Specified by:
canHandle in interface InteractionImplementor
Parameters:
interactionSpec - the InteractionSpec for the actual call
actualRequest - the request for the actual call
actualResponse - the response for the actual call, may be null
Returns:
true if this implementor will handle the request and will return the specified response, false otherwise

execute

public boolean execute(javax.resource.cci.InteractionSpec interactionSpec,
                       javax.resource.cci.Record actualRequest,
                       javax.resource.cci.Record actualResponse)
                throws javax.resource.ResourceException
Throws a ResourceException or returns false. You can use setThrowException(boolean) to configure this behaviour.

Specified by:
execute in interface InteractionImplementor
Parameters:
interactionSpec - the interaction spec
actualRequest - the actual request
actualResponse - the actual response
Returns:
true under normal conditions
Throws:
javax.resource.ResourceException

execute

public javax.resource.cci.Record execute(javax.resource.cci.InteractionSpec interactionSpec,
                                         javax.resource.cci.Record actualRequest)
                                  throws javax.resource.ResourceException
Throws a ResourceException or returns null. You can use setThrowException(boolean) to configure this behaviour.

Specified by:
execute in interface InteractionImplementor
Parameters:
interactionSpec - the interaction spec
actualRequest - the actual request
Returns:
the response according to the current request
Throws:
javax.resource.ResourceException