Clover Coverage Report - kew-test 2.0.0-SNAPSHOT
Coverage timestamp: Wed Dec 31 1969 19:00:00 EST
60   143   11   8.57
8   86   0.18   7
7     1.57  
1    
 
  WorkflowDocumentTest       Line # 34 60 0% 11 75 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.clientapp;
18   
19   
20    import org.junit.Test;
21   
22    import org.kuali.rice.kew.dto.RouteNodeInstanceDTO;
23    import org.kuali.rice.kew.dto.UserIdDTO;
24    import org.kuali.rice.kew.dto.WorkflowIdDTO;
25    import org.kuali.rice.kew.service.WorkflowDocument;
26    import org.kuali.rice.kew.test.KEWTestCase;
27   
28    import static org.junit.Assert.*;
29   
30    /**
31    * Place to test WorkflowDocument.
32    *
33    */
 
34    public class WorkflowDocumentTest extends KEWTestCase {
35   
 
36  0 toggle protected void loadTestData() throws Exception {
37  0 loadXmlFile("ClientAppConfig.xml");
38    }
39   
 
40  0 toggle @Test public void testLoadNonExistentDocument() throws Exception {
41  0 WorkflowDocument document = new WorkflowDocument(getPrincipalIdForName("ewestfal"), new Long(123456789));
42  0 assertNull("RouteHeaderVO should be null.", document.getRouteHeader());
43    }
44   
 
45  0 toggle @Test public void testWorkflowDocument() throws Exception {
46  0 WorkflowDocument document = new WorkflowDocument(getPrincipalIdForName("rkirkend"), "UnitTestDocument");
47  0 document.routeDocument("");
48   
49  0 document = new WorkflowDocument(getPrincipalIdForName("ewestfal"), document.getRouteHeaderId());
50  0 document.approve("");
51   
52  0 document = new WorkflowDocument(getPrincipalIdForName("jhopf"), document.getRouteHeaderId());
53  0 document.approve("");
54   
55  0 RouteNodeInstanceDTO[] nodeInstances = document.getRouteNodeInstances();
56  0 boolean containsInitiated = false;
57  0 boolean containsTemplate1 = false;
58  0 boolean containsTemplate2 = false;
59  0 for (int j = 0; j < nodeInstances.length; j++) {
60  0 RouteNodeInstanceDTO routeNodeInstance = nodeInstances[j];
61  0 if (routeNodeInstance.getName().equals("Initiated")) {
62  0 containsInitiated = true;
63  0 } else if (routeNodeInstance.getName().equals("Template1")) {
64  0 containsTemplate1 = true;
65  0 } else if (routeNodeInstance.getName().equals("Template2")) {
66  0 containsTemplate2 = true;
67    }
68    }
69   
70  0 assertTrue("Should have gone through initiated node", containsInitiated);
71  0 assertTrue("Should have gone through template1 node", containsTemplate1);
72  0 assertTrue("Should have gone through template2 node", containsTemplate2);
73    }
74   
75    /**
76    * Test that the document is being updated appropriately after a return to previous call
77    *
78    * @throws Exception
79    */
 
80  0 toggle @Test public void testReturnToPreviousCorrectlyUpdatingDocumentStatus() throws Exception {
81   
82  0 WorkflowDocument document = new WorkflowDocument(getPrincipalIdForName("rkirkend"), "UnitTestDocument");
83  0 document.routeDocument("");
84   
85  0 document = new WorkflowDocument(getPrincipalIdForName("ewestfal"), document.getRouteHeaderId());
86  0 document.returnToPreviousNode("", "Initiated");
87   
88  0 assertFalse("ewestfal should no longer have approval status", document.isApprovalRequested());
89  0 assertFalse("ewestfal should no long have blanket approve status", document.isBlanketApproveCapable());
90   
91    //just for good measure
92  0 document = new WorkflowDocument(getPrincipalIdForName("rkirkend"), document.getRouteHeaderId());
93  0 assertTrue("rkirkend should now have an approve request", document.isApprovalRequested());
94    }
95   
 
96  0 toggle @Test public void testGetPreviousRouteNodeNames() throws Exception {
97   
98  0 WorkflowDocument document = new WorkflowDocument(getPrincipalIdForName("rkirkend"), "UnitTestDocument");
99  0 document.routeDocument("");
100   
101  0 document = new WorkflowDocument(getPrincipalIdForName("ewestfal"), document.getRouteHeaderId());
102  0 document.approve("");
103   
104  0 document = new WorkflowDocument(getPrincipalIdForName("jhopf"), document.getRouteHeaderId());
105  0 String[] previousNodeNames = document.getPreviousNodeNames();
106  0 assertEquals("Should have 2 previous Node Names", 2, previousNodeNames.length);
107  0 assertEquals("Last node name should be the first visisted", "Initiated", previousNodeNames[0]);
108  0 assertEquals("First node name should be last node visited", "Template1", previousNodeNames[1]);
109  0 String[] currentNodes = document.getNodeNames();
110  0 assertEquals("Should have 1 current node name", 1, currentNodes.length);
111  0 assertEquals("Current node name incorrect", "Template2", currentNodes[0]);
112  0 document.returnToPreviousNode("", "Template1");
113  0 previousNodeNames = document.getPreviousNodeNames();
114  0 assertEquals("Should have 1 previous Node Name", 1, previousNodeNames.length);
115  0 assertEquals("Previous Node name incorrect", "Initiated", previousNodeNames[0]);
116   
117    }
118   
 
119  0 toggle @Test public void testIsRouteCapable() throws Exception {
120   
121  0 WorkflowDocument doc = new WorkflowDocument(getPrincipalIdForName("rkirkend"), "UnitTestDocument");
122   
123  0 verifyIsRouteCapable(false, getPrincipalIdForName("ewestfal"), doc.getRouteHeaderId());
124  0 verifyIsRouteCapable(false, "2001", doc.getRouteHeaderId());
125   
126  0 verifyIsRouteCapable(true, getPrincipalIdForName("rkirkend"), doc.getRouteHeaderId());
127  0 verifyIsRouteCapable(true, "2002", doc.getRouteHeaderId());
128   
129  0 doc = new WorkflowDocument(getPrincipalIdForName("rkirkend"), "NonInitiatorCanRouteDocument");
130   
131  0 verifyIsRouteCapable(true, getPrincipalIdForName("ewestfal"), doc.getRouteHeaderId());
132  0 verifyIsRouteCapable(true, "2001", doc.getRouteHeaderId());
133   
134  0 verifyIsRouteCapable(true, getPrincipalIdForName("rkirkend"), doc.getRouteHeaderId());
135  0 verifyIsRouteCapable(true, "2002", doc.getRouteHeaderId());
136    }
137   
 
138  0 toggle private void verifyIsRouteCapable(boolean routeCapable, String userId, Long docId) throws Exception {
139  0 WorkflowDocument doc = new WorkflowDocument(userId, docId);
140  0 assertEquals(routeCapable, doc.isRouteCapable());
141    }
142   
143    }