Package kong.unirest.core
Class Invocation
- java.lang.Object
-
- kong.unirest.core.Invocation
-
- All Implemented Interfaces:
Expectation
class Invocation extends java.lang.Object implements Expectation
-
-
Field Summary
Fields Modifier and Type Field Description private java.lang.Boolean
expected
private BodyMatcher
expectedBody
private MatchStatus
expectedBodyStatus
private Headers
expectedHeaders
private Headers
expectedQueryParams
private ExpectedResponseRecord
expectedResponse
private Times
expectedTimes
private java.util.function.Function<HttpRequest<?>,ExpectedResponse>
functionalResponse
private java.util.List<HttpRequest>
requests
private Routes
routes
-
Constructor Summary
Constructors Constructor Description Invocation()
Invocation(Routes routes)
Invocation(Routes routes, HttpRequest request)
Invocation(Routes routes, Invocation other)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private Headers
allHeaders()
Expectation
body(java.lang.String body)
A expected body for a requestExpectation
body(BodyMatcher matcher)
A matcher for the body for a requestprivate java.lang.String
details()
private java.util.stream.Stream<Body>
getBodyStream()
java.util.List<HttpRequest>
getRequests()
(package private) RawResponse
getResponse(Config config, HttpRequest request)
boolean
hasBody(java.lang.String body)
boolean
hasExpectedHeader(java.lang.String key, java.lang.String value)
boolean
hasField(java.lang.String name, java.lang.String value)
private boolean
hasField(java.lang.String name, java.lang.String value, Body b)
Expectation
header(java.lang.String key, java.lang.String value)
A expected header for a requestjava.lang.Boolean
isExpected()
void
log(HttpRequest request)
private java.lang.Integer
matchBody(Body b)
Expectation
queryString(java.lang.String key, java.lang.String value)
A expected header for a requestjava.lang.Integer
requestSize()
private int
scoreBody(HttpRequest request)
private int
scoreHeaders(HttpRequest request)
java.lang.Integer
scoreMatch(HttpRequest request)
private int
scoreQuery(HttpRequest request)
ExpectedResponse
thenReturn()
expect a null responseExpectedResponse
thenReturn(java.lang.Object pojo)
expect a object response as defined by a pojo using the requests / configuration object mapperExpectedResponse
thenReturn(java.lang.String body)
expect a string responsevoid
thenReturn(java.util.function.Function<HttpRequest<?>,ExpectedResponse> fun)
Allows for a full override of the way a expected response is built.ExpectedResponse
thenReturn(java.util.function.Supplier<java.lang.String> supplier)
A supplier for the expected body which will get invoked at the time of build the response.ExpectedResponse
thenReturn(JSONElement jsonObject)
expect a json responseExpectation
times(Times times)
private static <T,M extends T>
java.util.Optional<M>tryCast(T original, java.lang.Class<M> too)
private boolean
uniBodyMatches(java.lang.String body, Body o)
void
verify()
verify that all Expectations was fulfilled at least once.void
verify(Times times)
-
-
-
Field Detail
-
routes
private Routes routes
-
requests
private java.util.List<HttpRequest> requests
-
expectedHeaders
private Headers expectedHeaders
-
expectedQueryParams
private Headers expectedQueryParams
-
expected
private java.lang.Boolean expected
-
expectedBody
private BodyMatcher expectedBody
-
expectedBodyStatus
private MatchStatus expectedBodyStatus
-
expectedResponse
private ExpectedResponseRecord expectedResponse
-
functionalResponse
private java.util.function.Function<HttpRequest<?>,ExpectedResponse> functionalResponse
-
expectedTimes
private Times expectedTimes
-
-
Constructor Detail
-
Invocation
public Invocation(Routes routes)
-
Invocation
public Invocation(Routes routes, HttpRequest request)
-
Invocation
Invocation(Routes routes, Invocation other)
-
Invocation
Invocation()
-
-
Method Detail
-
thenReturn
public ExpectedResponse thenReturn(java.lang.String body)
Description copied from interface:Expectation
expect a string response- Specified by:
thenReturn
in interfaceExpectation
- Parameters:
body
- the expected response body- Returns:
- The ExpectedResponse
-
thenReturn
public ExpectedResponse thenReturn(JSONElement jsonObject)
Description copied from interface:Expectation
expect a json response- Specified by:
thenReturn
in interfaceExpectation
- Parameters:
jsonObject
- the expected response body- Returns:
- The ExpectedResponse
-
thenReturn
public ExpectedResponse thenReturn(java.lang.Object pojo)
Description copied from interface:Expectation
expect a object response as defined by a pojo using the requests / configuration object mapper- Specified by:
thenReturn
in interfaceExpectation
- Parameters:
pojo
- the expected response body- Returns:
- The ExpectedResponse
-
thenReturn
public ExpectedResponse thenReturn(java.util.function.Supplier<java.lang.String> supplier)
Description copied from interface:Expectation
A supplier for the expected body which will get invoked at the time of build the response.- Specified by:
thenReturn
in interfaceExpectation
- Parameters:
supplier
- the expected response body supplier- Returns:
- The ExpectedResponse
-
thenReturn
public void thenReturn(java.util.function.Function<HttpRequest<?>,ExpectedResponse> fun)
Description copied from interface:Expectation
Allows for a full override of the way a expected response is built. useful in building more complicated test-doubles of services that implement logic- Specified by:
thenReturn
in interfaceExpectation
- Parameters:
fun
- the function to convert a request to a response
-
getResponse
RawResponse getResponse(Config config, HttpRequest request)
-
allHeaders
private Headers allHeaders()
-
log
public void log(HttpRequest request)
-
header
public Expectation header(java.lang.String key, java.lang.String value)
Description copied from interface:Expectation
A expected header for a request- Specified by:
header
in interfaceExpectation
- Parameters:
key
- the header keyvalue
- the header value- Returns:
- this Expectation
-
queryString
public Expectation queryString(java.lang.String key, java.lang.String value)
Description copied from interface:Expectation
A expected header for a request- Specified by:
queryString
in interfaceExpectation
- Parameters:
key
- the query keyvalue
- the query value- Returns:
- this Expectation
-
body
public Expectation body(java.lang.String body)
Description copied from interface:Expectation
A expected body for a request- Specified by:
body
in interfaceExpectation
- Parameters:
body
- the expected body- Returns:
- this Expectation
-
body
public Expectation body(BodyMatcher matcher)
Description copied from interface:Expectation
A matcher for the body for a request- Specified by:
body
in interfaceExpectation
- Parameters:
matcher
- the matcher- Returns:
- this Expectation
-
thenReturn
public ExpectedResponse thenReturn()
Description copied from interface:Expectation
expect a null response- Specified by:
thenReturn
in interfaceExpectation
- Returns:
- The ExpectedResponse
-
verify
public void verify()
Description copied from interface:Expectation
verify that all Expectations was fulfilled at least once.- Specified by:
verify
in interfaceExpectation
-
verify
public void verify(Times times)
- Specified by:
verify
in interfaceExpectation
-
times
public Expectation times(Times times)
- Specified by:
times
in interfaceExpectation
-
details
private java.lang.String details()
-
hasExpectedHeader
public boolean hasExpectedHeader(java.lang.String key, java.lang.String value)
-
getBodyStream
private java.util.stream.Stream<Body> getBodyStream()
-
hasBody
public boolean hasBody(java.lang.String body)
-
uniBodyMatches
private boolean uniBodyMatches(java.lang.String body, Body o)
-
hasField
public boolean hasField(java.lang.String name, java.lang.String value)
-
hasField
private boolean hasField(java.lang.String name, java.lang.String value, Body b)
-
requestSize
public java.lang.Integer requestSize()
-
getRequests
public java.util.List<HttpRequest> getRequests()
-
isExpected
public java.lang.Boolean isExpected()
-
scoreMatch
public java.lang.Integer scoreMatch(HttpRequest request)
-
scoreBody
private int scoreBody(HttpRequest request)
-
matchBody
private java.lang.Integer matchBody(Body b)
-
scoreHeaders
private int scoreHeaders(HttpRequest request)
-
scoreQuery
private int scoreQuery(HttpRequest request)
-
tryCast
private static <T,M extends T> java.util.Optional<M> tryCast(T original, java.lang.Class<M> too)
-
-