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