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.
|
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). |
MkContainer next(MkAnswer answer)
answer
- Next answer to giveMkQuery take()
NoSuchElementException
if no more elements in the list).int 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–2014 jcabi.com. All rights reserved.