You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@shiro.apache.org by bd...@apache.org on 2018/05/02 16:45:11 UTC

[2/3] shiro git commit: Added unit test

Added unit test


Project: http://git-wip-us.apache.org/repos/asf/shiro/repo
Commit: http://git-wip-us.apache.org/repos/asf/shiro/commit/154d5e2d
Tree: http://git-wip-us.apache.org/repos/asf/shiro/tree/154d5e2d
Diff: http://git-wip-us.apache.org/repos/asf/shiro/diff/154d5e2d

Branch: refs/heads/master
Commit: 154d5e2d11c786a67b5be63aa58c928d97055cce
Parents: 2105c1b
Author: kp <ph...@sprecher-automation.com>
Authored: Mon Oct 30 14:33:47 2017 +0100
Committer: kp <ph...@sprecher-automation.com>
Committed: Mon Oct 30 14:33:47 2017 +0100

----------------------------------------------------------------------
 .../servlet/ShiroHttpServletRequestTest.java    | 78 ++++++++++++++++++++
 1 file changed, 78 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/shiro/blob/154d5e2d/web/src/test/java/org/apache/shiro/web/servlet/ShiroHttpServletRequestTest.java
----------------------------------------------------------------------
diff --git a/web/src/test/java/org/apache/shiro/web/servlet/ShiroHttpServletRequestTest.java b/web/src/test/java/org/apache/shiro/web/servlet/ShiroHttpServletRequestTest.java
new file mode 100644
index 0000000..85da229
--- /dev/null
+++ b/web/src/test/java/org/apache/shiro/web/servlet/ShiroHttpServletRequestTest.java
@@ -0,0 +1,78 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.apache.shiro.web.servlet;
+
+import static org.easymock.EasyMock.*;
+
+import javax.servlet.ServletContext;
+import javax.servlet.http.HttpServletRequest;
+
+import org.apache.shiro.session.Session;
+import org.apache.shiro.subject.Subject;
+import org.apache.shiro.util.ThreadContext;
+import org.junit.Before;
+import org.junit.Test;
+
+import junit.framework.TestCase;
+
+public class ShiroHttpServletRequestTest extends TestCase {
+
+	private ShiroHttpServletRequest request;
+	
+	private HttpServletRequest mockRequest;
+    private ServletContext mockContext;
+    private Subject mockSubject;
+	
+    @Before
+    public void setUp() throws Exception {
+    	this.mockRequest = createMock(HttpServletRequest.class);
+    	this.mockContext = createMock(ServletContext.class);
+    	this.mockSubject = createMock(Subject.class);
+    	
+    	ThreadContext.bind(this.mockSubject);
+    	this.request = new ShiroHttpServletRequest(mockRequest, mockContext, false);
+    }
+    
+    /**
+     * Test asserting <a href="https://issues.apache.org/jira/browse/SHIRO-637">SHIRO-637<a/>.
+     */
+    @Test
+    public void testRegetSession() throws Exception {
+        Session session1 = createMock(Session.class);
+        Session session2 = createMock(Session.class);
+    	
+        mockSubject.logout();
+        expect(mockSubject.getSession(true))
+           .andReturn(session1).times(1)
+           .andReturn(session2).times(1);
+        expect(mockSubject.getSession(false))
+            .andReturn(session1).times(2)
+            .andReturn(null).times(3);
+        replay(mockSubject);
+        
+        assertNotNull(request.getSession(true));
+        assertNotNull(request.getSession(false));
+        
+        mockSubject.logout();
+        
+        assertNull(request.getSession(false));
+        assertNotNull(request.getSession(true));
+        verify(mockSubject);
+    }
+}