27 changed files with 1454 additions and 353 deletions
@ -0,0 +1,152 @@
@@ -0,0 +1,152 @@
|
||||
/* |
||||
* Copyright 2002-2008 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.IOException; |
||||
import java.io.UnsupportedEncodingException; |
||||
import java.io.Writer; |
||||
import java.net.URLEncoder; |
||||
import java.util.Collections; |
||||
import java.util.LinkedHashMap; |
||||
import java.util.Map; |
||||
import java.util.Set; |
||||
import javax.portlet.BaseURL; |
||||
import javax.portlet.PortletSecurityException; |
||||
|
||||
import org.springframework.util.Assert; |
||||
import org.springframework.util.StringUtils; |
||||
|
||||
/** |
||||
* Mock implementation of the {@link javax.portlet.BaseURL} interface. |
||||
* |
||||
* @author Juergen Hoeller |
||||
* @since 3.0 |
||||
*/ |
||||
public abstract class MockBaseURL implements BaseURL { |
||||
|
||||
public static final String URL_TYPE_RENDER = "render"; |
||||
|
||||
public static final String URL_TYPE_ACTION = "action"; |
||||
|
||||
private static final String ENCODING = "UTF-8"; |
||||
|
||||
|
||||
protected final Map<String, String[]> parameters = new LinkedHashMap<String, String[]>(); |
||||
|
||||
private boolean secure = false; |
||||
|
||||
private final Map<String, String[]> properties = new LinkedHashMap<String, String[]>(); |
||||
|
||||
|
||||
//---------------------------------------------------------------------
|
||||
// BaseURL methods
|
||||
//---------------------------------------------------------------------
|
||||
|
||||
public void setParameter(String key, String value) { |
||||
Assert.notNull(key, "Parameter key must be null"); |
||||
Assert.notNull(value, "Parameter value must not be null"); |
||||
this.parameters.put(key, new String[] {value}); |
||||
} |
||||
|
||||
public void setParameter(String key, String[] values) { |
||||
Assert.notNull(key, "Parameter key must be null"); |
||||
Assert.notNull(values, "Parameter values must not be null"); |
||||
this.parameters.put(key, values); |
||||
} |
||||
|
||||
public void setParameters(Map<String, String[]> parameters) { |
||||
Assert.notNull(parameters, "Parameters Map must not be null"); |
||||
this.parameters.clear(); |
||||
this.parameters.putAll(parameters); |
||||
} |
||||
|
||||
public Set<String> getParameterNames() { |
||||
return this.parameters.keySet(); |
||||
} |
||||
|
||||
public String getParameter(String name) { |
||||
String[] arr = this.parameters.get(name); |
||||
return (arr != null && arr.length > 0 ? arr[0] : null); |
||||
} |
||||
|
||||
public String[] getParameterValues(String name) { |
||||
return this.parameters.get(name); |
||||
} |
||||
|
||||
public Map<String, String[]> getParameterMap() { |
||||
return Collections.unmodifiableMap(this.parameters); |
||||
} |
||||
|
||||
public void setSecure(boolean secure) throws PortletSecurityException { |
||||
this.secure = secure; |
||||
} |
||||
|
||||
public boolean isSecure() { |
||||
return this.secure; |
||||
} |
||||
|
||||
public void write(Writer out) throws IOException { |
||||
out.write(toString()); |
||||
} |
||||
|
||||
public void write(Writer out, boolean escapeXML) throws IOException { |
||||
out.write(toString()); |
||||
} |
||||
|
||||
public void addProperty(String key, String value) { |
||||
String[] values = this.properties.get(key); |
||||
if (values != null) { |
||||
this.properties.put(key, StringUtils.addStringToArray(values, value)); |
||||
} |
||||
else { |
||||
this.properties.put(key, new String[] {value}); |
||||
} |
||||
} |
||||
|
||||
public void setProperty(String key, String value) { |
||||
this.properties.put(key, new String[] {value}); |
||||
} |
||||
|
||||
public Map<String, String[]> getProperties() { |
||||
return Collections.unmodifiableMap(this.properties); |
||||
} |
||||
|
||||
|
||||
protected String encodeParameter(String name, String value) { |
||||
try { |
||||
return URLEncoder.encode(name, ENCODING) + "=" + URLEncoder.encode(value, ENCODING); |
||||
} |
||||
catch (UnsupportedEncodingException ex) { |
||||
return null; |
||||
} |
||||
} |
||||
|
||||
protected String encodeParameter(String name, String[] values) { |
||||
try { |
||||
StringBuilder sb = new StringBuilder(); |
||||
for (int i = 0, n = values.length; i < n; i++) { |
||||
sb.append(i > 0 ? ";" : "").append(URLEncoder.encode(name, ENCODING)).append("=") |
||||
.append(URLEncoder.encode(values[i], ENCODING)); |
||||
} |
||||
return sb.toString(); |
||||
} |
||||
catch (UnsupportedEncodingException ex) { |
||||
return null; |
||||
} |
||||
} |
||||
|
||||
} |
@ -0,0 +1,70 @@
@@ -0,0 +1,70 @@
|
||||
/* |
||||
* Copyright 2002-2008 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 javax.portlet.CacheControl; |
||||
|
||||
/** |
||||
* Mock implementation of the {@link javax.portlet.CacheControl} interface. |
||||
* |
||||
* @author Juergen Hoeller |
||||
* @since 3.0 |
||||
*/ |
||||
public class MockCacheControl implements CacheControl { |
||||
|
||||
private int expirationTime = 0; |
||||
|
||||
private boolean publicScope = false; |
||||
|
||||
private String etag; |
||||
|
||||
private boolean useCachedContent = false; |
||||
|
||||
|
||||
public int getExpirationTime() { |
||||
return this.expirationTime; |
||||
} |
||||
|
||||
public void setExpirationTime(int time) { |
||||
this.expirationTime = time; |
||||
} |
||||
|
||||
public boolean isPublicScope() { |
||||
return this.publicScope; |
||||
} |
||||
|
||||
public void setPublicScope(boolean publicScope) { |
||||
this.publicScope = publicScope; |
||||
} |
||||
|
||||
public String getETag() { |
||||
return this.etag; |
||||
} |
||||
|
||||
public void setETag(String token) { |
||||
this.etag = token; |
||||
} |
||||
|
||||
public boolean useCachedContent() { |
||||
return this.useCachedContent; |
||||
} |
||||
|
||||
public void setUseCachedContent(boolean useCachedContent) { |
||||
this.useCachedContent = useCachedContent; |
||||
} |
||||
|
||||
} |
@ -0,0 +1,129 @@
@@ -0,0 +1,129 @@
|
||||
/* |
||||
* Copyright 2002-2008 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.BufferedReader; |
||||
import java.io.ByteArrayInputStream; |
||||
import java.io.IOException; |
||||
import java.io.InputStream; |
||||
import java.io.InputStreamReader; |
||||
import java.io.Reader; |
||||
import java.io.UnsupportedEncodingException; |
||||
import javax.portlet.ClientDataRequest; |
||||
import javax.portlet.PortalContext; |
||||
import javax.portlet.PortletContext; |
||||
import javax.portlet.PortletMode; |
||||
|
||||
/** |
||||
* Mock implementation of the {@link javax.portlet.ClientDataRequest} interface. |
||||
* |
||||
* @author Juergen Hoeller |
||||
* @since 3.0 |
||||
*/ |
||||
public class MockClientDataRequest extends MockPortletRequest implements ClientDataRequest { |
||||
|
||||
private String characterEncoding; |
||||
|
||||
private byte[] content; |
||||
|
||||
private String contentType; |
||||
|
||||
private String method; |
||||
|
||||
|
||||
/** |
||||
* Create a new MockClientDataRequest with a default {@link MockPortalContext} |
||||
* and a default {@link MockPortletContext}. |
||||
* @see org.springframework.mock.web.portlet.MockPortalContext |
||||
* @see org.springframework.mock.web.portlet.MockPortletContext |
||||
*/ |
||||
public MockClientDataRequest() { |
||||
super(); |
||||
} |
||||
|
||||
/** |
||||
* Create a new MockClientDataRequest with a default {@link MockPortalContext}. |
||||
* @param portletContext the PortletContext that the request runs in |
||||
*/ |
||||
public MockClientDataRequest(PortletContext portletContext) { |
||||
super(portletContext); |
||||
} |
||||
|
||||
/** |
||||
* Create a new MockClientDataRequest. |
||||
* @param portalContext the PortalContext that the request runs in |
||||
* @param portletContext the PortletContext that the request runs in |
||||
*/ |
||||
public MockClientDataRequest(PortalContext portalContext, PortletContext portletContext) { |
||||
super(portalContext, portletContext); |
||||
} |
||||
|
||||
|
||||
public void setContent(byte[] content) { |
||||
this.content = content; |
||||
} |
||||
|
||||
public InputStream getPortletInputStream() throws IOException { |
||||
if (this.content != null) { |
||||
return new ByteArrayInputStream(this.content); |
||||
} |
||||
else { |
||||
return null; |
||||
} |
||||
} |
||||
|
||||
public void setCharacterEncoding(String characterEncoding) { |
||||
this.characterEncoding = characterEncoding; |
||||
} |
||||
|
||||
public BufferedReader getReader() throws UnsupportedEncodingException { |
||||
if (this.content != null) { |
||||
InputStream sourceStream = new ByteArrayInputStream(this.content); |
||||
Reader sourceReader = (this.characterEncoding != null) ? |
||||
new InputStreamReader(sourceStream, this.characterEncoding) : new InputStreamReader(sourceStream); |
||||
return new BufferedReader(sourceReader); |
||||
} |
||||
else { |
||||
return null; |
||||
} |
||||
} |
||||
|
||||
public String getCharacterEncoding() { |
||||
return this.characterEncoding; |
||||
} |
||||
|
||||
public void setContentType(String contentType) { |
||||
this.contentType = contentType; |
||||
} |
||||
|
||||
public String getContentType() { |
||||
return this.contentType; |
||||
} |
||||
|
||||
public int getContentLength() { |
||||
return (this.content != null ? content.length : -1); |
||||
} |
||||
|
||||
public void setMethod(String method) { |
||||
this.method = method; |
||||
} |
||||
|
||||
public String getMethod() { |
||||
return this.method; |
||||
} |
||||
|
||||
} |
@ -0,0 +1,86 @@
@@ -0,0 +1,86 @@
|
||||
/* |
||||
* Copyright 2002-2008 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 javax.portlet.Event; |
||||
import javax.portlet.EventRequest; |
||||
import javax.portlet.PortalContext; |
||||
import javax.portlet.PortletContext; |
||||
|
||||
/** |
||||
* Mock implementation of the {@link javax.portlet.RenderRequest} interface. |
||||
* |
||||
* @author Juergen Hoeller |
||||
* @since 3.0 |
||||
*/ |
||||
public class MockEventRequest extends MockPortletRequest implements EventRequest { |
||||
|
||||
private final Event event; |
||||
|
||||
private String method; |
||||
|
||||
|
||||
/** |
||||
* Create a new MockRenderRequest with a default {@link MockPortalContext} |
||||
* and a default {@link MockPortletContext}. |
||||
* @param event the event that this request wraps |
||||
*/ |
||||
public MockEventRequest(Event event) { |
||||
super(); |
||||
this.event = event; |
||||
} |
||||
|
||||
/** |
||||
* Create a new MockRenderRequest with a default {@link MockPortalContext}. |
||||
* @param event the event that this request wraps |
||||
* @param portletContext the PortletContext that the request runs in |
||||
*/ |
||||
public MockEventRequest(Event event, PortletContext portletContext) { |
||||
super(portletContext); |
||||
this.event = event; |
||||
} |
||||
|
||||
/** |
||||
* Create a new MockRenderRequest. |
||||
* @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 |
||||
*/ |
||||
public MockEventRequest(Event event, PortalContext portalContext, PortletContext portletContext) { |
||||
super(portalContext, portletContext); |
||||
this.event = event; |
||||
} |
||||
|
||||
|
||||
@Override |
||||
protected String getLifecyclePhase() { |
||||
return EVENT_PHASE; |
||||
} |
||||
|
||||
public Event getEvent() { |
||||
return this.event; |
||||
} |
||||
|
||||
public void setMethod(String method) { |
||||
this.method = method; |
||||
} |
||||
|
||||
public String getMethod() { |
||||
return this.method; |
||||
} |
||||
|
||||
} |
@ -0,0 +1,34 @@
@@ -0,0 +1,34 @@
|
||||
/* |
||||
* Copyright 2002-2008 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 javax.portlet.EventResponse; |
||||
import javax.portlet.EventRequest; |
||||
|
||||
/** |
||||
* Mock implementation of the {@link javax.portlet.EventResponse} interface. |
||||
* |
||||
* @author Juergen Hoeller |
||||
* @since 3.0 |
||||
*/ |
||||
public class MockEventResponse extends MockStateAwareResponse implements EventResponse { |
||||
|
||||
public void setRenderParameters(EventRequest request) { |
||||
setRenderParameters(request.getParameterMap()); |
||||
} |
||||
|
||||
} |
@ -0,0 +1,222 @@
@@ -0,0 +1,222 @@
|
||||
/* |
||||
* Copyright 2002-2008 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.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.MimeResponse; |
||||
import javax.portlet.ResourceURL; |
||||
import javax.portlet.PortletRequest; |
||||
|
||||
import org.springframework.util.CollectionUtils; |
||||
import org.springframework.web.util.WebUtils; |
||||
|
||||
/** |
||||
* Mock implementation of the {@link javax.portlet.MimeResponse} interface. |
||||
* |
||||
* @author Juergen Hoeller |
||||
* @since 3.0 |
||||
*/ |
||||
public class MockMimeResponse extends MockPortletResponse implements MimeResponse { |
||||
|
||||
private PortletRequest request; |
||||
|
||||
private String contentType; |
||||
|
||||
private String characterEncoding = WebUtils.DEFAULT_CHARACTER_ENCODING; |
||||
|
||||
private PrintWriter writer; |
||||
|
||||
private Locale locale = Locale.getDefault(); |
||||
|
||||
private int bufferSize = 4096; |
||||
|
||||
private final ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); |
||||
|
||||
private final CacheControl cacheControl = new MockCacheControl(); |
||||
|
||||
private boolean committed; |
||||
|
||||
private String includedUrl; |
||||
|
||||
|
||||
/** |
||||
* Create a new MockMimeResponse with a default {@link MockPortalContext}. |
||||
* @see org.springframework.mock.web.portlet.MockPortalContext |
||||
*/ |
||||
public MockMimeResponse() { |
||||
super(); |
||||
} |
||||
|
||||
/** |
||||
* Create a new MockMimeResponse. |
||||
* @param portalContext the PortalContext defining the supported |
||||
* PortletModes and WindowStates |
||||
*/ |
||||
public MockMimeResponse(PortalContext portalContext) { |
||||
super(portalContext); |
||||
} |
||||
|
||||
/** |
||||
* Create a new MockMimeResponse. |
||||
* @param portalContext the PortalContext defining the supported |
||||
* PortletModes and WindowStates |
||||
* @param request the corresponding render/resource request that this response |
||||
* is being generated for |
||||
*/ |
||||
public MockMimeResponse(PortalContext portalContext, PortletRequest request) { |
||||
super(portalContext); |
||||
this.request = request; |
||||
} |
||||
|
||||
|
||||
//---------------------------------------------------------------------
|
||||
// RenderResponse methods
|
||||
//---------------------------------------------------------------------
|
||||
|
||||
public void setContentType(String contentType) { |
||||
if (this.request != null) { |
||||
Enumeration<String> supportedTypes = this.request.getResponseContentTypes(); |
||||
if (!CollectionUtils.contains(supportedTypes, contentType)) { |
||||
throw new IllegalArgumentException("Content type [" + contentType + "] not in supported list: " + |
||||
Collections.list(supportedTypes)); |
||||
} |
||||
} |
||||
this.contentType = contentType; |
||||
} |
||||
|
||||
public String getContentType() { |
||||
return this.contentType; |
||||
} |
||||
|
||||
public void setCharacterEncoding(String characterEncoding) { |
||||
this.characterEncoding = characterEncoding; |
||||
} |
||||
|
||||
public String getCharacterEncoding() { |
||||
return this.characterEncoding; |
||||
} |
||||
|
||||
public PrintWriter getWriter() throws UnsupportedEncodingException { |
||||
if (this.writer == null) { |
||||
Writer targetWriter = (this.characterEncoding != null |
||||
? new OutputStreamWriter(this.outputStream, this.characterEncoding) |
||||
: new OutputStreamWriter(this.outputStream)); |
||||
this.writer = new PrintWriter(targetWriter); |
||||
} |
||||
return this.writer; |
||||
} |
||||
|
||||
public byte[] getContentAsByteArray() { |
||||
flushBuffer(); |
||||
return this.outputStream.toByteArray(); |
||||
} |
||||
|
||||
public String getContentAsString() throws UnsupportedEncodingException { |
||||
flushBuffer(); |
||||
return (this.characterEncoding != null) |
||||
? this.outputStream.toString(this.characterEncoding) |
||||
: this.outputStream.toString(); |
||||
} |
||||
|
||||
public void setLocale(Locale locale) { |
||||
this.locale = locale; |
||||
} |
||||
|
||||
public Locale getLocale() { |
||||
return this.locale; |
||||
} |
||||
|
||||
public void setBufferSize(int bufferSize) { |
||||
this.bufferSize = bufferSize; |
||||
} |
||||
|
||||
public int getBufferSize() { |
||||
return this.bufferSize; |
||||
} |
||||
|
||||
public void flushBuffer() { |
||||
if (this.writer != null) { |
||||
this.writer.flush(); |
||||
} |
||||
if (this.outputStream != null) { |
||||
try { |
||||
this.outputStream.flush(); |
||||
} |
||||
catch (IOException ex) { |
||||
throw new IllegalStateException("Could not flush OutputStream: " + ex.getMessage()); |
||||
} |
||||
} |
||||
this.committed = true; |
||||
} |
||||
|
||||
public void resetBuffer() { |
||||
if (this.committed) { |
||||
throw new IllegalStateException("Cannot reset buffer - response is already committed"); |
||||
} |
||||
this.outputStream.reset(); |
||||
} |
||||
|
||||
public void setCommitted(boolean committed) { |
||||
this.committed = committed; |
||||
} |
||||
|
||||
public boolean isCommitted() { |
||||
return this.committed; |
||||
} |
||||
|
||||
public void reset() { |
||||
resetBuffer(); |
||||
this.characterEncoding = null; |
||||
this.contentType = null; |
||||
this.locale = null; |
||||
} |
||||
|
||||
public OutputStream getPortletOutputStream() throws IOException { |
||||
return this.outputStream; |
||||
} |
||||
|
||||
public PortletURL createRenderURL() { |
||||
return new MockPortletURL(getPortalContext(), MockPortletURL.URL_TYPE_RENDER); |
||||
} |
||||
|
||||
public PortletURL createActionURL() { |
||||
return new MockPortletURL(getPortalContext(), MockPortletURL.URL_TYPE_ACTION); |
||||
} |
||||
|
||||
public ResourceURL createResourceURL() { |
||||
return new MockResourceURL(); |
||||
} |
||||
|
||||
public CacheControl getCacheControl() { |
||||
return this.cacheControl; |
||||
} |
||||
|
||||
} |
@ -0,0 +1,128 @@
@@ -0,0 +1,128 @@
|
||||
/* |
||||
* Copyright 2002-2008 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.util.Collections; |
||||
import java.util.LinkedHashMap; |
||||
import java.util.Map; |
||||
import javax.portlet.PortalContext; |
||||
import javax.portlet.PortletContext; |
||||
import javax.portlet.RenderRequest; |
||||
import javax.portlet.ResourceRequest; |
||||
|
||||
/** |
||||
* Mock implementation of the {@link javax.portlet.ActionRequest} interface. |
||||
* |
||||
* @author Juergen Hoeller |
||||
* @since 3.0 |
||||
*/ |
||||
public class MockResourceRequest extends MockClientDataRequest implements ResourceRequest { |
||||
|
||||
private String resourceID; |
||||
|
||||
private String cacheability; |
||||
|
||||
private final Map<String, String[]> privateRenderParameterMap = new LinkedHashMap<String, String[]>(); |
||||
|
||||
|
||||
/** |
||||
* Create a new MockResourceRequest with a default {@link MockPortalContext} |
||||
* and a default {@link MockPortletContext}. |
||||
* @see org.springframework.mock.web.portlet.MockPortalContext |
||||
* @see org.springframework.mock.web.portlet.MockPortletContext |
||||
*/ |
||||
public MockResourceRequest() { |
||||
super(); |
||||
} |
||||
|
||||
/** |
||||
* Create a new MockResourceRequest with a default {@link MockPortalContext} |
||||
* and a default {@link MockPortletContext}. |
||||
* @param resourceID the resource id for this request |
||||
*/ |
||||
public MockResourceRequest(String resourceID) { |
||||
super(); |
||||
this.resourceID = resourceID; |
||||
} |
||||
|
||||
/** |
||||
* Create a new MockResourceRequest with a default {@link MockPortalContext} |
||||
* and a default {@link MockPortletContext}. |
||||
* @param url the resource URL for this request |
||||
*/ |
||||
public MockResourceRequest(MockResourceURL url) { |
||||
super(); |
||||
this.resourceID = url.getResourceID(); |
||||
this.cacheability = url.getCacheability(); |
||||
} |
||||
|
||||
/** |
||||
* Create a new MockResourceRequest with a default {@link MockPortalContext}. |
||||
* @param portletContext the PortletContext that the request runs in |
||||
*/ |
||||
public MockResourceRequest(PortletContext portletContext) { |
||||
super(portletContext); |
||||
} |
||||
|
||||
/** |
||||
* Create a new MockResourceRequest. |
||||
* @param portalContext the PortalContext that the request runs in |
||||
* @param portletContext the PortletContext that the request runs in |
||||
*/ |
||||
public MockResourceRequest(PortalContext portalContext, PortletContext portletContext) { |
||||
super(portalContext, portletContext); |
||||
} |
||||
|
||||
|
||||
@Override |
||||
protected String getLifecyclePhase() { |
||||
return RESOURCE_PHASE; |
||||
} |
||||
|
||||
public void setResourceID(String resourceID) { |
||||
this.resourceID = resourceID; |
||||
} |
||||
|
||||
public String getResourceID() { |
||||
return this.resourceID; |
||||
} |
||||
|
||||
public void setCacheability(String cacheLevel) { |
||||
this.cacheability = cacheLevel; |
||||
} |
||||
|
||||
public String getCacheability() { |
||||
return this.cacheability; |
||||
} |
||||
|
||||
public String getETag() { |
||||
return getProperty(RenderRequest.ETAG); |
||||
} |
||||
|
||||
public void addPrivateRenderParameter(String key, String value) { |
||||
this.privateRenderParameterMap.put(key, new String[] {value}); |
||||
} |
||||
|
||||
public void addPrivateRenderParameter(String key, String[] values) { |
||||
this.privateRenderParameterMap.put(key, values); |
||||
} |
||||
|
||||
public Map<String, String[]> getPrivateRenderParameterMap() { |
||||
return Collections.unmodifiableMap(this.privateRenderParameterMap); |
||||
} |
||||
|
||||
} |
@ -0,0 +1,40 @@
@@ -0,0 +1,40 @@
|
||||
/* |
||||
* Copyright 2002-2008 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 javax.portlet.ResourceResponse; |
||||
|
||||
/** |
||||
* Mock implementation of the {@link javax.portlet.ResourceResponse} interface. |
||||
* |
||||
* @author Juergen Hoeller |
||||
* @since 3.0 |
||||
*/ |
||||
public class MockResourceResponse extends MockMimeResponse implements ResourceResponse { |
||||
|
||||
private int contentLength = 0; |
||||
|
||||
|
||||
public void setContentLength(int len) { |
||||
this.contentLength = len; |
||||
} |
||||
|
||||
public int getContentLength() { |
||||
return this.contentLength; |
||||
} |
||||
|
||||
} |
@ -0,0 +1,69 @@
@@ -0,0 +1,69 @@
|
||||
/* |
||||
* Copyright 2002-2008 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.util.Map; |
||||
import javax.portlet.ResourceURL; |
||||
|
||||
/** |
||||
* Mock implementation of the {@link javax.portlet.ResourceURL} interface. |
||||
* |
||||
* @author Juergen Hoeller |
||||
* @since 3.0 |
||||
*/ |
||||
public class MockResourceURL extends MockBaseURL implements ResourceURL { |
||||
|
||||
private String resourceID; |
||||
|
||||
private String cacheability; |
||||
|
||||
|
||||
//---------------------------------------------------------------------
|
||||
// ResourceURL methods
|
||||
//---------------------------------------------------------------------
|
||||
|
||||
public void setResourceID(String resourceID) { |
||||
this.resourceID = resourceID; |
||||
} |
||||
|
||||
public String getResourceID() { |
||||
return this.resourceID; |
||||
} |
||||
|
||||
public void setCacheability(String cacheLevel) { |
||||
this.cacheability = cacheLevel; |
||||
} |
||||
|
||||
public String getCacheability() { |
||||
return this.cacheability; |
||||
} |
||||
|
||||
|
||||
public String toString() { |
||||
StringBuilder sb = new StringBuilder(); |
||||
sb.append(encodeParameter("resourceID", this.resourceID)); |
||||
if (this.cacheability != null) { |
||||
sb.append(";").append(encodeParameter("cacheability", this.cacheability)); |
||||
} |
||||
for (Map.Entry<String, String[]> entry : this.parameters.entrySet()) { |
||||
sb.append(";").append(encodeParameter("param_" + entry.getKey(), entry.getValue())); |
||||
} |
||||
return (isSecure() ? "https:" : "http:") + |
||||
"//localhost/mockportlet?" + sb.toString(); |
||||
} |
||||
|
||||
} |
@ -0,0 +1,156 @@
@@ -0,0 +1,156 @@
|
||||
/* |
||||
* Copyright 2002-2008 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.IOException; |
||||
import java.io.Serializable; |
||||
import java.util.Collections; |
||||
import java.util.HashMap; |
||||
import java.util.Iterator; |
||||
import java.util.LinkedHashMap; |
||||
import java.util.Map; |
||||
import javax.portlet.ActionResponse; |
||||
import javax.portlet.PortalContext; |
||||
import javax.portlet.PortletMode; |
||||
import javax.portlet.PortletModeException; |
||||
import javax.portlet.WindowState; |
||||
import javax.portlet.WindowStateException; |
||||
import javax.portlet.StateAwareResponse; |
||||
import javax.xml.namespace.QName; |
||||
|
||||
import org.springframework.util.Assert; |
||||
import org.springframework.util.CollectionUtils; |
||||
|
||||
/** |
||||
* Mock implementation of the {@link javax.portlet.StateAwareResponse} interface. |
||||
* |
||||
* @author Juergen Hoeller |
||||
* @since 3.0 |
||||
*/ |
||||
public class MockStateAwareResponse extends MockPortletResponse implements StateAwareResponse { |
||||
|
||||
private WindowState windowState; |
||||
|
||||
private PortletMode portletMode; |
||||
|
||||
private final Map<String, String[]> renderParameters = new LinkedHashMap<String, String[]>(); |
||||
|
||||
private final Map<QName, Serializable> events = new HashMap<QName, Serializable>(); |
||||
|
||||
|
||||
/** |
||||
* Create a new MockActionResponse with a default {@link MockPortalContext}. |
||||
* @see org.springframework.mock.web.portlet.MockPortalContext |
||||
*/ |
||||
public MockStateAwareResponse() { |
||||
super(); |
||||
} |
||||
|
||||
/** |
||||
* Create a new MockActionResponse. |
||||
* @param portalContext the PortalContext defining the supported |
||||
* PortletModes and WindowStates |
||||
*/ |
||||
public MockStateAwareResponse(PortalContext portalContext) { |
||||
super(portalContext); |
||||
} |
||||
|
||||
|
||||
public void setWindowState(WindowState windowState) throws WindowStateException { |
||||
if (!CollectionUtils.contains(getPortalContext().getSupportedWindowStates(), windowState)) { |
||||
throw new WindowStateException("WindowState not supported", windowState); |
||||
} |
||||
this.windowState = windowState; |
||||
} |
||||
|
||||
public WindowState getWindowState() { |
||||
return this.windowState; |
||||
} |
||||
|
||||
public void setPortletMode(PortletMode portletMode) throws PortletModeException { |
||||
if (!CollectionUtils.contains(getPortalContext().getSupportedPortletModes(), portletMode)) { |
||||
throw new PortletModeException("PortletMode not supported", portletMode); |
||||
} |
||||
this.portletMode = portletMode; |
||||
} |
||||
|
||||
public PortletMode getPortletMode() { |
||||
return this.portletMode; |
||||
} |
||||
|
||||
public void setRenderParameters(Map<String, String[]> parameters) { |
||||
Assert.notNull(parameters, "Parameters Map must not be null"); |
||||
this.renderParameters.clear(); |
||||
this.renderParameters.putAll(parameters); |
||||
} |
||||
|
||||
public void setRenderParameter(String key, String value) { |
||||
Assert.notNull(key, "Parameter key must not be null"); |
||||
Assert.notNull(value, "Parameter value must not be null"); |
||||
this.renderParameters.put(key, new String[] {value}); |
||||
} |
||||
|
||||
public void setRenderParameter(String key, String[] values) { |
||||
Assert.notNull(key, "Parameter key must not be null"); |
||||
Assert.notNull(values, "Parameter values must not be null"); |
||||
this.renderParameters.put(key, values); |
||||
} |
||||
|
||||
public String getRenderParameter(String key) { |
||||
Assert.notNull(key, "Parameter key must not be null"); |
||||
String[] arr = this.renderParameters.get(key); |
||||
return (arr != null && arr.length > 0 ? arr[0] : null); |
||||
} |
||||
|
||||
public String[] getRenderParameterValues(String key) { |
||||
Assert.notNull(key, "Parameter key must not be null"); |
||||
return this.renderParameters.get(key); |
||||
} |
||||
|
||||
public Iterator<String> getRenderParameterNames() { |
||||
return this.renderParameters.keySet().iterator(); |
||||
} |
||||
|
||||
public Map<String, String[]> getRenderParameterMap() { |
||||
return Collections.unmodifiableMap(this.renderParameters); |
||||
} |
||||
|
||||
public void removePublicRenderParameter(String name) { |
||||
this.renderParameters.remove(name); |
||||
} |
||||
|
||||
public void setEvent(QName name, Serializable value) { |
||||
this.events.put(name, value); |
||||
} |
||||
|
||||
public void setEvent(String name, Serializable value) { |
||||
this.events.put(new QName(name), value); |
||||
} |
||||
|
||||
public Iterator<QName> getEventNames() { |
||||
return this.events.keySet().iterator(); |
||||
} |
||||
|
||||
public Serializable getEvent(QName name) { |
||||
return this.events.get(name); |
||||
} |
||||
|
||||
public Serializable getEvent(String name) { |
||||
return this.events.get(new QName(name)); |
||||
} |
||||
|
||||
} |
Loading…
Reference in new issue