final String responseContentType = "response/type";
final HttpURI uri = new HttpURI("http://www.example.com/aaa+bbb/ccc?param=hello%20there&other=true");
final TraceTokenManager tokenManager = new TraceTokenManager();
InMemoryEventClient eventClient = new InMemoryEventClient();
MockCurrentTimeMillisProvider currentTimeMillisProvider = new MockCurrentTimeMillisProvider(timestamp + timeToLastByte);
DelimitedRequestLog logger = new DelimitedRequestLog(file.getAbsolutePath(), 1, tokenManager, eventClient, currentTimeMillisProvider);
when(principal.getName()).thenReturn(user);
when(request.getTimeStamp()).thenReturn(timestamp);
when(request.getHeader("User-Agent")).thenReturn(agent);
when(request.getHeader("Referer")).thenReturn(referrer);
when(request.getRemoteAddr()).thenReturn("9.9.9.9");
when(request.getHeaders("X-FORWARDED-FOR")).thenReturn(Collections.enumeration(ImmutableList.of("1.1.1.1, 2.2.2.2", "3.3.3.3, " + ip)));
when(request.getProtocol()).thenReturn("unknown");
when(request.getHeader("X-FORWARDED-PROTO")).thenReturn(protocol);
when(request.getAttribute(TimingFilter.FIRST_BYTE_TIME)).thenReturn(timestamp + timeToFirstByte);
when(request.getUri()).thenReturn(uri);
when(request.getUserPrincipal()).thenReturn(principal);
when(request.getMethod()).thenReturn(method);
when(request.getContentRead()).thenReturn(requestSize);
when(request.getHeader("Content-Type")).thenReturn(requestContentType);
when(response.getStatus()).thenReturn(responseCode);
when(response.getContentCount()).thenReturn(responseSize);
when(response.getHeader("Content-Type")).thenReturn(responseContentType);
tokenManager.createAndRegisterNewRequestToken();
logger.log(request, response);
logger.stop();
List<Object> events = eventClient.getEvents();
Assert.assertEquals(events.size(), 1);
HttpRequestEvent event = (HttpRequestEvent) events.get(0);
Assert.assertEquals(event.getTimeStamp().getMillis(), timestamp);