use of org.iobserve.monitoring.probe.servlet.SessionAndTraceRegistrationPayloadFilter in project iobserve-analysis by research-iobserve.
the class SessionAndTraceRegistrationPayloadFilterTest method testDoFilter.
/**
* Test method for
* {@link org.iobserve.monitoring.probe.servlet.SessionAndTraceRegistrationPayloadFilter#doFilter(javax.servlet.ServletRequest, javax.servlet.ServletResponse, javax.servlet.FilterChain)}.
*
* @throws InterruptedException
* during the sleep time of the thread
*/
// TODO Something goes occasionally wrong in this test. FixME!
// @Test
public void testDoFilter() throws InterruptedException {
final ServletContext context = new TestServletContext();
final ServletResponse response = new TestHttpServletResponse();
final HttpSession session = new TestHttpSession(context);
final TestHttpServletRequest request = new TestHttpServletRequest(context, session);
final FilterConfig filterConfig = new TestFilterConfig(context);
final SessionAndTraceRegistrationPayloadFilter filter = new SessionAndTraceRegistrationPayloadFilter();
try {
filter.init(filterConfig);
filter.doFilter(request, response, this.createChain());
MonitoringController.getInstance().terminateMonitoring();
while (!MonitoringController.getInstance().isMonitoringTerminated()) {
Thread.sleep(1000);
}
final List<IMonitoringRecord> storage = TestDummyWriter.getEvents();
Assert.assertTrue("No records received", !storage.isEmpty());
IMonitoringRecord record = storage.get(0);
Assert.assertEquals("Should be KiekerMetadataRecord", KiekerMetadataRecord.class, record.getClass());
record = storage.get(1);
Assert.assertEquals("Should be TraceMetadata", TraceMetadata.class, record.getClass());
record = storage.get(2);
Assert.assertEquals("Should be EntryLevelBeforeOperationEvent", EntryLevelBeforeOperationEvent.class, record.getClass());
if (record instanceof EntryLevelBeforeOperationEvent) {
final EntryLevelBeforeOperationEvent beforeEvent = (EntryLevelBeforeOperationEvent) record;
Assert.assertEquals("Class signature does not match", TestServletContext.CONTEXT_PATH, beforeEvent.getClassSignature());
Assert.assertEquals("Operation signature does not match", TestHttpServletRequest.REQUEST_URI, beforeEvent.getOperationSignature());
final Iterator<String> keys = request.getParameters().keySet().iterator();
for (final String label : beforeEvent.getParameters()) {
if (!keys.hasNext()) {
Assert.fail("Found more parameters than defined in the request.");
} else {
Assert.assertEquals("Same parameter", keys.next(), label);
}
}
final Iterator<String> values = request.getParameters().values().iterator();
for (final String label : beforeEvent.getValues()) {
if (!values.hasNext()) {
Assert.fail("Found more parameters than defined in the request.");
} else {
Assert.assertEquals("Same parameter", values.next(), label);
}
}
}
record = storage.get(3);
Assert.assertEquals("Should be AfterOperationEvent", AfterOperationEvent.class, record.getClass());
Assert.assertEquals("Wrong number of records ", 4, storage.size());
} catch (final ServletException e) {
Assert.fail(e.getMessage());
} catch (final IOException e) {
Assert.fail(e.getMessage());
}
}
Aggregations