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.ArrayList; 020import java.util.Collections; 021import java.util.Enumeration; 022import java.util.HashMap; 023import java.util.List; 024import java.util.Map; 025import javax.portlet.PortalContext; 026import javax.portlet.PortletMode; 027import javax.portlet.WindowState; 028 029/** 030 * Mock implementation of the {@link javax.portlet.PortalContext} interface. 031 * 032 * @author John A. Lewis 033 * @author Juergen Hoeller 034 * @since 2.0 035 */ 036public class MockPortalContext implements PortalContext { 037 038 private final Map<String, String> properties = new HashMap<String, String>(); 039 040 private final List<PortletMode> portletModes; 041 042 private final List<WindowState> windowStates; 043 044 045 /** 046 * Create a new MockPortalContext 047 * with default PortletModes (VIEW, EDIT, HELP) 048 * and default WindowStates (NORMAL, MAXIMIZED, MINIMIZED). 049 * @see javax.portlet.PortletMode 050 * @see javax.portlet.WindowState 051 */ 052 public MockPortalContext() { 053 this.portletModes = new ArrayList<PortletMode>(3); 054 this.portletModes.add(PortletMode.VIEW); 055 this.portletModes.add(PortletMode.EDIT); 056 this.portletModes.add(PortletMode.HELP); 057 058 this.windowStates = new ArrayList<WindowState>(3); 059 this.windowStates.add(WindowState.NORMAL); 060 this.windowStates.add(WindowState.MAXIMIZED); 061 this.windowStates.add(WindowState.MINIMIZED); 062 } 063 064 /** 065 * Create a new MockPortalContext with the given PortletModes and WindowStates. 066 * @param supportedPortletModes the List of supported PortletMode instances 067 * @param supportedWindowStates the List of supported WindowState instances 068 * @see javax.portlet.PortletMode 069 * @see javax.portlet.WindowState 070 */ 071 public MockPortalContext(List<PortletMode> supportedPortletModes, List<WindowState> supportedWindowStates) { 072 this.portletModes = new ArrayList<PortletMode>(supportedPortletModes); 073 this.windowStates = new ArrayList<WindowState>(supportedWindowStates); 074 } 075 076 077 @Override 078 public String getPortalInfo() { 079 return "MockPortal/1.0"; 080 } 081 082 public void setProperty(String name, String value) { 083 this.properties.put(name, value); 084 } 085 086 @Override 087 public String getProperty(String name) { 088 return this.properties.get(name); 089 } 090 091 @Override 092 public Enumeration<String> getPropertyNames() { 093 return Collections.enumeration(this.properties.keySet()); 094 } 095 096 @Override 097 public Enumeration<PortletMode> getSupportedPortletModes() { 098 return Collections.enumeration(this.portletModes); 099 } 100 101 @Override 102 public Enumeration<WindowState> getSupportedWindowStates() { 103 return Collections.enumeration(this.windowStates); 104 } 105 106}