org.springframework.mock.web.test.MockHttpSession Java Examples
The following examples show how to use
org.springframework.mock.web.test.MockHttpSession.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: HttpSessionHandshakeInterceptorTests.java From spring-analysis-note with MIT License | 6 votes |
@Test public void constructorWithAttributeNames() throws Exception { Map<String, Object> attributes = new HashMap<>(); WebSocketHandler wsHandler = Mockito.mock(WebSocketHandler.class); this.servletRequest.setSession(new MockHttpSession(null, "123")); this.servletRequest.getSession().setAttribute("foo", "bar"); this.servletRequest.getSession().setAttribute("bar", "baz"); Set<String> names = Collections.singleton("foo"); HttpSessionHandshakeInterceptor interceptor = new HttpSessionHandshakeInterceptor(names); interceptor.beforeHandshake(this.request, this.response, wsHandler, attributes); assertEquals(2, attributes.size()); assertEquals("bar", attributes.get("foo")); assertEquals("123", attributes.get(HttpSessionHandshakeInterceptor.HTTP_SESSION_ID_ATTR_NAME)); }
Example #2
Source File: SessionScopeTests.java From spring4-understanding with Apache License 2.0 | 6 votes |
@Test public void destructionAtSessionTermination() throws Exception { MockHttpSession session = new MockHttpSession(); MockHttpServletRequest request = new MockHttpServletRequest(); request.setSession(session); ServletRequestAttributes requestAttributes = new ServletRequestAttributes(request); RequestContextHolder.setRequestAttributes(requestAttributes); String name = "sessionScopedDisposableObject"; assertNull(session.getAttribute(name)); DerivedTestBean bean = (DerivedTestBean) this.beanFactory.getBean(name); assertEquals(session.getAttribute(name), bean); assertSame(bean, this.beanFactory.getBean(name)); requestAttributes.requestCompleted(); session.invalidate(); assertTrue(bean.wasDestroyed()); }
Example #3
Source File: HttpSessionHandshakeInterceptorTests.java From spring4-understanding with Apache License 2.0 | 6 votes |
@Test public void constructorWithAttributeNames() throws Exception { Map<String, Object> attributes = new HashMap<String, Object>(); WebSocketHandler wsHandler = Mockito.mock(WebSocketHandler.class); this.servletRequest.setSession(new MockHttpSession(null, "123")); this.servletRequest.getSession().setAttribute("foo", "bar"); this.servletRequest.getSession().setAttribute("bar", "baz"); Set<String> names = Collections.singleton("foo"); HttpSessionHandshakeInterceptor interceptor = new HttpSessionHandshakeInterceptor(names); interceptor.beforeHandshake(this.request, this.response, wsHandler, attributes); assertEquals(2, attributes.size()); assertEquals("bar", attributes.get("foo")); assertEquals("123", attributes.get(HttpSessionHandshakeInterceptor.HTTP_SESSION_ID_ATTR_NAME)); }
Example #4
Source File: HttpSessionHandshakeInterceptorTests.java From spring4-understanding with Apache License 2.0 | 6 votes |
@Test public void defaultConstructor() throws Exception { Map<String, Object> attributes = new HashMap<String, Object>(); WebSocketHandler wsHandler = Mockito.mock(WebSocketHandler.class); this.servletRequest.setSession(new MockHttpSession(null, "123")); this.servletRequest.getSession().setAttribute("foo", "bar"); this.servletRequest.getSession().setAttribute("bar", "baz"); HttpSessionHandshakeInterceptor interceptor = new HttpSessionHandshakeInterceptor(); interceptor.beforeHandshake(this.request, this.response, wsHandler, attributes); assertEquals(3, attributes.size()); assertEquals("bar", attributes.get("foo")); assertEquals("baz", attributes.get("bar")); assertEquals("123", attributes.get(HttpSessionHandshakeInterceptor.HTTP_SESSION_ID_ATTR_NAME)); }
Example #5
Source File: SessionScopeTests.java From java-technology-stack with MIT License | 6 votes |
@Test public void destructionAtSessionTermination() throws Exception { MockHttpSession session = new MockHttpSession(); MockHttpServletRequest request = new MockHttpServletRequest(); request.setSession(session); ServletRequestAttributes requestAttributes = new ServletRequestAttributes(request); RequestContextHolder.setRequestAttributes(requestAttributes); String name = "sessionScopedDisposableObject"; assertNull(session.getAttribute(name)); DerivedTestBean bean = (DerivedTestBean) this.beanFactory.getBean(name); assertEquals(session.getAttribute(name), bean); assertSame(bean, this.beanFactory.getBean(name)); requestAttributes.requestCompleted(); session.invalidate(); assertTrue(bean.wasDestroyed()); }
Example #6
Source File: HttpSessionHandshakeInterceptorTests.java From java-technology-stack with MIT License | 6 votes |
@Test public void constructorWithAttributeNames() throws Exception { Map<String, Object> attributes = new HashMap<>(); WebSocketHandler wsHandler = Mockito.mock(WebSocketHandler.class); this.servletRequest.setSession(new MockHttpSession(null, "123")); this.servletRequest.getSession().setAttribute("foo", "bar"); this.servletRequest.getSession().setAttribute("bar", "baz"); Set<String> names = Collections.singleton("foo"); HttpSessionHandshakeInterceptor interceptor = new HttpSessionHandshakeInterceptor(names); interceptor.beforeHandshake(this.request, this.response, wsHandler, attributes); assertEquals(2, attributes.size()); assertEquals("bar", attributes.get("foo")); assertEquals("123", attributes.get(HttpSessionHandshakeInterceptor.HTTP_SESSION_ID_ATTR_NAME)); }
Example #7
Source File: HttpSessionHandshakeInterceptorTests.java From java-technology-stack with MIT License | 6 votes |
@Test public void defaultConstructor() throws Exception { Map<String, Object> attributes = new HashMap<>(); WebSocketHandler wsHandler = Mockito.mock(WebSocketHandler.class); this.servletRequest.setSession(new MockHttpSession(null, "123")); this.servletRequest.getSession().setAttribute("foo", "bar"); this.servletRequest.getSession().setAttribute("bar", "baz"); HttpSessionHandshakeInterceptor interceptor = new HttpSessionHandshakeInterceptor(); interceptor.beforeHandshake(this.request, this.response, wsHandler, attributes); assertEquals(3, attributes.size()); assertEquals("bar", attributes.get("foo")); assertEquals("baz", attributes.get("bar")); assertEquals("123", attributes.get(HttpSessionHandshakeInterceptor.HTTP_SESSION_ID_ATTR_NAME)); }
Example #8
Source File: HttpSessionHandshakeInterceptorTests.java From spring-analysis-note with MIT License | 6 votes |
@Test public void defaultConstructor() throws Exception { Map<String, Object> attributes = new HashMap<>(); WebSocketHandler wsHandler = Mockito.mock(WebSocketHandler.class); this.servletRequest.setSession(new MockHttpSession(null, "123")); this.servletRequest.getSession().setAttribute("foo", "bar"); this.servletRequest.getSession().setAttribute("bar", "baz"); HttpSessionHandshakeInterceptor interceptor = new HttpSessionHandshakeInterceptor(); interceptor.beforeHandshake(this.request, this.response, wsHandler, attributes); assertEquals(3, attributes.size()); assertEquals("bar", attributes.get("foo")); assertEquals("baz", attributes.get("bar")); assertEquals("123", attributes.get(HttpSessionHandshakeInterceptor.HTTP_SESSION_ID_ATTR_NAME)); }
Example #9
Source File: SessionScopeTests.java From spring-analysis-note with MIT License | 6 votes |
@Test public void destructionAtSessionTermination() throws Exception { MockHttpSession session = new MockHttpSession(); MockHttpServletRequest request = new MockHttpServletRequest(); request.setSession(session); ServletRequestAttributes requestAttributes = new ServletRequestAttributes(request); RequestContextHolder.setRequestAttributes(requestAttributes); String name = "sessionScopedDisposableObject"; assertNull(session.getAttribute(name)); DerivedTestBean bean = (DerivedTestBean) this.beanFactory.getBean(name); assertEquals(session.getAttribute(name), bean); assertSame(bean, this.beanFactory.getBean(name)); requestAttributes.requestCompleted(); session.invalidate(); assertTrue(bean.wasDestroyed()); }
Example #10
Source File: HttpSessionHandshakeInterceptorTests.java From spring-analysis-note with MIT License | 5 votes |
@Test public void doNotCopyAttributes() throws Exception { Map<String, Object> attributes = new HashMap<>(); WebSocketHandler wsHandler = Mockito.mock(WebSocketHandler.class); this.servletRequest.setSession(new MockHttpSession(null, "123")); this.servletRequest.getSession().setAttribute("foo", "bar"); HttpSessionHandshakeInterceptor interceptor = new HttpSessionHandshakeInterceptor(); interceptor.setCopyAllAttributes(false); interceptor.beforeHandshake(this.request, this.response, wsHandler, attributes); assertEquals(1, attributes.size()); assertEquals("123", attributes.get(HttpSessionHandshakeInterceptor.HTTP_SESSION_ID_ATTR_NAME)); }
Example #11
Source File: SessionScopeTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Test public void getFromScope() throws Exception { MockHttpSession session = new MockHttpSession(); MockHttpServletRequest request = new MockHttpServletRequest(); request.setSession(session); ServletRequestAttributes requestAttributes = new ServletRequestAttributes(request); RequestContextHolder.setRequestAttributes(requestAttributes); String name = "sessionScopedObject"; assertNull(session.getAttribute(name)); TestBean bean = (TestBean) this.beanFactory.getBean(name); assertEquals(session.getAttribute(name), bean); assertSame(bean, this.beanFactory.getBean(name)); }
Example #12
Source File: ServletRequestAttributesTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Test public void removeSessionScopedAttribute() throws Exception { MockHttpSession session = new MockHttpSession(); session.setAttribute(KEY, VALUE); MockHttpServletRequest request = new MockHttpServletRequest(); request.setSession(session); ServletRequestAttributes attrs = new ServletRequestAttributes(request); attrs.removeAttribute(KEY, RequestAttributes.SCOPE_SESSION); Object value = session.getAttribute(KEY); assertNull(value); }
Example #13
Source File: ServletRequestAttributesTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Test public void setGlobalSessionScopedAttributeAfterCompletion() throws Exception { MockHttpSession session = new MockHttpSession(); session.setAttribute(KEY, VALUE); MockHttpServletRequest request = new MockHttpServletRequest(); request.setSession(session); ServletRequestAttributes attrs = new ServletRequestAttributes(request); attrs.requestCompleted(); request.close(); attrs.setAttribute(KEY, VALUE, RequestAttributes.SCOPE_GLOBAL_SESSION); Object value = session.getAttribute(KEY); assertSame(VALUE, value); }
Example #14
Source File: ServletRequestAttributesTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Test public void setGlobalSessionScopedAttribute() throws Exception { MockHttpSession session = new MockHttpSession(); session.setAttribute(KEY, VALUE); MockHttpServletRequest request = new MockHttpServletRequest(); request.setSession(session); ServletRequestAttributes attrs = new ServletRequestAttributes(request); attrs.setAttribute(KEY, VALUE, RequestAttributes.SCOPE_GLOBAL_SESSION); Object value = session.getAttribute(KEY); assertSame(VALUE, value); }
Example #15
Source File: ServletRequestAttributesTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Test public void setSessionScopedAttributeAfterCompletion() throws Exception { MockHttpSession session = new MockHttpSession(); session.setAttribute(KEY, VALUE); MockHttpServletRequest request = new MockHttpServletRequest(); request.setSession(session); ServletRequestAttributes attrs = new ServletRequestAttributes(request); attrs.requestCompleted(); request.close(); attrs.setAttribute(KEY, VALUE, RequestAttributes.SCOPE_SESSION); Object value = session.getAttribute(KEY); assertSame(VALUE, value); }
Example #16
Source File: ServletRequestAttributesTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Test public void setSessionScopedAttribute() throws Exception { MockHttpSession session = new MockHttpSession(); session.setAttribute(KEY, VALUE); MockHttpServletRequest request = new MockHttpServletRequest(); request.setSession(session); ServletRequestAttributes attrs = new ServletRequestAttributes(request); attrs.setAttribute(KEY, VALUE, RequestAttributes.SCOPE_SESSION); Object value = session.getAttribute(KEY); assertSame(VALUE, value); }
Example #17
Source File: HttpSessionHandshakeInterceptorTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Test public void doNotCopyAttributes() throws Exception { Map<String, Object> attributes = new HashMap<String, Object>(); WebSocketHandler wsHandler = Mockito.mock(WebSocketHandler.class); this.servletRequest.setSession(new MockHttpSession(null, "123")); this.servletRequest.getSession().setAttribute("foo", "bar"); HttpSessionHandshakeInterceptor interceptor = new HttpSessionHandshakeInterceptor(); interceptor.setCopyAllAttributes(false); interceptor.beforeHandshake(this.request, this.response, wsHandler, attributes); assertEquals(1, attributes.size()); assertEquals("123", attributes.get(HttpSessionHandshakeInterceptor.HTTP_SESSION_ID_ATTR_NAME)); }
Example #18
Source File: HttpSessionHandshakeInterceptorTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Test public void doNotCopyHttpSessionId() throws Exception { Map<String, Object> attributes = new HashMap<String, Object>(); WebSocketHandler wsHandler = Mockito.mock(WebSocketHandler.class); this.servletRequest.setSession(new MockHttpSession(null, "123")); this.servletRequest.getSession().setAttribute("foo", "bar"); HttpSessionHandshakeInterceptor interceptor = new HttpSessionHandshakeInterceptor(); interceptor.setCopyHttpSessionId(false); interceptor.beforeHandshake(this.request, this.response, wsHandler, attributes); assertEquals(1, attributes.size()); assertEquals("bar", attributes.get("foo")); }
Example #19
Source File: HttpSessionHandshakeInterceptorTests.java From spring-analysis-note with MIT License | 5 votes |
@Test public void doNotCopyHttpSessionId() throws Exception { Map<String, Object> attributes = new HashMap<>(); WebSocketHandler wsHandler = Mockito.mock(WebSocketHandler.class); this.servletRequest.setSession(new MockHttpSession(null, "123")); this.servletRequest.getSession().setAttribute("foo", "bar"); HttpSessionHandshakeInterceptor interceptor = new HttpSessionHandshakeInterceptor(); interceptor.setCopyHttpSessionId(false); interceptor.beforeHandshake(this.request, this.response, wsHandler, attributes); assertEquals(1, attributes.size()); assertEquals("bar", attributes.get("foo")); }
Example #20
Source File: MockPortletSession.java From spring4-understanding with Apache License 2.0 | 5 votes |
protected void doClearAttributes(Map<String, Object> attributes) { for (Iterator<Map.Entry<String, Object>> it = attributes.entrySet().iterator(); it.hasNext();) { Map.Entry<String, Object> entry = it.next(); String name = entry.getKey(); Object value = entry.getValue(); it.remove(); if (value instanceof HttpSessionBindingListener) { ((HttpSessionBindingListener) value).valueUnbound( new HttpSessionBindingEvent(new MockHttpSession(), name, value)); } } }
Example #21
Source File: ServletRequestAttributesTests.java From spring-analysis-note with MIT License | 5 votes |
@Test public void setSessionScopedAttribute() throws Exception { MockHttpSession session = new MockHttpSession(); session.setAttribute(KEY, VALUE); MockHttpServletRequest request = new MockHttpServletRequest(); request.setSession(session); ServletRequestAttributes attrs = new ServletRequestAttributes(request); attrs.setAttribute(KEY, VALUE, RequestAttributes.SCOPE_SESSION); assertSame(VALUE, session.getAttribute(KEY)); }
Example #22
Source File: ServletRequestAttributesTests.java From java-technology-stack with MIT License | 5 votes |
@Test public void removeSessionScopedAttribute() throws Exception { MockHttpSession session = new MockHttpSession(); session.setAttribute(KEY, VALUE); MockHttpServletRequest request = new MockHttpServletRequest(); request.setSession(session); ServletRequestAttributes attrs = new ServletRequestAttributes(request); attrs.removeAttribute(KEY, RequestAttributes.SCOPE_SESSION); Object value = session.getAttribute(KEY); assertNull(value); }
Example #23
Source File: ServletRequestAttributesTests.java From java-technology-stack with MIT License | 5 votes |
@Test public void setSessionScopedAttributeAfterCompletion() throws Exception { MockHttpSession session = new MockHttpSession(); session.setAttribute(KEY, VALUE); MockHttpServletRequest request = new MockHttpServletRequest(); request.setSession(session); ServletRequestAttributes attrs = new ServletRequestAttributes(request); assertSame(VALUE, attrs.getAttribute(KEY, RequestAttributes.SCOPE_SESSION)); attrs.requestCompleted(); request.close(); attrs.setAttribute(KEY, VALUE, RequestAttributes.SCOPE_SESSION); assertSame(VALUE, session.getAttribute(KEY)); }
Example #24
Source File: ServletRequestAttributesTests.java From java-technology-stack with MIT License | 5 votes |
@Test public void setSessionScopedAttribute() throws Exception { MockHttpSession session = new MockHttpSession(); session.setAttribute(KEY, VALUE); MockHttpServletRequest request = new MockHttpServletRequest(); request.setSession(session); ServletRequestAttributes attrs = new ServletRequestAttributes(request); attrs.setAttribute(KEY, VALUE, RequestAttributes.SCOPE_SESSION); assertSame(VALUE, session.getAttribute(KEY)); }
Example #25
Source File: HttpSessionHandshakeInterceptorTests.java From java-technology-stack with MIT License | 5 votes |
@Test public void doNotCopyAttributes() throws Exception { Map<String, Object> attributes = new HashMap<>(); WebSocketHandler wsHandler = Mockito.mock(WebSocketHandler.class); this.servletRequest.setSession(new MockHttpSession(null, "123")); this.servletRequest.getSession().setAttribute("foo", "bar"); HttpSessionHandshakeInterceptor interceptor = new HttpSessionHandshakeInterceptor(); interceptor.setCopyAllAttributes(false); interceptor.beforeHandshake(this.request, this.response, wsHandler, attributes); assertEquals(1, attributes.size()); assertEquals("123", attributes.get(HttpSessionHandshakeInterceptor.HTTP_SESSION_ID_ATTR_NAME)); }
Example #26
Source File: HttpSessionHandshakeInterceptorTests.java From java-technology-stack with MIT License | 5 votes |
@Test public void doNotCopyHttpSessionId() throws Exception { Map<String, Object> attributes = new HashMap<>(); WebSocketHandler wsHandler = Mockito.mock(WebSocketHandler.class); this.servletRequest.setSession(new MockHttpSession(null, "123")); this.servletRequest.getSession().setAttribute("foo", "bar"); HttpSessionHandshakeInterceptor interceptor = new HttpSessionHandshakeInterceptor(); interceptor.setCopyHttpSessionId(false); interceptor.beforeHandshake(this.request, this.response, wsHandler, attributes); assertEquals(1, attributes.size()); assertEquals("bar", attributes.get("foo")); }
Example #27
Source File: ServletRequestAttributesTests.java From spring-analysis-note with MIT License | 5 votes |
@Test public void setSessionScopedAttributeAfterCompletion() throws Exception { MockHttpSession session = new MockHttpSession(); session.setAttribute(KEY, VALUE); MockHttpServletRequest request = new MockHttpServletRequest(); request.setSession(session); ServletRequestAttributes attrs = new ServletRequestAttributes(request); assertSame(VALUE, attrs.getAttribute(KEY, RequestAttributes.SCOPE_SESSION)); attrs.requestCompleted(); request.close(); attrs.setAttribute(KEY, VALUE, RequestAttributes.SCOPE_SESSION); assertSame(VALUE, session.getAttribute(KEY)); }
Example #28
Source File: ServletRequestAttributesTests.java From spring-analysis-note with MIT License | 5 votes |
@Test public void removeSessionScopedAttribute() throws Exception { MockHttpSession session = new MockHttpSession(); session.setAttribute(KEY, VALUE); MockHttpServletRequest request = new MockHttpServletRequest(); request.setSession(session); ServletRequestAttributes attrs = new ServletRequestAttributes(request); attrs.removeAttribute(KEY, RequestAttributes.SCOPE_SESSION); Object value = session.getAttribute(KEY); assertNull(value); }