Test for RequestLogger.queryString()
@@ -70,6 +70,28 @@ public class RequestLoggerTest {
}, onComplete);
}
+ @Test
+ public void queryString() throws Exception {
+ new MockUnit(Request.class, Response.class)
+ .expect(capture)
+ .expect(timestamp(7L))
+ .expect(ip("127.0.0.1"))
+ .expect(method("GET"))
+ .expect(path("/path"))
+ .expect(query("query=true"))
+ .expect(protocol("HTTP/1.1"))
+ .expect(status(Status.OK))
+ .expect(len(345L))
+ .run(unit -> {
+ new RequestLogger()
+ .dateFormatter(ZoneId.of("UTC"))
+ .queryString()
+ .log(line -> assertEquals(
+ "127.0.0.1 - - [01/Jan/1970:00:00:00 +0000] \"GET /path?query=true HTTP/1.1\" 200 345", line))
+ .handle(unit.get(Request.class), unit.get(Response.class));
+ }, onComplete);
+ }
+
@Test
public void extended() throws Exception {
new MockUnit(Request.class, Response.class)
@@ -147,6 +169,13 @@ public class RequestLoggerTest {
};
}
+ private Block query(final String query) {
+ return unit -> {
+ Request req = unit.get(Request.class);
+ expect(req.queryString()).andReturn(Optional.of(query)).atLeastOnce();
+ };
+ }
+
private Block status(final Status status) {
return unit -> {
Response rsp = unit.get(Response.class);
