You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by mg...@apache.org on 2012/01/30 13:21:24 UTC

git commit: WICKET-4370 HttpSession getSession() in MockHttpServletRequest is not compliant with the j2ee servlet spec

Updated Branches:
  refs/heads/master e64e617bd -> 7ca927c17


WICKET-4370
HttpSession getSession() in MockHttpServletRequest is not compliant with the j2ee servlet spec


Project: http://git-wip-us.apache.org/repos/asf/wicket/repo
Commit: http://git-wip-us.apache.org/repos/asf/wicket/commit/7ca927c1
Tree: http://git-wip-us.apache.org/repos/asf/wicket/tree/7ca927c1
Diff: http://git-wip-us.apache.org/repos/asf/wicket/diff/7ca927c1

Branch: refs/heads/master
Commit: 7ca927c1704592d2e05928ccde7541fa78ee9ecc
Parents: e64e617
Author: Martin Tzvetanov Grigorov <mg...@apache.org>
Authored: Mon Jan 30 14:21:15 2012 +0200
Committer: Martin Tzvetanov Grigorov <mg...@apache.org>
Committed: Mon Jan 30 14:21:15 2012 +0200

----------------------------------------------------------------------
 .../protocol/http/mock/MockHttpServletRequest.java |   22 ++++++---
 .../http/mock/MockHttpServletRequestTest.java      |   36 +++++++++++++++
 2 files changed, 50 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/wicket/blob/7ca927c1/wicket-core/src/main/java/org/apache/wicket/protocol/http/mock/MockHttpServletRequest.java
----------------------------------------------------------------------
diff --git a/wicket-core/src/main/java/org/apache/wicket/protocol/http/mock/MockHttpServletRequest.java b/wicket-core/src/main/java/org/apache/wicket/protocol/http/mock/MockHttpServletRequest.java
index a93eb7f..73dc26f 100755
--- a/wicket-core/src/main/java/org/apache/wicket/protocol/http/mock/MockHttpServletRequest.java
+++ b/wicket-core/src/main/java/org/apache/wicket/protocol/http/mock/MockHttpServletRequest.java
@@ -1068,11 +1068,7 @@ public class MockHttpServletRequest implements HttpServletRequest
 	@Override
 	public HttpSession getSession()
 	{
-		if (session instanceof MockHttpSession && ((MockHttpSession)session).isTemporary())
-		{
-			return null;
-		}
-		return session;
+		return getSession(true);
 	}
 
 	/**
@@ -1085,11 +1081,21 @@ public class MockHttpServletRequest implements HttpServletRequest
 	@Override
 	public HttpSession getSession(boolean b)
 	{
-		if (b && session instanceof MockHttpSession)
+		HttpSession sess = null;
+		if (session instanceof MockHttpSession)
 		{
-			((MockHttpSession)session).setTemporary(false);
+			MockHttpSession mockHttpSession = (MockHttpSession) session;
+			if (b)
+			{
+				mockHttpSession.setTemporary(false);
+			}
+
+			if (mockHttpSession.isTemporary() == false)
+			{
+				sess = session;
+			}
 		}
-		return getSession();
+		return sess;
 	}
 
 	/**

http://git-wip-us.apache.org/repos/asf/wicket/blob/7ca927c1/wicket-core/src/test/java/org/apache/wicket/protocol/http/mock/MockHttpServletRequestTest.java
----------------------------------------------------------------------
diff --git a/wicket-core/src/test/java/org/apache/wicket/protocol/http/mock/MockHttpServletRequestTest.java b/wicket-core/src/test/java/org/apache/wicket/protocol/http/mock/MockHttpServletRequestTest.java
index 092410f..807896a 100755
--- a/wicket-core/src/test/java/org/apache/wicket/protocol/http/mock/MockHttpServletRequestTest.java
+++ b/wicket-core/src/test/java/org/apache/wicket/protocol/http/mock/MockHttpServletRequestTest.java
@@ -16,10 +16,13 @@
  */
 package org.apache.wicket.protocol.http.mock;
 
+import javax.servlet.http.HttpSession;
+
 import org.apache.wicket.WicketTestCase;
 import org.apache.wicket.request.Url;
 import org.apache.wicket.util.tester.WicketTester;
 import org.junit.Test;
+import org.mockito.Mockito;
 
 /**
  * test features of {@link MockHttpServletRequest}
@@ -100,4 +103,37 @@ public class MockHttpServletRequestTest extends WicketTestCase
 		String pathInfo = request.getPathInfo();
 		assertEquals("/foo/bar/baz.html", pathInfo);
 	}
+	
+	@Test
+	public void getSessionFromNonMockHttpSession()
+	{
+		HttpSession httpSession = Mockito.mock(HttpSession.class);
+		MockHttpServletRequest request = new MockHttpServletRequest(null, httpSession, null);
+		assertNull("MockHttpServletRequest knows how to work only with MockHttpSession", request.getSession(true));
+		assertNull("MockHttpServletRequest knows how to work only with MockHttpSession", request.getSession(false));
+	}
+
+	@Test
+	public void getSessionFalseFromMockHttpSession()
+	{
+		HttpSession httpSession = new MockHttpSession(null);
+		MockHttpServletRequest request = new MockHttpServletRequest(null, httpSession, null);
+		assertNull("HttpSession should not be created!", request.getSession(false));
+	}
+
+	@Test
+	public void getSessionDefaultFromMockHttpSession()
+	{
+		HttpSession httpSession = new MockHttpSession(null);
+		MockHttpServletRequest request = new MockHttpServletRequest(null, httpSession, null);
+		assertSame("HttpSession should be created!", httpSession, request.getSession());
+	}
+
+	@Test
+	public void getSessionTrueFromMockHttpSession()
+	{
+		HttpSession httpSession = new MockHttpSession(null);
+		MockHttpServletRequest request = new MockHttpServletRequest(null, httpSession, null);
+		assertSame("HttpSession should be created!", httpSession, request.getSession(true));
+	}
 }