001: /*
002: * Copyright 2005-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:
017: package org.kuali.core.workflow.service;
018:
019: import org.kuali.kfs.context.KualiTestBase;
020: import org.kuali.kfs.context.SpringContext;
021: import org.kuali.test.ConfigureContext;
022:
023: import edu.iu.uis.eden.clientapp.vo.NetworkIdVO;
024: import edu.iu.uis.eden.clientapp.vo.UserVO;
025: import edu.iu.uis.eden.exception.EdenUserNotFoundException;
026: import edu.iu.uis.eden.exception.WorkflowException;
027:
028: /**
029: * This class tests the WorkflowUser service.
030: */
031: @ConfigureContext
032: public class WorkflowInfoServiceTest extends KualiTestBase {
033: private static final String KNOWN_USERNAME = "KHUNTLEY";
034:
035: public final void testGetWorkflowUser_nullUserId() throws Exception {
036: boolean failedAsExpected = false;
037:
038: try {
039: SpringContext.getBean(KualiWorkflowInfo.class)
040: .getWorkflowUser(null);
041: } catch (WorkflowException e) {
042: failedAsExpected = true;
043: }
044:
045: assertTrue("nullUserId failed to fail properly",
046: failedAsExpected);
047: }
048:
049: public final void testGetWorkflowUser_blankAuthenticationUserId()
050: throws Exception {
051: boolean failedAsExpected = false;
052:
053: try {
054: SpringContext.getBean(KualiWorkflowInfo.class)
055: .getWorkflowUser(new NetworkIdVO());
056: } catch (WorkflowException e) {
057: failedAsExpected = true;
058: }
059:
060: assertTrue(
061: "blank authenticationUserId failed to fail properly",
062: failedAsExpected);
063: }
064:
065: public final void testGetWorkflowUser_unknownAuthenticationUserId()
066: throws Exception {
067: boolean failedAsExpected = false;
068:
069: try {
070: SpringContext.getBean(KualiWorkflowInfo.class)
071: .getWorkflowUser(new NetworkIdVO("unknownUserId"));
072: } catch (WorkflowException we) {
073: // in the case of embedded mode, we get the actual EdenUserNotFoundException as the cause of the WorkflowException
074: if (we
075: .getMessage()
076: .startsWith(
077: "edu.iu.uis.eden.exception.WorkflowException: edu.iu.uis.eden.exception.EdenUserNotFoundException")
078: || we.getCause() instanceof EdenUserNotFoundException) {
079: failedAsExpected = true;
080: }
081: }
082:
083: assertTrue(
084: "unknown authenticationUserId failed to fail properly",
085: failedAsExpected);
086: }
087:
088: public final void testGetWorkflowUser_knownAuthenticationUserId()
089: throws Exception {
090: NetworkIdVO knownUserId = new NetworkIdVO(KNOWN_USERNAME);
091: UserVO workflowUser = SpringContext.getBean(
092: KualiWorkflowInfo.class).getWorkflowUser(knownUserId);
093:
094: // TODO The network ID comes back as lower case. It's listed in the constant as lower case.
095: // Is this a bug?
096: assertEquals(
097: "workflowUser.authenticationUserId inequal to input authenticationUserId",
098: workflowUser.getNetworkId().toUpperCase(),
099: KNOWN_USERNAME);
100: }
101:
102: public final void testRouteHeaderExists_NullId()
103: throws IllegalArgumentException {
104: boolean errorThrown = false;
105: try {
106: boolean result = SpringContext.getBean(
107: KualiWorkflowInfo.class).routeHeaderExists(null);
108: } catch (IllegalArgumentException e) {
109: errorThrown = true;
110: }
111: assertTrue("An error should have been thrown.", errorThrown);
112: }
113:
114: public final void testRouteHeaderExists_NegativeId() {
115: boolean errorThrown = false;
116: boolean result = true;
117: try {
118: result = SpringContext.getBean(KualiWorkflowInfo.class)
119: .routeHeaderExists(new Long(-10));
120: } catch (Exception e) {
121: errorThrown = true;
122: }
123: assertFalse("An error should not have been thrown.",
124: errorThrown);
125: assertFalse(
126: "The routeHeader should never exist for a negative routeHeaderId.",
127: result);
128: }
129:
130: public final void testRouteHeaderExists_KnownBadZeroId() {
131: boolean errorThrown = false;
132: boolean result = true;
133: try {
134: result = SpringContext.getBean(KualiWorkflowInfo.class)
135: .routeHeaderExists(new Long(0));
136: } catch (Exception e) {
137: errorThrown = true;
138: }
139: assertFalse("An error should not have been thrown.",
140: errorThrown);
141: assertFalse(
142: "The routeHeader should never exist for a negative routeHeaderId.",
143: result);
144: }
145:
146: public final void testRouteHeaderExists_KnownGood() {
147: // no good way to test this without mocking the workflow service, and in a
148: // way that will be good over the long term, across data changes
149: assertTrue(
150: "This has been checked with a known-good id in the DB at this time.",
151: true);
152: }
153:
154: }
|