001: /* Copyright 2005 The JA-SIG Collaborative. All rights reserved.
002: * See license distributed with this file and
003: * available online at http://www.uportal.org/license.html
004: */
005:
006: package org.jasig.portal.groups;
007:
008: import java.util.HashMap;
009: import java.util.Map;
010:
011: import org.jasig.portal.security.IPerson;
012: import org.jasig.portal.services.persondir.IPersonAttributeDao;
013: import org.jasig.portal.services.persondir.support.ComplexStubPersonAttributeDao;
014:
015: import junit.framework.TestCase;
016:
017: /**
018: * Testcase for PersonDirNameFinder
019: * @version $Revision: 35537 $ $Date: 2005-04-11 08:59:54 -0700 (Mon, 11 Apr 2005) $
020: */
021: public class PersonDirNameFinderTest extends TestCase {
022:
023: /**
024: * Test PersonDirNameFinder instance backed by a stub
025: * IPersonAttributeDao.
026: */
027: PersonDirNameFinder finder;
028:
029: protected void setUp() throws Exception {
030: super .setUp();
031:
032: Map userWithDisplayNameAttributes = new HashMap();
033: userWithDisplayNameAttributes.put("phone", "777-7777");
034: userWithDisplayNameAttributes
035: .put("displayName", "Display Name");
036:
037: Map userWithEmptyDisplayNameAttributes = new HashMap();
038: userWithEmptyDisplayNameAttributes.put("phone", "888-8888");
039: userWithEmptyDisplayNameAttributes.put("displayName", "");
040:
041: Map userWithoutDisplayNameAttributes = new HashMap();
042: userWithoutDisplayNameAttributes.put("phone", "666-6666");
043: userWithoutDisplayNameAttributes.put("givenName", "Howard");
044:
045: Map daoBackingMap = new HashMap();
046:
047: daoBackingMap.put("userWithDisplayName",
048: userWithDisplayNameAttributes);
049: daoBackingMap.put("userWithEmptyDisplayName",
050: userWithEmptyDisplayNameAttributes);
051: daoBackingMap.put("userWithoutDisplayName",
052: userWithoutDisplayNameAttributes);
053:
054: IPersonAttributeDao paDao = new ComplexStubPersonAttributeDao(
055: daoBackingMap);
056:
057: this .finder = new PersonDirNameFinder(paDao);
058:
059: }
060:
061: protected void tearDown() throws Exception {
062: super .tearDown();
063: }
064:
065: /**
066: * Test getting the display name for a user.
067: */
068: public void testGetName() {
069: assertEquals("Display Name", this .finder
070: .getName("userWithDisplayName"));
071: }
072:
073: public void testGetNameWhereDisplayNameEmpty() {
074: assertEquals("userWithEmptyDisplayName", this .finder
075: .getName("userWithEmptyDisplayName"));
076: }
077:
078: /**
079: * Test that getting the name for a user without a display name returns the
080: * uid.
081: */
082: public void testGetNameWhereNoDisplayName() {
083: assertEquals("userWithoutDisplayName", this .finder
084: .getName("userWithoutDisplayName"));
085: }
086:
087: /**
088: * Test that getting the name for an unknown user returns the uid.
089: */
090: public void testGetNameUnknownUser() {
091: assertEquals("unknownUser", this .finder.getName("unknownUser"));
092: }
093:
094: /**
095: * Test getting display name for several users. Uses individual users tested
096: * in other test methods in this testcase.
097: */
098: public void testGetNames() {
099: String[] keys = { "userWithDisplayName",
100: "userWithEmptyDisplayName", "userWithoutDisplayName",
101: "unknownUser" };
102:
103: Map expected = new HashMap();
104: expected.put("userWithDisplayName", "Display Name");
105: expected.put("userWithEmptyDisplayName",
106: "userWithEmptyDisplayName");
107: expected
108: .put("userWithoutDisplayName", "userWithoutDisplayName");
109: expected.put("unknownUser", "unknownUser");
110:
111: assertEquals(expected, this .finder.getNames(keys));
112: }
113:
114: /**
115: * Test that PersonDirNameFinders report their type as being IPerson.
116: */
117: public void testGetType() {
118: assertEquals(IPerson.class, this.finder.getType());
119: }
120:
121: }
|