Esempio n. 1
0
  @Test
  public void should_log_request_and_response_into_file() throws Exception {
    File file = folder.newFile();
    HttpServer server = httpServer(port(), log(file.getAbsolutePath()));
    server.request(by("0XCAFE")).response("0XBABE");

    running(
        server,
        new Runnable() {
          @Override
          public void run() throws Exception {
            assertThat(helper.postContent(root(), "0XCAFE"), is("0XBABE"));
          }
        });

    String actual = Files.toString(file, Charset.defaultCharset());
    assertThat(actual, containsString("0XCAFE"));
    assertThat(actual, containsString("0XCAFE"));
  }
Esempio n. 2
0
  @Test
  public void should_log_request_and_response_with_exception() throws Exception {
    File file = folder.newFile();
    HttpServer server = httpServer(port(), log(file.getAbsolutePath()));
    ResponseHandler mock = mock(ResponseHandler.class);
    doThrow(RuntimeException.class).when(mock).writeToResponse(any(SessionContext.class));

    server.request(by("0XCAFE")).response(mock);

    running(
        server,
        new Runnable() {
          @Override
          public void run() throws Exception {
            try {
              helper.postContent(root(), "0XCAFE");
            } catch (IOException ignored) {
            }
          }
        });

    String actual = Files.toString(file, Charset.defaultCharset());
    assertThat(actual, containsString("RuntimeException"));
  }