sessionControl.setVoidCallable(1);
sfControl.replay();
sessionControl.replay();
MockServletContext sc = new MockServletContext();
StaticWebApplicationContext wac = new StaticWebApplicationContext();
wac.setServletContext(sc);
wac.getDefaultListableBeanFactory().registerSingleton("sessionFactory", sf);
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");
OpenSessionInViewInterceptor rawInterceptor = new OpenSessionInViewInterceptor();
rawInterceptor.setSessionFactory(sf);
rawInterceptor.setSingleSession(false);
HandlerInterceptor interceptor = new WebRequestHandlerInterceptorAdapter(rawInterceptor);
interceptor.preHandle(request, response, "handler");
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();
try {
session.close();
}
catch (HibernateException ex) {
}
sessionControl.setReturnValue(null, 1);
sessionControl.replay();
servletRequest.setAttribute("invoked", Boolean.TRUE);
}
};
FilterChain filterChain2 = new FilterChain() {
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse)
throws IOException, ServletException {
filter.doFilter(servletRequest, servletResponse, filterChain);
}
};
filter.doFilter(request, response, filterChain2);
assertNotNull(request.getAttribute("invoked"));
interceptor.postHandle(request, response, "handler", null);
interceptor.afterCompletion(request, response, "handler", null);
sfControl.verify();
sessionControl.verify();
wac.close();
}