001: package edu.iu.uis.eden.user;
002:
003: import junit.framework.TestCase;
004: import edu.iu.uis.eden.SpringServiceLocator;
005: import edu.iu.uis.eden.applicationconstants.ApplicationConstant;
006: import edu.iu.uis.eden.applicationconstants.ApplicationConstantsService;
007: import edu.iu.uis.eden.cache.ApplicationConstantsCache;
008: import edu.iu.uis.eden.user.impl.IUWorkflowUser;
009: import edu.iu.uis.eden.util.Utilities;
010: import edu.iu.uis.sit.cache.Cache;
011:
012: public class UserTester extends TestCase {
013:
014: private UserService userService;
015: private ApplicationConstantsService constantsService;
016:
017: private String authenticationName = "phooten";
018:
019: private String workflowId = "100000000000";
020:
021: protected void setUp() throws Exception {
022: SpringServiceLocator.setToTestMode(null);
023: Cache cache = (Cache) SpringServiceLocator
024: .getService(SpringServiceLocator.CACHE_MANAGER);
025: ApplicationConstantsCache applicationConstantsCache = new ApplicationConstantsCache();
026: applicationConstantsCache.reload();
027: cache.add(applicationConstantsCache);
028: Utilities.seedCache(cache);
029: userService = (UserService) SpringServiceLocator
030: .getService(SpringServiceLocator.USER_SERVICE);
031: constantsService = (ApplicationConstantsService) SpringServiceLocator
032: .getService(SpringServiceLocator.CONSTANTS_SERVICE);
033: }
034:
035: public void testUserFetchByAuthenticationId() throws Exception {
036: WorkflowUser user = userService
037: .getWorkflowUser(new AuthenticationUserId(
038: authenticationName));
039:
040: assertNotNull(user);
041: assertEquals(user.getAuthenticationUserId()
042: .getAuthenticationId(), authenticationName);
043: assertEquals(user.getWorkflowUserId().getWorkflowId(),
044: "100000000085");
045: }
046:
047: // public void testUserFetchByUUID() throws Exception {
048: // WorkflowUser user = userService.getWorkflowUser(new
049: // IUUserId(IUUserId.UUID,"1000128501"));
050: // assertNotNull(user);
051: // assertEquals(user.getEmplId(), "0001808586");
052: // assertEquals(user.getAuthenticationId(), "jacscamp");
053: // assertEquals(user.getUuId(), "1000128501");
054: // assertEquals(user.getWorkflowId(), "100000000012");
055: // }
056: //
057: // public void testUserFetchByEmplid() throws Exception {
058: // WorkflowUser user = userService.getWorkflowUser(new
059: // IUUserId(IUUserId.EMPLID,"0001808586"));
060: // assertNotNull(user);
061: // assertEquals(user.getEmplId(), "0001808586");
062: // assertEquals(user.getAuthenticationId(), "jacscamp");
063: // assertEquals(user.getUuId(), "1000128501");
064: // assertEquals(user.getWorkflowId(), "100000000012");
065: // }
066:
067: public void testUserFetchByWorkflowId() throws Exception {
068: WorkflowUser user = userService
069: .getWorkflowUser(new WorkflowUserId(workflowId));
070: assertNotNull(user);
071: assertEquals(user.getAuthenticationUserId()
072: .getAuthenticationId(), "nbaxter");
073: assertEquals(user.getWorkflowUserId().getWorkflowId(),
074: workflowId);
075: }
076:
077: public void testUserFetchCachesCorrectly() throws Exception {
078: // get the cache value and save it off in a temp...
079: String minutesToSave = Utilities
080: .getApplicationConstant("Config.Application.MinutesToCacheUsers");
081: ApplicationConstant constant = constantsService
082: .findByName("Config.Application.MinutesToCacheUsers");
083: constant.setApplicationConstantValue("1");
084: constantsService.save(constant);
085: Thread.sleep(10 * 1000);
086:
087: WorkflowUser user1 = userService
088: .getWorkflowUser(new AuthenticationUserId("bmcgough"));
089: Thread.sleep(65 * 1000);
090: WorkflowUser user2 = userService
091: .getWorkflowUser(new AuthenticationUserId("bmcgough"));
092: if (((IUWorkflowUser) user1).getLastUpdateDate().equals(
093: ((IUWorkflowUser) user2).getLastUpdateDate())) {
094: fail("users last update timestamp were the same and should not have been");
095: } else {
096: }
097:
098: WorkflowUser user3 = userService
099: .getWorkflowUser(new AuthenticationUserId("bmcgough"));
100: WorkflowUser user4 = userService
101: .getWorkflowUser(new AuthenticationUserId("bmcgough"));
102: if (((IUWorkflowUser) user3).getLastUpdateDate().equals(
103: ((IUWorkflowUser) user4).getLastUpdateDate())) {
104: } else {
105: fail("users last update timestamp were the same and should not have been");
106: }
107:
108: constant = constantsService
109: .findByName("Config.Application.MinutesToCacheUsers");
110: constant.setApplicationConstantValue(minutesToSave);
111: constantsService.save(constant);
112:
113: Thread.sleep(65 * 1000);
114: }
115:
116: }
|