You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by cz...@apache.org on 2018/04/04 09:13:25 UTC
svn commit: r1828312 -
/felix/trunk/osgi-r7/http/base/src/test/java/org/apache/felix/http/base/internal/handler/HttpSessionWrapperTest.java
Author: cziegeler
Date: Wed Apr 4 09:13:24 2018
New Revision: 1828312
URL: http://svn.apache.org/viewvc?rev=1828312&view=rev
Log:
FELIX-5819 : Add test case
Modified:
felix/trunk/osgi-r7/http/base/src/test/java/org/apache/felix/http/base/internal/handler/HttpSessionWrapperTest.java
Modified: felix/trunk/osgi-r7/http/base/src/test/java/org/apache/felix/http/base/internal/handler/HttpSessionWrapperTest.java
URL: http://svn.apache.org/viewvc/felix/trunk/osgi-r7/http/base/src/test/java/org/apache/felix/http/base/internal/handler/HttpSessionWrapperTest.java?rev=1828312&r1=1828311&r2=1828312&view=diff
==============================================================================
--- felix/trunk/osgi-r7/http/base/src/test/java/org/apache/felix/http/base/internal/handler/HttpSessionWrapperTest.java (original)
+++ felix/trunk/osgi-r7/http/base/src/test/java/org/apache/felix/http/base/internal/handler/HttpSessionWrapperTest.java Wed Apr 4 09:13:24 2018
@@ -27,11 +27,18 @@ import static org.mockito.Mockito.when;
import java.util.Arrays;
import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
import java.util.Set;
import javax.servlet.http.HttpSession;
+import javax.servlet.http.HttpSessionListener;
+import org.apache.felix.http.base.internal.context.ExtServletContext;
import org.junit.Test;
+import org.mockito.Mockito;
+import org.mockito.invocation.InvocationOnMock;
+import org.mockito.stubbing.Answer;
/**
* Test cases for {@link HttpSessionWrapper}.
@@ -75,4 +82,56 @@ public class HttpSessionWrapperTest
return session;
}
+
+ /**
+ * FELIX-5819 : Container session should not be invalidated
+ */
+ @Test
+ public void testContainerSessionInvalidation()
+ {
+ // create container session
+ final Map<String, Object> attributes = new HashMap<>();
+ final HttpSession containerSession = mock(HttpSession.class);
+ when(containerSession.getAttributeNames()).thenReturn(Collections.enumeration(attributes.keySet()));
+ when(containerSession.getAttribute(Mockito.anyString())).thenAnswer(new Answer<Object>() {
+ @Override
+ public Object answer(InvocationOnMock invocation) throws Throwable {
+ return attributes.get(invocation.getArgumentAt(0, String.class));
+ }
+ });
+ when(containerSession.getAttribute(Mockito.anyString())).thenAnswer(new Answer<Object>() {
+ @Override
+ public Object answer(InvocationOnMock invocation) throws Throwable {
+ return attributes.get(invocation.getArgumentAt(0, String.class));
+ }
+ });
+ Mockito.doAnswer(new Answer<Object>() {
+ @Override
+ public Object answer(InvocationOnMock invocation) throws Throwable {
+ attributes.put(invocation.getArgumentAt(0, String.class), invocation.getArgumentAt(1, Object.class));
+ return null;
+ }
+ }).when(containerSession).setAttribute(Mockito.anyString(), Mockito.any());
+ Mockito.doAnswer(new Answer<Object>() {
+ @Override
+ public Object answer(InvocationOnMock invocation) throws Throwable {
+ attributes.remove(invocation.getArgumentAt(0, String.class));
+ return null;
+ }
+ }).when(containerSession).removeAttribute(Mockito.anyString());
+
+ final HttpSessionListener listener = mock(HttpSessionListener.class);
+
+ // create context session
+ final ExtServletContext context = mock(ExtServletContext.class);
+ when(context.getServletContextName()).thenReturn("default");
+ when(context.getHttpSessionListener()).thenReturn(listener);
+
+ final HttpSession contextSession = new HttpSessionWrapper(containerSession, context, false);
+ // invalidate context session and verify that invalidate is not called on the container session
+ contextSession.invalidate();
+ assertTrue(attributes.isEmpty());
+ Mockito.verify(containerSession, Mockito.never()).invalidate();
+ }
+
}