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.actions;
018:
019: import java.util.Collection;
020:
021: import org.junit.Test;
022: import org.kuali.workflow.test.WorkflowTestCase;
023:
024: import edu.iu.uis.eden.EdenConstants;
025: import edu.iu.uis.eden.KEWServiceLocator;
026: import edu.iu.uis.eden.clientapp.WorkflowDocument;
027: import edu.iu.uis.eden.clientapp.vo.NetworkIdVO;
028: import edu.iu.uis.eden.exception.WorkflowException;
029:
030: public class RouteDocumentTest extends WorkflowTestCase {
031:
032: public static final String DOCUMENT_TYPE_NAME = "BlanketApproveSequentialTest";
033: public static final String DOCUMENT_TYPE_POLICY_TEST_NAME = "BlanketApprovePolicyTest";
034:
035: protected void loadTestData() throws Exception {
036: loadXmlFile("ActionsConfig.xml");
037: }
038:
039: /**
040: * Tests that an exception is thrown if you try to execute a "route" command on an already routed document.
041: */
042: @Test
043: public void testRouteAlreadyRoutedDocument() throws Exception {
044: WorkflowDocument document = new WorkflowDocument(
045: new NetworkIdVO("user1"), DOCUMENT_TYPE_NAME);
046: document.routeDocument("");
047:
048: assertTrue("Document should be ENROUTE.", document
049: .stateIsEnroute());
050: assertFalse("There should not be a request to ewestfal.",
051: document.isApprovalRequested());
052:
053: // verify that only 1 action taken has been performed
054: Collection actionTakens = KEWServiceLocator
055: .getActionTakenService().findByRouteHeaderId(
056: document.getRouteHeaderId());
057: assertEquals("There should be only 1 action taken.", 1,
058: actionTakens.size());
059:
060: // now try and route the document again, an exception should be thrown
061: try {
062: document.routeDocument("");
063: fail("A WorkflowException should have been thrown.");
064: } catch (WorkflowException e) {
065: e.printStackTrace();
066: }
067:
068: // verify that there is still only 1 action taken (the transaction above should have rolled back)
069: actionTakens = KEWServiceLocator.getActionTakenService()
070: .findByRouteHeaderId(document.getRouteHeaderId());
071: assertEquals("There should still be only 1 action taken.", 1,
072: actionTakens.size());
073: }
074:
075: /**
076: * Tests that an exception is not thrown if you try to execute a "route" command on a document you did not initiate.
077: */
078: @Test
079: public void testRouteDocumentAsNonInitiatorUser() throws Exception {
080: WorkflowDocument firstDocument = new WorkflowDocument(
081: new NetworkIdVO("user1"),
082: DOCUMENT_TYPE_POLICY_TEST_NAME);
083: WorkflowDocument document = new WorkflowDocument(
084: new NetworkIdVO("user2"), firstDocument
085: .getRouteHeaderId());
086: try {
087: document.routeDocument("");
088: } catch (Exception e) {
089: e.printStackTrace();
090: fail("Exception thrown but should not have have been... Exception was of type "
091: + e.getClass().getName()
092: + " and message was "
093: + e.getMessage());
094: }
095: document = new WorkflowDocument(new NetworkIdVO("user1"),
096: firstDocument.getRouteHeaderId());
097: assertEquals("Document should be in Enroute status.",
098: EdenConstants.ROUTE_HEADER_ENROUTE_CD, document
099: .getRouteHeader().getDocRouteStatus());
100:
101: // verify that there is 1 action taken
102: Collection actionTakens = KEWServiceLocator
103: .getActionTakenService().findByRouteHeaderId(
104: document.getRouteHeaderId());
105: assertEquals("There should be 1 action taken.", 1, actionTakens
106: .size());
107: }
108:
109: /**
110: * Tests that an exception is not thrown if you try to execute a "route" command on a document you did not initiate.
111: */
112: @Test
113: public void testRouteDefaultDocumentAsNonInitiatorUser()
114: throws Exception {
115: WorkflowDocument firstDocument = new WorkflowDocument(
116: new NetworkIdVO("user1"), DOCUMENT_TYPE_NAME);
117: WorkflowDocument document = new WorkflowDocument(
118: new NetworkIdVO("user2"), firstDocument
119: .getRouteHeaderId());
120: try {
121: document.routeDocument("");
122: fail("Exception should have been thrown.");
123: } catch (Exception e) {
124: e.printStackTrace();
125: }
126: assertFalse("Document should not be ENROUTE.", document
127: .stateIsEnroute());
128: assertFalse("There should not be a request to user2.", document
129: .isApprovalRequested());
130:
131: // verify that there are no actions taken
132: Collection actionTakens = KEWServiceLocator
133: .getActionTakenService().findByRouteHeaderId(
134: document.getRouteHeaderId());
135: assertEquals("There should be 0 actions taken.", 0,
136: actionTakens.size());
137: }
138:
139: }
|