Clover Coverage Report - kew-test 2.0.0-SNAPSHOT
Coverage timestamp: Wed Dec 31 1969 19:00:00 EST
33   107   7   8.25
0   60   0.21   4
4     1.75  
1    
 
  RouteDocumentTest       Line # 31 33 0% 7 37 0% 0.0
 
No Tests
 
1    /*
2    * Copyright 2005-2007 The Kuali Foundation
3    *
4    *
5    * Licensed under the Educational Community License, Version 2.0 (the "License");
6    * you may not use this file except in compliance with the License.
7    * You may obtain a copy of the License at
8    *
9    * http://www.opensource.org/licenses/ecl2.php
10    *
11    * Unless required by applicable law or agreed to in writing, software
12    * distributed under the License is distributed on an "AS IS" BASIS,
13    * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14    * See the License for the specific language governing permissions and
15    * limitations under the License.
16    */
17    package org.kuali.rice.kew.actions;
18   
19    import org.junit.Test;
20   
21    import org.kuali.rice.kew.exception.WorkflowException;
22    import org.kuali.rice.kew.service.KEWServiceLocator;
23    import org.kuali.rice.kew.service.WorkflowDocument;
24    import org.kuali.rice.kew.test.KEWTestCase;
25    import org.kuali.rice.kew.util.KEWConstants;
26   
27    import java.util.Collection;
28   
29    import static org.junit.Assert.*;
30   
 
31    public class RouteDocumentTest extends KEWTestCase {
32   
33    public static final String DOCUMENT_TYPE_NAME = "BlanketApproveSequentialTest";
34    public static final String DOCUMENT_TYPE_POLICY_TEST_NAME = "BlanketApprovePolicyTest";
35   
 
36  0 toggle protected void loadTestData() throws Exception {
37  0 loadXmlFile("ActionsConfig.xml");
38    }
39   
40    /**
41    * Tests that an exception is thrown if you try to execute a "route" command on an already routed document.
42    */
 
43  0 toggle @Test public void testRouteAlreadyRoutedDocument() throws Exception {
44  0 WorkflowDocument document = new WorkflowDocument(getPrincipalIdForName("user1"), DOCUMENT_TYPE_NAME);
45  0 document.routeDocument("");
46   
47  0 assertTrue("Document should be ENROUTE.", document.stateIsEnroute());
48  0 assertFalse("There should not be a request to ewestfal.", document.isApprovalRequested());
49   
50    // verify that only 1 action taken has been performed
51  0 Collection actionTakens = KEWServiceLocator.getActionTakenService().findByRouteHeaderId(document.getRouteHeaderId());
52  0 assertEquals("There should be only 1 action taken.", 1, actionTakens.size());
53   
54    // now try and route the document again, an exception should be thrown
55  0 try {
56  0 document.routeDocument("");
57  0 fail("A WorkflowException should have been thrown.");
58    } catch (WorkflowException e) {
59  0 e.printStackTrace();
60    }
61   
62    // verify that there is still only 1 action taken (the transaction above should have rolled back)
63  0 actionTakens = KEWServiceLocator.getActionTakenService().findByRouteHeaderId(document.getRouteHeaderId());
64  0 assertEquals("There should still be only 1 action taken.", 1, actionTakens.size());
65    }
66   
67    /**
68    * Tests that an exception is not thrown if you try to execute a "route" command on a document you did not initiate.
69    */
 
70  0 toggle @Test public void testRouteDocumentAsNonInitiatorUser() throws Exception {
71  0 WorkflowDocument firstDocument = new WorkflowDocument(getPrincipalIdForName("user1"), DOCUMENT_TYPE_POLICY_TEST_NAME);
72  0 WorkflowDocument document = new WorkflowDocument(getPrincipalIdForName("user2"), firstDocument.getRouteHeaderId());
73  0 try {
74  0 document.routeDocument("");
75    } catch (Exception e) {
76  0 e.printStackTrace();
77  0 fail("Exception thrown but should not have have been... Exception was of type " + e.getClass().getName() + " and message was " + e.getMessage());
78    }
79  0 document = new WorkflowDocument(getPrincipalIdForName("user1"), firstDocument.getRouteHeaderId());
80  0 assertEquals("Document should be in Enroute status.", KEWConstants.ROUTE_HEADER_ENROUTE_CD, document.getRouteHeader().getDocRouteStatus());
81   
82    // verify that there is 1 action taken
83  0 Collection actionTakens = KEWServiceLocator.getActionTakenService().findByRouteHeaderId(document.getRouteHeaderId());
84  0 assertEquals("There should be 1 action taken.", 1, actionTakens.size());
85    }
86   
87    /**
88    * Tests that an exception is not thrown if you try to execute a "route" command on a document you did not initiate.
89    */
 
90  0 toggle @Test public void testRouteDefaultDocumentAsNonInitiatorUser() throws Exception {
91  0 WorkflowDocument firstDocument = new WorkflowDocument(getPrincipalIdForName("user1"), DOCUMENT_TYPE_NAME);
92  0 WorkflowDocument document = new WorkflowDocument(getPrincipalIdForName("user2"), firstDocument.getRouteHeaderId());
93  0 try {
94  0 document.routeDocument("");
95  0 fail("Exception should have been thrown.");
96    } catch (Exception e) {
97  0 e.printStackTrace();
98    }
99  0 assertFalse("Document should not be ENROUTE.", document.stateIsEnroute());
100  0 assertFalse("There should not be a request to user2.", document.isApprovalRequested());
101   
102    // verify that there are no actions taken
103  0 Collection actionTakens = KEWServiceLocator.getActionTakenService().findByRouteHeaderId(document.getRouteHeaderId());
104  0 assertEquals("There should be 0 actions taken.", 0, actionTakens.size());
105    }
106   
107    }