View Javadoc

1   /*
2    * Copyright 2007-2009 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 java.io.StringReader;
19  
20  import javax.xml.xpath.XPath;
21  import javax.xml.xpath.XPathConstants;
22  
23  import org.junit.Test;
24  import org.kuali.rice.kew.dto.NetworkIdDTO;
25  import org.kuali.rice.kew.dto.PropertyDefinitionDTO;
26  import org.kuali.rice.kew.dto.WorkflowAttributeDefinitionDTO;
27  import org.kuali.rice.kew.rule.xmlrouting.XPathHelper;
28  import org.kuali.rice.kew.service.WorkflowDocument;
29  import org.kuali.rice.kew.test.KEWTestCase;
30  import org.kuali.rice.kim.service.KIMServiceLocator;
31  import org.xml.sax.InputSource;
32  
33  /**
34   * This is a description of what this class does - ewestfal don't forget to fill
35   * this in.
36   * 
37   * @author Kuali Rice Team (rice.collab@kuali.org)
38   * 
39   */
40  public class PrincipalIdRoleAttributeTest extends KEWTestCase {
41  
42  	private static final String ATTRIBUTE_NAME = "PrincipalIdRoleAttribute";
43  	private static final String PRINCIPAL_ID_PROP = "principalId";
44  
45  	@Test
46  	public void testPrincipalIdAttribute() throws Exception {
47  		loadXmlFile("PrincipalIdRoleAttributeTestConfig.xml");
48  
49  		WorkflowDocument document = new WorkflowDocument(new NetworkIdDTO(
50  				"ewestfal"), "PrincipalIdRoleAttributeTest");
51  
52  		WorkflowAttributeDefinitionDTO principalIdDef1 = new WorkflowAttributeDefinitionDTO(
53  				"PrincipalIdRoleAttribute");
54  		PropertyDefinitionDTO principalIdProp1 = new PropertyDefinitionDTO(
55  				PRINCIPAL_ID_PROP, KIMServiceLocator.getIdentityManagementService().getPrincipalByPrincipalName("rkirkend").getPrincipalId());
56  		principalIdDef1.addProperty(principalIdProp1);
57  
58  		WorkflowAttributeDefinitionDTO principalIdDef2 = new WorkflowAttributeDefinitionDTO(
59  				"PrincipalIdRoleAttribute");
60  		PropertyDefinitionDTO principalIdProp2 = new PropertyDefinitionDTO(
61  				PRINCIPAL_ID_PROP, KIMServiceLocator.getIdentityManagementService().getPrincipalByPrincipalName("bmcgough").getPrincipalId());
62  		principalIdDef2.addProperty(principalIdProp2);
63  
64  		document.addAttributeDefinition(principalIdDef1);
65  		document.addAttributeDefinition(principalIdDef2);
66  
67  		document.routeDocument("Routing!");
68  
69  		// load the document as rkirkend
70  
71  		document = new WorkflowDocument(new NetworkIdDTO("rkirkend"), document
72  				.getRouteHeaderId());
73  		assertTrue("Document should be ENROUTE", document.stateIsEnroute());
74  		assertTrue("rkirkend should have an approve request.", document
75  				.isApprovalRequested());
76  
77  		// load the document as bmcgough
78  		document = new WorkflowDocument(new NetworkIdDTO("bmcgough"), document
79  				.getRouteHeaderId());
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 = new WorkflowDocument(new NetworkIdDTO("rkirkend"), document
88  				.getRouteHeaderId());
89  		assertTrue("Document should be ENROUTE", document.stateIsEnroute());
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.stateIsFinal());
96  
97  	}
98  
99  	@Test
100 	public void testParameterizedPrincipalIdAttribute() throws Exception {
101 		loadXmlFile("ParameterizedPrincipalIdRoleAttributeTestConfig.xml");
102 
103 		WorkflowDocument document = new WorkflowDocument(new NetworkIdDTO(
104 				"ewestfal"), "PrincipalIdRoleAttributeTest");
105 
106 		WorkflowAttributeDefinitionDTO principalIdDef1 = new WorkflowAttributeDefinitionDTO(
107 				"PrincipalIdRoleAttribute");
108 		PropertyDefinitionDTO principalIdProp1 = new PropertyDefinitionDTO(
109 				PRINCIPAL_ID_PROP, KIMServiceLocator.getIdentityManagementService().getPrincipalByPrincipalName("rkirkend").getPrincipalId());
110 		principalIdDef1.addProperty(principalIdProp1);
111 
112 		document.addAttributeDefinition(principalIdDef1);
113 
114 		document.routeDocument("Routing!");
115 
116 		// load the document as rkirkend
117 
118 		document = new WorkflowDocument(new NetworkIdDTO("rkirkend"), document
119 				.getRouteHeaderId());
120 		assertTrue("Document should be ENROUTE", document.stateIsEnroute());
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 }