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 this in.
036 *
037 * @author Kuali Rice Team (rice.collab@kuali.org)
038 *
039 */
040 public class UniversityIdRoleAttributeTest extends KEWTestCase {
041
042 private static final String UNIVERSITY_ID_PROP = "universityId";
043
044 @Test
045 public void testUniversityIdAttribute() throws Exception {
046 loadXmlFile("UniversityIdRoleAttributeTestConfig.xml");
047
048 // network id to university id mapping as defined in DefaultSuiteTestData.xml
049 // -----------------------------------
050 // ewestfal -> 2001
051 // rkirkend -> 2002
052 // bmcgough -> 2004
053
054 WorkflowDocument document = WorkflowDocumentFactory.createDocument("2001", "UniversityIdRoleAttributeTest");
055
056 WorkflowAttributeDefinition.Builder universityIdDef1 = WorkflowAttributeDefinition.Builder.create("UniversityIdRoleAttribute");
057 PropertyDefinition universityIdProp1 = PropertyDefinition.create(UNIVERSITY_ID_PROP, "2002");
058 universityIdDef1.addPropertyDefinition(universityIdProp1);
059
060 WorkflowAttributeDefinition.Builder universityIdDef2 = WorkflowAttributeDefinition.Builder.create("UniversityIdRoleAttribute");
061 PropertyDefinition universityIdProp2 = PropertyDefinition.create(UNIVERSITY_ID_PROP, "2004");
062 universityIdDef2.addPropertyDefinition(universityIdProp2);
063
064 document.addAttributeDefinition(universityIdDef1.build());
065 document.addAttributeDefinition(universityIdDef2.build());
066
067 document.route("Routing!");
068
069 // load the document as rkirkend
070
071 document = WorkflowDocumentFactory.loadDocument("2002", document.getDocumentId());
072 assertTrue("Document should be ENROUTE", document.isEnroute());
073 assertTrue("rkirkend should have an approve request.", document.isApprovalRequested());
074
075 // load the document as bmcgough
076 document = WorkflowDocumentFactory.loadDocument("2004", document.getDocumentId());
077 assertTrue("bmcgough should have an approve request.", document.isApprovalRequested());
078
079 // submit an approve as bmcgough
080 document.approve("i approve");
081
082 // reload as rkirkend, verify still enroute
083 document = WorkflowDocumentFactory.loadDocument("2002", document.getDocumentId());
084 assertTrue("Document should be ENROUTE", document.isEnroute());
085 assertTrue("rkirkend should have an approve request.", document.isApprovalRequested());
086 document.approve("i also approve");
087
088 // now the document should be FINAL
089 assertTrue("Document should be FINAL", document.isFinal());
090
091 }
092
093 @Test
094 public void testParameterizedUniversityIdAttribute() throws Exception {
095 loadXmlFile("ParameterizedUniversityIdRoleAttributeTestConfig.xml");
096
097 WorkflowDocument document = WorkflowDocumentFactory.createDocument(getPrincipalIdForName("ewestfal"), "UniversityIdRoleAttributeTest");
098
099 WorkflowAttributeDefinition.Builder univIdDef1 = WorkflowAttributeDefinition.Builder.create("UniversityIdRoleAttribute");
100 PropertyDefinition univIdProp1 = PropertyDefinition.create(UNIVERSITY_ID_PROP, "2002");
101 univIdDef1.addPropertyDefinition(univIdProp1);
102
103 document.addAttributeDefinition(univIdDef1.build());
104
105 document.route("Routing!");
106
107 // load the document as rkirkend
108
109 document = WorkflowDocumentFactory.loadDocument("2002", document.getDocumentId());
110 assertTrue("Document should be ENROUTE", document.isEnroute());
111 assertTrue("rkirkend should have an approve request.", document.isApprovalRequested());
112
113 // now let's verify the XML
114
115 XPath xPath = XPathHelper.newXPath();
116 assertTrue("Should have found the ID.", (Boolean)xPath.evaluate("//UniversityIdRoleAttribute/thisIdRocks", new InputSource(new StringReader(document.getDocumentContent().getFullContent())), XPathConstants.BOOLEAN));
117
118 }
119
120 }