|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.mockrunner.connector.MappedRecordInteraction
public class MappedRecordInteraction
This interaction implementor works with mapped records. It takes a Map
for
the request and a Map
or a Record
instance for the response.
If the request Map
is null
, which is the default,
the implementor accepts any request and returns the specified result. If a request
Map
is specified, this implementor accepts only requests that contain the same
data as the specified expected request Map
. The underlying maps are compared
as described in the Map.equals
method.
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 and the response.
Please check out the documentation of the various methods for details.
Constructor Summary | |
---|---|
MappedRecordInteraction()
Sets the expected request and the response to null ,
i.e. an empty response is returned for every request. |
|
MappedRecordInteraction(java.util.Map responseMap)
Sets the expected request to null and prepares
the specified response Map . |
|
MappedRecordInteraction(java.util.Map responseMap,
java.lang.Class responseClass)
Sets the expected request to null and prepares
the specified response Map . |
|
MappedRecordInteraction(java.util.Map expectedRequest,
java.util.Map responseMap)
Sets the specified expected request Map and prepares
the specified response Map . |
|
MappedRecordInteraction(java.util.Map expectedRequest,
java.util.Map responseMap,
java.lang.Class responseClass)
Sets the specified expected request Map and prepares
the specified response Map . |
|
MappedRecordInteraction(java.util.Map expectedRequest,
javax.resource.cci.Record responseRecord)
Sets the specified expected request Map and the response
Record for the execute(InteractionSpec, Record)
method. |
|
MappedRecordInteraction(javax.resource.cci.Record responseRecord)
Sets the expected request to null and prepares the response
Record for the execute(InteractionSpec, Record)
method. |
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 will handle the request. |
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)
First version of the execute methods. |
boolean |
execute(javax.resource.cci.InteractionSpec interactionSpec,
javax.resource.cci.Record actualRequest,
javax.resource.cci.Record actualResponse)
Second version of the execute methods. |
void |
setExpectedRequest(java.util.Map expectedRequest)
Sets the specified expected request Map . |
void |
setResponse(java.util.Map responseMap)
Prepares the specified response Map . |
void |
setResponse(java.util.Map responseMap,
java.lang.Class responseClass)
Prepares the specified response Map . |
void |
setResponse(javax.resource.cci.Record responseRecord)
Prepares the response Record for the
execute(InteractionSpec, Record) method. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public MappedRecordInteraction()
null
,
i.e. an empty response is returned for every request.
public MappedRecordInteraction(java.util.Map responseMap)
null
and prepares
the specified response Map
. The response class for the
execute(InteractionSpec,Record)
method is set
to the default MockMappedRecord
.
It is allowed to pass null
for the response Map
which is equivalent to an empty response.
The specified response is returned for every request.
responseMap
- the response Map
public MappedRecordInteraction(java.util.Map expectedRequest, java.util.Map responseMap)
Map
and prepares
the specified response Map
. The response class for the
execute(InteractionSpec,Record)
method is set
to the default MockMappedRecord
.
It is allowed to pass null
for the request and response Map
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.
expectedRequest
- the expected request Map
responseMap
- the response Map
public MappedRecordInteraction(java.util.Map responseMap, java.lang.Class responseClass)
null
and prepares
the specified response Map
. The response class for the
execute(InteractionSpec,Record)
method is set
to the specified responseClass
. The specified
responseClass
must implement MappedRecord
,
otherwise an IllegalArgumentException
will be thrown.
It is allowed to pass null
for the response Map
which is equivalent to an empty response.
The specified response is returned for every request.
responseMap
- the response MapresponseClass
- the response Record
class
Throws:
java.lang.IllegalArgumentException
- if the responseClass
is not valid
MappedRecordInteraction
public MappedRecordInteraction(java.util.Map expectedRequest,
java.util.Map responseMap,
java.lang.Class responseClass)
- Sets the specified expected request
Map
and prepares
the specified response Map
. The response class for the
execute(InteractionSpec,Record)
method is set
to the specified responseClass
. The specified
responseClass
must implement MappedRecord
,
otherwise an IllegalArgumentException
will be thrown.
It is allowed to pass null
for the request and response Map
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.
- Parameters:
expectedRequest
- the expected request Map
responseMap
- the response MapresponseClass
- the response Record
class
Throws:
java.lang.IllegalArgumentException
- if the responseClass
is not valid
MappedRecordInteraction
public MappedRecordInteraction(java.util.Map expectedRequest,
javax.resource.cci.Record responseRecord)
- Sets the specified expected request
Map
and the response
Record
for the execute(InteractionSpec, Record)
method. The response Record
is ignored for
execute(InteractionSpec,Record,Record)
but takes precedence
over the specified response Map
for execute(InteractionSpec, Record)
.
It is allowed to pass null
for the request and response Record
which is equivalent to an empty expected request (i.e. every request is accepted)
or to no specified response Record
, i.e. the specified response
Map
is taken.
The specified response is returned, if the actual request matches the specified expected
request.
- Parameters:
expectedRequest
- the expected request Map
responseRecord
- the response Record
MappedRecordInteraction
public MappedRecordInteraction(javax.resource.cci.Record responseRecord)
- Sets the expected request to
null
and prepares the response
Record
for the execute(InteractionSpec, Record)
method. The response Record
is ignored for
execute(InteractionSpec,Record,Record)
but takes precedence
over the specified response Map
for execute(InteractionSpec, Record)
.
It is allowed to pass null
for the response Record
which is equivalent to no specified response Record
, i.e. the specified response
Map
is taken.
The specified response is returned for every request.
- Parameters:
responseRecord
- the response Record
Method Detail
enable
public void enable()
- Enables this implementor.
disable
public void disable()
- Disables this implementor.
canHandle(InteractionSpec, Record, Record)
always returns false
, if this implementor is disabled.
setExpectedRequest
public void setExpectedRequest(java.util.Map expectedRequest)
- Sets the specified expected request
Map
. The response is returned,
if the actual request matches the specified expected request Map
according to Map.equals
.
It is allowed to pass null
for the request Map
which is equivalent to an empty expected request (i.e. every request
is accepted).
- Parameters:
expectedRequest
- the expected request Map
setResponse
public void setResponse(java.util.Map responseMap)
- Prepares the specified response
Map
. The response class for the
execute(InteractionSpec,Record)
method is set
to the default MockMappedRecord
.
It is allowed to pass null
for the response Map
which is equivalent to an empty response.
- Parameters:
responseMap
- the response Map
setResponse
public void setResponse(java.util.Map responseMap,
java.lang.Class responseClass)
- Prepares the specified response
Map
. The response class for the
execute(InteractionSpec,Record)
method is set
to the specified responseClass
. The specified
responseClass
must implement MappedRecord
,
otherwise an IllegalArgumentException
will be thrown.
It is allowed to pass null
for the response Map
which is equivalent to an empty response.
- Parameters:
responseMap
- the response Map
responseClass
- the response Record
class
- Throws:
java.lang.IllegalArgumentException
- if the responseClass
is not valid
setResponse
public void setResponse(javax.resource.cci.Record responseRecord)
- Prepares the response
Record
for the
execute(InteractionSpec, Record)
method. The response
Record
is ignored for execute(InteractionSpec,Record,Record)
but takes precedence over the specified response Map
for
execute(InteractionSpec, Record)
.
It is allowed to pass null
for the response Record
which is equivalent to no specified response Record
, i.e. the specified response
Map
is taken.
- Parameters:
responseRecord
- the response Record
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 will handle the request.
This method returns true
if the following prerequisites are fulfilled:
It is enabled.
The response Record
must implement MappedRecord
or it must be null
(which is the case, if the actual request
targets the execute(InteractionSpec,Record)
method instead of
execute(InteractionSpec,Record,Record)
).
The expected request must be null
(use the various
setExpectedRequest
methods) or the actual request Record
must implement MappedRecord
and must contain the same data as
the specified expected request Map
according to Map.equals
.
Otherwise, false
is returned.
- Specified by:
canHandle
in interface InteractionImplementor
- Parameters:
interactionSpec
- the InteractionSpec
for the actual callactualRequest
- the request for the actual callactualResponse
- 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 javax.resource.cci.Record execute(javax.resource.cci.InteractionSpec interactionSpec,
javax.resource.cci.Record actualRequest)
throws javax.resource.ResourceException
- First version of the
execute
methods.
This method returns null
, if the request does not match
according to the contract of canHandle(javax.resource.cci.InteractionSpec, javax.resource.cci.Record, javax.resource.cci.Record)
. This never happens under
normal conditions since the InteractionHandler
does not call
execute
, if canHandle(javax.resource.cci.InteractionSpec, javax.resource.cci.Record, javax.resource.cci.Record)
returns false
.
Otherwise, this method returns the specified response. If a response
Record
object is specified (use setResponse(Record)
),
it always takes precedence, i.e. the response Map
will be ignored.
If no Record
object is specified, a Record
object
is created and filled with the specified response Map
data. Use the
setResponse
methods that take a Map
to prepare the response Map
. The created Record
is of the the
specified type (the setResponse
method that takes a second
Class
parameter allows for specifying a type). If no type
is specified, a MockMappedRecord
is created. If no response Map
is specified at all, an empty
MockMappedRecord
will be returned.
- Specified by:
execute
in interface InteractionImplementor
- Parameters:
interactionSpec
- the interaction specactualRequest
- the actual request
- Returns:
- the response according to the current request
- Throws:
javax.resource.ResourceException
execute
public boolean execute(javax.resource.cci.InteractionSpec interactionSpec,
javax.resource.cci.Record actualRequest,
javax.resource.cci.Record actualResponse)
throws javax.resource.ResourceException
- Second version of the
execute
methods.
This method returns false
, if the request does not match
according to the contract of canHandle(javax.resource.cci.InteractionSpec, javax.resource.cci.Record, javax.resource.cci.Record)
. This never happens under
normal conditions since the InteractionHandler
does not call
execute
, if canHandle(javax.resource.cci.InteractionSpec, javax.resource.cci.Record, javax.resource.cci.Record)
returns false
.
Otherwise, this method fills the response Record
with the
specified response Map
data. Use the setResponse
methods that
take a Map
to prepare the response Map
.
The response Record
must implement MappedRecord
(it does, otherwise the request would have been rejected by
canHandle(javax.resource.cci.InteractionSpec, javax.resource.cci.Record, javax.resource.cci.Record)
). If no response Map
is specified at all,
the response Record
is not touched but true
is returned anyway
- Specified by:
execute
in interface InteractionImplementor
- Parameters:
interactionSpec
- the interaction specactualRequest
- the actual requestactualResponse
- the actual response
- Returns:
true
under normal conditions
- Throws:
javax.resource.ResourceException
Overview
Package
Class
Use
Tree
Deprecated
Index
Help
PREV CLASS
NEXT CLASS
FRAMES
NO FRAMES
All Classes
SUMMARY: NESTED | FIELD | CONSTR | METHOD
DETAIL: FIELD | CONSTR | METHOD