Package com.jcabi.http.mock
Interface MkContainer
- 
- All Superinterfaces:
- AutoCloseable,- Closeable
 - All Known Implementing Classes:
- MkGrizzlyContainer
 
 public interface MkContainer extends Closeable Mock version of Java Servlet container.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().Since version 0.11 container implements Closeableand can be used in try-with-resource block.- Since:
- 0.10
- See Also:
- Examples
 
- 
- 
Method SummaryAll Methods Instance Methods Abstract Methods Modifier and Type Method Description URIhome()Get its home.MkContainernext(MkAnswer answer)Give this answer on the next request.MkContainernext(MkAnswer answer, org.hamcrest.Matcher<MkQuery> condition)Give this answer on the next request if the matcher condition is satisfied.MkContainernext(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.intqueries()How many queries we have left.MkContainerstart()Start it on the first available TCP port.MkContainerstart(int prt)Start it on a provided port.voidstop()Stop container.MkQuerytake()Get the oldest request received (NoSuchElementExceptionif no more elements in the list).MkQuerytake(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.
 
- 
- 
- 
Method Detail- 
nextMkContainer next(MkAnswer answer) Give this answer on the next request.- Parameters:
- answer- Next answer to give
- Returns:
- This object
 
 - 
nextMkContainer next(MkAnswer answer, org.hamcrest.Matcher<MkQuery> condition) Give this answer on the next request if the matcher condition is satisfied.- Parameters:
- answer- Next answer to give
- condition- The condition to match
- Returns:
- This object
 
 - 
nextMkContainer 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.- Parameters:
- answer- Next answer to give
- condition- The condition to match
- count- Number of requests to match
- Returns:
- This object
 
 - 
takeMkQuery take() Get the oldest request received (NoSuchElementExceptionif no more elements in the list).- Returns:
- Request received
 
 - 
takeMkQuery take(org.hamcrest.Matcher<MkAnswer> matcher) Get the oldest request received subject to the matching condition. (NoSuchElementExceptionif no elements satisfy the condition).- Parameters:
- matcher- The matcher specifying the condition
- Returns:
- Request received satisfying the matcher
 
 - 
takeAllCollection<MkQuery> takeAll(org.hamcrest.Matcher<MkAnswer> matcher) Get the all requests received satisfying the given matcher. (NoSuchElementExceptionif no elements satisfy the condition).- Parameters:
- matcher- The matcher specifying the condition
- Returns:
- Collection of all requests satisfying the matcher, ordered from oldest to newest.
 
 - 
queriesint queries() How many queries we have left.- Returns:
- Total number of queries you can retrieve with take()
- Since:
- 1.0
 
 - 
startMkContainer start() throws IOException Start it on the first available TCP port.- Returns:
- This object
- Throws:
- IOException- If fails
 
 - 
startMkContainer start(int prt) throws IOException Start it on a provided port.- Parameters:
- prt- The port where it should start listening
- Returns:
- This object
- Throws:
- IOException- If fails
 
 - 
stopvoid stop() Stop container.
 - 
homeURI home() Get its home.- Returns:
- URI of the started container
 
 
- 
 
-