@Test
public void testProcess() throws IOException, SAXException {

    // test session creation
    HttpServletRequest httpServletRequest = mocksControl.createMock(HttpServletRequest.class);
    expect(serverRuntimeContext.getNextSessionId()).andReturn("200");
    expect(serverRuntimeContext.getServerEntity()).andReturn(new EntityImpl(null, "vysper.org", null));
    expect(serverRuntimeContext.getDefaultXMLLang()).andReturn("en");
    AsyncContext asyncContext = mocksControl.createMock(AsyncContext.class);
    expect(httpServletRequest.startAsync()).andReturn(asyncContext).atLeastOnce();
    expect(httpServletRequest.getAsyncContext()).andReturn(asyncContext).atLeastOnce();
    asyncContext.setTimeout(anyLong());
    Capture<BoshRequest> br = new Capture<BoshRequest>();
    httpServletRequest.setAttribute(eq(BOSH_REQUEST_ATTRIBUTE), EasyMock.<BoshRequest>capture(br));
    asyncContext.addListener(EasyMock.<AsyncListener> anyObject());
    asyncContext.dispatch();
    ServerFeatures serverFeatures = mocksControl.createMock(ServerFeatures.class);
    expect(serverRuntimeContext.getServerFeatures()).andReturn(serverFeatures);
    expect(serverFeatures.getAuthenticationMethods()).andReturn(Collections.<SASLMechanism> emptyList());
    expect(serverRuntimeContext.getModule(InBandRegistrationModule.class)).andReturn(null);
    Capture<BoshResponse> captured = new Capture<BoshResponse>();
    httpServletRequest.setAttribute(eq(BOSH_RESPONSE_ATTRIBUTE), EasyMock.<BoshResponse> capture(captured));
    mocksControl.replay();
    Stanza boshRequest = createSessionRequest();
    boshHandler.process(httpServletRequest, boshRequest);
    mocksControl.verify();
    
    assertEquals(httpServletRequest, br.getValue().getHttpServletRequest());
    assertEquals(boshRequest, br.getValue().getBody());
    Stanza response = new XMLUtil(new String(captured.getValue().getContent())).parse();
    assertNotNull(response);
    assertEquals("body", response.getName());
    assertEquals(NamespaceURIs.XEP0124_BOSH, response.getNamespaceURI());
    assertEquals("200", response.getAttributeValue("sid"));
    assertEquals("vysper.org", response.getAttributeValue("from"));
    assertEquals("60", response.getAttributeValue("wait"));
    assertEquals("1", response.getAttributeValue("hold"));
    assertEquals("1.9", response.getAttributeValue("ver"));
    assertEquals(1, response.getInnerElements().size());
    XMLElement streamFeatures = response.getInnerElements().get(0);
    assertEquals("features", streamFeatures.getName());
    assertEquals(NamespaceURIs.HTTP_ETHERX_JABBER_ORG_STREAMS, streamFeatures.getNamespaceURI());
    assertEquals(1, streamFeatures.getInnerElements().size());
    XMLElement saslMechanisms = streamFeatures.getInnerElements().get(0);
    assertEquals("mechanisms", saslMechanisms.getName());
    assertEquals(NamespaceURIs.URN_IETF_PARAMS_XML_NS_XMPP_SASL, saslMechanisms.getNamespaceURI());
    // test session retrieval, retrieves the session above identified by sid=200
    mocksControl.reset();
    expect(httpServletRequest.startAsync()).andReturn(asyncContext).atLeastOnce();
    expect(httpServletRequest.getAsyncContext()).andReturn(asyncContext).anyTimes();
    asyncContext.setTimeout(anyLong());
    httpServletRequest.setAttribute(eq(BOSH_REQUEST_ATTRIBUTE), EasyMock.capture(br));
    asyncContext.addListener(EasyMock.anyObject());
    Capture<Stanza> stanzaCaptured = new Capture<>();
    stanzaProcessor.processStanza(eq(serverRuntimeContext), EasyMock.anyObject(),
            EasyMock.capture(stanzaCaptured), EasyMock.anyObject());
    mocksControl.replay();
    boshRequest = createSaslRequest();
    boshHandler.process(httpServletRequest, boshRequest);
    mocksControl.verify();
    
    assertEquals(httpServletRequest, br.getValue().getHttpServletRequest());
    assertEquals(boshRequest, br.getValue().getBody());
    
    Stanza stanza = stanzaCaptured.getValue();
    assertNotNull(stanza);
    assertEquals("auth", stanza.getName());
    assertEquals(NamespaceURIs.URN_IETF_PARAMS_XML_NS_XMPP_SASL, stanza.getNamespaceURI());
    assertEquals("DIGEST-MD5", stanza.getAttributeValue("mechanism"));
}