001/*
002 * Copyright 2002-2012 the original author or authors.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *      https://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016
017package org.springframework.mock.web.portlet;
018
019import java.util.Collections;
020import java.util.LinkedHashMap;
021import java.util.Map;
022import javax.portlet.PortalContext;
023import javax.portlet.PortletContext;
024import javax.portlet.RenderRequest;
025import javax.portlet.ResourceRequest;
026
027/**
028 * Mock implementation of the {@link javax.portlet.ResourceRequest} interface.
029 *
030 * @author Juergen Hoeller
031 * @since 3.0
032 */
033public class MockResourceRequest extends MockClientDataRequest implements ResourceRequest {
034
035        private String resourceID;
036
037        private String cacheability;
038
039        private final Map<String, String[]> privateRenderParameterMap = new LinkedHashMap<String, String[]>();
040
041
042        /**
043         * Create a new MockResourceRequest with a default {@link MockPortalContext}
044         * and a default {@link MockPortletContext}.
045         * @see org.springframework.mock.web.portlet.MockPortalContext
046         * @see org.springframework.mock.web.portlet.MockPortletContext
047         */
048        public MockResourceRequest() {
049                super();
050        }
051
052        /**
053         * Create a new MockResourceRequest with a default {@link MockPortalContext}
054         * and a default {@link MockPortletContext}.
055         * @param resourceID the resource id for this request
056         */
057        public MockResourceRequest(String resourceID) {
058                super();
059                this.resourceID = resourceID;
060        }
061
062        /**
063         * Create a new MockResourceRequest with a default {@link MockPortalContext}
064         * and a default {@link MockPortletContext}.
065         * @param url the resource URL for this request
066         */
067        public MockResourceRequest(MockResourceURL url) {
068                super();
069                this.resourceID = url.getResourceID();
070                this.cacheability = url.getCacheability();
071        }
072
073        /**
074         * Create a new MockResourceRequest with a default {@link MockPortalContext}.
075         * @param portletContext the PortletContext that the request runs in
076         */
077        public MockResourceRequest(PortletContext portletContext) {
078                super(portletContext);
079        }
080
081        /**
082         * Create a new MockResourceRequest.
083         * @param portalContext the PortalContext that the request runs in
084         * @param portletContext the PortletContext that the request runs in
085         */
086        public MockResourceRequest(PortalContext portalContext, PortletContext portletContext) {
087                super(portalContext, portletContext);
088        }
089
090
091        @Override
092        protected String getLifecyclePhase() {
093                return RESOURCE_PHASE;
094        }
095
096        public void setResourceID(String resourceID) {
097                this.resourceID = resourceID;
098        }
099
100        @Override
101        public String getResourceID() {
102                return this.resourceID;
103        }
104
105        public void setCacheability(String cacheLevel) {
106                this.cacheability = cacheLevel;
107        }
108
109        @Override
110        public String getCacheability() {
111                return this.cacheability;
112        }
113
114        @Override
115        public String getETag() {
116                return getProperty(RenderRequest.ETAG);
117        }
118
119        public void addPrivateRenderParameter(String key, String value) {
120                this.privateRenderParameterMap.put(key, new String[] {value});
121        }
122
123        public void addPrivateRenderParameter(String key, String[] values) {
124                this.privateRenderParameterMap.put(key, values);
125        }
126
127        @Override
128        public Map<String, String[]> getPrivateRenderParameterMap() {
129                return Collections.unmodifiableMap(this.privateRenderParameterMap);
130        }
131
132}