Package io.karatelabs.core
Class MockServer
java.lang.Object
io.karatelabs.core.MockServer
- All Implemented Interfaces:
io.karatelabs.js.ObjectLike,io.karatelabs.js.SimpleObject
Public API for creating mock servers from feature files.
Usage:
MockServer server = MockServer.feature("api.feature")
.port(8080)
.arg(Map.of("key", "value"))
.start();
// ... use server ...
server.stopAsync(); // non-blocking
server.stopAndWait(); // blocking
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classBuilder for creating MockServer instances. -
Field Summary
Fields inherited from interface io.karatelabs.js.SimpleObject
TO_STRING -
Method Summary
Modifier and TypeMethodDescriptionstatic MockServer.Builderfeature(io.karatelabs.common.Resource resource) Create a builder for a mock server from a Resource.static MockServer.BuilderCreate a builder for a mock server from a parsed Feature.static MockServer.BuilderCreate a builder for a mock server from a feature file path.static MockServer.BuilderfeatureString(String featureContent) Create a builder for a mock server from a feature string.Get the underlying MockHandler.intgetPort()Get the port the server is listening on.getUrl()Get the base URL for the server (e.g., http://localhost:8080 or https://localhost:8443).getVariable(String name) Get a variable from the mock handler's global context.booleanisSsl()Check if the server is using SSL/TLS.voidStop the mock server and wait for shutdown to complete (blocking).voidStop the mock server asynchronously (non-blocking).voidwaitSync()Wait for the server to be stopped (blocking).Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface io.karatelabs.js.ObjectLike
getMember, getPrototype, isExtensible, isFrozen, isOwnProperty, isSealed, putMember, removeMember, setExtensible, setFrozen, setSealedMethods inherited from interface io.karatelabs.js.SimpleObject
getMember, jsKeys, jsToString, putMember, removeMember, toMap
-
Method Details
-
feature
Create a builder for a mock server from a feature file path. -
feature
Create a builder for a mock server from a parsed Feature. -
feature
Create a builder for a mock server from a Resource. -
featureString
Create a builder for a mock server from a feature string. Useful for inline feature definitions in tests. -
getPort
public int getPort()Get the port the server is listening on. -
isSsl
public boolean isSsl()Check if the server is using SSL/TLS. -
getUrl
Get the base URL for the server (e.g., http://localhost:8080 or https://localhost:8443). -
stopAndWait
public void stopAndWait()Stop the mock server and wait for shutdown to complete (blocking).- See Also:
-
stopAsync
public void stopAsync()Stop the mock server asynchronously (non-blocking).- See Also:
-
waitSync
public void waitSync()Wait for the server to be stopped (blocking). -
getVariable
Get a variable from the mock handler's global context. -
getHandler
Get the underlying MockHandler. -
jsGet
- Specified by:
jsGetin interfaceio.karatelabs.js.SimpleObject
-