View Javadoc
1   /**
2    * Copyright 2005-2014 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.engine;
17  
18  import static org.junit.Assert.assertNotNull;
19  
20  import java.io.IOException;
21  import java.util.Map;
22  
23  import org.apache.log4j.Logger;
24  import org.custommonkey.xmlunit.XMLAssert;
25  import org.custommonkey.xmlunit.XMLUnit;
26  import org.junit.Test;
27  import org.kuali.rice.kew.doctype.bo.DocumentType;
28  import org.kuali.rice.kew.engine.node.RouteNode;
29  import org.kuali.rice.kew.service.KEWServiceLocator;
30  import org.kuali.rice.kew.test.KEWTestCase;
31  import org.kuali.rice.kew.util.Utilities;
32  import org.xml.sax.SAXException;
33  
34  /**
35   * Tests the parsing of route node config params 
36   * @author Kuali Rice Team (rice.collab@kuali.org)
37   */
38  public class RouteNodeConfigParamTest extends KEWTestCase {
39  
40      private static final Logger LOG = Logger.getLogger(RouteNodeConfigParamTest.class);
41  
42      protected void loadTestData() throws Exception {
43          loadXmlFile("RouteNodeConfigParams.xml");
44      }
45  
46      /**
47       * Asserts that specified route node definition has the specified config parameter
48       */
49      protected void assertHasConfigParam(RouteNode routeNodeDef, String key, String value) {
50          Map<String, String> cfgMap = Utilities.getKeyValueCollectionAsMap(routeNodeDef.getConfigParams());
51          try {
52              XMLUnit.setIgnoreWhitespace(true);
53              XMLAssert.assertXMLEqual(value, cfgMap.get(key));
54          } catch (SAXException e) {
55              e.printStackTrace();
56          } catch (IOException e) {
57              e.printStackTrace();
58          }
59      }
60  
61      @Test public void testRouteNodeConfigParams() {
62          DocumentType docType = KEWServiceLocator.getDocumentTypeService().findByName("RouteNodeConfigParams");
63          assertNotNull(docType);
64          assertNotNull(docType.getDocumentTypeId());
65  
66          // adhoc node
67          RouteNode routeNodeDef = KEWServiceLocator.getRouteNodeService().findRouteNodeByName(docType.getDocumentTypeId(), "AdHoc");
68          assertNotNull(routeNodeDef);
69          assertHasConfigParam(routeNodeDef, RouteNode.CONTENT_FRAGMENT_CFG_KEY, "<start name=\"AdHoc\"><activationType>P</activationType></start>");
70          assertHasConfigParam(routeNodeDef, "activationType", "P");
71  
72          routeNodeDef = KEWServiceLocator.getRouteNodeService().findRouteNodeByName(docType.getDocumentTypeId(), "setStartedVar");
73          assertNotNull(routeNodeDef);
74          assertHasConfigParam(routeNodeDef, RouteNode.CONTENT_FRAGMENT_CFG_KEY, "<simple name=\"setStartedVar\"><type>org.kuali.rice.kew.engine.node.var.SetVarNode</type><name>started</name><value>startedVariableValue</value></simple>");
75          assertHasConfigParam(routeNodeDef, "type", "org.kuali.rice.kew.engine.node.var.SetVarNode");
76          assertHasConfigParam(routeNodeDef, "name", "started");
77          assertHasConfigParam(routeNodeDef, "value", "startedVariableValue");
78  
79          routeNodeDef = KEWServiceLocator.getRouteNodeService().findRouteNodeByName(docType.getDocumentTypeId(), "setCopiedVar");
80          assertNotNull(routeNodeDef);
81          assertHasConfigParam(routeNodeDef, RouteNode.CONTENT_FRAGMENT_CFG_KEY, "<simple name=\"setCopiedVar\"><type>org.kuali.rice.kew.engine.node.var.SetVarNode</type><name>copiedVar</name><value>var:started</value></simple>");
82          assertHasConfigParam(routeNodeDef, "type", "org.kuali.rice.kew.engine.node.var.SetVarNode");
83          assertHasConfigParam(routeNodeDef, "name", "copiedVar");
84          assertHasConfigParam(routeNodeDef, "value", "var:started");
85  
86          routeNodeDef = KEWServiceLocator.getRouteNodeService().findRouteNodeByName(docType.getDocumentTypeId(), "PreApprovalTestOne");
87          assertNotNull(routeNodeDef);
88          assertHasConfigParam(routeNodeDef, RouteNode.CONTENT_FRAGMENT_CFG_KEY, "<requests name=\"PreApprovalTestOne\"><activationType>S</activationType><ruleSelector>Named</ruleSelector><ruleName>TestRule1</ruleName></requests>");
89          assertHasConfigParam(routeNodeDef, "activationType", "S");
90          assertHasConfigParam(routeNodeDef, "ruleSelector", "Named");
91          assertHasConfigParam(routeNodeDef, "ruleName", "TestRule1");
92          
93          routeNodeDef = KEWServiceLocator.getRouteNodeService().findRouteNodeByName(docType.getDocumentTypeId(), "setEndedVar");
94          assertNotNull(routeNodeDef);
95          assertHasConfigParam(routeNodeDef, RouteNode.CONTENT_FRAGMENT_CFG_KEY, "<simple name=\"setEndedVar\"><type>org.kuali.rice.kew.engine.node.var.SetVarNode</type><name>ended</name><value>endedVariableValue</value></simple>");
96          assertHasConfigParam(routeNodeDef, "type", "org.kuali.rice.kew.engine.node.var.SetVarNode");
97          assertHasConfigParam(routeNodeDef, "name", "ended");
98          assertHasConfigParam(routeNodeDef, "value", "endedVariableValue");
99          
100         routeNodeDef = KEWServiceLocator.getRouteNodeService().findRouteNodeByName(docType.getDocumentTypeId(), "setGoogleVar");
101         assertNotNull(routeNodeDef);
102         assertHasConfigParam(routeNodeDef, RouteNode.CONTENT_FRAGMENT_CFG_KEY, "<simple name=\"setGoogleVar\"><type>org.kuali.rice.kew.engine.node.var.SetVarNode</type><name>google</name><value>url:http://google.com</value></simple>");
103         assertHasConfigParam(routeNodeDef, "type", "org.kuali.rice.kew.engine.node.var.SetVarNode");
104         assertHasConfigParam(routeNodeDef, "name", "google");
105         assertHasConfigParam(routeNodeDef, "value", "url:http://google.com");
106 
107         routeNodeDef = KEWServiceLocator.getRouteNodeService().findRouteNodeByName(docType.getDocumentTypeId(), "setXPathVar");
108         assertNotNull(routeNodeDef);
109         assertHasConfigParam(routeNodeDef, RouteNode.CONTENT_FRAGMENT_CFG_KEY, "<simple name=\"setXPathVar\"><type>org.kuali.rice.kew.engine.node.var.SetVarNode</type><name>xpath</name><value>xpath:concat(local-name(//documentContent),$ended)</value></simple>");
110         assertHasConfigParam(routeNodeDef, "type", "org.kuali.rice.kew.engine.node.var.SetVarNode");
111         assertHasConfigParam(routeNodeDef, "name", "xpath");
112         assertHasConfigParam(routeNodeDef, "value", "xpath:concat(local-name(//documentContent),$ended)");
113 
114         routeNodeDef = KEWServiceLocator.getRouteNodeService().findRouteNodeByName(docType.getDocumentTypeId(), "resetStartedVar");
115         assertNotNull(routeNodeDef);
116         assertHasConfigParam(routeNodeDef, RouteNode.CONTENT_FRAGMENT_CFG_KEY, "<simple name=\"resetStartedVar\"><type>org.kuali.rice.kew.engine.node.var.SetVarNode</type><name>started</name><value>aNewStartedVariableValue</value></simple>");
117         assertHasConfigParam(routeNodeDef, "type", "org.kuali.rice.kew.engine.node.var.SetVarNode");
118         assertHasConfigParam(routeNodeDef, "name", "started");
119         assertHasConfigParam(routeNodeDef, "value", "aNewStartedVariableValue");
120 
121         routeNodeDef = KEWServiceLocator.getRouteNodeService().findRouteNodeByName(docType.getDocumentTypeId(), "logNode");
122         assertNotNull(routeNodeDef);
123         assertHasConfigParam(routeNodeDef, RouteNode.CONTENT_FRAGMENT_CFG_KEY, "<simple name=\"logNode\"><type>org.kuali.rice.kew.engine.node.LogNode</type><message>var:xpath</message></simple>");
124         assertHasConfigParam(routeNodeDef, "type", "org.kuali.rice.kew.engine.node.LogNode");
125         assertHasConfigParam(routeNodeDef, "message", "var:xpath");
126 
127         routeNodeDef = KEWServiceLocator.getRouteNodeService().findRouteNodeByName(docType.getDocumentTypeId(), "logNode2");
128         assertNotNull(routeNodeDef);
129         assertHasConfigParam(routeNodeDef, RouteNode.CONTENT_FRAGMENT_CFG_KEY, "<simple name=\"logNode2\"><type>org.kuali.rice.kew.engine.node.LogNode</type><level>ErRoR</level><log>Custom.Logger.Name</log><message>THAT'S ALL FOLKS</message></simple>");
130         assertHasConfigParam(routeNodeDef, "type", "org.kuali.rice.kew.engine.node.LogNode");
131         assertHasConfigParam(routeNodeDef, "level", "ErRoR");
132         assertHasConfigParam(routeNodeDef, "message", "THAT'S ALL FOLKS");
133     }   
134 }