View Javadoc

1   /**
2    * Copyright 2005-2013 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   *
36   * @author Kuali Rice Team (rice.collab@kuali.org)
37   *
38   */
39  public class UniversityIdRoleAttributeTest extends KEWTestCase {
40      
41      private static final String UNIVERSITY_ID_PROP = "universityId";
42      
43      @Test
44      public void testUniversityIdAttribute() throws Exception {
45  	loadXmlFile("UniversityIdRoleAttributeTestConfig.xml");
46  	
47  	// network id to university id mapping as defined in DefaultSuiteTestData.xml
48  	// -----------------------------------
49  	// ewestfal     ->     2001
50  	// rkirkend     ->     2002
51  	// bmcgough     ->     2004
52  	
53  	WorkflowDocument document = WorkflowDocumentFactory.createDocument("2001", "UniversityIdRoleAttributeTest");
54  	
55  	WorkflowAttributeDefinition.Builder universityIdDef1 = WorkflowAttributeDefinition.Builder.create("UniversityIdRoleAttribute");
56  	PropertyDefinition universityIdProp1 = PropertyDefinition.create(UNIVERSITY_ID_PROP, "2002");
57  	universityIdDef1.addPropertyDefinition(universityIdProp1);
58  	
59  	WorkflowAttributeDefinition.Builder universityIdDef2 = WorkflowAttributeDefinition.Builder.create("UniversityIdRoleAttribute");
60  	PropertyDefinition universityIdProp2 = PropertyDefinition.create(UNIVERSITY_ID_PROP, "2004");
61  	universityIdDef2.addPropertyDefinition(universityIdProp2);
62  	
63  	document.addAttributeDefinition(universityIdDef1.build());
64  	document.addAttributeDefinition(universityIdDef2.build());
65  	
66  	document.route("Routing!");
67  	
68  	// load the document as rkirkend
69  	
70  	document = WorkflowDocumentFactory.loadDocument("2002", document.getDocumentId());
71  	assertTrue("Document should be ENROUTE", document.isEnroute());
72  	assertTrue("rkirkend should have an approve request.", document.isApprovalRequested());
73  	
74  	// load the document as bmcgough
75  	document = WorkflowDocumentFactory.loadDocument("2004", document.getDocumentId());
76  	assertTrue("bmcgough should have an approve request.", document.isApprovalRequested());
77  	
78  	// submit an approve as bmcgough
79  	document.approve("i approve");
80  	
81  	// reload as rkirkend, verify still enroute
82  	document = WorkflowDocumentFactory.loadDocument("2002", document.getDocumentId());
83  	assertTrue("Document should be ENROUTE", document.isEnroute());
84  	assertTrue("rkirkend should have an approve request.", document.isApprovalRequested());
85  	document.approve("i also approve");
86  	
87  	// now the document should be FINAL
88  	assertTrue("Document should be FINAL", document.isFinal());
89  	
90      }
91      
92      @Test
93      public void testParameterizedUniversityIdAttribute() throws Exception {
94  	loadXmlFile("ParameterizedUniversityIdRoleAttributeTestConfig.xml");
95  	
96  	WorkflowDocument document = WorkflowDocumentFactory.createDocument(getPrincipalIdForName("ewestfal"), "UniversityIdRoleAttributeTest");
97  	
98  	WorkflowAttributeDefinition.Builder univIdDef1 = WorkflowAttributeDefinition.Builder.create("UniversityIdRoleAttribute");
99  	PropertyDefinition univIdProp1 = PropertyDefinition.create(UNIVERSITY_ID_PROP, "2002");
100 	univIdDef1.addPropertyDefinition(univIdProp1);
101 		
102 	document.addAttributeDefinition(univIdDef1.build());
103 	
104 	document.route("Routing!");
105 	
106 	// load the document as rkirkend
107 	
108 	document = WorkflowDocumentFactory.loadDocument("2002", document.getDocumentId());
109 	assertTrue("Document should be ENROUTE", document.isEnroute());
110 	assertTrue("rkirkend should have an approve request.", document.isApprovalRequested());
111 	
112 	// now let's verify the XML
113 	
114 	XPath xPath = XPathHelper.newXPath();
115 	assertTrue("Should have found the ID.", (Boolean)xPath.evaluate("//UniversityIdRoleAttribute/thisIdRocks", new InputSource(new StringReader(document.getDocumentContent().getFullContent())), XPathConstants.BOOLEAN));
116 	
117     }
118 
119 }