From 8af66c83adb7055afb07cd19fc4268e697c2294a Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Mon, 19 Jan 2009 23:35:42 +0000 Subject: [PATCH] consistent mock behavior --- .../mock/web/MockPageContext.java | 12 +-- .../mock/web/portlet/MockActionRequest.java | 2 +- .../mock/web/portlet/MockActionResponse.java | 2 +- .../mock/web/portlet/MockBaseURL.java | 2 +- .../mock/web/portlet/MockCacheControl.java | 2 +- .../web/portlet/MockClientDataRequest.java | 2 +- .../mock/web/portlet/MockEvent.java | 88 +++++++++++++++++++ .../mock/web/portlet/MockEventRequest.java | 12 +-- .../mock/web/portlet/MockEventResponse.java | 2 +- .../mock/web/portlet/MockMimeResponse.java | 33 +++++-- .../portlet/MockMultipartActionRequest.java | 2 +- .../mock/web/portlet/MockPortalContext.java | 2 +- .../mock/web/portlet/MockPortletConfig.java | 2 +- .../mock/web/portlet/MockPortletContext.java | 2 +- .../web/portlet/MockPortletPreferences.java | 2 +- .../mock/web/portlet/MockPortletRequest.java | 4 +- .../portlet/MockPortletRequestDispatcher.java | 31 ++++--- .../mock/web/portlet/MockPortletResponse.java | 2 +- .../mock/web/portlet/MockPortletSession.java | 2 +- .../mock/web/portlet/MockPortletURL.java | 2 +- .../mock/web/portlet/MockRenderRequest.java | 15 +++- .../mock/web/portlet/MockRenderResponse.java | 33 +------ .../mock/web/portlet/MockResourceRequest.java | 4 +- .../web/portlet/MockResourceResponse.java | 2 +- .../mock/web/portlet/MockResourceURL.java | 2 +- .../web/portlet/MockStateAwareResponse.java | 2 +- .../mock/web/MockPageContext.java | 33 +++---- .../mock/web/MockPageContext.java | 12 +-- 28 files changed, 207 insertions(+), 104 deletions(-) create mode 100644 org.springframework.test/src/main/java/org/springframework/mock/web/portlet/MockEvent.java diff --git a/org.springframework.test/src/main/java/org/springframework/mock/web/MockPageContext.java b/org.springframework.test/src/main/java/org/springframework/mock/web/MockPageContext.java index 6de51d391c..c278ce4696 100644 --- a/org.springframework.test/src/main/java/org/springframework/mock/web/MockPageContext.java +++ b/org.springframework.test/src/main/java/org/springframework/mock/web/MockPageContext.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2008 the original author or authors. + * Copyright 2002-2009 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,6 +21,7 @@ import java.util.Collections; import java.util.Enumeration; import java.util.HashMap; import java.util.Map; +import javax.el.ELContext; import javax.servlet.Servlet; import javax.servlet.ServletConfig; import javax.servlet.ServletContext; @@ -34,7 +35,6 @@ import javax.servlet.jsp.JspWriter; import javax.servlet.jsp.PageContext; import javax.servlet.jsp.el.ExpressionEvaluator; import javax.servlet.jsp.el.VariableResolver; -import javax.el.ELContext; import org.springframework.util.Assert; @@ -279,11 +279,11 @@ public class MockPageContext extends PageContext { } public ELContext getELContext() { - throw new UnsupportedOperationException("getELContext"); + return null; } public VariableResolver getVariableResolver() { - throw new UnsupportedOperationException("getVariableResolver"); + return null; } public HttpSession getSession() { @@ -291,7 +291,7 @@ public class MockPageContext extends PageContext { } public Object getPage() { - throw new UnsupportedOperationException("getPage"); + return this; } public ServletRequest getRequest() { @@ -303,7 +303,7 @@ public class MockPageContext extends PageContext { } public Exception getException() { - throw new UnsupportedOperationException("getException"); + return null; } public ServletConfig getServletConfig() { diff --git a/org.springframework.test/src/main/java/org/springframework/mock/web/portlet/MockActionRequest.java b/org.springframework.test/src/main/java/org/springframework/mock/web/portlet/MockActionRequest.java index 3d8f3ec081..a687ccb671 100644 --- a/org.springframework.test/src/main/java/org/springframework/mock/web/portlet/MockActionRequest.java +++ b/org.springframework.test/src/main/java/org/springframework/mock/web/portlet/MockActionRequest.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2008 the original author or authors. + * Copyright 2002-2009 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/org.springframework.test/src/main/java/org/springframework/mock/web/portlet/MockActionResponse.java b/org.springframework.test/src/main/java/org/springframework/mock/web/portlet/MockActionResponse.java index 3b7a4ee1a1..e9c8587745 100644 --- a/org.springframework.test/src/main/java/org/springframework/mock/web/portlet/MockActionResponse.java +++ b/org.springframework.test/src/main/java/org/springframework/mock/web/portlet/MockActionResponse.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2008 the original author or authors. + * Copyright 2002-2009 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/org.springframework.test/src/main/java/org/springframework/mock/web/portlet/MockBaseURL.java b/org.springframework.test/src/main/java/org/springframework/mock/web/portlet/MockBaseURL.java index 0339d9341c..aad992058b 100644 --- a/org.springframework.test/src/main/java/org/springframework/mock/web/portlet/MockBaseURL.java +++ b/org.springframework.test/src/main/java/org/springframework/mock/web/portlet/MockBaseURL.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2008 the original author or authors. + * Copyright 2002-2009 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/org.springframework.test/src/main/java/org/springframework/mock/web/portlet/MockCacheControl.java b/org.springframework.test/src/main/java/org/springframework/mock/web/portlet/MockCacheControl.java index 5a96a43c0f..45dcae7d5e 100644 --- a/org.springframework.test/src/main/java/org/springframework/mock/web/portlet/MockCacheControl.java +++ b/org.springframework.test/src/main/java/org/springframework/mock/web/portlet/MockCacheControl.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2008 the original author or authors. + * Copyright 2002-2009 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/org.springframework.test/src/main/java/org/springframework/mock/web/portlet/MockClientDataRequest.java b/org.springframework.test/src/main/java/org/springframework/mock/web/portlet/MockClientDataRequest.java index 3ed0489f59..4a71c7d7a8 100644 --- a/org.springframework.test/src/main/java/org/springframework/mock/web/portlet/MockClientDataRequest.java +++ b/org.springframework.test/src/main/java/org/springframework/mock/web/portlet/MockClientDataRequest.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2008 the original author or authors. + * Copyright 2002-2009 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/org.springframework.test/src/main/java/org/springframework/mock/web/portlet/MockEvent.java b/org.springframework.test/src/main/java/org/springframework/mock/web/portlet/MockEvent.java new file mode 100644 index 0000000000..b58aced0ba --- /dev/null +++ b/org.springframework.test/src/main/java/org/springframework/mock/web/portlet/MockEvent.java @@ -0,0 +1,88 @@ +/* + * Copyright 2002-2009 the original author or authors. + * + * Licensed 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.springframework.mock.web.portlet; + +import java.io.Serializable; +import javax.portlet.Event; +import javax.xml.namespace.QName; + +/** + * Mock implementation of the {@link javax.portlet.Event} interface. + * + * @author Juergen Hoeller + * @since 3.0 + * @see MockEventRequest + */ +public class MockEvent implements Event { + + private final QName name; + + private final Serializable value; + + + /** + * Create a new MockEvent with the given name. + * @param name the name of the event + */ + public MockEvent(QName name) { + this.name = name; + this.value = null; + } + + /** + * Create a new MockEvent with the given name and value. + * @param name the name of the event + * @param value the associated payload of the event + */ + public MockEvent(QName name, Serializable value) { + this.name = name; + this.value = value; + } + + /** + * Create a new MockEvent with the given name. + * @param name the name of the event + */ + public MockEvent(String name) { + this.name = new QName(name); + this.value = null; + } + + /** + * Create a new MockEvent with the given name and value. + * @param name the name of the event + * @param value the associated payload of the event + */ + public MockEvent(String name, Serializable value) { + this.name = new QName(name); + this.value = value; + } + + + public QName getQName() { + return this.name; + } + + public String getName() { + return this.name.getLocalPart(); + } + + public Serializable getValue() { + return this.value; + } + +} \ No newline at end of file diff --git a/org.springframework.test/src/main/java/org/springframework/mock/web/portlet/MockEventRequest.java b/org.springframework.test/src/main/java/org/springframework/mock/web/portlet/MockEventRequest.java index 090627617f..2406f18d01 100644 --- a/org.springframework.test/src/main/java/org/springframework/mock/web/portlet/MockEventRequest.java +++ b/org.springframework.test/src/main/java/org/springframework/mock/web/portlet/MockEventRequest.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2008 the original author or authors. + * Copyright 2002-2009 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -22,7 +22,7 @@ import javax.portlet.PortalContext; import javax.portlet.PortletContext; /** - * Mock implementation of the {@link javax.portlet.RenderRequest} interface. + * Mock implementation of the {@link javax.portlet.EventRequest} interface. * * @author Juergen Hoeller * @since 3.0 @@ -35,9 +35,10 @@ public class MockEventRequest extends MockPortletRequest implements EventRequest /** - * Create a new MockRenderRequest with a default {@link MockPortalContext} + * Create a new MockEventRequest with a default {@link MockPortalContext} * and a default {@link MockPortletContext}. * @param event the event that this request wraps + * @see MockEvent */ public MockEventRequest(Event event) { super(); @@ -45,9 +46,10 @@ public class MockEventRequest extends MockPortletRequest implements EventRequest } /** - * Create a new MockRenderRequest with a default {@link MockPortalContext}. + * Create a new MockEventRequest with a default {@link MockPortalContext}. * @param event the event that this request wraps * @param portletContext the PortletContext that the request runs in + * @see MockEvent */ public MockEventRequest(Event event, PortletContext portletContext) { super(portletContext); @@ -55,7 +57,7 @@ public class MockEventRequest extends MockPortletRequest implements EventRequest } /** - * Create a new MockRenderRequest. + * Create a new MockEventRequest. * @param event the event that this request wraps * @param portalContext the PortletContext that the request runs in * @param portletContext the PortletContext that the request runs in diff --git a/org.springframework.test/src/main/java/org/springframework/mock/web/portlet/MockEventResponse.java b/org.springframework.test/src/main/java/org/springframework/mock/web/portlet/MockEventResponse.java index 2f81528b31..aa8dac4ce1 100644 --- a/org.springframework.test/src/main/java/org/springframework/mock/web/portlet/MockEventResponse.java +++ b/org.springframework.test/src/main/java/org/springframework/mock/web/portlet/MockEventResponse.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2008 the original author or authors. + * Copyright 2002-2009 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/org.springframework.test/src/main/java/org/springframework/mock/web/portlet/MockMimeResponse.java b/org.springframework.test/src/main/java/org/springframework/mock/web/portlet/MockMimeResponse.java index 639a1a4b66..e606fc808d 100644 --- a/org.springframework.test/src/main/java/org/springframework/mock/web/portlet/MockMimeResponse.java +++ b/org.springframework.test/src/main/java/org/springframework/mock/web/portlet/MockMimeResponse.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2008 the original author or authors. + * Copyright 2002-2009 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,17 +23,15 @@ import java.io.OutputStreamWriter; import java.io.PrintWriter; import java.io.UnsupportedEncodingException; import java.io.Writer; -import java.util.Collection; import java.util.Collections; import java.util.Enumeration; import java.util.Locale; import javax.portlet.CacheControl; -import javax.portlet.PortalContext; -import javax.portlet.PortletMode; -import javax.portlet.PortletURL; import javax.portlet.MimeResponse; -import javax.portlet.ResourceURL; +import javax.portlet.PortalContext; import javax.portlet.PortletRequest; +import javax.portlet.PortletURL; +import javax.portlet.ResourceURL; import org.springframework.util.CollectionUtils; import org.springframework.web.util.WebUtils; @@ -66,6 +64,8 @@ public class MockMimeResponse extends MockPortletResponse implements MimeRespons private String includedUrl; + private String forwardedUrl; + /** * Create a new MockMimeResponse with a default {@link MockPortalContext}. @@ -219,4 +219,25 @@ public class MockMimeResponse extends MockPortletResponse implements MimeRespons return this.cacheControl; } + + //--------------------------------------------------------------------- + // Methods for MockPortletRequestDispatcher + //--------------------------------------------------------------------- + + public void setIncludedUrl(String includedUrl) { + this.includedUrl = includedUrl; + } + + public String getIncludedUrl() { + return this.includedUrl; + } + + public void setForwardedUrl(String forwardedUrl) { + this.forwardedUrl = forwardedUrl; + } + + public String getForwardedUrl() { + return this.forwardedUrl; + } + } diff --git a/org.springframework.test/src/main/java/org/springframework/mock/web/portlet/MockMultipartActionRequest.java b/org.springframework.test/src/main/java/org/springframework/mock/web/portlet/MockMultipartActionRequest.java index cc2b2277cf..50d095d3e1 100644 --- a/org.springframework.test/src/main/java/org/springframework/mock/web/portlet/MockMultipartActionRequest.java +++ b/org.springframework.test/src/main/java/org/springframework/mock/web/portlet/MockMultipartActionRequest.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2008 the original author or authors. + * Copyright 2002-2009 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/org.springframework.test/src/main/java/org/springframework/mock/web/portlet/MockPortalContext.java b/org.springframework.test/src/main/java/org/springframework/mock/web/portlet/MockPortalContext.java index 1a81847f97..949d077b9a 100644 --- a/org.springframework.test/src/main/java/org/springframework/mock/web/portlet/MockPortalContext.java +++ b/org.springframework.test/src/main/java/org/springframework/mock/web/portlet/MockPortalContext.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2008 the original author or authors. + * Copyright 2002-2009 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/org.springframework.test/src/main/java/org/springframework/mock/web/portlet/MockPortletConfig.java b/org.springframework.test/src/main/java/org/springframework/mock/web/portlet/MockPortletConfig.java index 304fb6777c..d69e75d0c1 100644 --- a/org.springframework.test/src/main/java/org/springframework/mock/web/portlet/MockPortletConfig.java +++ b/org.springframework.test/src/main/java/org/springframework/mock/web/portlet/MockPortletConfig.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2008 the original author or authors. + * Copyright 2002-2009 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/org.springframework.test/src/main/java/org/springframework/mock/web/portlet/MockPortletContext.java b/org.springframework.test/src/main/java/org/springframework/mock/web/portlet/MockPortletContext.java index e28715b6cf..f297a637de 100644 --- a/org.springframework.test/src/main/java/org/springframework/mock/web/portlet/MockPortletContext.java +++ b/org.springframework.test/src/main/java/org/springframework/mock/web/portlet/MockPortletContext.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2008 the original author or authors. + * Copyright 2002-2009 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/org.springframework.test/src/main/java/org/springframework/mock/web/portlet/MockPortletPreferences.java b/org.springframework.test/src/main/java/org/springframework/mock/web/portlet/MockPortletPreferences.java index 122ead007e..ec9574491c 100644 --- a/org.springframework.test/src/main/java/org/springframework/mock/web/portlet/MockPortletPreferences.java +++ b/org.springframework.test/src/main/java/org/springframework/mock/web/portlet/MockPortletPreferences.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2008 the original author or authors. + * Copyright 2002-2009 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/org.springframework.test/src/main/java/org/springframework/mock/web/portlet/MockPortletRequest.java b/org.springframework.test/src/main/java/org/springframework/mock/web/portlet/MockPortletRequest.java index b1c710a554..92973e5f1a 100644 --- a/org.springframework.test/src/main/java/org/springframework/mock/web/portlet/MockPortletRequest.java +++ b/org.springframework.test/src/main/java/org/springframework/mock/web/portlet/MockPortletRequest.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2008 the original author or authors. + * Copyright 2002-2009 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -127,7 +127,7 @@ public class MockPortletRequest implements PortletRequest { this.portletContext = (portletContext != null ? portletContext : new MockPortletContext()); this.responseContentTypes.add("text/html"); this.locales.add(Locale.ENGLISH); - this.parameters.put(LIFECYCLE_PHASE, new String[] {getLifecyclePhase()}); + this.attributes.put(LIFECYCLE_PHASE, getLifecyclePhase()); } diff --git a/org.springframework.test/src/main/java/org/springframework/mock/web/portlet/MockPortletRequestDispatcher.java b/org.springframework.test/src/main/java/org/springframework/mock/web/portlet/MockPortletRequestDispatcher.java index 1a05db6114..ca8695f90e 100644 --- a/org.springframework.test/src/main/java/org/springframework/mock/web/portlet/MockPortletRequestDispatcher.java +++ b/org.springframework.test/src/main/java/org/springframework/mock/web/portlet/MockPortletRequestDispatcher.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2006 the original author or authors. + * Copyright 2002-2009 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,13 +17,12 @@ package org.springframework.mock.web.portlet; import java.io.IOException; - import javax.portlet.PortletException; +import javax.portlet.PortletRequest; import javax.portlet.PortletRequestDispatcher; +import javax.portlet.PortletResponse; import javax.portlet.RenderRequest; import javax.portlet.RenderResponse; -import javax.portlet.PortletRequest; -import javax.portlet.PortletResponse; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -55,23 +54,31 @@ public class MockPortletRequestDispatcher implements PortletRequestDispatcher { public void include(RenderRequest request, RenderResponse response) throws PortletException, IOException { + include((PortletRequest) request, (PortletResponse) response); + } + + public void include(PortletRequest request, PortletResponse response) throws PortletException, IOException { Assert.notNull(request, "Request must not be null"); Assert.notNull(response, "Response must not be null"); - if (!(response instanceof MockRenderResponse)) { - throw new IllegalArgumentException("MockPortletRequestDispatcher requires MockRenderResponse"); + if (!(response instanceof MockMimeResponse)) { + throw new IllegalArgumentException("MockPortletRequestDispatcher requires MockMimeResponse"); } - ((MockRenderResponse) response).setIncludedUrl(this.url); + ((MockMimeResponse) response).setIncludedUrl(this.url); if (logger.isDebugEnabled()) { logger.debug("MockPortletRequestDispatcher: including URL [" + this.url + "]"); } } - public void include(PortletRequest request, PortletResponse response) throws PortletException, IOException { - // TODO - } - public void forward(PortletRequest request, PortletResponse response) throws PortletException, IOException { - // TODO + Assert.notNull(request, "Request must not be null"); + Assert.notNull(response, "Response must not be null"); + if (!(response instanceof MockMimeResponse)) { + throw new IllegalArgumentException("MockPortletRequestDispatcher requires MockMimeResponse"); + } + ((MockMimeResponse) response).setForwardedUrl(this.url); + if (logger.isDebugEnabled()) { + logger.debug("MockPortletRequestDispatcher: forwarding to URL [" + this.url + "]"); + } } } diff --git a/org.springframework.test/src/main/java/org/springframework/mock/web/portlet/MockPortletResponse.java b/org.springframework.test/src/main/java/org/springframework/mock/web/portlet/MockPortletResponse.java index 6d1eb699f1..b556209fcd 100644 --- a/org.springframework.test/src/main/java/org/springframework/mock/web/portlet/MockPortletResponse.java +++ b/org.springframework.test/src/main/java/org/springframework/mock/web/portlet/MockPortletResponse.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2008 the original author or authors. + * Copyright 2002-2009 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/org.springframework.test/src/main/java/org/springframework/mock/web/portlet/MockPortletSession.java b/org.springframework.test/src/main/java/org/springframework/mock/web/portlet/MockPortletSession.java index b0845c0711..558961121d 100644 --- a/org.springframework.test/src/main/java/org/springframework/mock/web/portlet/MockPortletSession.java +++ b/org.springframework.test/src/main/java/org/springframework/mock/web/portlet/MockPortletSession.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2008 the original author or authors. + * Copyright 2002-2009 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/org.springframework.test/src/main/java/org/springframework/mock/web/portlet/MockPortletURL.java b/org.springframework.test/src/main/java/org/springframework/mock/web/portlet/MockPortletURL.java index c030f00f31..12abdf57c9 100644 --- a/org.springframework.test/src/main/java/org/springframework/mock/web/portlet/MockPortletURL.java +++ b/org.springframework.test/src/main/java/org/springframework/mock/web/portlet/MockPortletURL.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2008 the original author or authors. + * Copyright 2002-2009 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/org.springframework.test/src/main/java/org/springframework/mock/web/portlet/MockRenderRequest.java b/org.springframework.test/src/main/java/org/springframework/mock/web/portlet/MockRenderRequest.java index 5331b08418..d86ba7f2ad 100644 --- a/org.springframework.test/src/main/java/org/springframework/mock/web/portlet/MockRenderRequest.java +++ b/org.springframework.test/src/main/java/org/springframework/mock/web/portlet/MockRenderRequest.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2008 the original author or authors. + * Copyright 2002-2009 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,6 +20,7 @@ import javax.portlet.PortalContext; import javax.portlet.PortletContext; import javax.portlet.PortletMode; import javax.portlet.RenderRequest; +import javax.portlet.WindowState; /** * Mock implementation of the {@link javax.portlet.RenderRequest} interface. @@ -50,6 +51,18 @@ public class MockRenderRequest extends MockPortletRequest implements RenderReque setPortletMode(portletMode); } + /** + * Create a new MockRenderRequest with a default {@link MockPortalContext} + * and a default {@link MockPortletContext}. + * @param portletMode the mode that the portlet runs in + * @param windowState the window state to run the portlet in + */ + public MockRenderRequest(PortletMode portletMode, WindowState windowState) { + super(); + setPortletMode(portletMode); + setWindowState(windowState); + } + /** * Create a new MockRenderRequest with a default {@link MockPortalContext}. * @param portletContext the PortletContext that the request runs in diff --git a/org.springframework.test/src/main/java/org/springframework/mock/web/portlet/MockRenderResponse.java b/org.springframework.test/src/main/java/org/springframework/mock/web/portlet/MockRenderResponse.java index 298f3760aa..a2feeb3726 100644 --- a/org.springframework.test/src/main/java/org/springframework/mock/web/portlet/MockRenderResponse.java +++ b/org.springframework.test/src/main/java/org/springframework/mock/web/portlet/MockRenderResponse.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2008 the original author or authors. + * Copyright 2002-2009 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,27 +16,11 @@ package org.springframework.mock.web.portlet; -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.OutputStream; -import java.io.OutputStreamWriter; -import java.io.PrintWriter; -import java.io.UnsupportedEncodingException; -import java.io.Writer; import java.util.Collection; -import java.util.Collections; -import java.util.Enumeration; -import java.util.Locale; -import javax.portlet.CacheControl; import javax.portlet.PortalContext; import javax.portlet.PortletMode; -import javax.portlet.PortletURL; import javax.portlet.RenderRequest; import javax.portlet.RenderResponse; -import javax.portlet.ResourceURL; - -import org.springframework.util.CollectionUtils; -import org.springframework.web.util.WebUtils; /** * Mock implementation of the {@link javax.portlet.RenderResponse} interface. @@ -51,8 +35,6 @@ public class MockRenderResponse extends MockMimeResponse implements RenderRespon private Collection nextPossiblePortletModes; - private String includedUrl; - /** * Create a new MockRenderResponse with a default {@link MockPortalContext}. @@ -103,17 +85,4 @@ public class MockRenderResponse extends MockMimeResponse implements RenderRespon return this.nextPossiblePortletModes; } - - //--------------------------------------------------------------------- - // Methods for MockPortletRequestDispatcher - //--------------------------------------------------------------------- - - public void setIncludedUrl(String includedUrl) { - this.includedUrl = includedUrl; - } - - public String getIncludedUrl() { - return this.includedUrl; - } - } diff --git a/org.springframework.test/src/main/java/org/springframework/mock/web/portlet/MockResourceRequest.java b/org.springframework.test/src/main/java/org/springframework/mock/web/portlet/MockResourceRequest.java index f8a94dc738..7cce4ba3c6 100644 --- a/org.springframework.test/src/main/java/org/springframework/mock/web/portlet/MockResourceRequest.java +++ b/org.springframework.test/src/main/java/org/springframework/mock/web/portlet/MockResourceRequest.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2008 the original author or authors. + * Copyright 2002-2009 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -25,7 +25,7 @@ import javax.portlet.RenderRequest; import javax.portlet.ResourceRequest; /** - * Mock implementation of the {@link javax.portlet.ActionRequest} interface. + * Mock implementation of the {@link javax.portlet.ResourceRequest} interface. * * @author Juergen Hoeller * @since 3.0 diff --git a/org.springframework.test/src/main/java/org/springframework/mock/web/portlet/MockResourceResponse.java b/org.springframework.test/src/main/java/org/springframework/mock/web/portlet/MockResourceResponse.java index 1f8ea709af..297a19682e 100644 --- a/org.springframework.test/src/main/java/org/springframework/mock/web/portlet/MockResourceResponse.java +++ b/org.springframework.test/src/main/java/org/springframework/mock/web/portlet/MockResourceResponse.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2008 the original author or authors. + * Copyright 2002-2009 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/org.springframework.test/src/main/java/org/springframework/mock/web/portlet/MockResourceURL.java b/org.springframework.test/src/main/java/org/springframework/mock/web/portlet/MockResourceURL.java index 5b46d24869..cce36b18d5 100644 --- a/org.springframework.test/src/main/java/org/springframework/mock/web/portlet/MockResourceURL.java +++ b/org.springframework.test/src/main/java/org/springframework/mock/web/portlet/MockResourceURL.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2008 the original author or authors. + * Copyright 2002-2009 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/org.springframework.test/src/main/java/org/springframework/mock/web/portlet/MockStateAwareResponse.java b/org.springframework.test/src/main/java/org/springframework/mock/web/portlet/MockStateAwareResponse.java index 39c6885b12..131110971d 100644 --- a/org.springframework.test/src/main/java/org/springframework/mock/web/portlet/MockStateAwareResponse.java +++ b/org.springframework.test/src/main/java/org/springframework/mock/web/portlet/MockStateAwareResponse.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2008 the original author or authors. + * Copyright 2002-2009 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/org.springframework.web.servlet/src/test/java/org/springframework/mock/web/MockPageContext.java b/org.springframework.web.servlet/src/test/java/org/springframework/mock/web/MockPageContext.java index 1e06c36c04..c278ce4696 100644 --- a/org.springframework.web.servlet/src/test/java/org/springframework/mock/web/MockPageContext.java +++ b/org.springframework.web.servlet/src/test/java/org/springframework/mock/web/MockPageContext.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2008 the original author or authors. + * Copyright 2002-2009 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,8 +17,10 @@ package org.springframework.mock.web; import java.io.IOException; +import java.util.Collections; import java.util.Enumeration; -import java.util.Hashtable; +import java.util.HashMap; +import java.util.Map; import javax.el.ELContext; import javax.servlet.Servlet; import javax.servlet.ServletConfig; @@ -59,23 +61,23 @@ public class MockPageContext extends PageContext { private final ServletConfig servletConfig; - private final Hashtable attributes = new Hashtable(); + private final Map attributes = new HashMap(); private JspWriter out; /** - * Create new MockPageContext with a default {@link org.springframework.mock.web.MockServletContext}, - * {@link org.springframework.mock.web.MockHttpServletRequest}, {@link org.springframework.mock.web.MockHttpServletResponse}, - * {@link org.springframework.mock.web.MockServletConfig}. + * Create new MockPageContext with a default {@link MockServletContext}, + * {@link MockHttpServletRequest}, {@link MockHttpServletResponse}, + * {@link MockServletConfig}. */ public MockPageContext() { this(null, null, null, null); } /** - * Create new MockPageContext with a default {@link org.springframework.mock.web.MockHttpServletRequest}, - * {@link org.springframework.mock.web.MockHttpServletResponse}, {@link org.springframework.mock.web.MockServletConfig}. + * Create new MockPageContext with a default {@link MockHttpServletRequest}, + * {@link MockHttpServletResponse}, {@link MockServletConfig}. * @param servletContext the ServletContext that the JSP page runs in * (only necessary when actually accessing the ServletContext) */ @@ -244,11 +246,12 @@ public class MockPageContext extends PageContext { } } - public Enumeration getAttributeNames() { - return this.attributes.keys(); + public Enumeration getAttributeNames() { + return Collections.enumeration(this.attributes.keySet()); } - public Enumeration getAttributeNamesInScope(int scope) { + @SuppressWarnings("unchecked") + public Enumeration getAttributeNamesInScope(int scope) { switch (scope) { case PAGE_SCOPE: return getAttributeNames(); @@ -276,7 +279,7 @@ public class MockPageContext extends PageContext { } public ELContext getELContext() { - throw new UnsupportedOperationException("getELContext"); + return null; } public VariableResolver getVariableResolver() { @@ -288,7 +291,7 @@ public class MockPageContext extends PageContext { } public Object getPage() { - throw new UnsupportedOperationException("getPage"); + return this; } public ServletRequest getRequest() { @@ -300,7 +303,7 @@ public class MockPageContext extends PageContext { } public Exception getException() { - throw new UnsupportedOperationException("getException"); + return null; } public ServletConfig getServletConfig() { @@ -331,4 +334,4 @@ public class MockPageContext extends PageContext { throw new UnsupportedOperationException("handlePageException"); } -} \ No newline at end of file +} diff --git a/org.springframework.web/src/test/java/org/springframework/mock/web/MockPageContext.java b/org.springframework.web/src/test/java/org/springframework/mock/web/MockPageContext.java index 6de51d391c..c278ce4696 100644 --- a/org.springframework.web/src/test/java/org/springframework/mock/web/MockPageContext.java +++ b/org.springframework.web/src/test/java/org/springframework/mock/web/MockPageContext.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2008 the original author or authors. + * Copyright 2002-2009 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,6 +21,7 @@ import java.util.Collections; import java.util.Enumeration; import java.util.HashMap; import java.util.Map; +import javax.el.ELContext; import javax.servlet.Servlet; import javax.servlet.ServletConfig; import javax.servlet.ServletContext; @@ -34,7 +35,6 @@ import javax.servlet.jsp.JspWriter; import javax.servlet.jsp.PageContext; import javax.servlet.jsp.el.ExpressionEvaluator; import javax.servlet.jsp.el.VariableResolver; -import javax.el.ELContext; import org.springframework.util.Assert; @@ -279,11 +279,11 @@ public class MockPageContext extends PageContext { } public ELContext getELContext() { - throw new UnsupportedOperationException("getELContext"); + return null; } public VariableResolver getVariableResolver() { - throw new UnsupportedOperationException("getVariableResolver"); + return null; } public HttpSession getSession() { @@ -291,7 +291,7 @@ public class MockPageContext extends PageContext { } public Object getPage() { - throw new UnsupportedOperationException("getPage"); + return this; } public ServletRequest getRequest() { @@ -303,7 +303,7 @@ public class MockPageContext extends PageContext { } public Exception getException() { - throw new UnsupportedOperationException("getException"); + return null; } public ServletConfig getServletConfig() {