Mokksy Server Java
Java-friendly wrapper around MokksyServer that provides a fully instance-method-based API.
Eliminates Kotlin-specific boilerplate from Java test code:
start()andshutdown()are instance methodsHTTP stub methods (
get,post, etc.) acceptConsumer<RequestSpecificationBuilder<P>>instead of Kotlin lambdas with receivers (noreturn Unit.INSTANCE)Returns JavaBuildingStep, which exposes
respondsWithandrespondsWithStreamas chainable instance methods (no separateMokksyJava.respondsWith(step, ...)call)
Example:
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
class MyTest {
private final MokksyServerJava mokksy = new MokksyServerJava();
@BeforeAll void setUp() { mokksy.start(); }
@AfterAll void tearDown() { mokksy.shutdown(); }
@Test
void myTest() throws Exception {
mokksy.get(spec -> spec.path("/ping"))
.respondsWith(builder -> builder.setBody("Pong"));
// ... make HTTP call and assert
}
}Constructors
Wraps an existing MokksyServer instance.
Creates a MokksyServerJava backed by a new MokksyServer.
Properties
The underlying MokksyServer. Accessible for advanced configuration and for Kotlin callers that mix the two APIs.
Functions
Registers a DELETE stub with a String request body.
Registers a DELETE stub with a String request body and StubConfiguration.
Registers a DELETE stub with a typed request body.
Registers a DELETE stub with a typed request body and StubConfiguration.
Returns all requests that were not matched by any stub.
Returns all stubs that were never matched.
Registers a GET stub with a String request body.
Registers a GET stub with a String request body and StubConfiguration.
Registers a GET stub with a typed request body.
Registers a GET stub with a typed request body and StubConfiguration.
Registers a HEAD stub.
Registers a HEAD stub with StubConfiguration.
Registers a HEAD stub with a typed request body.
Registers a HEAD stub with a typed request body and StubConfiguration.
Registers an OPTIONS stub.
Registers an OPTIONS stub with StubConfiguration.
Registers an OPTIONS stub with a typed request body.
Registers an OPTIONS stub with a typed request body and StubConfiguration.
Registers a PATCH stub with a String request body.
Registers a PATCH stub with a String request body and StubConfiguration.
Registers a PATCH stub with a typed request body.
Registers a PATCH stub with a typed request body and StubConfiguration.
Registers a POST stub with a String request body.
Registers a POST stub with a String request body and StubConfiguration.
Registers a POST stub with a typed request body.
Registers a POST stub with a typed request body and StubConfiguration.
Registers a PUT stub with a String request body.
Registers a PUT stub with a String request body and StubConfiguration.
Registers a PUT stub with a typed request body.
Registers a PUT stub with a typed request body and StubConfiguration.
Resets stub match counts and clears the request journal.
Stops the server and blocks the calling thread until shutdown is complete.
Asserts that every request received by the server was matched by a stub.
Asserts that every registered stub was matched at least once.