001 /* 002 * Copyright 2007-2009 The Kuali Foundation 003 * 004 * Licensed under the Educational Community License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.opensource.org/licenses/ecl2.php 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 package org.kuali.rice.kew.rule; 017 018 import java.io.StringReader; 019 020 import javax.xml.xpath.XPath; 021 import javax.xml.xpath.XPathConstants; 022 023 import org.junit.Test; 024 import org.kuali.rice.kew.dto.NetworkIdDTO; 025 import org.kuali.rice.kew.dto.PropertyDefinitionDTO; 026 import org.kuali.rice.kew.dto.WorkflowAttributeDefinitionDTO; 027 import org.kuali.rice.kew.rule.xmlrouting.XPathHelper; 028 import org.kuali.rice.kew.service.WorkflowDocument; 029 import org.kuali.rice.kew.test.KEWTestCase; 030 import org.kuali.rice.kim.service.KIMServiceLocator; 031 import org.xml.sax.InputSource; 032 033 /** 034 * This is a description of what this class does - ewestfal don't forget to fill 035 * this in. 036 * 037 * @author Kuali Rice Team (rice.collab@kuali.org) 038 * 039 */ 040 public class PrincipalIdRoleAttributeTest extends KEWTestCase { 041 042 private static final String ATTRIBUTE_NAME = "PrincipalIdRoleAttribute"; 043 private static final String PRINCIPAL_ID_PROP = "principalId"; 044 045 @Test 046 public void testPrincipalIdAttribute() throws Exception { 047 loadXmlFile("PrincipalIdRoleAttributeTestConfig.xml"); 048 049 WorkflowDocument document = new WorkflowDocument(new NetworkIdDTO( 050 "ewestfal"), "PrincipalIdRoleAttributeTest"); 051 052 WorkflowAttributeDefinitionDTO principalIdDef1 = new WorkflowAttributeDefinitionDTO( 053 "PrincipalIdRoleAttribute"); 054 PropertyDefinitionDTO principalIdProp1 = new PropertyDefinitionDTO( 055 PRINCIPAL_ID_PROP, KIMServiceLocator.getIdentityManagementService().getPrincipalByPrincipalName("rkirkend").getPrincipalId()); 056 principalIdDef1.addProperty(principalIdProp1); 057 058 WorkflowAttributeDefinitionDTO principalIdDef2 = new WorkflowAttributeDefinitionDTO( 059 "PrincipalIdRoleAttribute"); 060 PropertyDefinitionDTO principalIdProp2 = new PropertyDefinitionDTO( 061 PRINCIPAL_ID_PROP, KIMServiceLocator.getIdentityManagementService().getPrincipalByPrincipalName("bmcgough").getPrincipalId()); 062 principalIdDef2.addProperty(principalIdProp2); 063 064 document.addAttributeDefinition(principalIdDef1); 065 document.addAttributeDefinition(principalIdDef2); 066 067 document.routeDocument("Routing!"); 068 069 // load the document as rkirkend 070 071 document = new WorkflowDocument(new NetworkIdDTO("rkirkend"), document 072 .getRouteHeaderId()); 073 assertTrue("Document should be ENROUTE", document.stateIsEnroute()); 074 assertTrue("rkirkend should have an approve request.", document 075 .isApprovalRequested()); 076 077 // load the document as bmcgough 078 document = new WorkflowDocument(new NetworkIdDTO("bmcgough"), document 079 .getRouteHeaderId()); 080 assertTrue("bmcgough should have an approve request.", document 081 .isApprovalRequested()); 082 083 // submit an approve as bmcgough 084 document.approve("i approve"); 085 086 // reload as rkirkend, verify still enroute 087 document = new WorkflowDocument(new NetworkIdDTO("rkirkend"), document 088 .getRouteHeaderId()); 089 assertTrue("Document should be ENROUTE", document.stateIsEnroute()); 090 assertTrue("rkirkend should have an approve request.", document 091 .isApprovalRequested()); 092 document.approve("i also approve"); 093 094 // now the document should be FINAL 095 assertTrue("Document should be FINAL", document.stateIsFinal()); 096 097 } 098 099 @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 }