public interface MkContainer
A convenient tool to test your application classes against a web service. For example:
MkContainer container = new MkGrizzlyContainer() .next(new MkAnswer.Simple(200, "works fine!")) .start(); new JdkRequest(container.home()) .header("Accept", "text/xml") .fetch().as(RestResponse.class) .assertStatus(200) .assertBody(Matchers.equalTo("works fine!")); MatcherAssert.assertThat( container.take().method(), Matchers.equalTo("GET") ); container.stop();
Keep in mind that container automatically reserves a new free TCP port
and works until JVM is shut down. The only way to stop it is to call
stop()
.
Modifier and Type | Method and Description |
---|---|
URI |
home()
Get its home.
|
MkContainer |
next(MkAnswer answer)
Give this answer on the next request.
|
MkContainer |
next(MkAnswer answer,
org.hamcrest.Matcher<MkQuery> condition)
Give this answer on the next request if the matcher condition is
satisfied.
|
MkContainer |
next(MkAnswer answer,
org.hamcrest.Matcher<MkQuery> condition,
int count)
Give this answer on the next request(s) if the matcher condition is
satisfied up to a certain number of requests.
|
int |
queries()
How many queries we have left.
|
MkContainer |
start()
Start it on the first available TCP port.
|
MkContainer |
start(int prt)
Start it on a provided port.
|
void |
stop()
Stop container.
|
MkQuery |
take()
Get the oldest request received
(
NoSuchElementException
if no more elements in the list). |
MkQuery |
take(org.hamcrest.Matcher<MkAnswer> matcher)
Get the oldest request received subject to the matching condition.
|
Collection<MkQuery> |
takeAll(org.hamcrest.Matcher<MkAnswer> matcher)
Get the all requests received satisfying the given matcher.
|
MkContainer next(MkAnswer answer)
answer
- Next answer to giveMkContainer next(MkAnswer answer, org.hamcrest.Matcher<MkQuery> condition)
answer
- Next answer to givecondition
- The condition to matchMkContainer next(MkAnswer answer, org.hamcrest.Matcher<MkQuery> condition, int count)
answer
- Next answer to givecondition
- The condition to matchcount
- Number of requests to matchMkQuery take()
NoSuchElementException
if no more elements in the list).MkQuery take(org.hamcrest.Matcher<MkAnswer> matcher)
NoSuchElementException
if no elements satisfy the
condition).matcher
- The matcher specifying the conditionCollection<MkQuery> takeAll(org.hamcrest.Matcher<MkAnswer> matcher)
NoSuchElementException
if no elements satisfy the
condition).matcher
- The matcher specifying the conditionint queries()
take()
MkContainer start() throws IOException
IOException
- If failsMkContainer start(int prt) throws IOException
prt
- The port where it should start listeningIOException
- If failsvoid stop()
URI home()
Copyright © 2012–2015 jcabi.com. All rights reserved.