Search in sources :

Example 1 with SessionAndTraceRegistrationPayloadFilter

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());
    }
}
Also used : ServletResponse(javax.servlet.ServletResponse) HttpSession(javax.servlet.http.HttpSession) SessionAndTraceRegistrationPayloadFilter(org.iobserve.monitoring.probe.servlet.SessionAndTraceRegistrationPayloadFilter) IOException(java.io.IOException) ServletException(javax.servlet.ServletException) EntryLevelBeforeOperationEvent(org.iobserve.common.record.EntryLevelBeforeOperationEvent) IMonitoringRecord(kieker.common.record.IMonitoringRecord) ServletContext(javax.servlet.ServletContext) FilterConfig(javax.servlet.FilterConfig)

Aggregations

IOException (java.io.IOException)1 FilterConfig (javax.servlet.FilterConfig)1 ServletContext (javax.servlet.ServletContext)1 ServletException (javax.servlet.ServletException)1 ServletResponse (javax.servlet.ServletResponse)1 HttpSession (javax.servlet.http.HttpSession)1 IMonitoringRecord (kieker.common.record.IMonitoringRecord)1 EntryLevelBeforeOperationEvent (org.iobserve.common.record.EntryLevelBeforeOperationEvent)1 SessionAndTraceRegistrationPayloadFilter (org.iobserve.monitoring.probe.servlet.SessionAndTraceRegistrationPayloadFilter)1