session2Control.replay();
txControl.replay();
conControl.replay();
MockServletContext sc = new MockServletContext();
StaticWebApplicationContext wac = new StaticWebApplicationContext();
wac.setServletContext(sc);
wac.getDefaultListableBeanFactory().registerSingleton("sessionFactory", sf);
wac.getDefaultListableBeanFactory().registerSingleton("mySessionFactory", sf2);
wac.refresh();
sc.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, wac);
MockHttpServletRequest request = new MockHttpServletRequest(sc);
MockHttpServletResponse response = new MockHttpServletResponse();
MockFilterConfig filterConfig = new MockFilterConfig(wac.getServletContext(), "filter");
MockFilterConfig filterConfig2 = new MockFilterConfig(wac.getServletContext(), "filter2");
filterConfig.addInitParameter("singleSession", "false");
filterConfig2.addInitParameter("singleSession", "false");
filterConfig2.addInitParameter("sessionFactoryBeanName", "mySessionFactory");
final OpenSessionInViewFilter filter = new OpenSessionInViewFilter();
filter.init(filterConfig);
final OpenSessionInViewFilter filter2 = new OpenSessionInViewFilter();
filter2.init(filterConfig2);
final FilterChain filterChain = new FilterChain() {
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse) {
HibernateTransactionManager tm = new HibernateTransactionManager(sf);
TransactionStatus ts = tm.getTransaction(
new DefaultTransactionDefinition(TransactionDefinition.PROPAGATION_SUPPORTS));
org.hibernate.Session sess = SessionFactoryUtils.getSession(sf, true);
SessionFactoryUtils.releaseSession(sess, sf);
tm.commit(ts);
sessionControl.verify();
sessionControl.reset();
session.close();
sessionControl.setReturnValue(null, 1);
sessionControl.replay();
servletRequest.setAttribute("invoked", Boolean.TRUE);
}
};
final FilterChain filterChain2 = new FilterChain() {
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse)
throws IOException, ServletException {
HibernateTransactionManager tm = new HibernateTransactionManager(sf2);
TransactionStatus ts = tm.getTransaction(new DefaultTransactionDefinition());
tm.commit(ts);
session2Control.verify();
session2Control.reset();
session2.close();
session2Control.setReturnValue(null, 1);
session2Control.replay();
filter.doFilter(servletRequest, servletResponse, filterChain);
}
};
FilterChain filterChain3 = new PassThroughFilterChain(filter2, filterChain2);
filter2.doFilter(request, response, filterChain3);
assertNotNull(request.getAttribute("invoked"));
sfControl.verify();
sessionControl.verify();
sf2Control.verify();
session2Control.verify();
txControl.verify();
conControl.verify();
wac.close();
}