aboutsummaryrefslogtreecommitdiffstats
path: root/container-core/src/test/java/com/yahoo/container/handler/AccessLogRequestHandlerTest.java
blob: 728118c38cc533f424b842b7d07601a786d3e9c3 (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
// 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.jupiter.api.Test;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.concurrent.Executor;

import static org.junit.jupiter.api.Assertions.assertEquals;
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
    void testOneLogLine() throws IOException {
        keeper.addUri("foo");
        HttpResponse response = handler.handle(null);
        response.render(out);
        assertEquals("{\"entries\":[{\"url\":\"foo\"}]}", out.toString());
    }

    @Test
    void testEmpty() throws IOException {
        HttpResponse response = handler.handle(null);
        response.render(out);
        assertEquals("{\"entries\":[]}", out.toString());
    }

    @Test
    void testManyLogLines() throws IOException {
        keeper.addUri("foo");
        keeper.addUri("foo");
        HttpResponse response = handler.handle(null);
        response.render(out);
        assertEquals("{\"entries\":[{\"url\":\"foo\"},{\"url\":\"foo\"}]}", out.toString());
    }

}