Skip to content

Commit a4f62bb

Browse files
committed
moved OpenSessionInViewTests back to orm module
1 parent 80def4b commit a4f62bb

File tree

5 files changed

+66
-100
lines changed

5 files changed

+66
-100
lines changed
Lines changed: 66 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2007 the original author or authors.
2+
* Copyright 2002-2011 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -16,25 +16,21 @@
1616

1717
package org.springframework.orm.hibernate3.support;
1818

19-
import junit.framework.TestCase;
20-
21-
import org.easymock.MockControl;
22-
import org.hibernate.classic.Session;
23-
import org.hibernate.SessionFactory;
24-
2519
import java.io.IOException;
2620
import java.sql.Connection;
27-
2821
import javax.servlet.FilterChain;
2922
import javax.servlet.ServletException;
3023
import javax.servlet.ServletRequest;
3124
import javax.servlet.ServletResponse;
3225
import javax.transaction.TransactionManager;
3326

34-
27+
import junit.framework.TestCase;
28+
import org.easymock.MockControl;
3529
import org.hibernate.FlushMode;
3630
import org.hibernate.HibernateException;
31+
import org.hibernate.SessionFactory;
3732
import org.hibernate.Transaction;
33+
import org.hibernate.classic.Session;
3834
import org.hibernate.engine.SessionFactoryImplementor;
3935

4036
import org.springframework.mock.web.MockFilterConfig;
@@ -50,9 +46,8 @@
5046
import org.springframework.transaction.support.DefaultTransactionDefinition;
5147
import org.springframework.transaction.support.TransactionSynchronizationManager;
5248
import org.springframework.web.context.WebApplicationContext;
49+
import org.springframework.web.context.request.ServletWebRequest;
5350
import org.springframework.web.context.support.StaticWebApplicationContext;
54-
import org.springframework.web.servlet.HandlerInterceptor;
55-
import org.springframework.web.servlet.handler.WebRequestHandlerInterceptorAdapter;
5651

