001: /*
002: * Copyright 2005-2007 The Kuali Foundation.
003: *
004: *
005: * Licensed under the Educational Community License, Version 1.0 (the "License");
006: * you may not use this file except in compliance with the License.
007: * You may obtain a copy of the License at
008: *
009: * http://www.opensource.org/licenses/ecl1.php
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 edu.iu.uis.eden.user;
018:
019: import org.junit.Test;
020: import org.kuali.workflow.test.WorkflowTestCase;
021:
022: import edu.iu.uis.eden.KEWServiceLocator;
023: import edu.iu.uis.eden.clientapp.vo.EmplIdVO;
024: import edu.iu.uis.eden.clientapp.vo.NetworkIdVO;
025: import edu.iu.uis.eden.clientapp.vo.UuIdVO;
026: import edu.iu.uis.eden.clientapp.vo.WorkflowIdVO;
027: import edu.iu.uis.eden.exception.EdenUserNotFoundException;
028:
029: public class UserServiceTest extends WorkflowTestCase {
030:
031: private UserService userService;
032:
033: protected void loadTestData() throws Exception {
034: loadXmlFile("UserConfig.xml");
035: }
036:
037: protected void setUpTransaction() throws Exception {
038: userService = KEWServiceLocator.getUserService();
039: }
040:
041: /**
042: * Tests the retrieval of users from the service. There are quite a few users in the default data set that
043: * we will query for.
044: */
045: @Test
046: public void testGetWorkflowUser() throws Exception {
047: // should be 'ewestfal', check all of the values on the user object to assert that the XML import is functioning properly
048: WorkflowUser user = userService
049: .getWorkflowUser(new WorkflowUserId("1"));
050: assertNotNull(user);
051: assertEquals("1", user.getWorkflowId());
052: assertEquals("1", user.getEmplId().getEmplId());
053: assertEquals("1", user.getUuId().getUuId());
054: assertEquals("ewestfal", user.getAuthenticationUserId()
055: .getAuthenticationId());
056: assertEquals("ewestfal@indiana.edu", user.getEmailAddress());
057: assertEquals("Eric Westfall", user.getDisplayName());
058: assertEquals("Eric", user.getGivenName());
059: assertEquals("Westfall", user.getLastName());
060:
061: // get 'ewestfal' by authentication id
062: user = userService.getWorkflowUser(new AuthenticationUserId(
063: "ewestfal"));
064: assertNotNull(user);
065: assertEquals("1", user.getWorkflowId());
066: assertEquals("ewestfal", user.getAuthenticationUserId()
067: .getAuthenticationId());
068:
069: // get 'ewestfal' by empl id
070: user = userService.getWorkflowUser(new EmplId("1"));
071: assertNotNull(user);
072: assertEquals("1", user.getWorkflowId());
073: assertEquals("ewestfal", user.getAuthenticationUserId()
074: .getAuthenticationId());
075:
076: // get 'ewestfal' by uuid
077: user = userService.getWorkflowUser(new UuId("1"));
078: assertNotNull(user);
079: assertEquals("1", user.getWorkflowId());
080: assertEquals("ewestfal", user.getAuthenticationUserId()
081: .getAuthenticationId());
082:
083: // check the VO version of the same method
084:
085: //get 'ewestfal' by workflow id VO
086: user = userService.getWorkflowUser(new WorkflowIdVO("1"));
087: assertNotNull(user);
088: assertEquals("1", user.getWorkflowId());
089: assertEquals("ewestfal", user.getAuthenticationUserId()
090: .getAuthenticationId());
091:
092: // get 'ewestfal' by authentication id VO
093: user = userService.getWorkflowUser(new NetworkIdVO("ewestfal"));
094: assertNotNull(user);
095: assertEquals("1", user.getWorkflowId());
096: assertEquals("ewestfal", user.getAuthenticationUserId()
097: .getAuthenticationId());
098:
099: // get 'ewestfal' by empl id VO
100: user = userService.getWorkflowUser(new EmplIdVO("1"));
101: assertNotNull(user);
102: assertEquals("1", user.getWorkflowId());
103: assertEquals("ewestfal", user.getAuthenticationUserId()
104: .getAuthenticationId());
105:
106: // get 'ewestfal' by uuid VO
107: user = userService.getWorkflowUser(new UuIdVO("1"));
108: assertNotNull(user);
109: assertEquals("1", user.getWorkflowId());
110: assertEquals("ewestfal", user.getAuthenticationUserId()
111: .getAuthenticationId());
112:
113: // Try fetching a different user, UserServiceTestUser
114:
115: user = userService.getWorkflowUser(new WorkflowUserId(
116: "123456789"));
117: assertNotNull(user);
118: assertEquals("123456789", user.getWorkflowId());
119: assertEquals("UserServiceTestUser", user
120: .getAuthenticationUserId().getAuthenticationId());
121:
122: user = userService.getWorkflowUser(new AuthenticationUserId(
123: "UserServiceTestUser"));
124: assertNotNull(user);
125: assertEquals("123456789", user.getWorkflowId());
126: assertEquals("UserServiceTestUser", user
127: .getAuthenticationUserId().getAuthenticationId());
128:
129: user = userService.getWorkflowUser(new EmplId("00abc987123"));
130: assertNotNull(user);
131: assertEquals("123456789", user.getWorkflowId());
132: assertEquals("UserServiceTestUser", user
133: .getAuthenticationUserId().getAuthenticationId());
134:
135: user = userService.getWorkflowUser(new UuId("1029384756"));
136: assertNotNull(user);
137: assertEquals("123456789", user.getWorkflowId());
138: assertEquals("UserServiceTestUser", user
139: .getAuthenticationUserId().getAuthenticationId());
140:
141: // Now try fetching some bad users and watch the EdenUserNotFoundExceptions fly...
142:
143: try {
144: user = userService
145: .getWorkflowUser(new AuthenticationUserId(
146: "BadIdWhichWillNeverReturnAUser,NotInAMillionYears"));
147: fail("Bad id should have thrown an exception.");
148: } catch (EdenUserNotFoundException e) {
149: }
150:
151: try {
152: user = userService
153: .getWorkflowUser(new WorkflowUserId("-1"));
154: fail("Bad id should have thrown an exception.");
155: } catch (EdenUserNotFoundException e) {
156: }
157:
158: // try fetching with a null id, should throw IllegalArgumentException
159: try {
160: user = userService.getWorkflowUser((UserId) null);
161: fail("Passing null should have thrown an exception");
162: } catch (IllegalArgumentException e) {
163: }
164:
165: // try fetching with a null "wrapped" id, should throw EdenUserNotFoundException
166: try {
167: user = userService
168: .getWorkflowUser(new AuthenticationUserId(null));
169: fail("Null id should have thrown an exception");
170: } catch (EdenUserNotFoundException e) {
171: }
172:
173: }
174:
175: @Test
176: public void testGetBlankUser() throws Exception {
177: // the service implementation used by the tests is the one which comes out of the box, so we should be
178: // creating instances of SimpleUsers
179: WorkflowUser blankUser = userService.getBlankUser();
180: assertNotNull(blankUser);
181: }
182:
183: }
|