blob: 1aede0e9850e14387a09fb361145d4ef0a686031 (
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.jdisc.http.server.jetty.servlet;
import com.google.inject.AbstractModule;
import com.google.inject.Module;
import com.google.inject.util.Modules;
import com.yahoo.container.logging.AccessLog;
import com.yahoo.container.logging.AccessLogEntry;
import com.yahoo.jdisc.http.server.jetty.TestDriver;
import com.yahoo.jdisc.http.server.jetty.TestDrivers;
import org.mockito.verification.VerificationMode;
import org.testng.annotations.Test;
import java.io.IOException;
import java.util.concurrent.TimeUnit;
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.timeout;
import static org.mockito.Mockito.verify;
/**
* @author <a href="mailto:bakksjo@yahoo-inc.com">Oyvind Bakksjo</a>
*/
public class ServletAccessLoggingTest extends ServletTestBase {
private static final int MAX_LOG_WAIT_TIME_MILLIS = (int) TimeUnit.SECONDS.toMillis(60);
@Test
public void accessLogIsInvokedForNonJDiscServlet() throws Exception {
final AccessLog accessLog = mock(AccessLog.class);
final TestDriver testDriver = newTestDriver(accessLog);
httpGet(testDriver, TestServlet.PATH).execute();
verifyCallsLog(accessLog, timeout(MAX_LOG_WAIT_TIME_MILLIS).times(1));
}
@Test
public void accessLogIsInvokedForJDiscServlet() throws Exception {
final AccessLog accessLog = mock(AccessLog.class);
final TestDriver testDriver = newTestDriver(accessLog);
testDriver.client().newGet("/status.html").execute();
verifyCallsLog(accessLog, timeout(MAX_LOG_WAIT_TIME_MILLIS).times(1));
}
private void verifyCallsLog(final AccessLog accessLog, final VerificationMode verificationMode) {
verify(accessLog, verificationMode).log(any(AccessLogEntry.class));
}
private TestDriver newTestDriver(final AccessLog accessLog) throws IOException {
return TestDrivers.newInstance(dummyRequestHandler, bindings(accessLog));
}
private Module bindings(final AccessLog accessLog) {
return Modules.combine(
new AbstractModule() {
@Override
protected void configure() {
bind(AccessLog.class).toInstance(accessLog);
}
},
guiceModule());
}
}
|