001 /**
002 * Copyright 2005-2011 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 static org.junit.Assert.assertTrue;
019
020 import java.io.StringReader;
021
022 import javax.xml.xpath.XPath;
023 import javax.xml.xpath.XPathConstants;
024
025 import org.junit.Test;
026 import org.kuali.rice.kew.api.WorkflowDocument;
027 import org.kuali.rice.kew.api.WorkflowDocumentFactory;
028 import org.kuali.rice.kew.api.document.PropertyDefinition;
029 import org.kuali.rice.kew.api.document.attribute.WorkflowAttributeDefinition;
030 import org.kuali.rice.kew.rule.xmlrouting.XPathHelper;
031 import org.kuali.rice.kew.test.KEWTestCase;
032 import org.xml.sax.InputSource;
033
034 /**
035 * This is a description of what this class does - ewestfal don't forget to fill
036 * this in.
037 *
038 * @author Kuali Rice Team (rice.collab@kuali.org)
039 *
040 */
041 public class NetworkIdRoleAttributeTest extends KEWTestCase {
042
043 private static final String ATTRIBUTE_NAME = "NetworkIdRoleAttribute";
044 private static final String NETWORK_ID_PROP = "networkId";
045
046 @Test
047 public void testNetworkIdAttribute() throws Exception {
048 loadXmlFile("NetworkIdRoleAttributeTestConfig.xml");
049
050 WorkflowDocument document = WorkflowDocumentFactory.createDocument(getPrincipalIdForName(
051 "ewestfal"), "NetworkIdRoleAttributeTest");
052
053 WorkflowAttributeDefinition.Builder networkIdDef1 = WorkflowAttributeDefinition.Builder.create("NetworkIdRoleAttribute");
054 PropertyDefinition networkIdProp1 = PropertyDefinition.create(
055 NETWORK_ID_PROP, "rkirkend");
056 networkIdDef1.addPropertyDefinition(networkIdProp1);
057
058 WorkflowAttributeDefinition.Builder networkIdDef2 = WorkflowAttributeDefinition.Builder.create(
059 "NetworkIdRoleAttribute");
060 PropertyDefinition networkIdProp2 = PropertyDefinition.create(
061 NETWORK_ID_PROP, "bmcgough");
062 networkIdDef2.addPropertyDefinition(networkIdProp2);
063
064 document.addAttributeDefinition(networkIdDef1.build());
065 document.addAttributeDefinition(networkIdDef2.build());
066
067 document.route("Routing!");
068
069 // load the document as rkirkend
070
071 document = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("rkirkend"), document
072 .getDocumentId());
073 assertTrue("Document should be ENROUTE", document.isEnroute());
074 assertTrue("rkirkend should have an approve request.", document
075 .isApprovalRequested());
076
077 // load the document as bmcgough
078 document = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("bmcgough"), document
079 .getDocumentId());
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 = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("rkirkend"), document
088 .getDocumentId());
089 assertTrue("Document should be ENROUTE", document.isEnroute());
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.isFinal());
096
097 }
098
099 @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 }