| java.lang.Object com.mockrunner.connector.StreamableRecordByteArrayInteraction
StreamableRecordByteArrayInteraction | public class StreamableRecordByteArrayInteraction implements InteractionImplementor(Code) | | This interaction implementor works with bytes arrays and streamable
records. It takes a byte array for the request and a byte array or
a Record instance for the response. If the request byte array
is null , which is the default, the implementor accepts any
request and returns the specified result. If a request byte array is specified,
this implementor accepts only requests that are equal to the specified request
byte array. If a request is accepted, this implementor replies with the specified
response. You can use the various constructors and set methods
to configure the expected request data and the response.
Please check out the documentation of the various methods for details.
|
Method Summary | |
public boolean | canHandle(InteractionSpec interactionSpec, Record actualRequest, Record actualResponse) Returns true if this implementor is enabled and will handle the request. | public void | disable() Disables this implementor. | public void | enable() Enables this implementor. | public Record | execute(InteractionSpec interactionSpec, Record actualRequest) First version of the execute methods.
This method returns null , if the request does not match
according to the contract of
StreamableRecordByteArrayInteraction.canHandle . | public boolean | execute(InteractionSpec interactionSpec, Record actualRequest, Record actualResponse) Second version of the execute methods.
This method returns false , if the request does not match
according to the contract of
StreamableRecordByteArrayInteraction.canHandle . | public void | setExpectedRequest(byte[] expectedRequest) Sets the specified expected request data. | public void | setExpectedRequest(InputStream expectedRequest) Reads the expected request data from the specified InputStream .
The response is returned, if the actual request matches the expected request data.
It is allowed to pass null for the InputStream
which is equivalent to an empty expected request (i.e. | public void | setResponse(byte[] responseData) Prepares the specified response data. | public void | setResponse(byte[] responseData, Class responseClass) Prepares the specified response data. | public void | setResponse(InputStream responseData) Reads the response data from the specified InputStream . | public void | setResponse(InputStream responseData, Class responseClass) Reads the response data from the specified InputStream . | public void | setResponse(Record responseRecord) Prepares the response Record for the
StreamableRecordByteArrayInteraction.execute(InteractionSpec,Record) method. |
StreamableRecordByteArrayInteraction | public StreamableRecordByteArrayInteraction()(Code) | | Sets the expected request and the response to null ,
i.e. an empty response is returned for every request.
|
StreamableRecordByteArrayInteraction | public StreamableRecordByteArrayInteraction(byte[] expectedRequest, byte[] responseData)(Code) | | Sets the specified expected request data and prepares
the specified response data. The response class for the
StreamableRecordByteArrayInteraction.execute(InteractionSpec,Record) method is set
to the default
com.mockrunner.mock.connector.cci.MockStreamableByteArrayRecord .
It is allowed to pass null for the request and response data
which is equivalent to an empty expected request (i.e. every request is accepted)
or to an empty response respectively.
The specified response is returned, if the actual request matches the specified expected
request data.
Parameters: expectedRequest - the expected request data Parameters: responseData - the response data |
StreamableRecordByteArrayInteraction | public StreamableRecordByteArrayInteraction(byte[] responseData, Class responseClass)(Code) | | Sets the expected request to null and prepares
the specified response data. The response class for the
StreamableRecordByteArrayInteraction.execute(InteractionSpec,Record) method is set
to the specified responseClass . The specified
responseClass must implement Record
and Streamable , otherwise an
IllegalArgumentException will be thrown.
It is allowed to pass null for the response data which is
equivalent to an empty response.
The specified response is returned for every request.
Parameters: responseData - the response data Parameters: responseClass - the response Record class throws: IllegalArgumentException - if the responseClass is not valid |
StreamableRecordByteArrayInteraction | public StreamableRecordByteArrayInteraction(byte[] expectedRequest, byte[] responseData, Class responseClass)(Code) | | Sets the specified expected request data and prepares
the specified response data. The response class for the
StreamableRecordByteArrayInteraction.execute(InteractionSpec,Record) method is set
to the specified responseClass . The specified
responseClass must implement Record
and Streamable , otherwise an
IllegalArgumentException will be thrown.
It is allowed to pass null for the request and response data
which is equivalent to an empty expected request (i.e. every request is accepted)
or to an empty response respectively.
The specified response is returned, if the actual request matches the specified expected
request data.
Parameters: expectedRequest - the expected request data Parameters: responseData - the response data Parameters: responseClass - the response Record class throws: IllegalArgumentException - if the responseClass is not valid |
canHandle | public boolean canHandle(InteractionSpec interactionSpec, Record actualRequest, Record actualResponse)(Code) | | Returns true if this implementor is enabled and will handle the request.
This method returns true if the following prerequisites are fulfilled:
It is enabled.
The response Record must implement Streamable
or it must be null (which is the case, if the actual request
targets the
StreamableRecordByteArrayInteraction.execute(InteractionSpec,Record) method instead of
StreamableRecordByteArrayInteraction.execute(InteractionSpec,Record,Record) ).
The expected request must be null (use the various
setExpectedRequest methods) or the actual request Record
must implement Streamable and must contain the same data as
the specified expected request.
Otherwise, false is returned.
Parameters: interactionSpec - the InteractionSpec for the actual call Parameters: actualRequest - the request for the actual call Parameters: actualResponse - the response for the actual call, may be null true if this implementor will handle the request andwill return the specified response, false otherwise |
enable | public void enable()(Code) | | Enables this implementor.
|
execute | public boolean execute(InteractionSpec interactionSpec, Record actualRequest, Record actualResponse) throws ResourceException(Code) | | Second version of the execute methods.
This method returns false , if the request does not match
according to the contract of
StreamableRecordByteArrayInteraction.canHandle . This never happens under
normal conditions since the
InteractionHandler does not call
execute , if
StreamableRecordByteArrayInteraction.canHandle returns false .
Otherwise, this method fills the response Record with the
specified byte response data. Use the setResponse methods that
take a byte array or an InputStream to prepare response data.
The response Record must implement Streamable
(it does, otherwise the request would have been rejected by
StreamableRecordByteArrayInteraction.canHandle ). If no response data is specified at all,
the response Record is not touched but true
is returned anyway
Parameters: interactionSpec - the interaction spec Parameters: actualRequest - the actual request Parameters: actualResponse - the actual response true under normal conditions |
setExpectedRequest | public void setExpectedRequest(byte[] expectedRequest)(Code) | | Sets the specified expected request data. The response is returned,
if the actual request matches the specified expected request data.
It is allowed to pass null for the request data
which is equivalent to an empty expected request (i.e. every request
is accepted).
Parameters: expectedRequest - the expected request data |
setExpectedRequest | public void setExpectedRequest(InputStream expectedRequest)(Code) | | Reads the expected request data from the specified InputStream .
The response is returned, if the actual request matches the expected request data.
It is allowed to pass null for the InputStream
which is equivalent to an empty expected request (i.e. every request
is accepted).
Parameters: expectedRequest - the expected request |
setResponse | public void setResponse(byte[] responseData, Class responseClass)(Code) | | Prepares the specified response data. The response class for the
StreamableRecordByteArrayInteraction.execute(InteractionSpec,Record) method is set
to the specified responseClass . The specified
responseClass must implement Record
and Streamable , otherwise an
IllegalArgumentException will be thrown.
It is allowed to pass null for the response data
which is equivalent to an empty response.
Parameters: responseData - the response data Parameters: responseClass - the response Record class throws: IllegalArgumentException - if the responseClass is not valid |
setResponse | public void setResponse(InputStream responseData, Class responseClass)(Code) | | Reads the response data from the specified InputStream .
The response class for the
StreamableRecordByteArrayInteraction.execute(InteractionSpec,Record) method is set
to the specified responseClass . The specified
responseClass must implement Record
and Streamable , otherwise an
IllegalArgumentException will be thrown.
It is allowed to pass null for the InputStream
which is equivalent to an empty response.
Parameters: responseData - the response data Parameters: responseClass - the response Record class throws: IllegalArgumentException - if the responseClass is not valid |
|
|