SPR-5619 - (OpenSessionInViewTests, ClassUtilTests fixed)
Update org.sf.web/.classpath to refer to tiles 2.1.2
This commit is contained in:
parent
8c9346718b
commit
69422e771f
|
|
@ -0,0 +1,41 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2002-2009 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.springframework.aop.support;
|
||||||
|
|
||||||
|
import junit.framework.TestCase;
|
||||||
|
|
||||||
|
import org.springframework.aop.framework.ProxyFactory;
|
||||||
|
import test.beans.TestBean;
|
||||||
|
import org.springframework.util.ClassUtils;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Colin Sampaleanu
|
||||||
|
* @author Juergen Hoeller
|
||||||
|
* @author Rob Harrop
|
||||||
|
* @author Rick Evans
|
||||||
|
*/
|
||||||
|
public class ClassUtilsTests extends TestCase {
|
||||||
|
|
||||||
|
public void testGetShortNameForCglibClass() {
|
||||||
|
TestBean tb = new TestBean();
|
||||||
|
ProxyFactory pf = new ProxyFactory();
|
||||||
|
pf.setTarget(tb);
|
||||||
|
pf.setProxyTargetClass(true);
|
||||||
|
TestBean proxy = (TestBean) pf.getProxy();
|
||||||
|
String className = ClassUtils.getShortName(proxy.getClass());
|
||||||
|
assertEquals("Class name did not match", "TestBean", className);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -129,17 +129,6 @@ public class ClassUtilsTests extends TestCase {
|
||||||
assertEquals("Class name did not match", "ClassUtilsTests.InnerClass", className);
|
assertEquals("Class name did not match", "ClassUtilsTests.InnerClass", className);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Ignore
|
|
||||||
public void ignoreTestGetShortNameForCglibClass() {
|
|
||||||
// TestBean tb = new TestBean();
|
|
||||||
// ProxyFactory pf = new ProxyFactory();
|
|
||||||
// pf.setTarget(tb);
|
|
||||||
// pf.setProxyTargetClass(true);
|
|
||||||
// TestBean proxy = (TestBean) pf.getProxy();
|
|
||||||
// String className = ClassUtils.getShortName(proxy.getClass());
|
|
||||||
// assertEquals("Class name did not match", "TestBean", className);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testGetShortNameAsProperty() {
|
public void testGetShortNameAsProperty() {
|
||||||
String shortName = ClassUtils.getShortNameAsProperty(this.getClass());
|
String shortName = ClassUtils.getShortNameAsProperty(this.getClass());
|
||||||
assertEquals("Class name did not match", "classUtilsTests", shortName);
|
assertEquals("Class name did not match", "classUtilsTests", shortName);
|
||||||
|
|
|
||||||
|
|
@ -1,631 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright 2002-2007 the original author or authors.
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.springframework.orm.hibernate3.support;
|
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
|
||||||
|
|
||||||
import org.junit.Ignore;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Juergen Hoeller
|
|
||||||
* @since 05.03.2005
|
|
||||||
*/
|
|
||||||
@Ignore // getting errors on mocks
|
|
||||||
public class OpenSessionInViewTests extends TestCase {
|
|
||||||
|
|
||||||
// public void testOpenSessionInViewInterceptorWithSingleSession() throws Exception {
|
|
||||||
// MockControl sfControl = MockControl.createControl(SessionFactory.class);
|
|
||||||
// final SessionFactory sf = (SessionFactory) sfControl.getMock();
|
|
||||||
// MockControl sessionControl = MockControl.createControl(Session.class);
|
|
||||||
// Session session = (Session) sessionControl.getMock();
|
|
||||||
//
|
|
||||||
// OpenSessionInViewInterceptor rawInterceptor = new OpenSessionInViewInterceptor();
|
|
||||||
// rawInterceptor.setSessionFactory(sf);
|
|
||||||
// HandlerInterceptor interceptor = new WebRequestHandlerInterceptorAdapter(rawInterceptor);
|
|
||||||
//
|
|
||||||
// MockServletContext sc = new MockServletContext();
|
|
||||||
// MockHttpServletRequest request = new MockHttpServletRequest(sc);
|
|
||||||
// MockHttpServletResponse response = new MockHttpServletResponse();
|
|
||||||
//
|
|
||||||
// sf.openSession();
|
|
||||||
// sfControl.setReturnValue(session, 1);
|
|
||||||
// session.getSessionFactory();
|
|
||||||
// sessionControl.setReturnValue(sf, 2);
|
|
||||||
// session.isOpen();
|
|
||||||
// sessionControl.setReturnValue(true, 1);
|
|
||||||
// session.setFlushMode(FlushMode.NEVER);
|
|
||||||
// sessionControl.setVoidCallable(1);
|
|
||||||
// sfControl.replay();
|
|
||||||
// sessionControl.replay();
|
|
||||||
// interceptor.preHandle(request, response, "handler");
|
|
||||||
// assertTrue(TransactionSynchronizationManager.hasResource(sf));
|
|
||||||
//
|
|
||||||
// // check that further invocations simply participate
|
|
||||||
// interceptor.preHandle(request, response, "handler");
|
|
||||||
//
|
|
||||||
// assertEquals(session, SessionFactoryUtils.getSession(sf, false));
|
|
||||||
//
|
|
||||||
// interceptor.preHandle(request, response, "handler");
|
|
||||||
// interceptor.postHandle(request, response, "handler", null);
|
|
||||||
// interceptor.afterCompletion(request, response, "handler", null);
|
|
||||||
//
|
|
||||||
// interceptor.postHandle(request, response, "handler", null);
|
|
||||||
// interceptor.afterCompletion(request, response, "handler", null);
|
|
||||||
//
|
|
||||||
// interceptor.preHandle(request, response, "handler");
|
|
||||||
// interceptor.postHandle(request, response, "handler", null);
|
|
||||||
// interceptor.afterCompletion(request, response, "handler", null);
|
|
||||||
//
|
|
||||||
// sfControl.verify();
|
|
||||||
// sessionControl.verify();
|
|
||||||
//
|
|
||||||
// sfControl.reset();
|
|
||||||
// sessionControl.reset();
|
|
||||||
// sfControl.replay();
|
|
||||||
// sessionControl.replay();
|
|
||||||
// interceptor.postHandle(request, response, "handler", null);
|
|
||||||
// assertTrue(TransactionSynchronizationManager.hasResource(sf));
|
|
||||||
// sfControl.verify();
|
|
||||||
// sessionControl.verify();
|
|
||||||
//
|
|
||||||
// sfControl.reset();
|
|
||||||
// sessionControl.reset();
|
|
||||||
// session.close();
|
|
||||||
// sessionControl.setReturnValue(null, 1);
|
|
||||||
// sfControl.replay();
|
|
||||||
// sessionControl.replay();
|
|
||||||
// interceptor.afterCompletion(request, response, "handler", null);
|
|
||||||
// assertFalse(TransactionSynchronizationManager.hasResource(sf));
|
|
||||||
// sfControl.verify();
|
|
||||||
// sessionControl.verify();
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// public void testOpenSessionInViewInterceptorWithSingleSessionAndJtaTm() throws Exception {
|
|
||||||
// MockControl sfControl = MockControl.createControl(SessionFactoryImplementor.class);
|
|
||||||
// final SessionFactoryImplementor sf = (SessionFactoryImplementor) sfControl.getMock();
|
|
||||||
// MockControl sessionControl = MockControl.createControl(Session.class);
|
|
||||||
// Session session = (Session) sessionControl.getMock();
|
|
||||||
//
|
|
||||||
// MockControl tmControl = MockControl.createControl(TransactionManager.class);
|
|
||||||
// TransactionManager tm = (TransactionManager) tmControl.getMock();
|
|
||||||
// tm.getTransaction();
|
|
||||||
// tmControl.setReturnValue(null, 2);
|
|
||||||
//
|
|
||||||
// OpenSessionInViewInterceptor rawInterceptor = new OpenSessionInViewInterceptor();
|
|
||||||
// rawInterceptor.setSessionFactory(sf);
|
|
||||||
// HandlerInterceptor interceptor = new WebRequestHandlerInterceptorAdapter(rawInterceptor);
|
|
||||||
//
|
|
||||||
// MockServletContext sc = new MockServletContext();
|
|
||||||
// MockHttpServletRequest request = new MockHttpServletRequest(sc);
|
|
||||||
// MockHttpServletResponse response = new MockHttpServletResponse();
|
|
||||||
//
|
|
||||||
// sf.getTransactionManager();
|
|
||||||
// sfControl.setReturnValue(tm, 2);
|
|
||||||
// sf.openSession();
|
|
||||||
// sfControl.setReturnValue(session, 1);
|
|
||||||
// session.isOpen();
|
|
||||||
// sessionControl.setReturnValue(true, 1);
|
|
||||||
// session.setFlushMode(FlushMode.NEVER);
|
|
||||||
// sessionControl.setVoidCallable(1);
|
|
||||||
//
|
|
||||||
// tmControl.replay();
|
|
||||||
// sfControl.replay();
|
|
||||||
// sessionControl.replay();
|
|
||||||
//
|
|
||||||
// interceptor.preHandle(request, response, "handler");
|
|
||||||
// assertTrue(TransactionSynchronizationManager.hasResource(sf));
|
|
||||||
//
|
|
||||||
// // check that further invocations simply participate
|
|
||||||
// interceptor.preHandle(request, response, "handler");
|
|
||||||
//
|
|
||||||
// assertEquals(session, SessionFactoryUtils.getSession(sf, false));
|
|
||||||
//
|
|
||||||
// interceptor.preHandle(request, response, "handler");
|
|
||||||
// interceptor.postHandle(request, response, "handler", null);
|
|
||||||
// interceptor.afterCompletion(request, response, "handler", null);
|
|
||||||
//
|
|
||||||
// interceptor.postHandle(request, response, "handler", null);
|
|
||||||
// interceptor.afterCompletion(request, response, "handler", null);
|
|
||||||
//
|
|
||||||
// interceptor.preHandle(request, response, "handler");
|
|
||||||
// interceptor.postHandle(request, response, "handler", null);
|
|
||||||
// interceptor.afterCompletion(request, response, "handler", null);
|
|
||||||
//
|
|
||||||
// sfControl.verify();
|
|
||||||
// sessionControl.verify();
|
|
||||||
//
|
|
||||||
// sfControl.reset();
|
|
||||||
// sessionControl.reset();
|
|
||||||
// sfControl.replay();
|
|
||||||
// sessionControl.replay();
|
|
||||||
// interceptor.postHandle(request, response, "handler", null);
|
|
||||||
// assertTrue(TransactionSynchronizationManager.hasResource(sf));
|
|
||||||
// sfControl.verify();
|
|
||||||
// sessionControl.verify();
|
|
||||||
//
|
|
||||||
// sfControl.reset();
|
|
||||||
// sessionControl.reset();
|
|
||||||
// session.close();
|
|
||||||
// sessionControl.setReturnValue(null, 1);
|
|
||||||
// sfControl.replay();
|
|
||||||
// sessionControl.replay();
|
|
||||||
// interceptor.afterCompletion(request, response, "handler", null);
|
|
||||||
// assertFalse(TransactionSynchronizationManager.hasResource(sf));
|
|
||||||
// sfControl.verify();
|
|
||||||
// sessionControl.verify();
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// public void testOpenSessionInViewInterceptorWithSingleSessionAndFlush() throws Exception {
|
|
||||||
// MockControl sfControl = MockControl.createControl(SessionFactory.class);
|
|
||||||
// final SessionFactory sf = (SessionFactory) sfControl.getMock();
|
|
||||||
// MockControl sessionControl = MockControl.createControl(Session.class);
|
|
||||||
// Session session = (Session) sessionControl.getMock();
|
|
||||||
//
|
|
||||||
// OpenSessionInViewInterceptor rawInterceptor = new OpenSessionInViewInterceptor();
|
|
||||||
// rawInterceptor.setSessionFactory(sf);
|
|
||||||
// rawInterceptor.setFlushMode(HibernateAccessor.FLUSH_AUTO);
|
|
||||||
// HandlerInterceptor interceptor = new WebRequestHandlerInterceptorAdapter(rawInterceptor);
|
|
||||||
//
|
|
||||||
// MockServletContext sc = new MockServletContext();
|
|
||||||
// MockHttpServletRequest request = new MockHttpServletRequest(sc);
|
|
||||||
// MockHttpServletResponse response = new MockHttpServletResponse();
|
|
||||||
//
|
|
||||||
// sf.openSession();
|
|
||||||
// sfControl.setReturnValue(session, 1);
|
|
||||||
// session.getSessionFactory();
|
|
||||||
// sessionControl.setReturnValue(sf);
|
|
||||||
// sfControl.replay();
|
|
||||||
// sessionControl.replay();
|
|
||||||
// interceptor.preHandle(request, response, "handler");
|
|
||||||
// assertTrue(TransactionSynchronizationManager.hasResource(sf));
|
|
||||||
// sfControl.verify();
|
|
||||||
// sessionControl.verify();
|
|
||||||
//
|
|
||||||
// sfControl.reset();
|
|
||||||
// sessionControl.reset();
|
|
||||||
// session.flush();
|
|
||||||
// sessionControl.setVoidCallable(1);
|
|
||||||
// sfControl.replay();
|
|
||||||
// sessionControl.replay();
|
|
||||||
// interceptor.postHandle(request, response, "handler", null);
|
|
||||||
// assertTrue(TransactionSynchronizationManager.hasResource(sf));
|
|
||||||
// sfControl.verify();
|
|
||||||
// sessionControl.verify();
|
|
||||||
//
|
|
||||||
// sfControl.reset();
|
|
||||||
// sessionControl.reset();
|
|
||||||
// session.close();
|
|
||||||
// sessionControl.setReturnValue(null, 1);
|
|
||||||
// sfControl.replay();
|
|
||||||
// sessionControl.replay();
|
|
||||||
// interceptor.afterCompletion(request, response, "handler", null);
|
|
||||||
// assertFalse(TransactionSynchronizationManager.hasResource(sf));
|
|
||||||
// sfControl.verify();
|
|
||||||
// sessionControl.verify();
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// public void testOpenSessionInViewInterceptorAndDeferredClose() throws Exception {
|
|
||||||
// MockControl sfControl = MockControl.createControl(SessionFactory.class);
|
|
||||||
// final SessionFactory sf = (SessionFactory) sfControl.getMock();
|
|
||||||
// MockControl sessionControl = MockControl.createControl(Session.class);
|
|
||||||
// Session session = (Session) sessionControl.getMock();
|
|
||||||
//
|
|
||||||
// OpenSessionInViewInterceptor rawInterceptor = new OpenSessionInViewInterceptor();
|
|
||||||
// rawInterceptor.setSessionFactory(sf);
|
|
||||||
// rawInterceptor.setSingleSession(false);
|
|
||||||
// HandlerInterceptor interceptor = new WebRequestHandlerInterceptorAdapter(rawInterceptor);
|
|
||||||
//
|
|
||||||
// MockServletContext sc = new MockServletContext();
|
|
||||||
// MockHttpServletRequest request = new MockHttpServletRequest(sc);
|
|
||||||
// MockHttpServletResponse response = new MockHttpServletResponse();
|
|
||||||
//
|
|
||||||
// sf.openSession();
|
|
||||||
// sfControl.setReturnValue(session, 1);
|
|
||||||
// session.getSessionFactory();
|
|
||||||
// sessionControl.setReturnValue(sf, 1);
|
|
||||||
// session.setFlushMode(FlushMode.NEVER);
|
|
||||||
// sessionControl.setVoidCallable(1);
|
|
||||||
// sfControl.replay();
|
|
||||||
// sessionControl.replay();
|
|
||||||
//
|
|
||||||
// interceptor.preHandle(request, response, "handler");
|
|
||||||
// org.hibernate.Session sess = SessionFactoryUtils.getSession(sf, true);
|
|
||||||
// SessionFactoryUtils.releaseSession(sess, sf);
|
|
||||||
//
|
|
||||||
// // check that further invocations simply participate
|
|
||||||
// interceptor.preHandle(request, response, "handler");
|
|
||||||
//
|
|
||||||
// interceptor.preHandle(request, response, "handler");
|
|
||||||
// interceptor.postHandle(request, response, "handler", null);
|
|
||||||
// interceptor.afterCompletion(request, response, "handler", null);
|
|
||||||
//
|
|
||||||
// interceptor.postHandle(request, response, "handler", null);
|
|
||||||
// interceptor.afterCompletion(request, response, "handler", null);
|
|
||||||
//
|
|
||||||
// interceptor.preHandle(request, response, "handler");
|
|
||||||
// interceptor.postHandle(request, response, "handler", null);
|
|
||||||
// interceptor.afterCompletion(request, response, "handler", null);
|
|
||||||
//
|
|
||||||
// sfControl.verify();
|
|
||||||
// sessionControl.verify();
|
|
||||||
// sfControl.reset();
|
|
||||||
// sessionControl.reset();
|
|
||||||
//
|
|
||||||
// session.close();
|
|
||||||
// sessionControl.setReturnValue(null, 1);
|
|
||||||
// sfControl.replay();
|
|
||||||
// sessionControl.replay();
|
|
||||||
//
|
|
||||||
// interceptor.postHandle(request, response, "handler", null);
|
|
||||||
// interceptor.afterCompletion(request, response, "handler", null);
|
|
||||||
// sfControl.verify();
|
|
||||||
// sessionControl.verify();
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// public void testOpenSessionInViewFilterWithSingleSession() throws Exception {
|
|
||||||
// MockControl sfControl = MockControl.createControl(SessionFactory.class);
|
|
||||||
// final SessionFactory sf = (SessionFactory) sfControl.getMock();
|
|
||||||
// MockControl sessionControl = MockControl.createControl(Session.class);
|
|
||||||
// Session session = (Session) sessionControl.getMock();
|
|
||||||
//
|
|
||||||
// sf.openSession();
|
|
||||||
// sfControl.setReturnValue(session, 1);
|
|
||||||
// session.getSessionFactory();
|
|
||||||
// sessionControl.setReturnValue(sf);
|
|
||||||
// session.setFlushMode(FlushMode.NEVER);
|
|
||||||
// sessionControl.setVoidCallable(1);
|
|
||||||
// session.close();
|
|
||||||
// sessionControl.setReturnValue(null, 1);
|
|
||||||
// sfControl.replay();
|
|
||||||
// sessionControl.replay();
|
|
||||||
//
|
|
||||||
// MockControl sf2Control = MockControl.createControl(SessionFactory.class);
|
|
||||||
// final SessionFactory sf2 = (SessionFactory) sf2Control.getMock();
|
|
||||||
// MockControl session2Control = MockControl.createControl(Session.class);
|
|
||||||
// Session session2 = (Session) session2Control.getMock();
|
|
||||||
//
|
|
||||||
// sf2.openSession();
|
|
||||||
// sf2Control.setReturnValue(session2, 1);
|
|
||||||
// session2.getSessionFactory();
|
|
||||||
// session2Control.setReturnValue(sf);
|
|
||||||
// session2.setFlushMode(FlushMode.AUTO);
|
|
||||||
// session2Control.setVoidCallable(1);
|
|
||||||
// session2.close();
|
|
||||||
// session2Control.setReturnValue(null, 1);
|
|
||||||
// sf2Control.replay();
|
|
||||||
// session2Control.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");
|
|
||||||
// filterConfig2.addInitParameter("sessionFactoryBeanName", "mySessionFactory");
|
|
||||||
// filterConfig2.addInitParameter("flushMode", "AUTO");
|
|
||||||
//
|
|
||||||
// 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) {
|
|
||||||
// assertTrue(TransactionSynchronizationManager.hasResource(sf));
|
|
||||||
// servletRequest.setAttribute("invoked", Boolean.TRUE);
|
|
||||||
// }
|
|
||||||
// };
|
|
||||||
//
|
|
||||||
// final FilterChain filterChain2 = new FilterChain() {
|
|
||||||
// public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse)
|
|
||||||
// throws IOException, ServletException {
|
|
||||||
// assertTrue(TransactionSynchronizationManager.hasResource(sf2));
|
|
||||||
// filter.doFilter(servletRequest, servletResponse, filterChain);
|
|
||||||
// }
|
|
||||||
// };
|
|
||||||
//
|
|
||||||
// FilterChain filterChain3 = new PassThroughFilterChain(filter2, filterChain2);
|
|
||||||
//
|
|
||||||
// assertFalse(TransactionSynchronizationManager.hasResource(sf));
|
|
||||||
// assertFalse(TransactionSynchronizationManager.hasResource(sf2));
|
|
||||||
// filter2.doFilter(request, response, filterChain3);
|
|
||||||
// assertFalse(TransactionSynchronizationManager.hasResource(sf));
|
|
||||||
// assertFalse(TransactionSynchronizationManager.hasResource(sf2));
|
|
||||||
// assertNotNull(request.getAttribute("invoked"));
|
|
||||||
//
|
|
||||||
// sfControl.verify();
|
|
||||||
// sessionControl.verify();
|
|
||||||
// sf2Control.verify();
|
|
||||||
// session2Control.verify();
|
|
||||||
//
|
|
||||||
// wac.close();
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// public void testOpenSessionInViewFilterWithSingleSessionAndPreBoundSession() throws Exception {
|
|
||||||
// MockControl sfControl = MockControl.createControl(SessionFactory.class);
|
|
||||||
// final SessionFactory sf = (SessionFactory) sfControl.getMock();
|
|
||||||
// MockControl sessionControl = MockControl.createControl(Session.class);
|
|
||||||
// Session session = (Session) sessionControl.getMock();
|
|
||||||
//
|
|
||||||
// sf.openSession();
|
|
||||||
// sfControl.setReturnValue(session, 1);
|
|
||||||
// session.getSessionFactory();
|
|
||||||
// sessionControl.setReturnValue(sf);
|
|
||||||
// session.setFlushMode(FlushMode.NEVER);
|
|
||||||
// sessionControl.setVoidCallable(1);
|
|
||||||
// session.close();
|
|
||||||
// sessionControl.setReturnValue(null, 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");
|
|
||||||
// filterConfig2.addInitParameter("sessionFactoryBeanName", "mySessionFactory");
|
|
||||||
//
|
|
||||||
// OpenSessionInViewInterceptor rawInterceptor = new OpenSessionInViewInterceptor();
|
|
||||||
// rawInterceptor.setSessionFactory(sf);
|
|
||||||
// HandlerInterceptor interceptor = new WebRequestHandlerInterceptorAdapter(rawInterceptor);
|
|
||||||
//
|
|
||||||
// interceptor.preHandle(request, response, "handler");
|
|
||||||
//
|
|
||||||
// final OpenSessionInViewFilter filter = new OpenSessionInViewFilter();
|
|
||||||
// filter.init(filterConfig);
|
|
||||||
//
|
|
||||||
// final FilterChain filterChain = new FilterChain() {
|
|
||||||
// public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse) {
|
|
||||||
// assertTrue(TransactionSynchronizationManager.hasResource(sf));
|
|
||||||
// servletRequest.setAttribute("invoked", Boolean.TRUE);
|
|
||||||
// }
|
|
||||||
// };
|
|
||||||
//
|
|
||||||
// assertTrue(TransactionSynchronizationManager.hasResource(sf));
|
|
||||||
// filter.doFilter(request, response, filterChain);
|
|
||||||
// assertTrue(TransactionSynchronizationManager.hasResource(sf));
|
|
||||||
// assertNotNull(request.getAttribute("invoked"));
|
|
||||||
//
|
|
||||||
// interceptor.postHandle(request, response, "handler", null);
|
|
||||||
// interceptor.afterCompletion(request, response, "handler", null);
|
|
||||||
//
|
|
||||||
// sfControl.verify();
|
|
||||||
// sessionControl.verify();
|
|
||||||
//
|
|
||||||
// wac.close();
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// public void testOpenSessionInViewFilterWithDeferredClose() throws Exception {
|
|
||||||
// MockControl sfControl = MockControl.createControl(SessionFactory.class);
|
|
||||||
// final SessionFactory sf = (SessionFactory) sfControl.getMock();
|
|
||||||
// final MockControl sessionControl = MockControl.createControl(Session.class);
|
|
||||||
// final Session session = (Session) sessionControl.getMock();
|
|
||||||
//
|
|
||||||
// sf.openSession();
|
|
||||||
// sfControl.setReturnValue(session, 1);
|
|
||||||
// session.getSessionFactory();
|
|
||||||
// sessionControl.setReturnValue(sf);
|
|
||||||
// session.getFlushMode();
|
|
||||||
// sessionControl.setReturnValue(FlushMode.NEVER, 1);
|
|
||||||
// session.setFlushMode(FlushMode.NEVER);
|
|
||||||
// sessionControl.setVoidCallable(1);
|
|
||||||
// sfControl.replay();
|
|
||||||
// sessionControl.replay();
|
|
||||||
//
|
|
||||||
// MockControl sf2Control = MockControl.createControl(SessionFactory.class);
|
|
||||||
// final SessionFactory sf2 = (SessionFactory) sf2Control.getMock();
|
|
||||||
// final MockControl session2Control = MockControl.createControl(Session.class);
|
|
||||||
// final Session session2 = (Session) session2Control.getMock();
|
|
||||||
// MockControl txControl = MockControl.createControl(Transaction.class);
|
|
||||||
// Transaction tx = (Transaction) txControl.getMock();
|
|
||||||
// MockControl conControl = MockControl.createControl(Connection.class);
|
|
||||||
// Connection con = (Connection) conControl.getMock();
|
|
||||||
//
|
|
||||||
// sf2.openSession();
|
|
||||||
// sf2Control.setReturnValue(session2, 1);
|
|
||||||
// session2.beginTransaction();
|
|
||||||
// session2Control.setReturnValue(tx, 1);
|
|
||||||
// session2.connection();
|
|
||||||
// session2Control.setReturnValue(con, 2);
|
|
||||||
// tx.commit();
|
|
||||||
// txControl.setVoidCallable(1);
|
|
||||||
// session2.isConnected();
|
|
||||||
// session2Control.setReturnValue(true, 1);
|
|
||||||
// con.isReadOnly();
|
|
||||||
// conControl.setReturnValue(false, 1);
|
|
||||||
// session2.setFlushMode(FlushMode.NEVER);
|
|
||||||
// session2Control.setVoidCallable(1);
|
|
||||||
//
|
|
||||||
// sf2Control.replay();
|
|
||||||
// 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();
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// public void testOpenSessionInViewFilterWithDeferredCloseAndAlreadyActiveDeferredClose() throws Exception {
|
|
||||||
// MockControl sfControl = MockControl.createControl(SessionFactory.class);
|
|
||||||
// final SessionFactory sf = (SessionFactory) sfControl.getMock();
|
|
||||||
// final MockControl sessionControl = MockControl.createControl(Session.class);
|
|
||||||
// final Session session = (Session) sessionControl.getMock();
|
|
||||||
//
|
|
||||||
// sf.openSession();
|
|
||||||
// sfControl.setReturnValue(session, 1);
|
|
||||||
// session.getSessionFactory();
|
|
||||||
// sessionControl.setReturnValue(sf);
|
|
||||||
// session.getFlushMode();
|
|
||||||
// sessionControl.setReturnValue(FlushMode.NEVER, 1);
|
|
||||||
// session.setFlushMode(FlushMode.NEVER);
|
|
||||||
// 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();
|
|
||||||
// }
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,47 +1,52 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<classpath>
|
<classpath>
|
||||||
<classpathentry kind="src" path="src/main/java"/>
|
<classpathentry kind="src" path="src/main/java"/>
|
||||||
<classpathentry kind="src" path="src/main/resources"/>
|
<classpathentry kind="src" path="src/main/resources"/>
|
||||||
<classpathentry kind="src" output="target/test-classes" path="src/test/java"/>
|
<classpathentry kind="src" output="target/test-classes" path="src/test/java"/>
|
||||||
<classpathentry kind="src" output="target/test-classes" path="src/test/resources"/>
|
<classpathentry kind="src" output="target/test-classes" path="src/test/resources"/>
|
||||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
|
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
|
||||||
<classpathentry combineaccessrules="false" kind="src" path="/org.springframework.aop"/>
|
<classpathentry combineaccessrules="false" kind="src" path="/org.springframework.aop"/>
|
||||||
<classpathentry combineaccessrules="false" kind="src" path="/org.springframework.beans"/>
|
<classpathentry combineaccessrules="false" kind="src" path="/org.springframework.beans"/>
|
||||||
<classpathentry combineaccessrules="false" kind="src" path="/org.springframework.context"/>
|
<classpathentry combineaccessrules="false" kind="src" path="/org.springframework.context"/>
|
||||||
<classpathentry combineaccessrules="false" kind="src" path="/org.springframework.context.support"/>
|
<classpathentry combineaccessrules="false" kind="src" path="/org.springframework.context.support"/>
|
||||||
<classpathentry combineaccessrules="false" kind="src" path="/org.springframework.core"/>
|
<classpathentry combineaccessrules="false" kind="src" path="/org.springframework.core"/>
|
||||||
<classpathentry combineaccessrules="false" kind="src" path="/org.springframework.orm"/>
|
<classpathentry combineaccessrules="false" kind="src" path="/org.springframework.orm"/>
|
||||||
<classpathentry combineaccessrules="false" kind="src" path="/org.springframework.oxm"/>
|
<classpathentry combineaccessrules="false" kind="src" path="/org.springframework.oxm"/>
|
||||||
<classpathentry combineaccessrules="false" kind="src" path="/org.springframework.web"/>
|
<classpathentry combineaccessrules="false" kind="src" path="/org.springframework.web"/>
|
||||||
<classpathentry kind="var" path="IVY_CACHE/com.lowagie.text/com.springsource.com.lowagie.text/2.0.8/com.springsource.com.lowagie.text-2.0.8.jar" sourcepath="/IVY_CACHE/com.lowagie.text/com.springsource.com.lowagie.text/2.0.8/com.springsource.com.lowagie.text-sources-2.0.8.jar"/>
|
<classpathentry kind="var" path="IVY_CACHE/com.lowagie.text/com.springsource.com.lowagie.text/2.0.8/com.springsource.com.lowagie.text-2.0.8.jar" sourcepath="/IVY_CACHE/com.lowagie.text/com.springsource.com.lowagie.text/2.0.8/com.springsource.com.lowagie.text-sources-2.0.8.jar"/>
|
||||||
<classpathentry kind="var" path="IVY_CACHE/com.sun.syndication/com.springsource.com.sun.syndication/1.0.0/com.springsource.com.sun.syndication-1.0.0.jar" sourcepath="/IVY_CACHE/com.sun.syndication/com.springsource.com.sun.syndication/1.0.0/com.springsource.com.sun.syndication-sources-1.0.0.jar"/>
|
<classpathentry kind="var" path="IVY_CACHE/com.sun.syndication/com.springsource.com.sun.syndication/1.0.0/com.springsource.com.sun.syndication-1.0.0.jar" sourcepath="/IVY_CACHE/com.sun.syndication/com.springsource.com.sun.syndication/1.0.0/com.springsource.com.sun.syndication-sources-1.0.0.jar"/>
|
||||||
<classpathentry kind="var" path="IVY_CACHE/javax.activation/com.springsource.javax.activation/1.1.0/com.springsource.javax.activation-1.1.0.jar" sourcepath="/IVY_CACHE/javax.activation/com.springsource.javax.activation/1.1.0/com.springsource.javax.activation-sources-1.1.0.jar"/>
|
<classpathentry kind="var" path="IVY_CACHE/javax.activation/com.springsource.javax.activation/1.1.0/com.springsource.javax.activation-1.1.0.jar" sourcepath="/IVY_CACHE/javax.activation/com.springsource.javax.activation/1.1.0/com.springsource.javax.activation-sources-1.1.0.jar"/>
|
||||||
<classpathentry kind="var" path="IVY_CACHE/javax.el/com.springsource.javax.el/1.0.0/com.springsource.javax.el-1.0.0.jar" sourcepath="/IVY_CACHE/javax.el/com.springsource.javax.el/1.0.0/com.springsource.javax.el-sources-1.0.0.jar"/>
|
<classpathentry kind="var" path="IVY_CACHE/javax.el/com.springsource.javax.el/1.0.0/com.springsource.javax.el-1.0.0.jar" sourcepath="/IVY_CACHE/javax.el/com.springsource.javax.el/1.0.0/com.springsource.javax.el-sources-1.0.0.jar"/>
|
||||||
<classpathentry kind="var" path="IVY_CACHE/javax.servlet/com.springsource.javax.servlet.jsp.jstl/1.1.2/com.springsource.javax.servlet.jsp.jstl-1.1.2.jar" sourcepath="/IVY_CACHE/javax.servlet/com.springsource.javax.servlet.jsp.jstl/1.1.2/com.springsource.javax.servlet.jsp.jstl-sources-1.1.2.jar"/>
|
<classpathentry kind="var" path="IVY_CACHE/javax.servlet/com.springsource.javax.servlet.jsp.jstl/1.1.2/com.springsource.javax.servlet.jsp.jstl-1.1.2.jar" sourcepath="/IVY_CACHE/javax.servlet/com.springsource.javax.servlet.jsp.jstl/1.1.2/com.springsource.javax.servlet.jsp.jstl-sources-1.1.2.jar"/>
|
||||||
<classpathentry kind="var" path="IVY_CACHE/javax.servlet/com.springsource.javax.servlet.jsp/2.1.0/com.springsource.javax.servlet.jsp-2.1.0.jar" sourcepath="/IVY_CACHE/javax.servlet/com.springsource.javax.servlet.jsp/2.1.0/com.springsource.javax.servlet.jsp-sources-2.1.0.jar"/>
|
<classpathentry kind="var" path="IVY_CACHE/javax.servlet/com.springsource.javax.servlet.jsp/2.1.0/com.springsource.javax.servlet.jsp-2.1.0.jar" sourcepath="/IVY_CACHE/javax.servlet/com.springsource.javax.servlet.jsp/2.1.0/com.springsource.javax.servlet.jsp-sources-2.1.0.jar"/>
|
||||||
<classpathentry kind="var" path="IVY_CACHE/javax.servlet/com.springsource.javax.servlet/2.5.0/com.springsource.javax.servlet-2.5.0.jar" sourcepath="/IVY_CACHE/javax.servlet/com.springsource.javax.servlet/2.5.0/com.springsource.javax.servlet-sources-2.5.0.jar"/>
|
<classpathentry kind="var" path="IVY_CACHE/javax.servlet/com.springsource.javax.servlet/2.5.0/com.springsource.javax.servlet-2.5.0.jar" sourcepath="/IVY_CACHE/javax.servlet/com.springsource.javax.servlet/2.5.0/com.springsource.javax.servlet-sources-2.5.0.jar"/>
|
||||||
<classpathentry kind="var" path="IVY_CACHE/net.sourceforge.jasperreports/com.springsource.net.sf.jasperreports/2.0.5/com.springsource.net.sf.jasperreports-2.0.5.jar" sourcepath="/IVY_CACHE/net.sourceforge.jasperreports/com.springsource.net.sf.jasperreports/2.0.5/com.springsource.net.sf.jasperreports-sources-2.0.5.jar"/>
|
<classpathentry kind="var" path="IVY_CACHE/net.sourceforge.jasperreports/com.springsource.net.sf.jasperreports/2.0.5/com.springsource.net.sf.jasperreports-2.0.5.jar" sourcepath="/IVY_CACHE/net.sourceforge.jasperreports/com.springsource.net.sf.jasperreports/2.0.5/com.springsource.net.sf.jasperreports-sources-2.0.5.jar"/>
|
||||||
<classpathentry kind="var" path="IVY_CACHE/net.sourceforge.jexcelapi/com.springsource.jxl/2.6.6/com.springsource.jxl-2.6.6.jar" sourcepath="/IVY_CACHE/net.sourceforge.jexcelapi/com.springsource.jxl/2.6.6/com.springsource.jxl-sources-2.6.6.jar"/>
|
<classpathentry kind="var" path="IVY_CACHE/net.sourceforge.jexcelapi/com.springsource.jxl/2.6.6/com.springsource.jxl-2.6.6.jar" sourcepath="/IVY_CACHE/net.sourceforge.jexcelapi/com.springsource.jxl/2.6.6/com.springsource.jxl-sources-2.6.6.jar"/>
|
||||||
<classpathentry kind="var" path="IVY_CACHE/org.aopalliance/com.springsource.org.aopalliance/1.0.0/com.springsource.org.aopalliance-1.0.0.jar" sourcepath="/IVY_CACHE/org.aopalliance/com.springsource.org.aopalliance/1.0.0/com.springsource.org.aopalliance-sources-1.0.0.jar"/>
|
<classpathentry kind="var" path="IVY_CACHE/org.aopalliance/com.springsource.org.aopalliance/1.0.0/com.springsource.org.aopalliance-1.0.0.jar" sourcepath="/IVY_CACHE/org.aopalliance/com.springsource.org.aopalliance/1.0.0/com.springsource.org.aopalliance-sources-1.0.0.jar"/>
|
||||||
<classpathentry kind="var" path="IVY_CACHE/org.apache.commons/com.springsource.org.apache.commons.fileupload/1.2.0/com.springsource.org.apache.commons.fileupload-1.2.0.jar" sourcepath="/IVY_CACHE/org.apache.commons/com.springsource.org.apache.commons.fileupload/1.2.0/com.springsource.org.apache.commons.fileupload-sources-1.2.0.jar"/>
|
<classpathentry kind="var" path="IVY_CACHE/org.apache.commons/com.springsource.org.apache.commons.fileupload/1.2.0/com.springsource.org.apache.commons.fileupload-1.2.0.jar" sourcepath="/IVY_CACHE/org.apache.commons/com.springsource.org.apache.commons.fileupload/1.2.0/com.springsource.org.apache.commons.fileupload-sources-1.2.0.jar"/>
|
||||||
<classpathentry kind="var" path="IVY_CACHE/org.apache.commons/com.springsource.org.apache.commons.lang/2.1.0/com.springsource.org.apache.commons.lang-2.1.0.jar" sourcepath="/IVY_CACHE/org.apache.commons/com.springsource.org.apache.commons.lang/2.1.0/com.springsource.org.apache.commons.lang-sources-2.1.0.jar"/>
|
<classpathentry kind="var" path="IVY_CACHE/org.apache.commons/com.springsource.org.apache.commons.lang/2.1.0/com.springsource.org.apache.commons.lang-2.1.0.jar" sourcepath="/IVY_CACHE/org.apache.commons/com.springsource.org.apache.commons.lang/2.1.0/com.springsource.org.apache.commons.lang-sources-2.1.0.jar"/>
|
||||||
<classpathentry kind="var" path="IVY_CACHE/org.apache.commons/com.springsource.org.apache.commons.logging/1.1.1/com.springsource.org.apache.commons.logging-1.1.1.jar" sourcepath="/IVY_CACHE/org.apache.commons/com.springsource.org.apache.commons.logging/1.1.1/com.springsource.org.apache.commons.logging-sources-1.1.1.jar"/>
|
<classpathentry kind="var" path="IVY_CACHE/org.apache.commons/com.springsource.org.apache.commons.logging/1.1.1/com.springsource.org.apache.commons.logging-1.1.1.jar" sourcepath="/IVY_CACHE/org.apache.commons/com.springsource.org.apache.commons.logging/1.1.1/com.springsource.org.apache.commons.logging-sources-1.1.1.jar"/>
|
||||||
<classpathentry kind="var" path="IVY_CACHE/org.apache.poi/com.springsource.org.apache.poi/3.0.2.FINAL/com.springsource.org.apache.poi-3.0.2.FINAL.jar" sourcepath="/IVY_CACHE/org.apache.poi/com.springsource.org.apache.poi/3.0.2.FINAL/com.springsource.org.apache.poi-sources-3.0.2.FINAL.jar"/>
|
<classpathentry kind="var" path="IVY_CACHE/org.apache.poi/com.springsource.org.apache.poi/3.0.2.FINAL/com.springsource.org.apache.poi-3.0.2.FINAL.jar" sourcepath="/IVY_CACHE/org.apache.poi/com.springsource.org.apache.poi/3.0.2.FINAL/com.springsource.org.apache.poi-sources-3.0.2.FINAL.jar"/>
|
||||||
<classpathentry kind="var" path="IVY_CACHE/org.apache.taglibs/com.springsource.org.apache.taglibs.standard/1.1.2/com.springsource.org.apache.taglibs.standard-1.1.2.jar" sourcepath="/IVY_CACHE/org.apache.taglibs/com.springsource.org.apache.taglibs.standard/1.1.2/com.springsource.org.apache.taglibs.standard-sources-1.1.2.jar"/>
|
<classpathentry kind="var" path="IVY_CACHE/org.apache.taglibs/com.springsource.org.apache.taglibs.standard/1.1.2/com.springsource.org.apache.taglibs.standard-1.1.2.jar" sourcepath="/IVY_CACHE/org.apache.taglibs/com.springsource.org.apache.taglibs.standard/1.1.2/com.springsource.org.apache.taglibs.standard-sources-1.1.2.jar"/>
|
||||||
<classpathentry kind="var" path="IVY_CACHE/org.apache.tiles/com.springsource.org.apache.tiles.core/2.0.5.osgi/com.springsource.org.apache.tiles.core-2.0.5.osgi.jar" sourcepath="/IVY_CACHE/org.apache.tiles/com.springsource.org.apache.tiles.core/2.0.5.osgi/com.springsource.org.apache.tiles.core-sources-2.0.5.osgi.jar"/>
|
<classpathentry kind="var" path="IVY_CACHE/org.apache.velocity/com.springsource.org.apache.velocity.tools.view/1.4.0/com.springsource.org.apache.velocity.tools.view-1.4.0.jar" sourcepath="/IVY_CACHE/org.apache.velocity/com.springsource.org.apache.velocity.tools.view/1.4.0/com.springsource.org.apache.velocity.tools.view-sources-1.4.0.jar"/>
|
||||||
<classpathentry kind="var" path="IVY_CACHE/org.apache.tiles/com.springsource.org.apache.tiles.jsp/2.0.5/com.springsource.org.apache.tiles.jsp-2.0.5.jar" sourcepath="/IVY_CACHE/org.apache.tiles/com.springsource.org.apache.tiles.jsp/2.0.5/com.springsource.org.apache.tiles.jsp-sources-2.0.5.jar"/>
|
<classpathentry kind="var" path="IVY_CACHE/org.apache.velocity/com.springsource.org.apache.velocity/1.5.0/com.springsource.org.apache.velocity-1.5.0.jar" sourcepath="/IVY_CACHE/org.apache.velocity/com.springsource.org.apache.velocity/1.5.0/com.springsource.org.apache.velocity-sources-1.5.0.jar"/>
|
||||||
<classpathentry kind="var" path="IVY_CACHE/org.apache.tiles/com.springsource.org.apache.tiles/2.0.5/com.springsource.org.apache.tiles-2.0.5.jar" sourcepath="/IVY_CACHE/org.apache.tiles/com.springsource.org.apache.tiles/2.0.5/com.springsource.org.apache.tiles-sources-2.0.5.jar"/>
|
<classpathentry kind="var" path="IVY_CACHE/org.codehaus.jackson/com.springsource.org.codehaus.jackson.mapper/1.0.0/com.springsource.org.codehaus.jackson.mapper-1.0.0.jar" sourcepath="/IVY_CACHE/org.codehaus.jackson/com.springsource.org.codehaus.jackson.mapper/1.0.0/com.springsource.org.codehaus.jackson.mapper-sources-1.0.0.jar"/>
|
||||||
<classpathentry kind="var" path="IVY_CACHE/org.apache.velocity/com.springsource.org.apache.velocity.tools.view/1.4.0/com.springsource.org.apache.velocity.tools.view-1.4.0.jar" sourcepath="/IVY_CACHE/org.apache.velocity/com.springsource.org.apache.velocity.tools.view/1.4.0/com.springsource.org.apache.velocity.tools.view-sources-1.4.0.jar"/>
|
<classpathentry kind="var" path="IVY_CACHE/org.codehaus.jackson/com.springsource.org.codehaus.jackson/1.0.0/com.springsource.org.codehaus.jackson-1.0.0.jar" sourcepath="/IVY_CACHE/org.codehaus.jackson/com.springsource.org.codehaus.jackson/1.0.0/com.springsource.org.codehaus.jackson-sources-1.0.0.jar"/>
|
||||||
<classpathentry kind="var" path="IVY_CACHE/org.apache.velocity/com.springsource.org.apache.velocity/1.5.0/com.springsource.org.apache.velocity-1.5.0.jar" sourcepath="/IVY_CACHE/org.apache.velocity/com.springsource.org.apache.velocity/1.5.0/com.springsource.org.apache.velocity-sources-1.5.0.jar"/>
|
<classpathentry kind="var" path="IVY_CACHE/org.custommonkey.xmlunit/com.springsource.org.custommonkey.xmlunit/1.2.0/com.springsource.org.custommonkey.xmlunit-1.2.0.jar" sourcepath="/IVY_CACHE/org.custommonkey.xmlunit/com.springsource.org.custommonkey.xmlunit/1.2.0/com.springsource.org.custommonkey.xmlunit-sources-1.2.0.jar"/>
|
||||||
<classpathentry kind="var" path="IVY_CACHE/org.codehaus.jackson/com.springsource.org.codehaus.jackson.mapper/1.0.0/com.springsource.org.codehaus.jackson.mapper-1.0.0.jar" sourcepath="/IVY_CACHE/org.codehaus.jackson/com.springsource.org.codehaus.jackson.mapper/1.0.0/com.springsource.org.codehaus.jackson.mapper-sources-1.0.0.jar"/>
|
<classpathentry kind="var" path="IVY_CACHE/org.dom4j/com.springsource.org.dom4j/1.6.1/com.springsource.org.dom4j-1.6.1.jar" sourcepath="/IVY_CACHE/org.dom4j/com.springsource.org.dom4j/1.6.1/com.springsource.org.dom4j-sources-1.6.1.jar"/>
|
||||||
<classpathentry kind="var" path="IVY_CACHE/org.codehaus.jackson/com.springsource.org.codehaus.jackson/1.0.0/com.springsource.org.codehaus.jackson-1.0.0.jar" sourcepath="/IVY_CACHE/org.codehaus.jackson/com.springsource.org.codehaus.jackson/1.0.0/com.springsource.org.codehaus.jackson-sources-1.0.0.jar"/>
|
<classpathentry kind="var" path="IVY_CACHE/org.easymock/com.springsource.org.easymock/2.5.1/com.springsource.org.easymock-2.5.1.jar" sourcepath="/IVY_CACHE/org.easymock/com.springsource.org.easymock/2.5.1/com.springsource.org.easymock-sources-2.5.1.jar"/>
|
||||||
<classpathentry kind="var" path="IVY_CACHE/org.custommonkey.xmlunit/com.springsource.org.custommonkey.xmlunit/1.2.0/com.springsource.org.custommonkey.xmlunit-1.2.0.jar" sourcepath="/IVY_CACHE/org.custommonkey.xmlunit/com.springsource.org.custommonkey.xmlunit/1.2.0/com.springsource.org.custommonkey.xmlunit-sources-1.2.0.jar"/>
|
<classpathentry kind="var" path="IVY_CACHE/org.freemarker/com.springsource.freemarker/2.3.15/com.springsource.freemarker-2.3.15.jar" sourcepath="/IVY_CACHE/org.freemarker/com.springsource.freemarker/2.3.15/com.springsource.freemarker-sources-2.3.15.jar"/>
|
||||||
<classpathentry kind="var" path="IVY_CACHE/org.dom4j/com.springsource.org.dom4j/1.6.1/com.springsource.org.dom4j-1.6.1.jar" sourcepath="/IVY_CACHE/org.dom4j/com.springsource.org.dom4j/1.6.1/com.springsource.org.dom4j-sources-1.6.1.jar"/>
|
<classpathentry kind="var" path="IVY_CACHE/org.jaxen/com.springsource.org.jaxen/1.1.1/com.springsource.org.jaxen-1.1.1.jar" sourcepath="/IVY_CACHE/org.jaxen/com.springsource.org.jaxen/1.1.1/com.springsource.org.jaxen-sources-1.1.1.jar"/>
|
||||||
<classpathentry kind="var" path="IVY_CACHE/org.easymock/com.springsource.org.easymock/2.5.1/com.springsource.org.easymock-2.5.1.jar" sourcepath="/IVY_CACHE/org.easymock/com.springsource.org.easymock/2.5.1/com.springsource.org.easymock-sources-2.5.1.jar"/>
|
<classpathentry kind="var" path="IVY_CACHE/org.jdom/com.springsource.org.jdom/1.0.0/com.springsource.org.jdom-1.0.0.jar" sourcepath="/IVY_CACHE/org.jdom/com.springsource.org.jdom/1.0.0/com.springsource.org.jdom-1.0.0.jar"/>
|
||||||
<classpathentry kind="var" path="IVY_CACHE/org.freemarker/com.springsource.freemarker/2.3.15/com.springsource.freemarker-2.3.15.jar" sourcepath="/IVY_CACHE/org.freemarker/com.springsource.freemarker/2.3.15/com.springsource.freemarker-sources-2.3.15.jar"/>
|
<classpathentry kind="var" path="IVY_CACHE/org.junit/com.springsource.org.junit/4.6.0/com.springsource.org.junit-4.6.0.jar" sourcepath="/IVY_CACHE/org.junit/com.springsource.org.junit/4.6.0/com.springsource.org.junit-sources-4.6.0.jar"/>
|
||||||
<classpathentry kind="var" path="IVY_CACHE/org.jaxen/com.springsource.org.jaxen/1.1.1/com.springsource.org.jaxen-1.1.1.jar" sourcepath="/IVY_CACHE/org.jaxen/com.springsource.org.jaxen/1.1.1/com.springsource.org.jaxen-sources-1.1.1.jar"/>
|
<classpathentry kind="var" path="IVY_CACHE/org.mozilla.javascript/com.springsource.org.mozilla.javascript/1.7.0.R2/com.springsource.org.mozilla.javascript-1.7.0.R2.jar"/>
|
||||||
<classpathentry kind="var" path="IVY_CACHE/org.jdom/com.springsource.org.jdom/1.0.0/com.springsource.org.jdom-1.0.0.jar" sourcepath="/IVY_CACHE/org.jdom/com.springsource.org.jdom/1.0.0/com.springsource.org.jdom-1.0.0.jar"/>
|
<classpathentry combineaccessrules="false" kind="src" path="/org.springframework.transaction"/>
|
||||||
<classpathentry kind="var" path="IVY_CACHE/org.junit/com.springsource.org.junit/4.6.0/com.springsource.org.junit-4.6.0.jar" sourcepath="/IVY_CACHE/org.junit/com.springsource.org.junit/4.6.0/com.springsource.org.junit-sources-4.6.0.jar"/>
|
<classpathentry combineaccessrules="false" kind="src" path="/org.springframework.jdbc"/>
|
||||||
<classpathentry kind="var" path="IVY_CACHE/org.mozilla.javascript/com.springsource.org.mozilla.javascript/1.7.0.R2/com.springsource.org.mozilla.javascript-1.7.0.R2.jar"/>
|
<classpathentry kind="var" path="IVY_CACHE/org.hibernate/com.springsource.org.hibernate/3.3.1.GA/com.springsource.org.hibernate-3.3.1.GA.jar"/>
|
||||||
<classpathentry kind="output" path="target/classes"/>
|
<classpathentry kind="var" path="IVY_CACHE/javax.transaction/com.springsource.javax.transaction/1.1.0/com.springsource.javax.transaction-1.1.0.jar" sourcepath="/IVY_CACHE/javax.transaction/com.springsource.javax.transaction/1.1.0/com.springsource.javax.transaction-sources-1.1.0.jar"/>
|
||||||
</classpath>
|
<classpathentry kind="var" path="IVY_CACHE/org.apache.tiles/com.springsource.org.apache.tiles/2.1.2.osgi/com.springsource.org.apache.tiles-2.1.2.osgi.jar"/>
|
||||||
|
<classpathentry kind="var" path="IVY_CACHE/org.apache.tiles/com.springsource.org.apache.tiles.core/2.1.2.osgi/com.springsource.org.apache.tiles.core-2.1.2.osgi.jar"/>
|
||||||
|
<classpathentry kind="var" path="IVY_CACHE/org.apache.tiles/com.springsource.org.apache.tiles.jsp/2.1.2/com.springsource.org.apache.tiles.jsp-2.1.2.jar"/>
|
||||||
|
<classpathentry kind="var" path="IVY_CACHE/org.apache.tiles/com.springsource.org.apache.tiles.servlet/2.1.2/com.springsource.org.apache.tiles.servlet-2.1.2.jar"/>
|
||||||
|
<classpathentry kind="output" path="target/classes"/>
|
||||||
|
</classpath>
|
||||||
|
|
|
||||||
|
|
@ -23,6 +23,7 @@
|
||||||
<conf name="poi" extends="runtime" description="JARs needed to create beans for Poi"/>
|
<conf name="poi" extends="runtime" description="JARs needed to create beans for Poi"/>
|
||||||
<conf name="tiles" extends="runtime" description="JARs neeeded to create beans for Tiles"/>
|
<conf name="tiles" extends="runtime" description="JARs neeeded to create beans for Tiles"/>
|
||||||
<conf name="velocity" extends="runtime" description="JARs needed to create beans for Velocity"/>
|
<conf name="velocity" extends="runtime" description="JARs needed to create beans for Velocity"/>
|
||||||
|
<conf name="hibernate" extends="runtime" description="JARs needed to use Hibernate"/>
|
||||||
</configurations>
|
</configurations>
|
||||||
|
|
||||||
<publications>
|
<publications>
|
||||||
|
|
@ -90,7 +91,13 @@
|
||||||
<dependency org="net.sourceforge.cglib" name="com.springsource.net.sf.cglib" rev="2.1.3" conf="test->compile"/>
|
<dependency org="net.sourceforge.cglib" name="com.springsource.net.sf.cglib" rev="2.1.3" conf="test->compile"/>
|
||||||
<dependency org="org.mozilla.javascript" name="com.springsource.org.mozilla.javascript" rev="1.7.0.R2"
|
<dependency org="org.mozilla.javascript" name="com.springsource.org.mozilla.javascript" rev="1.7.0.R2"
|
||||||
conf="test->runtime"/>
|
conf="test->runtime"/>
|
||||||
|
<dependency org="org.springframework" name="org.springframework.transaction" rev="latest.integration"
|
||||||
|
conf="test->compile"/>
|
||||||
|
<dependency org="org.springframework" name="org.springframework.orm" rev="latest.integration"
|
||||||
|
conf="test->compile"/>
|
||||||
|
<dependency org="org.hibernate" name="com.springsource.org.hibernate" rev="3.3.1.GA"
|
||||||
|
conf="test->compile"/>
|
||||||
|
<dependency org="javax.transaction" name="com.springsource.javax.transaction" rev="1.1.0" conf="provided->runtime"/>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
</ivy-module>
|
</ivy-module>
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,673 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2002-2007 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.springframework.orm.hibernate3.support;
|
||||||
|
|
||||||
|
import junit.framework.TestCase;
|
||||||
|
|
||||||
|
import org.easymock.MockControl;
|
||||||
|
import org.hibernate.classic.Session;
|
||||||
|
import org.hibernate.SessionFactory;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.sql.Connection;
|
||||||
|
|
||||||
|
import javax.servlet.FilterChain;
|
||||||
|
import javax.servlet.ServletException;
|
||||||
|
import javax.servlet.ServletRequest;
|
||||||
|
import javax.servlet.ServletResponse;
|
||||||
|
import javax.transaction.TransactionManager;
|
||||||
|
|
||||||
|
|
||||||
|
import org.hibernate.FlushMode;
|
||||||
|
import org.hibernate.HibernateException;
|
||||||
|
import org.hibernate.Transaction;
|
||||||
|
import org.hibernate.engine.SessionFactoryImplementor;
|
||||||
|
|
||||||
|
import org.springframework.mock.web.MockFilterConfig;
|
||||||
|
import org.springframework.mock.web.MockHttpServletRequest;
|
||||||
|
import org.springframework.mock.web.MockHttpServletResponse;
|
||||||
|
import org.springframework.mock.web.MockServletContext;
|
||||||
|
import org.springframework.mock.web.PassThroughFilterChain;
|
||||||
|
import org.springframework.orm.hibernate3.HibernateAccessor;
|
||||||
|
import org.springframework.orm.hibernate3.HibernateTransactionManager;
|
||||||
|
import org.springframework.orm.hibernate3.SessionFactoryUtils;
|
||||||
|
import org.springframework.transaction.TransactionDefinition;
|
||||||
|
import org.springframework.transaction.TransactionStatus;
|
||||||
|
import org.springframework.transaction.support.DefaultTransactionDefinition;
|
||||||
|
import org.springframework.transaction.support.TransactionSynchronizationManager;
|
||||||
|
import org.springframework.web.context.WebApplicationContext;
|
||||||
|
import org.springframework.web.context.support.StaticWebApplicationContext;
|
||||||
|
import org.springframework.web.servlet.HandlerInterceptor;
|
||||||
|
import org.springframework.web.servlet.handler.WebRequestHandlerInterceptorAdapter;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Juergen Hoeller
|
||||||
|
* @since 05.03.2005
|
||||||
|
*/
|
||||||
|
public class OpenSessionInViewTests extends TestCase {
|
||||||
|
|
||||||
|
public void testOpenSessionInViewInterceptorWithSingleSession() throws Exception {
|
||||||
|
|
||||||
|
//SessionFactory sf = createMock(SessionFactory.class);
|
||||||
|
//Session session = createMock(Session.class);
|
||||||
|
|
||||||
|
MockControl sfControl = MockControl.createControl(SessionFactory.class);
|
||||||
|
final SessionFactory sf = (SessionFactory) sfControl.getMock();
|
||||||
|
MockControl sessionControl = MockControl.createControl(Session.class);
|
||||||
|
Session session = (Session) sessionControl.getMock();
|
||||||
|
|
||||||
|
|
||||||
|
OpenSessionInViewInterceptor rawInterceptor = new OpenSessionInViewInterceptor();
|
||||||
|
rawInterceptor.setSessionFactory(sf);
|
||||||
|
HandlerInterceptor interceptor = new WebRequestHandlerInterceptorAdapter(rawInterceptor);
|
||||||
|
|
||||||
|
MockServletContext sc = new MockServletContext();
|
||||||
|
MockHttpServletRequest request = new MockHttpServletRequest(sc);
|
||||||
|
MockHttpServletResponse response = new MockHttpServletResponse();
|
||||||
|
|
||||||
|
|
||||||
|
//expect(mockStorage.size()).andReturn(expectedValue);
|
||||||
|
|
||||||
|
//expect(sf.openSession()).andReturn(session);
|
||||||
|
sf.openSession();
|
||||||
|
sfControl.setReturnValue(session, 1);
|
||||||
|
session.getSessionFactory();
|
||||||
|
sessionControl.setReturnValue(sf, 2);
|
||||||
|
session.isOpen();
|
||||||
|
sessionControl.setReturnValue(true, 1);
|
||||||
|
session.setFlushMode(FlushMode.MANUAL);
|
||||||
|
sessionControl.setVoidCallable(1);
|
||||||
|
sfControl.replay();
|
||||||
|
sessionControl.replay();
|
||||||
|
interceptor.preHandle(request, response, "handler");
|
||||||
|
assertTrue(TransactionSynchronizationManager.hasResource(sf));
|
||||||
|
|
||||||
|
// check that further invocations simply participate
|
||||||
|
interceptor.preHandle(request, response, "handler");
|
||||||
|
|
||||||
|
assertEquals(session, SessionFactoryUtils.getSession(sf, false));
|
||||||
|
|
||||||
|
interceptor.preHandle(request, response, "handler");
|
||||||
|
interceptor.postHandle(request, response, "handler", null);
|
||||||
|
interceptor.afterCompletion(request, response, "handler", null);
|
||||||
|
|
||||||
|
interceptor.postHandle(request, response, "handler", null);
|
||||||
|
interceptor.afterCompletion(request, response, "handler", null);
|
||||||
|
|
||||||
|
interceptor.preHandle(request, response, "handler");
|
||||||
|
interceptor.postHandle(request, response, "handler", null);
|
||||||
|
interceptor.afterCompletion(request, response, "handler", null);
|
||||||
|
|
||||||
|
sfControl.verify();
|
||||||
|
sessionControl.verify();
|
||||||
|
|
||||||
|
sfControl.reset();
|
||||||
|
sessionControl.reset();
|
||||||
|
sfControl.replay();
|
||||||
|
sessionControl.replay();
|
||||||
|
interceptor.postHandle(request, response, "handler", null);
|
||||||
|
assertTrue(TransactionSynchronizationManager.hasResource(sf));
|
||||||
|
sfControl.verify();
|
||||||
|
sessionControl.verify();
|
||||||
|
|
||||||
|
sfControl.reset();
|
||||||
|
sessionControl.reset();
|
||||||
|
session.close();
|
||||||
|
sessionControl.setReturnValue(null, 1);
|
||||||
|
sfControl.replay();
|
||||||
|
sessionControl.replay();
|
||||||
|
interceptor.afterCompletion(request, response, "handler", null);
|
||||||
|
assertFalse(TransactionSynchronizationManager.hasResource(sf));
|
||||||
|
sfControl.verify();
|
||||||
|
sessionControl.verify();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testOpenSessionInViewInterceptorWithSingleSessionAndJtaTm() throws Exception {
|
||||||
|
MockControl sfControl = MockControl.createControl(SessionFactoryImplementor.class);
|
||||||
|
final SessionFactoryImplementor sf = (SessionFactoryImplementor) sfControl.getMock();
|
||||||
|
MockControl sessionControl = MockControl.createControl(Session.class);
|
||||||
|
Session session = (Session) sessionControl.getMock();
|
||||||
|
|
||||||
|
MockControl tmControl = MockControl.createControl(TransactionManager.class);
|
||||||
|
TransactionManager tm = (TransactionManager) tmControl.getMock();
|
||||||
|
tm.getTransaction();
|
||||||
|
tmControl.setReturnValue(null, 2);
|
||||||
|
|
||||||
|
OpenSessionInViewInterceptor rawInterceptor = new OpenSessionInViewInterceptor();
|
||||||
|
rawInterceptor.setSessionFactory(sf);
|
||||||
|
HandlerInterceptor interceptor = new WebRequestHandlerInterceptorAdapter(rawInterceptor);
|
||||||
|
|
||||||
|
MockServletContext sc = new MockServletContext();
|
||||||
|
MockHttpServletRequest request = new MockHttpServletRequest(sc);
|
||||||
|
MockHttpServletResponse response = new MockHttpServletResponse();
|
||||||
|
|
||||||
|
sf.getTransactionManager();
|
||||||
|
sfControl.setReturnValue(tm, 2);
|
||||||
|
sf.openSession();
|
||||||
|
sfControl.setReturnValue(session, 1);
|
||||||
|
session.isOpen();
|
||||||
|
sessionControl.setReturnValue(true, 1);
|
||||||
|
session.setFlushMode(FlushMode.MANUAL);
|
||||||
|
sessionControl.setVoidCallable(1);
|
||||||
|
|
||||||
|
tmControl.replay();
|
||||||
|
sfControl.replay();
|
||||||
|
sessionControl.replay();
|
||||||
|
|
||||||
|
interceptor.preHandle(request, response, "handler");
|
||||||
|
assertTrue(TransactionSynchronizationManager.hasResource(sf));
|
||||||
|
|
||||||
|
// check that further invocations simply participate
|
||||||
|
interceptor.preHandle(request, response, "handler");
|
||||||
|
|
||||||
|
assertEquals(session, SessionFactoryUtils.getSession(sf, false));
|
||||||
|
|
||||||
|
interceptor.preHandle(request, response, "handler");
|
||||||
|
interceptor.postHandle(request, response, "handler", null);
|
||||||
|
interceptor.afterCompletion(request, response, "handler", null);
|
||||||
|
|
||||||
|
interceptor.postHandle(request, response, "handler", null);
|
||||||
|
interceptor.afterCompletion(request, response, "handler", null);
|
||||||
|
|
||||||
|
interceptor.preHandle(request, response, "handler");
|
||||||
|
interceptor.postHandle(request, response, "handler", null);
|
||||||
|
interceptor.afterCompletion(request, response, "handler", null);
|
||||||
|
|
||||||
|
sfControl.verify();
|
||||||
|
sessionControl.verify();
|
||||||
|
|
||||||
|
sfControl.reset();
|
||||||
|
sessionControl.reset();
|
||||||
|
sfControl.replay();
|
||||||
|
sessionControl.replay();
|
||||||
|
interceptor.postHandle(request, response, "handler", null);
|
||||||
|
assertTrue(TransactionSynchronizationManager.hasResource(sf));
|
||||||
|
sfControl.verify();
|
||||||
|
sessionControl.verify();
|
||||||
|
|
||||||
|
sfControl.reset();
|
||||||
|
sessionControl.reset();
|
||||||
|
session.close();
|
||||||
|
sessionControl.setReturnValue(null, 1);
|
||||||
|
sfControl.replay();
|
||||||
|
sessionControl.replay();
|
||||||
|
interceptor.afterCompletion(request, response, "handler", null);
|
||||||
|
assertFalse(TransactionSynchronizationManager.hasResource(sf));
|
||||||
|
sfControl.verify();
|
||||||
|
sessionControl.verify();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testOpenSessionInViewInterceptorWithSingleSessionAndFlush() throws Exception {
|
||||||
|
MockControl sfControl = MockControl.createControl(SessionFactory.class);
|
||||||
|
final SessionFactory sf = (SessionFactory) sfControl.getMock();
|
||||||
|
MockControl sessionControl = MockControl.createControl(Session.class);
|
||||||
|
Session session = (Session) sessionControl.getMock();
|
||||||
|
|
||||||
|
OpenSessionInViewInterceptor rawInterceptor = new OpenSessionInViewInterceptor();
|
||||||
|
rawInterceptor.setSessionFactory(sf);
|
||||||
|
rawInterceptor.setFlushMode(HibernateAccessor.FLUSH_AUTO);
|
||||||
|
HandlerInterceptor interceptor = new WebRequestHandlerInterceptorAdapter(rawInterceptor);
|
||||||
|
|
||||||
|
MockServletContext sc = new MockServletContext();
|
||||||
|
MockHttpServletRequest request = new MockHttpServletRequest(sc);
|
||||||
|
MockHttpServletResponse response = new MockHttpServletResponse();
|
||||||
|
|
||||||
|
sf.openSession();
|
||||||
|
sfControl.setReturnValue(session, 1);
|
||||||
|
session.getSessionFactory();
|
||||||
|
sessionControl.setReturnValue(sf);
|
||||||
|
sfControl.replay();
|
||||||
|
sessionControl.replay();
|
||||||
|
interceptor.preHandle(request, response, "handler");
|
||||||
|
assertTrue(TransactionSynchronizationManager.hasResource(sf));
|
||||||
|
sfControl.verify();
|
||||||
|
sessionControl.verify();
|
||||||
|
|
||||||
|
sfControl.reset();
|
||||||
|
sessionControl.reset();
|
||||||
|
session.flush();
|
||||||
|
sessionControl.setVoidCallable(1);
|
||||||
|
sfControl.replay();
|
||||||
|
sessionControl.replay();
|
||||||
|
interceptor.postHandle(request, response, "handler", null);
|
||||||
|
assertTrue(TransactionSynchronizationManager.hasResource(sf));
|
||||||
|
sfControl.verify();
|
||||||
|
sessionControl.verify();
|
||||||
|
|
||||||
|
sfControl.reset();
|
||||||
|
sessionControl.reset();
|
||||||
|
session.close();
|
||||||
|
sessionControl.setReturnValue(null, 1);
|
||||||
|
sfControl.replay();
|
||||||
|
sessionControl.replay();
|
||||||
|
interceptor.afterCompletion(request, response, "handler", null);
|
||||||
|
assertFalse(TransactionSynchronizationManager.hasResource(sf));
|
||||||
|
sfControl.verify();
|
||||||
|
sessionControl.verify();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testOpenSessionInViewInterceptorAndDeferredClose() throws Exception {
|
||||||
|
MockControl sfControl = MockControl.createControl(SessionFactory.class);
|
||||||
|
final SessionFactory sf = (SessionFactory) sfControl.getMock();
|
||||||
|
MockControl sessionControl = MockControl.createControl(Session.class);
|
||||||
|
Session session = (Session) sessionControl.getMock();
|
||||||
|
|
||||||
|
OpenSessionInViewInterceptor rawInterceptor = new OpenSessionInViewInterceptor();
|
||||||
|
rawInterceptor.setSessionFactory(sf);
|
||||||
|
rawInterceptor.setSingleSession(false);
|
||||||
|
HandlerInterceptor interceptor = new WebRequestHandlerInterceptorAdapter(rawInterceptor);
|
||||||
|
|
||||||
|
MockServletContext sc = new MockServletContext();
|
||||||
|
MockHttpServletRequest request = new MockHttpServletRequest(sc);
|
||||||
|
MockHttpServletResponse response = new MockHttpServletResponse();
|
||||||
|
|
||||||
|
sf.openSession();
|
||||||
|
sfControl.setReturnValue(session, 1);
|
||||||
|
session.getSessionFactory();
|
||||||
|
sessionControl.setReturnValue(sf, 1);
|
||||||
|
session.setFlushMode(FlushMode.MANUAL);
|
||||||
|
sessionControl.setVoidCallable(1);
|
||||||
|
sfControl.replay();
|
||||||
|
sessionControl.replay();
|
||||||
|
|
||||||
|
interceptor.preHandle(request, response, "handler");
|
||||||
|
org.hibernate.Session sess = SessionFactoryUtils.getSession(sf, true);
|
||||||
|
SessionFactoryUtils.releaseSession(sess, sf);
|
||||||
|
|
||||||
|
// check that further invocations simply participate
|
||||||
|
interceptor.preHandle(request, response, "handler");
|
||||||
|
|
||||||
|
interceptor.preHandle(request, response, "handler");
|
||||||
|
interceptor.postHandle(request, response, "handler", null);
|
||||||
|
interceptor.afterCompletion(request, response, "handler", null);
|
||||||
|
|
||||||
|
interceptor.postHandle(request, response, "handler", null);
|
||||||
|
interceptor.afterCompletion(request, response, "handler", null);
|
||||||
|
|
||||||
|
interceptor.preHandle(request, response, "handler");
|
||||||
|
interceptor.postHandle(request, response, "handler", null);
|
||||||
|
interceptor.afterCompletion(request, response, "handler", null);
|
||||||
|
|
||||||
|
sfControl.verify();
|
||||||
|
sessionControl.verify();
|
||||||
|
sfControl.reset();
|
||||||
|
sessionControl.reset();
|
||||||
|
|
||||||
|
session.close();
|
||||||
|
sessionControl.setReturnValue(null, 1);
|
||||||
|
sfControl.replay();
|
||||||
|
sessionControl.replay();
|
||||||
|
|
||||||
|
interceptor.postHandle(request, response, "handler", null);
|
||||||
|
interceptor.afterCompletion(request, response, "handler", null);
|
||||||
|
sfControl.verify();
|
||||||
|
sessionControl.verify();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testOpenSessionInViewFilterWithSingleSession() throws Exception {
|
||||||
|
MockControl sfControl = MockControl.createControl(SessionFactory.class);
|
||||||
|
final SessionFactory sf = (SessionFactory) sfControl.getMock();
|
||||||
|
MockControl sessionControl = MockControl.createControl(Session.class);
|
||||||
|
Session session = (Session) sessionControl.getMock();
|
||||||
|
|
||||||
|
sf.openSession();
|
||||||
|
sfControl.setReturnValue(session, 1);
|
||||||
|
session.getSessionFactory();
|
||||||
|
sessionControl.setReturnValue(sf);
|
||||||
|
session.setFlushMode(FlushMode.MANUAL);
|
||||||
|
sessionControl.setVoidCallable(1);
|
||||||
|
session.close();
|
||||||
|
sessionControl.setReturnValue(null, 1);
|
||||||
|
sfControl.replay();
|
||||||
|
sessionControl.replay();
|
||||||
|
|
||||||
|
MockControl sf2Control = MockControl.createControl(SessionFactory.class);
|
||||||
|
final SessionFactory sf2 = (SessionFactory) sf2Control.getMock();
|
||||||
|
MockControl session2Control = MockControl.createControl(Session.class);
|
||||||
|
Session session2 = (Session) session2Control.getMock();
|
||||||
|
|
||||||
|
sf2.openSession();
|
||||||
|
sf2Control.setReturnValue(session2, 1);
|
||||||
|
session2.getSessionFactory();
|
||||||
|
session2Control.setReturnValue(sf);
|
||||||
|
session2.setFlushMode(FlushMode.AUTO);
|
||||||
|
session2Control.setVoidCallable(1);
|
||||||
|
session2.close();
|
||||||
|
session2Control.setReturnValue(null, 1);
|
||||||
|
sf2Control.replay();
|
||||||
|
session2Control.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");
|
||||||
|
filterConfig2.addInitParameter("sessionFactoryBeanName", "mySessionFactory");
|
||||||
|
filterConfig2.addInitParameter("flushMode", "AUTO");
|
||||||
|
|
||||||
|
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) {
|
||||||
|
assertTrue(TransactionSynchronizationManager.hasResource(sf));
|
||||||
|
servletRequest.setAttribute("invoked", Boolean.TRUE);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
final FilterChain filterChain2 = new FilterChain() {
|
||||||
|
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse)
|
||||||
|
throws IOException, ServletException {
|
||||||
|
assertTrue(TransactionSynchronizationManager.hasResource(sf2));
|
||||||
|
filter.doFilter(servletRequest, servletResponse, filterChain);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
FilterChain filterChain3 = new PassThroughFilterChain(filter2, filterChain2);
|
||||||
|
|
||||||
|
assertFalse(TransactionSynchronizationManager.hasResource(sf));
|
||||||
|
assertFalse(TransactionSynchronizationManager.hasResource(sf2));
|
||||||
|
filter2.doFilter(request, response, filterChain3);
|
||||||
|
assertFalse(TransactionSynchronizationManager.hasResource(sf));
|
||||||
|
assertFalse(TransactionSynchronizationManager.hasResource(sf2));
|
||||||
|
assertNotNull(request.getAttribute("invoked"));
|
||||||
|
|
||||||
|
sfControl.verify();
|
||||||
|
sessionControl.verify();
|
||||||
|
sf2Control.verify();
|
||||||
|
session2Control.verify();
|
||||||
|
|
||||||
|
wac.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testOpenSessionInViewFilterWithSingleSessionAndPreBoundSession() throws Exception {
|
||||||
|
MockControl sfControl = MockControl.createControl(SessionFactory.class);
|
||||||
|
final SessionFactory sf = (SessionFactory) sfControl.getMock();
|
||||||
|
MockControl sessionControl = MockControl.createControl(Session.class);
|
||||||
|
Session session = (Session) sessionControl.getMock();
|
||||||
|
|
||||||
|
sf.openSession();
|
||||||
|
sfControl.setReturnValue(session, 1);
|
||||||
|
session.getSessionFactory();
|
||||||
|
sessionControl.setReturnValue(sf);
|
||||||
|
session.setFlushMode(FlushMode.MANUAL);
|
||||||
|
sessionControl.setVoidCallable(1);
|
||||||
|
session.close();
|
||||||
|
sessionControl.setReturnValue(null, 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");
|
||||||
|
filterConfig2.addInitParameter("sessionFactoryBeanName", "mySessionFactory");
|
||||||
|
|
||||||
|
OpenSessionInViewInterceptor rawInterceptor = new OpenSessionInViewInterceptor();
|
||||||
|
rawInterceptor.setSessionFactory(sf);
|
||||||
|
HandlerInterceptor interceptor = new WebRequestHandlerInterceptorAdapter(rawInterceptor);
|
||||||
|
|
||||||
|
interceptor.preHandle(request, response, "handler");
|
||||||
|
|
||||||
|
final OpenSessionInViewFilter filter = new OpenSessionInViewFilter();
|
||||||
|
filter.init(filterConfig);
|
||||||
|
|
||||||
|
final FilterChain filterChain = new FilterChain() {
|
||||||
|
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse) {
|
||||||
|
assertTrue(TransactionSynchronizationManager.hasResource(sf));
|
||||||
|
servletRequest.setAttribute("invoked", Boolean.TRUE);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
assertTrue(TransactionSynchronizationManager.hasResource(sf));
|
||||||
|
filter.doFilter(request, response, filterChain);
|
||||||
|
assertTrue(TransactionSynchronizationManager.hasResource(sf));
|
||||||
|
assertNotNull(request.getAttribute("invoked"));
|
||||||
|
|
||||||
|
interceptor.postHandle(request, response, "handler", null);
|
||||||
|
interceptor.afterCompletion(request, response, "handler", null);
|
||||||
|
|
||||||
|
sfControl.verify();
|
||||||
|
sessionControl.verify();
|
||||||
|
|
||||||
|
wac.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testOpenSessionInViewFilterWithDeferredClose() throws Exception {
|
||||||
|
MockControl sfControl = MockControl.createControl(SessionFactory.class);
|
||||||
|
final SessionFactory sf = (SessionFactory) sfControl.getMock();
|
||||||
|
final MockControl sessionControl = MockControl.createControl(Session.class);
|
||||||
|
final Session session = (Session) sessionControl.getMock();
|
||||||
|
|
||||||
|
sf.openSession();
|
||||||
|
sfControl.setReturnValue(session, 1);
|
||||||
|
session.getSessionFactory();
|
||||||
|
sessionControl.setReturnValue(sf);
|
||||||
|
session.getFlushMode();
|
||||||
|
sessionControl.setReturnValue(FlushMode.MANUAL, 1);
|
||||||
|
session.setFlushMode(FlushMode.MANUAL);
|
||||||
|
sessionControl.setVoidCallable(1);
|
||||||
|
sfControl.replay();
|
||||||
|
sessionControl.replay();
|
||||||
|
|
||||||
|
MockControl sf2Control = MockControl.createControl(SessionFactory.class);
|
||||||
|
final SessionFactory sf2 = (SessionFactory) sf2Control.getMock();
|
||||||
|
final MockControl session2Control = MockControl.createControl(Session.class);
|
||||||
|
final Session session2 = (Session) session2Control.getMock();
|
||||||
|
MockControl txControl = MockControl.createControl(Transaction.class);
|
||||||
|
Transaction tx = (Transaction) txControl.getMock();
|
||||||
|
MockControl conControl = MockControl.createControl(Connection.class);
|
||||||
|
Connection con = (Connection) conControl.getMock();
|
||||||
|
|
||||||
|
sf2.openSession();
|
||||||
|
sf2Control.setReturnValue(session2, 1);
|
||||||
|
session2.beginTransaction();
|
||||||
|
session2Control.setReturnValue(tx, 1);
|
||||||
|
session2.connection();
|
||||||
|
session2Control.setReturnValue(con, 2);
|
||||||
|
tx.commit();
|
||||||
|
txControl.setVoidCallable(1);
|
||||||
|
session2.isConnected();
|
||||||
|
session2Control.setReturnValue(true, 1);
|
||||||
|
con.isReadOnly();
|
||||||
|
conControl.setReturnValue(false, 1);
|
||||||
|
session2.setFlushMode(FlushMode.MANUAL);
|
||||||
|
session2Control.setVoidCallable(1);
|
||||||
|
|
||||||
|
sf2Control.replay();
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testOpenSessionInViewFilterWithDeferredCloseAndAlreadyActiveDeferredClose() throws Exception {
|
||||||
|
MockControl sfControl = MockControl.createControl(SessionFactory.class);
|
||||||
|
final SessionFactory sf = (SessionFactory) sfControl.getMock();
|
||||||
|
final MockControl sessionControl = MockControl.createControl(Session.class);
|
||||||
|
final Session session = (Session) sessionControl.getMock();
|
||||||
|
|
||||||
|
sf.openSession();
|
||||||
|
sfControl.setReturnValue(session, 1);
|
||||||
|
session.getSessionFactory();
|
||||||
|
sessionControl.setReturnValue(sf);
|
||||||
|
session.getFlushMode();
|
||||||
|
sessionControl.setReturnValue(FlushMode.MANUAL, 1);
|
||||||
|
session.setFlushMode(FlushMode.MANUAL);
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue