blob: aad064bc82e867b1ad9979d55fa03d490705bbb2 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.container.handler;
import com.yahoo.container.jdisc.HttpResponse;
import com.yahoo.container.logging.CircularArrayAccessLogKeeper;
import org.junit.Test;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.concurrent.Executor;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import static org.mockito.Mockito.mock;
public class AccessLogRequestHandlerTest {
private final CircularArrayAccessLogKeeper keeper = new CircularArrayAccessLogKeeper();
private final Executor executor = mock(Executor.class);
private final AccessLogRequestHandler handler = new AccessLogRequestHandler(executor, null, keeper);
private final ByteArrayOutputStream out = new ByteArrayOutputStream();
@Test
public void testOneLogLine() throws IOException {
keeper.addUri("foo");
HttpResponse response = handler.handle(null);
response.render(out);
assertThat(out.toString(), is("{\"entries\":[{\"url\":\"foo\"}]}"));
}
@Test
public void testEmpty() throws IOException {
HttpResponse response = handler.handle(null);
response.render(out);
assertThat(out.toString(), is("{\"entries\":[]}"));
}
@Test
public void testManyLogLines() throws IOException {
keeper.addUri("foo");
keeper.addUri("foo");
HttpResponse response = handler.handle(null);
response.render(out);
assertThat(out.toString(), is("{\"entries\":[{\"url\":\"foo\"},{\"url\":\"foo\"}]}"));
}
}
|