001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package org.apache.pluto.driver.services.impl;
018:
019: import java.io.IOException;
020: import java.security.Principal;
021: import java.util.Enumeration;
022: import java.util.Locale;
023: import java.util.Map;
024: import java.util.Properties;
025:
026: import javax.portlet.PortalContext;
027: import javax.portlet.PortletMode;
028: import javax.portlet.PortletPreferences;
029: import javax.portlet.PortletRequest;
030: import javax.portlet.PortletSession;
031: import javax.portlet.WindowState;
032:
033: import org.apache.pluto.PortletContainerException;
034: import org.apache.pluto.spi.optional.P3PAttributes;
035:
036: import junit.framework.TestCase;
037:
038: /**
039: * JUnit test class for UserInfoAttributesServicesImpl.
040: *
041: */
042: public class UserInfoAttributesServicesImplTest extends TestCase {
043: /* Represents properties in user-info-attributes.properties */
044: private Properties props = new Properties();
045: //Test data
046: /* Test user - used in MockPortletRequest */
047: private static final String TEST_REMOTE_USER = "tomcat";
048: private static final String TEST_USER_GENDER = "male";
049: private static final String TEST_USER_NAME_GIVEN = "Catalina";
050: private static final String TEST_USER_NAME_FAMILY = "Tomcat";
051:
052: protected void setUp() throws Exception {
053: super .setUp();
054: props.setProperty(TEST_REMOTE_USER + "."
055: + P3PAttributes.USER_GENDER, TEST_USER_GENDER);
056: props.setProperty(TEST_REMOTE_USER + "."
057: + P3PAttributes.USER_NAME_GIVEN, TEST_USER_NAME_GIVEN);
058: props
059: .setProperty(TEST_REMOTE_USER + "."
060: + P3PAttributes.USER_NAME_FAMILY,
061: TEST_USER_NAME_FAMILY);
062: }
063:
064: /*
065: * Test method for 'org.apache.pluto.services.optional.UserInfoAttributesServiceImpl.getUserInfo(PortletRequest)'
066: */
067: public void testGetAttributes() {
068: try {
069: Map map = null;
070: UserInfoAttributesServiceImpl uias = UserInfoAttributesServiceImpl
071: .getInstance(props);
072: PortletRequest pr = new MockPortletRequest();
073: map = uias.getUserInfo(pr);
074: String sex = (String) map.get(P3PAttributes.USER_GENDER);
075: assertTrue(sex.equals(TEST_USER_GENDER));
076: System.out.println("Sex: " + sex);
077: String fname = (String) map
078: .get(P3PAttributes.USER_NAME_GIVEN);
079: assertTrue(fname.equals(TEST_USER_NAME_GIVEN));
080: System.out.println("first name: " + fname);
081: String lname = (String) map
082: .get(P3PAttributes.USER_NAME_FAMILY);
083: assertTrue(lname.equals(TEST_USER_NAME_FAMILY));
084: System.out.println("last name: " + lname);
085: } catch (IOException e) {
086: e.printStackTrace();
087: fail(e.toString());
088: } catch (PortletContainerException e) {
089: e.printStackTrace();
090: fail(e.toString());
091: }
092: }
093:
094: /**
095: * Stubbed implementation used only by this class where only
096: * getRemoteUser() has been implemented to return a constant.
097: *
098: */
099: public class MockPortletRequest implements PortletRequest {
100:
101: public boolean isWindowStateAllowed(WindowState arg0) {
102: // TODO Auto-generated method stub
103: return false;
104: }
105:
106: public boolean isPortletModeAllowed(PortletMode arg0) {
107: // TODO Auto-generated method stub
108: return false;
109: }
110:
111: public PortletMode getPortletMode() {
112: // TODO Auto-generated method stub
113: return null;
114: }
115:
116: public WindowState getWindowState() {
117: // TODO Auto-generated method stub
118: return null;
119: }
120:
121: public PortletPreferences getPreferences() {
122: // TODO Auto-generated method stub
123: return null;
124: }
125:
126: public PortletSession getPortletSession() {
127: // TODO Auto-generated method stub
128: return null;
129: }
130:
131: public PortletSession getPortletSession(boolean arg0) {
132: // TODO Auto-generated method stub
133: return null;
134: }
135:
136: public String getProperty(String arg0) {
137: // TODO Auto-generated method stub
138: return null;
139: }
140:
141: public Enumeration getProperties(String arg0) {
142: // TODO Auto-generated method stub
143: return null;
144: }
145:
146: public Enumeration getPropertyNames() {
147: // TODO Auto-generated method stub
148: return null;
149: }
150:
151: public PortalContext getPortalContext() {
152: // TODO Auto-generated method stub
153: return null;
154: }
155:
156: public String getAuthType() {
157: // TODO Auto-generated method stub
158: return null;
159: }
160:
161: public String getContextPath() {
162: // TODO Auto-generated method stub
163: return null;
164: }
165:
166: public String getRemoteUser() {
167: return TEST_REMOTE_USER;
168: }
169:
170: public Principal getUserPrincipal() {
171: // TODO Auto-generated method stub
172: return null;
173: }
174:
175: public boolean isUserInRole(String arg0) {
176: // TODO Auto-generated method stub
177: return false;
178: }
179:
180: public Object getAttribute(String arg0) {
181: // TODO Auto-generated method stub
182: return null;
183: }
184:
185: public Enumeration getAttributeNames() {
186: // TODO Auto-generated method stub
187: return null;
188: }
189:
190: public String getParameter(String arg0) {
191: // TODO Auto-generated method stub
192: return null;
193: }
194:
195: public Enumeration getParameterNames() {
196: // TODO Auto-generated method stub
197: return null;
198: }
199:
200: public String[] getParameterValues(String arg0) {
201: // TODO Auto-generated method stub
202: return null;
203: }
204:
205: public Map getParameterMap() {
206: // TODO Auto-generated method stub
207: return null;
208: }
209:
210: public boolean isSecure() {
211: // TODO Auto-generated method stub
212: return false;
213: }
214:
215: public void setAttribute(String arg0, Object arg1) {
216: // TODO Auto-generated method stub
217:
218: }
219:
220: public void removeAttribute(String arg0) {
221: // TODO Auto-generated method stub
222:
223: }
224:
225: public String getRequestedSessionId() {
226: // TODO Auto-generated method stub
227: return null;
228: }
229:
230: public boolean isRequestedSessionIdValid() {
231: // TODO Auto-generated method stub
232: return false;
233: }
234:
235: public String getResponseContentType() {
236: // TODO Auto-generated method stub
237: return null;
238: }
239:
240: public Enumeration getResponseContentTypes() {
241: // TODO Auto-generated method stub
242: return null;
243: }
244:
245: public Locale getLocale() {
246: // TODO Auto-generated method stub
247: return null;
248: }
249:
250: public Enumeration getLocales() {
251: // TODO Auto-generated method stub
252: return null;
253: }
254:
255: public String getScheme() {
256: // TODO Auto-generated method stub
257: return null;
258: }
259:
260: public String getServerName() {
261: // TODO Auto-generated method stub
262: return null;
263: }
264:
265: public int getServerPort() {
266: // TODO Auto-generated method stub
267: return 0;
268: }
269:
270: }
271: }
|