Use to start a server on random port that will host static content from the specified directory. Groovy def myServer = server.serve("my-server", "data/staticcontent") Check servers/import-and-dependencies Import And Dependencies for prerequisites. Java WebTauServer myServer = server.serve("my-server", "src/test/resources/staticcontent"); Check servers/import-and-dependencies Import And Dependencies for prerequisites. { "id": "user-one", "type": "person" } Groovy http.get("${myServer.baseUrl}/data.json") { body.type == "person" } Java http.get(myServer.getBaseUrl() + "/data.json", ((header, body) -> { body.get("type").should(equal("person")); }));
Use to use the server's host and port as base url Groovy myServer.setAsBaseUrl() Java myServer.setAsBaseUrl();
Use static server to host html files and then open them using a browser. <body> <p>hello</p> </body> Groovy http.get("/hello.html") { body.should == expectedHtml } Java browser.open("/hello.html"); $("p").should(equal("hello"));
Use to modify response of a proxied server Groovy def router = server.router() .get("/hello/:name") {request -> server.response([message: "hello ${request.param("name")}"]) } myServer.addOverride(router) Java WebTauRouter router = server.router() .get("/hello/:name", (request) -> server.response(map("message", "hello " + request.param("name")))); myServer.addOverride(router);
Use to mark server as unresponsive Groovy myServer.markUnresponsive() code { http.get("/hello.html") } should throwException(~/request timed out/) Java myServer.markUnresponsive(); code(() -> { http.get("/hello.html"); }).should(throwException(Pattern.compile("request timed out")));
Use to mark server as broken Groovy myServer.markBroken() http.get("/hello.html") { statusCode.should == 500 body.should == null } Java myServer.markBroken(); http.get("/hello.html", (header, body) -> { header.statusCode.should(equal(500)); });
Use to remove broken and/or slowdown state myServer.fix()