View Javadoc

1   /**
2    * Copyright 2005-2011 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.rice.kew.rule;
17  
18  import static org.junit.Assert.assertTrue;
19  
20  import java.io.StringReader;
21  
22  import javax.xml.xpath.XPath;
23  import javax.xml.xpath.XPathConstants;
24  
25  import org.junit.Test;
26  import org.kuali.rice.kew.api.WorkflowDocument;
27  import org.kuali.rice.kew.api.WorkflowDocumentFactory;
28  import org.kuali.rice.kew.api.document.PropertyDefinition;
29  import org.kuali.rice.kew.api.document.attribute.WorkflowAttributeDefinition;
30  import org.kuali.rice.kew.rule.xmlrouting.XPathHelper;
31  import org.kuali.rice.kew.test.KEWTestCase;
32  import org.xml.sax.InputSource;
33  
34  /**
35   * This is a description of what this class does - ewestfal don't forget to fill this in. 
36   * 
37   * @author Kuali Rice Team (rice.collab@kuali.org)
38   *
39   */
40  public class UniversityIdRoleAttributeTest extends KEWTestCase {
41      
42      private static final String UNIVERSITY_ID_PROP = "universityId";
43      
44      @Test
45      public void testUniversityIdAttribute() throws Exception {
46  	loadXmlFile("UniversityIdRoleAttributeTestConfig.xml");
47  	
48  	// network id to university id mapping as defined in DefaultSuiteTestData.xml
49  	// -----------------------------------
50  	// ewestfal     ->     2001
51  	// rkirkend     ->     2002
52  	// bmcgough     ->     2004
53  	
54  	WorkflowDocument document = WorkflowDocumentFactory.createDocument("2001", "UniversityIdRoleAttributeTest");
55  	
56  	WorkflowAttributeDefinition.Builder universityIdDef1 = WorkflowAttributeDefinition.Builder.create("UniversityIdRoleAttribute");
57  	PropertyDefinition universityIdProp1 = PropertyDefinition.create(UNIVERSITY_ID_PROP, "2002");
58  	universityIdDef1.addPropertyDefinition(universityIdProp1);
59  	
60  	WorkflowAttributeDefinition.Builder universityIdDef2 = WorkflowAttributeDefinition.Builder.create("UniversityIdRoleAttribute");
61  	PropertyDefinition universityIdProp2 = PropertyDefinition.create(UNIVERSITY_ID_PROP, "2004");
62  	universityIdDef2.addPropertyDefinition(universityIdProp2);
63  	
64  	document.addAttributeDefinition(universityIdDef1.build());
65  	document.addAttributeDefinition(universityIdDef2.build());
66  	
67  	document.route("Routing!");
68  	
69  	// load the document as rkirkend
70  	
71  	document = WorkflowDocumentFactory.loadDocument("2002", document.getDocumentId());
72  	assertTrue("Document should be ENROUTE", document.isEnroute());
73  	assertTrue("rkirkend should have an approve request.", document.isApprovalRequested());
74  	
75  	// load the document as bmcgough
76  	document = WorkflowDocumentFactory.loadDocument("2004", document.getDocumentId());
77  	assertTrue("bmcgough should have an approve request.", document.isApprovalRequested());
78  	
79  	// submit an approve as bmcgough
80  	document.approve("i approve");
81  	
82  	// reload as rkirkend, verify still enroute
83  	document = WorkflowDocumentFactory.loadDocument("2002", document.getDocumentId());
84  	assertTrue("Document should be ENROUTE", document.isEnroute());
85  	assertTrue("rkirkend should have an approve request.", document.isApprovalRequested());
86  	document.approve("i also approve");
87  	
88  	// now the document should be FINAL
89  	assertTrue("Document should be FINAL", document.isFinal());
90  	
91      }
92      
93      @Test
94      public void testParameterizedUniversityIdAttribute() throws Exception {
95  	loadXmlFile("ParameterizedUniversityIdRoleAttributeTestConfig.xml");
96  	
97  	WorkflowDocument document = WorkflowDocumentFactory.createDocument(getPrincipalIdForName("ewestfal"), "UniversityIdRoleAttributeTest");
98  	
99  	WorkflowAttributeDefinition.Builder univIdDef1 = WorkflowAttributeDefinition.Builder.create("UniversityIdRoleAttribute");
100 	PropertyDefinition univIdProp1 = PropertyDefinition.create(UNIVERSITY_ID_PROP, "2002");
101 	univIdDef1.addPropertyDefinition(univIdProp1);
102 		
103 	document.addAttributeDefinition(univIdDef1.build());
104 	
105 	document.route("Routing!");
106 	
107 	// load the document as rkirkend
108 	
109 	document = WorkflowDocumentFactory.loadDocument("2002", document.getDocumentId());
110 	assertTrue("Document should be ENROUTE", document.isEnroute());
111 	assertTrue("rkirkend should have an approve request.", document.isApprovalRequested());
112 	
113 	// now let's verify the XML
114 	
115 	XPath xPath = XPathHelper.newXPath();
116 	assertTrue("Should have found the ID.", (Boolean)xPath.evaluate("//UniversityIdRoleAttribute/thisIdRocks", new InputSource(new StringReader(document.getDocumentContent().getFullContent())), XPathConstants.BOOLEAN));
117 	
118     }
119 
120 }