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.Booleanexpectedprivate BodyMatcherexpectedBodyprivate MatchStatusexpectedBodyStatusprivate HeadersexpectedHeadersprivate HeadersexpectedQueryParamsprivate ExpectedResponseRecordexpectedResponseprivate TimesexpectedTimesprivate java.util.function.Function<HttpRequest<?>,ExpectedResponse>functionalResponseprivate java.util.List<HttpRequest>requestsprivate Routesroutes
-
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 HeadersallHeaders()Expectationbody(java.lang.String body)A expected body for a requestExpectationbody(BodyMatcher matcher)A matcher for the body for a requestprivate java.lang.Stringdetails()private java.util.stream.Stream<Body>getBodyStream()java.util.List<HttpRequest>getRequests()(package private) RawResponsegetResponse(Config config, HttpRequest request)booleanhasBody(java.lang.String body)booleanhasExpectedHeader(java.lang.String key, java.lang.String value)booleanhasField(java.lang.String name, java.lang.String value)private booleanhasField(java.lang.String name, java.lang.String value, Body b)Expectationheader(java.lang.String key, java.lang.String value)A expected header for a requestjava.lang.BooleanisExpected()voidlog(HttpRequest request)private java.lang.IntegermatchBody(Body b)ExpectationqueryString(java.lang.String key, java.lang.String value)A expected header for a requestjava.lang.IntegerrequestSize()private intscoreBody(HttpRequest request)private intscoreHeaders(HttpRequest request)java.lang.IntegerscoreMatch(HttpRequest request)private intscoreQuery(HttpRequest request)ExpectedResponsethenReturn()expect a null responseExpectedResponsethenReturn(java.lang.Object pojo)expect a object response as defined by a pojo using the requests / configuration object mapperExpectedResponsethenReturn(java.lang.String body)expect a string responsevoidthenReturn(java.util.function.Function<HttpRequest<?>,ExpectedResponse> fun)Allows for a full override of the way a expected response is built.ExpectedResponsethenReturn(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.ExpectedResponsethenReturn(JSONElement jsonObject)expect a json responseExpectationtimes(Times times)private static <T,M extends T>
java.util.Optional<M>tryCast(T original, java.lang.Class<M> too)private booleanuniBodyMatches(java.lang.String body, Body o)voidverify()verify that all Expectations was fulfilled at least once.voidverify(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:Expectationexpect a string response- Specified by:
thenReturnin interfaceExpectation- Parameters:
body- the expected response body- Returns:
- The ExpectedResponse
-
thenReturn
public ExpectedResponse thenReturn(JSONElement jsonObject)
Description copied from interface:Expectationexpect a json response- Specified by:
thenReturnin interfaceExpectation- Parameters:
jsonObject- the expected response body- Returns:
- The ExpectedResponse
-
thenReturn
public ExpectedResponse thenReturn(java.lang.Object pojo)
Description copied from interface:Expectationexpect a object response as defined by a pojo using the requests / configuration object mapper- Specified by:
thenReturnin 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:ExpectationA supplier for the expected body which will get invoked at the time of build the response.- Specified by:
thenReturnin 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:ExpectationAllows 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:
thenReturnin 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:ExpectationA expected header for a request- Specified by:
headerin 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:ExpectationA expected header for a request- Specified by:
queryStringin interfaceExpectation- Parameters:
key- the query keyvalue- the query value- Returns:
- this Expectation
-
body
public Expectation body(java.lang.String body)
Description copied from interface:ExpectationA expected body for a request- Specified by:
bodyin interfaceExpectation- Parameters:
body- the expected body- Returns:
- this Expectation
-
body
public Expectation body(BodyMatcher matcher)
Description copied from interface:ExpectationA matcher for the body for a request- Specified by:
bodyin interfaceExpectation- Parameters:
matcher- the matcher- Returns:
- this Expectation
-
thenReturn
public ExpectedResponse thenReturn()
Description copied from interface:Expectationexpect a null response- Specified by:
thenReturnin interfaceExpectation- Returns:
- The ExpectedResponse
-
verify
public void verify()
Description copied from interface:Expectationverify that all Expectations was fulfilled at least once.- Specified by:
verifyin interfaceExpectation
-
verify
public void verify(Times times)
- Specified by:
verifyin interfaceExpectation
-
times
public Expectation times(Times times)
- Specified by:
timesin 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)
-
-