001: /*
002: * Copyright 2006-2007 The Kuali Foundation.
003: *
004: * Licensed under the Educational Community License, Version 1.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: * http://www.opensource.org/licenses/ecl1.php
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: package org.kuali.core.service.impl;
017:
018: import java.util.Collection;
019: import java.util.HashMap;
020: import java.util.Map;
021:
022: import org.kuali.core.bo.user.AuthenticationUserId;
023: import org.kuali.core.bo.user.UniversalUser;
024: import org.kuali.core.service.UniversalUserService;
025: import org.kuali.kfs.context.KualiTestBase;
026: import org.kuali.kfs.context.SpringContext;
027: import org.kuali.module.chart.bo.ChartUser;
028: import org.kuali.test.ConfigureContext;
029: import org.kuali.test.fixtures.UserNameFixture;
030:
031: @ConfigureContext
032: public class UniversalUserServiceImplTest extends KualiTestBase {
033:
034: /*
035: * Test method for 'org.kuali.core.service.impl.UniversalUserServiceImpl.getUniversalUser(UserId)'
036: */
037: public void testGetUniversalUserUserId() throws Exception {
038: UniversalUser user = SpringContext.getBean(
039: UniversalUserService.class).getUniversalUser(
040: new AuthenticationUserId(UserNameFixture.KHUNTLEY
041: .name()));
042: assertNotNull("user should not be null", user);
043: assertEquals("User ID does not match "
044: + UserNameFixture.KHUNTLEY, UserNameFixture.KHUNTLEY
045: .name(), user.getPersonUserIdentifier());
046: }
047:
048: /*
049: * Test method for 'org.kuali.core.service.impl.UniversalUserServiceImpl.getUniversalUser(String)'
050: */
051: public void testGetUniversalUserString() throws Exception {
052: UniversalUser user = SpringContext.getBean(
053: UniversalUserService.class).getUniversalUser(
054: new AuthenticationUserId(UserNameFixture.KHUNTLEY
055: .name()));
056: assertNotNull("user should not be null", user);
057: assertEquals("User ID does not match "
058: + UserNameFixture.KHUNTLEY, UserNameFixture.KHUNTLEY
059: .name(), user.getPersonUserIdentifier());
060: }
061:
062: /*
063: * Test method for 'org.kuali.core.service.impl.UniversalUserServiceImpl.updateUniversalUserIfNecessary(String, UniversalUser)'
064: */
065: public void testUpdateUniversalUserIfNecessary() throws Exception {
066: UniversalUserService uus = SpringContext
067: .getBean(UniversalUserService.class);
068: UniversalUser user = SpringContext.getBean(
069: UniversalUserService.class).getUniversalUser(
070: new AuthenticationUserId(UserNameFixture.KHUNTLEY
071: .name()));
072: assertNotNull("user should not be null", user);
073: UniversalUser newUser = uus.updateUniversalUserIfNecessary(user
074: .getPersonUniversalIdentifier(), user);
075: assertNotNull("newUser should not be null", newUser);
076: assertNotNull("newUser UUID should not be null", newUser
077: .getPersonUniversalIdentifier());
078: assertSame("user objects should be the same", user, newUser);
079: UniversalUser user2 = SpringContext.getBean(
080: UniversalUserService.class).getUniversalUser(
081: new AuthenticationUserId(UserNameFixture.CSWINSON
082: .name()));
083: assertNotNull("user2 should not be null", user2);
084: newUser = uus.updateUniversalUserIfNecessary(user2
085: .getPersonUniversalIdentifier(), user);
086: assertNotNull("newUser should not be null", newUser);
087: assertNotNull("newUser UUID should not be null", newUser
088: .getPersonUniversalIdentifier());
089: assertNotSame("user objects should not be the same", user,
090: newUser);
091: assertEquals("new user object should match the source object",
092: user2, newUser);
093: }
094:
095: public void testLoadModuleUserProperties() throws Exception {
096: UniversalUserService uus = SpringContext
097: .getBean(UniversalUserService.class);
098: UniversalUser user = SpringContext.getBean(
099: UniversalUserService.class).getUniversalUser(
100: new AuthenticationUserId(UserNameFixture.KHUNTLEY
101: .name()));
102: Map<String, Map<String, String>> userProps = uus
103: .loadModuleUserProperties(user);
104: assertNotNull("userProps must not be null", userProps);
105: assertNotNull("userProps must have a chart entry", userProps
106: .get(ChartUser.MODULE_ID));
107: assertNotNull("userProps(chart) must have an active entry",
108: userProps.get(ChartUser.MODULE_ID).get("active"));
109: }
110:
111: public void testSearchByUserActiveStatus() throws Exception {
112: HashMap<String, String> fieldValues = new HashMap<String, String>();
113: fieldValues.put("personUserIdentifier", "AA*");
114:
115: Collection allUsers = SpringContext.getBean(
116: UniversalUserService.class).findUniversalUsers(
117: fieldValues);
118: System.out.println("all AA* users: " + allUsers.size());
119: assertTrue("search by AA* must return rows",
120: allUsers.size() > 0);
121:
122: fieldValues.put("activeModuleCodeString", "CA");
123:
124: Collection searchResults2 = SpringContext.getBean(
125: UniversalUserService.class).findUniversalUsers(
126: fieldValues);
127: System.out.println("CA module users: " + searchResults2.size());
128: System.out.println("CA module users: " + searchResults2);
129:
130: fieldValues.put("activeModuleCodeString", "FP");
131: Collection searchResults3 = SpringContext.getBean(
132: UniversalUserService.class).findUniversalUsers(
133: fieldValues);
134: System.out.println("FP module users: " + searchResults3.size());
135: System.out.println("FP module users: " + searchResults3);
136: assertEquals("search results size for CA must match FP",
137: searchResults2.size(), searchResults3.size());
138:
139: fieldValues.put("activeModuleCodeString", "PA");
140: Collection searchResults4 = SpringContext.getBean(
141: UniversalUserService.class).findUniversalUsers(
142: fieldValues);
143:
144: System.out.println("Purap module users: "
145: + searchResults4.size());
146: }
147: }
|