MockHttpServletResponse filterResponse = new MockHttpServletResponse();
ByteArrayOutputStream filterbaos = new ByteArrayOutputStream();
filterResponse.setOutputStream(filterbaos);
spEmpl.doFilter(filterRequest, filterResponse, new MockFilterChain());
String spResponse = new String(filterbaos.toByteArray());
Document spHTMLResponse = DocumentUtil.getDocument(spResponse);
nodes = spHTMLResponse.getElementsByTagName("INPUT");
inputElement = (Element) nodes.item(0);
logoutOrigResponse = inputElement.getAttributeNode("VALUE").getValue();
relayState = null;
if (nodes.getLength() > 1)
relayState = ((Element) nodes.item(1)).getAttributeNode("VALUE").getValue();
// Now the SP (employee app) has logged out and sending a status response to IDP
Thread.currentThread().setContextClassLoader(mclIDP);
session.setAttribute("SAMLResponse", logoutOrigResponse);
session.setAttribute("RelayState", relayState);
idp.testPost(request, response);
idpResponse = new String(filterbaos.toByteArray());
assertNotNull(idpResponse);
htmlResponse = DocumentUtil.getDocument(idpResponse);
assertNotNull(htmlResponse);
nodes = htmlResponse.getElementsByTagName("INPUT");
inputElement = (Element) nodes.item(0);
logoutOrigResponse = inputElement.getAttributeNode("VALUE").getValue();
relayState = null;
if (nodes.getLength() > 1)
relayState = ((Element) nodes.item(1)).getAttributeNode("VALUE").getValue();
// Now we should have got a full success report from IDP
MockContextClassLoader mclSPSales = setupTCL(profile + "/sp/employee");
Thread.currentThread().setContextClassLoader(mclSPSales);
SPFilter spSales = new SPFilter();
spSales.init(filterConfig);
filterRequest.addParameter("SAMLResponse", logoutOrigResponse);
filterRequest.addParameter("RelayState", relayState);
spSales.doFilter(filterRequest, filterResponse, new MockFilterChain());
spResponse = new String(filterbaos.toByteArray());
assertEquals(0, server.stack().getParticipants(session.getId()));
assertEquals(0, server.stack().getNumOfParticipantsInTransit(session.getId()));