diff options
author | Ola Aunrønning <ola.aunroe@gmail.com> | 2018-09-20 14:34:44 +0200 |
---|---|---|
committer | Ola Aunrønning <ola.aunroe@gmail.com> | 2018-09-20 14:56:56 +0200 |
commit | 2fa4d31e2ef1bf749efce2df9ed5a7d4dcede8a2 (patch) | |
tree | 74607406579e0b68375ee8739aea6968d3251553 /container-core/src/test/java/com/yahoo/container/handler/LogHandlerTest.java | |
parent | c1d8a9f6bf3941f1388fb06fea2edd5eeeddbe6e (diff) |
Added test for LogHandler
Diffstat (limited to 'container-core/src/test/java/com/yahoo/container/handler/LogHandlerTest.java')
-rw-r--r-- | container-core/src/test/java/com/yahoo/container/handler/LogHandlerTest.java | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/container-core/src/test/java/com/yahoo/container/handler/LogHandlerTest.java b/container-core/src/test/java/com/yahoo/container/handler/LogHandlerTest.java new file mode 100644 index 00000000000..5a3b62be287 --- /dev/null +++ b/container-core/src/test/java/com/yahoo/container/handler/LogHandlerTest.java @@ -0,0 +1,54 @@ +package com.yahoo.container.handler; + +import com.yahoo.container.jdisc.HttpRequest; +import com.yahoo.container.jdisc.HttpResponse; +import org.json.JSONException; +import org.json.JSONObject; +import org.junit.Test; + +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.util.concurrent.Executor; + +import static org.junit.Assert.*; +import static org.mockito.Mockito.mock; + +public class LogHandlerTest { + + + @Test + public void handleCorrectlyParsesQueryParameters() throws IOException { + MockLogReader mockLogReader = new MockLogReader(); + LogHandler logHandler = new LogHandler(mock(Executor.class), mockLogReader); + + { + String uri = "http://myhost.com:1111/logs?from=1000&to=2000"; + HttpResponse response = logHandler.handle(HttpRequest.createTestRequest(uri, com.yahoo.jdisc.http.HttpRequest.Method.GET)); + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + response.render(bos); + String expectedResponse = "{\"logs\":{\"one\":\"newer_log\"}}"; + assertEquals(expectedResponse, bos.toString()); + } + + { + String uri = "http://myhost.com:1111/logs?from=0&to=1000"; + HttpResponse response = logHandler.handle(HttpRequest.createTestRequest(uri, com.yahoo.jdisc.http.HttpRequest.Method.GET)); + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + response.render(bos); + String expectedResponse = "{\"logs\":{\"two\":\"older_log\"}}"; + assertEquals(expectedResponse, bos.toString()); + } + + } + + class MockLogReader extends LogReader { + @Override + protected JSONObject readLogs(String logDirectory, long earliestLogThreshold, long latestLogThreshold) throws JSONException { + if(latestLogThreshold > 1000) { + return new JSONObject("{\"one\":\"newer_log\"}"); + } else { + return new JSONObject("{\"two\":\"older_log\"}"); + } + } + } +}
\ No newline at end of file |