@Test public void removeAttributeWithNoScopeSpecifiedRemovesValueFromAllScopes() throws Exception { ctx.setAttribute(key, value, PageContext.APPLICATION_SCOPE); ctx.removeAttribute(key); assertNull(ctx.getAttribute(key, PageContext.PAGE_SCOPE)); assertNull(ctx.getAttribute(key, PageContext.APPLICATION_SCOPE)); assertNull(ctx.getAttribute(key, PageContext.REQUEST_SCOPE)); assertNull(ctx.getAttribute(key, PageContext.SESSION_SCOPE)); }
@Override public Enumeration<String> getAttributeNamesInScope(int scope) { switch (scope) { case PAGE_SCOPE: return getAttributeNames(); case REQUEST_SCOPE: return this.request.getAttributeNames(); case SESSION_SCOPE: HttpSession session = this.request.getSession(false); return (session != null ? session.getAttributeNames() : Collections.emptyEnumeration()); case APPLICATION_SCOPE: return this.servletContext.getAttributeNames(); default: throw new IllegalArgumentException("Invalid scope: " + scope); } }
@Test public void setAttributeWithNoScopeUsesPageScope() throws Exception { ctx.setAttribute(key, value); assertEquals(value, ctx.getAttribute(key, PageContext.PAGE_SCOPE)); assertNull(ctx.getAttribute(key, PageContext.APPLICATION_SCOPE)); assertNull(ctx.getAttribute(key, PageContext.REQUEST_SCOPE)); assertNull(ctx.getAttribute(key, PageContext.SESSION_SCOPE)); }
protected void preProxySetup() { response = new MockHttpServletResponse(); pageContext = new MockPageContext(servletContext, request, response); }
@Override public int getAttributesScope(String name) { if (getAttribute(name) != null) { return PAGE_SCOPE; } else if (getAttribute(name, REQUEST_SCOPE) != null) { return REQUEST_SCOPE; } else if (getAttribute(name, SESSION_SCOPE) != null) { return SESSION_SCOPE; } else if (getAttribute(name, APPLICATION_SCOPE) != null) { return APPLICATION_SCOPE; } else { return 0; } }
@Override public void removeAttribute(String name) { Assert.notNull(name, "Attribute name must not be null"); this.removeAttribute(name, PageContext.PAGE_SCOPE); this.removeAttribute(name, PageContext.REQUEST_SCOPE); this.removeAttribute(name, PageContext.SESSION_SCOPE); this.removeAttribute(name, PageContext.APPLICATION_SCOPE); }
@Override public void setAttribute(String name, @Nullable Object value, int scope) { Assert.notNull(name, "Attribute name must not be null"); switch (scope) { case PAGE_SCOPE: setAttribute(name, value); break; case REQUEST_SCOPE: this.request.setAttribute(name, value); break; case SESSION_SCOPE: this.request.getSession().setAttribute(name, value); break; case APPLICATION_SCOPE: this.servletContext.setAttribute(name, value); break; default: throw new IllegalArgumentException("Invalid scope: " + scope); } }
public void finishExecution() { HttpSession session = this.request.getSession(); Enumeration attributeNames = session.getAttributeNames(); MockHttpServletRequest nextRequest = new MockHttpServletRequest(); while (attributeNames.hasMoreElements()) { String key = (String) attributeNames.nextElement(); Object attribute = session.getAttribute(key); nextRequest.getSession().setAttribute(key, attribute); } this.response = new MockHttpServletResponse(); this.request = nextRequest; this.pageContext = new MockPageContext(servletContext, request, response); }
@Override @Nullable public Object findAttribute(String name) { Object value = getAttribute(name); if (value == null) { value = getAttribute(name, REQUEST_SCOPE); if (value == null) { value = getAttribute(name, SESSION_SCOPE); if (value == null) { value = getAttribute(name, APPLICATION_SCOPE); } } } return value; }
@Override public void removeAttribute(String name) { Assert.notNull(name, "Attribute name must not be null"); this.removeAttribute(name, PageContext.PAGE_SCOPE); this.removeAttribute(name, PageContext.REQUEST_SCOPE); this.removeAttribute(name, PageContext.SESSION_SCOPE); this.removeAttribute(name, PageContext.APPLICATION_SCOPE); }
@Override public void setAttribute(String name, @Nullable Object value, int scope) { Assert.notNull(name, "Attribute name must not be null"); switch (scope) { case PAGE_SCOPE: setAttribute(name, value); break; case REQUEST_SCOPE: this.request.setAttribute(name, value); break; case SESSION_SCOPE: this.request.getSession().setAttribute(name, value); break; case APPLICATION_SCOPE: this.servletContext.setAttribute(name, value); break; default: throw new IllegalArgumentException("Invalid scope: " + scope); } }
protected void initServletMockObjects() { servletContext = new MockServletContext(resourceLoader); response = new MockHttpServletResponse(); request = new MockHttpServletRequest(); pageContext = new MockPageContext(servletContext, request, response); }
@Override @Nullable public Object getAttribute(String name, int scope) { Assert.notNull(name, "Attribute name must not be null"); switch (scope) { case PAGE_SCOPE: return getAttribute(name); case REQUEST_SCOPE: return this.request.getAttribute(name); case SESSION_SCOPE: HttpSession session = this.request.getSession(false); return (session != null ? session.getAttribute(name) : null); case APPLICATION_SCOPE: return this.servletContext.getAttribute(name); default: throw new IllegalArgumentException("Invalid scope: " + scope); } }
@Override public void removeAttribute(String name) { Assert.notNull(name, "Attribute name must not be null"); this.removeAttribute(name, PageContext.PAGE_SCOPE); this.removeAttribute(name, PageContext.REQUEST_SCOPE); this.removeAttribute(name, PageContext.SESSION_SCOPE); this.removeAttribute(name, PageContext.APPLICATION_SCOPE); }
@Override public void setAttribute(String name, Object value, int scope) { Assert.notNull(name, "Attribute name must not be null"); switch (scope) { case PAGE_SCOPE: setAttribute(name, value); break; case REQUEST_SCOPE: this.request.setAttribute(name, value); break; case SESSION_SCOPE: this.request.getSession().setAttribute(name, value); break; case APPLICATION_SCOPE: this.servletContext.setAttribute(name, value); break; default: throw new IllegalArgumentException("Invalid scope: " + scope); } }
@Override public Enumeration<String> getAttributeNamesInScope(int scope) { switch (scope) { case PAGE_SCOPE: return getAttributeNames(); case REQUEST_SCOPE: return this.request.getAttributeNames(); case SESSION_SCOPE: HttpSession session = this.request.getSession(false); return (session != null ? session.getAttributeNames() : null); case APPLICATION_SCOPE: return this.servletContext.getAttributeNames(); default: throw new IllegalArgumentException("Invalid scope: " + scope); } }
protected void initServletMockObjects() { servletContext = new MockServletContext(resourceLoader); response = new MockHttpServletResponse(); request = new MockHttpServletRequest(); pageContext = new MockPageContext(servletContext, request, response); }
@Override public Object findAttribute(String name) { Object value = getAttribute(name); if (value == null) { value = getAttribute(name, REQUEST_SCOPE); if (value == null) { value = getAttribute(name, SESSION_SCOPE); if (value == null) { value = getAttribute(name, APPLICATION_SCOPE); } } } return value; }
@Override public Enumeration<String> getAttributeNamesInScope(int scope) { switch (scope) { case PAGE_SCOPE: return getAttributeNames(); case REQUEST_SCOPE: return this.request.getAttributeNames(); case SESSION_SCOPE: HttpSession session = this.request.getSession(false); return (session != null ? session.getAttributeNames() : Collections.emptyEnumeration()); case APPLICATION_SCOPE: return this.servletContext.getAttributeNames(); default: throw new IllegalArgumentException("Invalid scope: " + scope); } }
@Override protected void initServletMockObjects() { servletContext = new MockServletContext(resourceLoader); response = new MockHttpServletResponse(); request = new MockHttpServletRequest(); pageContext = new MockPageContext(servletContext, request, response); resourceLoader = new ConventionPluginResourceLoader(); } }