View Javadoc
1   /**
2    * Copyright 2005-2014 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   * @author Kuali Rice Team (rice.collab@kuali.org)
36   * 
37   */
38  public class NetworkIdRoleAttributeTest extends KEWTestCase {
39  
40  	private static final String ATTRIBUTE_NAME = "NetworkIdRoleAttribute";
41  	private static final String NETWORK_ID_PROP = "networkId";
42  
43  	@Test
44  	public void testNetworkIdAttribute() throws Exception {
45  		loadXmlFile("NetworkIdRoleAttributeTestConfig.xml");
46  
47  		WorkflowDocument document = WorkflowDocumentFactory.createDocument(getPrincipalIdForName(
48  				"ewestfal"), "NetworkIdRoleAttributeTest");
49  
50  		WorkflowAttributeDefinition.Builder networkIdDef1 = WorkflowAttributeDefinition.Builder.create("NetworkIdRoleAttribute");
51  		PropertyDefinition networkIdProp1 = PropertyDefinition.create(
52  				NETWORK_ID_PROP, "rkirkend");
53  		networkIdDef1.addPropertyDefinition(networkIdProp1);
54  
55  		WorkflowAttributeDefinition.Builder networkIdDef2 = WorkflowAttributeDefinition.Builder.create(
56  				"NetworkIdRoleAttribute");
57  		PropertyDefinition networkIdProp2 = PropertyDefinition.create(
58  				NETWORK_ID_PROP, "bmcgough");
59  		networkIdDef2.addPropertyDefinition(networkIdProp2);
60  
61  		document.addAttributeDefinition(networkIdDef1.build());
62  		document.addAttributeDefinition(networkIdDef2.build());
63  
64  		document.route("Routing!");
65  
66  		// load the document as rkirkend
67  
68  		document = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("rkirkend"), document
69  				.getDocumentId());
70  		assertTrue("Document should be ENROUTE", document.isEnroute());
71  		assertTrue("rkirkend should have an approve request.", document
72  				.isApprovalRequested());
73  
74  		// load the document as bmcgough
75  		document = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("bmcgough"), document
76  				.getDocumentId());
77  		assertTrue("bmcgough should have an approve request.", document
78  				.isApprovalRequested());
79  
80  		// submit an approve as bmcgough
81  		document.approve("i approve");
82  
83  		// reload as rkirkend, verify still enroute
84  		document = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("rkirkend"), document
85  				.getDocumentId());
86  		assertTrue("Document should be ENROUTE", document.isEnroute());
87  		assertTrue("rkirkend should have an approve request.", document
88  				.isApprovalRequested());
89  		document.approve("i also approve");
90  
91  		// now the document should be FINAL
92  		assertTrue("Document should be FINAL", document.isFinal());
93  
94  	}
95  
96  	@Test
97  	public void testParameterizedNetworkIdAttribute() throws Exception {
98  		loadXmlFile("ParameterizedNetworkIdRoleAttributeTestConfig.xml");
99  
100 		WorkflowDocument document = WorkflowDocumentFactory.createDocument(getPrincipalIdForName(
101 				"ewestfal"), "NetworkIdRoleAttributeTest");
102 
103 		WorkflowAttributeDefinition.Builder networkIdDef1 = WorkflowAttributeDefinition.Builder.create(
104 				"NetworkIdRoleAttribute");
105 		PropertyDefinition networkIdProp1 = PropertyDefinition.create(
106 				NETWORK_ID_PROP, "rkirkend");
107 		networkIdDef1.addPropertyDefinition(networkIdProp1);
108 
109 		document.addAttributeDefinition(networkIdDef1.build());
110 
111 		document.route("Routing!");
112 
113 		// load the document as rkirkend
114 
115 		document = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("rkirkend"), document
116 				.getDocumentId());
117 		assertTrue("Document should be ENROUTE", document.isEnroute());
118 		assertTrue("rkirkend should have an approve request.", document
119 				.isApprovalRequested());
120 
121 		// now let's verify the XML
122 
123 		XPath xPath = XPathHelper.newXPath();
124 		assertTrue("Should have found the ID.", (Boolean) xPath.evaluate(
125 				"//" + ATTRIBUTE_NAME + "/thisIdRocks", new InputSource(
126 						new StringReader(document.getDocumentContent()
127 								.getFullContent())), XPathConstants.BOOLEAN));
128 
129 	}
130 
131 }