1 /*
2  * Copyright 2002-2009 the original author or authors.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package org.springframework.mock.web.portlet;
18 
19 import java.util.ArrayList;
20 import java.util.Collections;
21 import java.util.Enumeration;
22 import java.util.HashMap;
23 import java.util.List;
24 import java.util.Map;
25 import javax.portlet.PortalContext;
26 import javax.portlet.PortletMode;
27 import javax.portlet.WindowState;
28 
29 /**
30  * Mock implementation of the {@link javax.portlet.PortalContext} interface.
31  *
32  * @author John A. Lewis
33  * @author Juergen Hoeller
34  * @since 2.0
35  */
36 public class MockPortalContext implements PortalContext {
37 
38 	private final Map<String, String> properties = new HashMap<String, String>();
39 
40 	private final List<PortletMode> portletModes;
41 
42 	private final List<WindowState> windowStates;
43 
44 
45 	/**
46 	 * Create a new MockPortalContext
47 	 * with default PortletModes (VIEW, EDIT, HELP)
48 	 * and default WindowStates (NORMAL, MAXIMIZED, MINIMIZED).
49 	 * @see javax.portlet.PortletMode
50 	 * @see javax.portlet.WindowState
51 	 */
MockPortalContext()52 	public MockPortalContext() {
53 		this.portletModes = new ArrayList<PortletMode>(3);
54 		this.portletModes.add(PortletMode.VIEW);
55 		this.portletModes.add(PortletMode.EDIT);
56 		this.portletModes.add(PortletMode.HELP);
57 
58 		this.windowStates = new ArrayList<WindowState>(3);
59 		this.windowStates.add(WindowState.NORMAL);
60 		this.windowStates.add(WindowState.MAXIMIZED);
61 		this.windowStates.add(WindowState.MINIMIZED);
62 	}
63 
64 	/**
65 	 * Create a new MockPortalContext with the given PortletModes and WindowStates.
66 	 * @param supportedPortletModes the List of supported PortletMode instances
67 	 * @param supportedWindowStates the List of supported WindowState instances
68 	 * @see javax.portlet.PortletMode
69 	 * @see javax.portlet.WindowState
70 	 */
MockPortalContext(List<PortletMode> supportedPortletModes, List<WindowState> supportedWindowStates)71 	public MockPortalContext(List<PortletMode> supportedPortletModes, List<WindowState> supportedWindowStates) {
72 		this.portletModes = new ArrayList<PortletMode>(supportedPortletModes);
73 		this.windowStates = new ArrayList<WindowState>(supportedWindowStates);
74 	}
75 
76 
getPortalInfo()77 	public String getPortalInfo() {
78 		return "MockPortal/1.0";
79 	}
80 
setProperty(String name, String value)81 	public void setProperty(String name, String value) {
82 		this.properties.put(name, value);
83 	}
84 
getProperty(String name)85 	public String getProperty(String name) {
86 		return this.properties.get(name);
87 	}
88 
getPropertyNames()89 	public Enumeration<String> getPropertyNames() {
90 		return Collections.enumeration(this.properties.keySet());
91 	}
92 
getSupportedPortletModes()93 	public Enumeration<PortletMode> getSupportedPortletModes() {
94 		return Collections.enumeration(this.portletModes);
95 	}
96 
getSupportedWindowStates()97 	public Enumeration<WindowState> getSupportedWindowStates() {
98 		return Collections.enumeration(this.windowStates);
99 	}
100 
101 }
102