5752
/**
5853
* @author Juergen Hoeller
@@ -70,16 +65,12 @@ public void testOpenSessionInViewInterceptorWithSingleSession() throws Exception
7065
MockControl sessionControl = MockControl.createControl(Session.class);
7166
Session session = (Session) sessionControl.getMock();
7267

73-
74-
OpenSessionInViewInterceptor rawInterceptor = new OpenSessionInViewInterceptor();
75-
rawInterceptor.setSessionFactory(sf);
76-
HandlerInterceptor interceptor = new WebRequestHandlerInterceptorAdapter(rawInterceptor);
68+
OpenSessionInViewInterceptor interceptor = new OpenSessionInViewInterceptor();
69+
interceptor.setSessionFactory(sf);
7770

7871
MockServletContext sc = new MockServletContext();
7972
MockHttpServletRequest request = new MockHttpServletRequest(sc);
80-
MockHttpServletResponse response = new MockHttpServletResponse();
8173

82-
8374
//expect(mockStorage.size()).andReturn(expectedValue);
8475

8576
//expect(sf.openSession()).andReturn(session);
@@ -93,24 +84,24 @@ public void testOpenSessionInViewInterceptorWithSingleSession() throws Exception
9384
sessionControl.setVoidCallable(1);
9485
sfControl.replay();
9586
sessionControl.replay();
96-
interceptor.preHandle(request, response, "handler");
87+
interceptor.preHandle(new ServletWebRequest(request));
9788
assertTrue(TransactionSynchronizationManager.hasResource(sf));
9889

9990
// check that further invocations simply participate
100-
interceptor.preHandle(request, response, "handler");
91+
interceptor.preHandle(new ServletWebRequest(request));
10192

10293
assertEquals(session, SessionFactoryUtils.getSession(sf, false));
10394

104-
interceptor.preHandle(request, response, "handler");
105-
interceptor.postHandle(request, response, "handler", null);
106-
interceptor.afterCompletion(request, response, "handler", null);
95+
interceptor.preHandle(new ServletWebRequest(request));
96+
interceptor.postHandle(new ServletWebRequest(request), null);
97+
interceptor.afterCompletion(new ServletWebRequest(request), null);
10798

108-
interceptor.postHandle(request, response, "handler", null);
109-
interceptor.afterCompletion(request, response, "handler", null);
99+
interceptor.postHandle(new ServletWebRequest(request), null);
100+
interceptor.afterCompletion(new ServletWebRequest(request), null);
110101

111-
interceptor.preHandle(request, response, "handler");
112-
interceptor.postHandle(request, response, "handler", null);
113-
interceptor.afterCompletion(request, response, "handler", null);
102+
interceptor.preHandle(new ServletWebRequest(request));
103+
interceptor.postHandle(new ServletWebRequest(request), null);
104+
interceptor.afterCompletion(new ServletWebRequest(request), null);
114105

115106
sfControl.verify();
116107
sessionControl.verify();
@@ -119,7 +110,7 @@ public void testOpenSessionInViewInterceptorWithSingleSession() throws Exception
119110
sessionControl.reset();
120111
sfControl.replay();
121112
sessionControl.replay();
122-
interceptor.postHandle(request, response, "handler", null);
113+
interceptor.postHandle(new ServletWebRequest(request), null);
123114
assertTrue(TransactionSynchronizationManager.hasResource(sf));
124115
sfControl.verify();
125116
sessionControl.verify();
@@ -130,7 +121,7 @@ public void testOpenSessionInViewInterceptorWithSingleSession() throws Exception
130121
sessionControl.setReturnValue(null, 1);
131122
sfControl.replay();
132123
sessionControl.replay();
133-
interceptor.afterCompletion(request, response, "handler", null);
124+
interceptor.afterCompletion(new ServletWebRequest(request), null);
134125
assertFalse(TransactionSynchronizationManager.hasResource(sf));
135126
sfControl.verify();
136127
sessionControl.verify();
@@ -147,9 +138,8 @@ public void testOpenSessionInViewInterceptorWithSingleSessionAndJtaTm() throws E
147138
tm.getTransaction();
148139
tmControl.setReturnValue(null, 2);
149140

150-
OpenSessionInViewInterceptor rawInterceptor = new OpenSessionInViewInterceptor();
151-
rawInterceptor.setSessionFactory(sf);
152-
HandlerInterceptor interceptor = new WebRequestHandlerInterceptorAdapter(rawInterceptor);
141+
OpenSessionInViewInterceptor interceptor = new OpenSessionInViewInterceptor();
142+
interceptor.setSessionFactory(sf);
153143

154144
MockServletContext sc = new MockServletContext();
155145
MockHttpServletRequest request = new MockHttpServletRequest(sc);
@@ -168,24 +158,24 @@ public void testOpenSessionInViewInterceptorWithSingleSessionAndJtaTm() throws E
168158
sfControl.replay();
169159
sessionControl.replay();
170160

171-
interceptor.preHandle(request, response, "handler");
161+
interceptor.preHandle(new ServletWebRequest(request));
172162
assertTrue(TransactionSynchronizationManager.hasResource(sf));
173163

174164
// check that further invocations simply participate
175-
interceptor.preHandle(request, response, "handler");
165+
interceptor.preHandle(new ServletWebRequest(request));
176166

177167
assertEquals(session, SessionFactoryUtils.getSession(sf, false));
178168

179-
interceptor.preHandle(request, response, "handler");
180-
interceptor.postHandle(request, response, "handler", null);
181-
interceptor.afterCompletion(request, response, "handler", null);
169+
interceptor.preHandle(new ServletWebRequest(request));
170+
interceptor.postHandle(new ServletWebRequest(request), null);
171+
interceptor.afterCompletion(new ServletWebRequest(request), null);
182172

183-
interceptor.postHandle(request, response, "handler", null);
184-
interceptor.afterCompletion(request, response, "handler", null);
173+
interceptor.postHandle(new ServletWebRequest(request), null);
174+
interceptor.afterCompletion(new ServletWebRequest(request), null);
185175

186-
interceptor.preHandle(request, response, "handler");
187-
interceptor.postHandle(request, response, "handler", null);
188-
interceptor.afterCompletion(request, response, "handler", null);
176+
interceptor.preHandle(new ServletWebRequest(request));
177+
interceptor.postHandle(new ServletWebRequest(request), null);
178+
interceptor.afterCompletion(new ServletWebRequest(request), null);
189179

190180
sfControl.verify();
191181
sessionControl.verify();
@@ -194,7 +184,7 @@ public void testOpenSessionInViewInterceptorWithSingleSessionAndJtaTm() throws E
194184
sessionControl.reset();
195185
sfControl.replay();
196186
sessionControl.replay();
197-
interceptor.postHandle(request, response, "handler", null);
187+
interceptor.postHandle(new ServletWebRequest(request), null);
198188
assertTrue(TransactionSynchronizationManager.hasResource(sf));
199189
sfControl.verify();
200190
sessionControl.verify();
@@ -205,7 +195,7 @@ public void testOpenSessionInViewInterceptorWithSingleSessionAndJtaTm() throws E
205195
sessionControl.setReturnValue(null, 1);
206196
sfControl.replay();
207197
sessionControl.replay();
208-
interceptor.afterCompletion(request, response, "handler", null);
198+
interceptor.afterCompletion(new ServletWebRequest(request), null);
209199
assertFalse(TransactionSynchronizationManager.hasResource(sf));
210200
sfControl.verify();
211201
sessionControl.verify();
@@ -217,10 +207,9 @@ public void testOpenSessionInViewInterceptorWithSingleSessionAndFlush() throws E
217207
MockControl sessionControl = MockControl.createControl(Session.class);
218208
Session session = (Session) sessionControl.getMock();
219209

220-
OpenSessionInViewInterceptor rawInterceptor = new OpenSessionInViewInterceptor();
221-
rawInterceptor.setSessionFactory(sf);
222-
rawInterceptor.setFlushMode(HibernateAccessor.FLUSH_AUTO);
223-
HandlerInterceptor interceptor = new WebRequestHandlerInterceptorAdapter(rawInterceptor);
210+
OpenSessionInViewInterceptor interceptor = new OpenSessionInViewInterceptor();
211+
interceptor.setSessionFactory(sf);
212+
interceptor.setFlushMode(HibernateAccessor.FLUSH_AUTO);
224213

225214
MockServletContext sc = new MockServletContext();
226215
MockHttpServletRequest request = new MockHttpServletRequest(sc);
@@ -232,7 +221,7 @@ public void testOpenSessionInViewInterceptorWithSingleSessionAndFlush() throws E
232221
sessionControl.setReturnValue(sf);
233222
sfControl.replay();
234223
sessionControl.replay();
235-
interceptor.preHandle(request, response, "handler");
224+
interceptor.preHandle(new ServletWebRequest(request));
236225
assertTrue(TransactionSynchronizationManager.hasResource(sf));
237226
sfControl.verify();
238227
sessionControl.verify();
@@ -243,7 +232,7 @@ public void testOpenSessionInViewInterceptorWithSingleSessionAndFlush() throws E
243232
sessionControl.setVoidCallable(1);
244233
sfControl.replay();
245234
sessionControl.replay();
246-
interceptor.postHandle(request, response, "handler", null);
235+
interceptor.postHandle(new ServletWebRequest(request), null);
247236
assertTrue(TransactionSynchronizationManager.hasResource(sf));
248237
sfControl.verify();
249238
sessionControl.verify();
@@ -254,7 +243,7 @@ public void testOpenSessionInViewInterceptorWithSingleSessionAndFlush() throws E
254243
sessionControl.setReturnValue(null, 1);
255244
sfControl.replay();
256245
sessionControl.replay();
257-
interceptor.afterCompletion(request, response, "handler", null);
246+
interceptor.afterCompletion(new ServletWebRequest(request), null);
258247
assertFalse(TransactionSynchronizationManager.hasResource(sf));
259248
sfControl.verify();
260249
sessionControl.verify();
@@ -266,10 +255,9 @@ public void testOpenSessionInViewInterceptorAndDeferredClose() throws Exception
266255
MockControl sessionControl = MockControl.createControl(Session.class);
267256
Session session = (Session) sessionControl.getMock();
268257

269-
OpenSessionInViewInterceptor rawInterceptor = new OpenSessionInViewInterceptor();
270-
rawInterceptor.setSessionFactory(sf);
271-
rawInterceptor.setSingleSession(false);
272-
HandlerInterceptor interceptor = new WebRequestHandlerInterceptorAdapter(rawInterceptor);
258+
OpenSessionInViewInterceptor interceptor = new OpenSessionInViewInterceptor();
259+
interceptor.setSessionFactory(sf);
260+
interceptor.setSingleSession(false);
273261

274262
MockServletContext sc = new MockServletContext();
275263
MockHttpServletRequest request = new MockHttpServletRequest(sc);
@@ -284,23 +272,23 @@ public void testOpenSessionInViewInterceptorAndDeferredClose() throws Exception
284272
sfControl.replay();
285273
sessionControl.replay();
286274

287-
interceptor.preHandle(request, response, "handler");
275+
interceptor.preHandle(new ServletWebRequest(request));
288276
org.hibernate.Session sess = SessionFactoryUtils.getSession(sf, true);
289277
SessionFactoryUtils.releaseSession(sess, sf);
290278

291279
// check that further invocations simply participate
292-
interceptor.preHandle(request, response, "handler");
280+
interceptor.preHandle(new ServletWebRequest(request));
293281

294-
interceptor.preHandle(request, response, "handler");
295-
interceptor.postHandle(request, response, "handler", null);
296-
interceptor.afterCompletion(request, response, "handler", null);
282+
interceptor.preHandle(new ServletWebRequest(request));
283+
interceptor.postHandle(new ServletWebRequest(request), null);
284+
interceptor.afterCompletion(new ServletWebRequest(request), null);
297285

298-
interceptor.postHandle(request, response, "handler", null);
299-
interceptor.afterCompletion(request, response, "handler", null);
286+
interceptor.postHandle(new ServletWebRequest(request), null);
287+
interceptor.afterCompletion(new ServletWebRequest(request), null);
300288

301-
interceptor.preHandle(request, response, "handler");
302-
interceptor.postHandle(request, response, "handler", null);
303-
interceptor.afterCompletion(request, response, "handler", null);
289+
interceptor.preHandle(new ServletWebRequest(request));
290+
interceptor.postHandle(new ServletWebRequest(request), null);
291+
interceptor.afterCompletion(new ServletWebRequest(request), null);
304292

305293
sfControl.verify();
306294
sessionControl.verify();
@@ -312,8 +300,8 @@ public void testOpenSessionInViewInterceptorAndDeferredClose() throws Exception
312300
sfControl.replay();
313301
sessionControl.replay();
314302

315-
interceptor.postHandle(request, response, "handler", null);
316-
interceptor.afterCompletion(request, response, "handler", null);
303+
interceptor.postHandle(new ServletWebRequest(request), null);
304+
interceptor.afterCompletion(new ServletWebRequest(request), null);
317305
sfControl.verify();
318306
sessionControl.verify();
319307
}
@@ -433,11 +421,10 @@ public void testOpenSessionInViewFilterWithSingleSessionAndPreBoundSession() thr
433421
MockFilterConfig filterConfig2 = new MockFilterConfig(wac.getServletContext(), "filter2");
434422
filterConfig2.addInitParameter("sessionFactoryBeanName", "mySessionFactory");
435423

436-
OpenSessionInViewInterceptor rawInterceptor = new OpenSessionInViewInterceptor();
437-
rawInterceptor.setSessionFactory(sf);
438-
HandlerInterceptor interceptor = new WebRequestHandlerInterceptorAdapter(rawInterceptor);
424+
OpenSessionInViewInterceptor interceptor = new OpenSessionInViewInterceptor();
425+
interceptor.setSessionFactory(sf);
439426

440-
interceptor.preHandle(request, response, "handler");
427+
interceptor.preHandle(new ServletWebRequest(request));
441428

442429
final OpenSessionInViewFilter filter = new OpenSessionInViewFilter();
443430
filter.init(filterConfig);
@@ -454,8 +441,8 @@ public void doFilter(ServletRequest servletRequest, ServletResponse servletRespo
454441
assertTrue(TransactionSynchronizationManager.hasResource(sf));
455442
assertNotNull(request.getAttribute("invoked"));
456443

457-
interceptor.postHandle(request, response, "handler", null);
458-
interceptor.afterCompletion(request, response, "handler", null);
444+
interceptor.postHandle(new ServletWebRequest(request), null);
445+
interceptor.afterCompletion(new ServletWebRequest(request), null);
459446

460447
sfControl.verify();
461448
sessionControl.verify();
@@ -616,12 +603,11 @@ public void testOpenSessionInViewFilterWithDeferredCloseAndAlreadyActiveDeferred
616603
filterConfig2.addInitParameter("singleSession", "false");
617604
filterConfig2.addInitParameter("sessionFactoryBeanName", "mySessionFactory");
618605

619-
OpenSessionInViewInterceptor rawInterceptor = new OpenSessionInViewInterceptor();
620-
rawInterceptor.setSessionFactory(sf);
621-
rawInterceptor.setSingleSession(false);
622-
HandlerInterceptor interceptor = new WebRequestHandlerInterceptorAdapter(rawInterceptor);
606+
OpenSessionInViewInterceptor interceptor = new OpenSessionInViewInterceptor();
607+
interceptor.setSessionFactory(sf);
608+
interceptor.setSingleSession(false);
623609

624-
interceptor.preHandle(request, response, "handler");
610+
interceptor.preHandle(new ServletWebRequest(request));
625611

626612
final OpenSessionInViewFilter filter = new OpenSessionInViewFilter();
627613
filter.init(filterConfig);
@@ -661,8 +647,8 @@ public void doFilter(ServletRequest servletRequest, ServletResponse servletRespo
661647
filter.doFilter(request, response, filterChain2);
662648
assertNotNull(request.getAttribute("invoked"));
663649

664-
interceptor.postHandle(request, response, "handler", null);
665-
interceptor.afterCompletion(request, response, "handler", null);
650+
interceptor.postHandle(new ServletWebRequest(request), null);
651+
interceptor.afterCompletion(new ServletWebRequest(request), null);
666652

667653
sfControl.verify();
668654
sessionControl.verify();

org.springframework.web.servlet/.classpath

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@
4141
<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"/>
4242
<classpathentry kind="var" path="IVY_CACHE/org.junit/com.springsource.org.junit/4.7.0/com.springsource.org.junit-4.7.0.jar" sourcepath="/IVY_CACHE/org.junit/com.springsource.org.junit/4.7.0/com.springsource.org.junit-sources-4.6.0.jar"/>
4343
<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"/>
44-
<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"/>
4544
<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"/>
4645
<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"/>
4746
<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"/>

org.springframework.web.servlet/ivy.xml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
<conf name="poi" extends="runtime" description="JARs needed to create beans for Poi"/>
2323
<conf name="tiles" extends="runtime" description="JARs neeeded to create beans for Tiles"/>
2424
<conf name="velocity" extends="runtime" description="JARs needed to create beans for Velocity"/>
25-
<conf name="hibernate" extends="runtime" description="JARs needed to use Hibernate"/>
2625
</configurations>
2726

2827
<publications>
@@ -98,8 +97,6 @@
9897
conf="test->compile"/>
9998
<dependency org="org.springframework" name="org.springframework.orm" rev="latest.integration"
10099
conf="test->compile"/>
101-
<dependency org="org.hibernate" name="com.springsource.org.hibernate" rev="3.3.1.GA"
102-
conf="test->compile"/>
103100
<dependency org="javax.transaction" name="com.springsource.javax.transaction" rev="1.1.0" conf="provided->runtime"/>
104101
<dependency org="javax.validation" name="com.springsource.javax.validation" rev="1.0.0.GA" conf="test->compile"/>
105102
<dependency org="org.hibernate" name="com.springsource.org.hibernate.validator" rev="4.1.0.GA" conf="test->runtime"/>

org.springframework.web.servlet/pom.xml

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -279,13 +279,6 @@
279279
<version>1.0.0.GA</version>
280280
<scope>provided</scope>
281281
</dependency>
282-
<dependency>
283-
<groupId>org.hibernate</groupId>
284-
<artifactId>hibernate-core</artifactId>
285-
<version>3.3.1.GA</version>
286-
<scope>test</scope>
287-
<optional>true</optional>
288-
</dependency>
289282
<dependency>
290283
<groupId>org.hibernate</groupId>
291284
<artifactId>hibernate-validator</artifactId>

org.springframework.web.servlet/web-servlet.iml

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -300,15 +300,6 @@
300300
</SOURCES>
301301
</library>
302302
</orderEntry>
303-
<orderEntry type="module-library">
304-
<library>
305-
<CLASSES>
306-
<root url="jar://$IVY_CACHE$/org.hibernate/com.springsource.org.hibernate/3.3.1.GA/com.springsource.org.hibernate-3.3.1.GA.jar!/" />
307-
</CLASSES>
308-
<JAVADOC />
309-
<SOURCES />
310-
</library>
311-
</orderEntry>
312303
<orderEntry type="module-library">
313304
<library>
314305
<CLASSES>

0 commit comments

Comments
 (0)