View Javadoc

1   /*
2    * Copyright 2005-2007 The Kuali Foundation
3    * 
4    * 
5    * Licensed under the Educational Community License, Version 2.0 (the "License");
6    * you may not use this file except in compliance with the License.
7    * You may obtain a copy of the License at
8    * 
9    * http://www.opensource.org/licenses/ecl2.php
10   * 
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  package org.kuali.rice.kew.edl;
18  
19  import java.io.InputStream;
20  import java.util.Map;
21  
22  import javax.xml.parsers.DocumentBuilderFactory;
23  
24  import org.junit.Test;
25  import org.kuali.rice.kew.edl.EDLGlobalConfig;
26  import org.kuali.rice.kew.edl.EDLGlobalConfigFactory;
27  import org.kuali.rice.kew.test.KEWTestCase;
28  import org.kuali.rice.kew.test.TestUtilities;
29  import org.w3c.dom.Document;
30  import org.w3c.dom.Node;
31  import org.w3c.dom.NodeList;
32  
33  
34  public class EDLGlobalConfigFactoryTest extends KEWTestCase {
35  
36  	/**
37  	 * Test a positive case global parsing..
38  	 * 
39  	 * @throws Exception
40  	 */
41  	@Test public void testEDLGlobalConfigParsing() throws Exception {
42  		
43  		EDLGlobalConfig edlGlobalConfig = EDLGlobalConfigFactory.createEDLGlobalConfig("classpath:org/kuali/rice/kew/edl/TestEDLConfig.xml");
44  		Map preProcessors = edlGlobalConfig.getPreProcessors();
45  		Map postProcessors = edlGlobalConfig.getPostProcessors();
46  		Map stateComps = edlGlobalConfig.getStateComponents();
47  		
48  		InputStream fakeyEDL = TestUtilities.loadResource(this.getClass(), "FakeyEDL.xml");
49  		Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(fakeyEDL);
50  		
51  		Object configProcessorInst = null;
52  		NodeList edlDefinitionNodes = doc.getElementsByTagName("fieldDef");
53  		for (int i = 0; i < edlDefinitionNodes.getLength(); i++) {
54  			Node definitionNode = edlDefinitionNodes.item(i);
55  			Class configClass = (Class)edlGlobalConfig.getConfigProcessor(definitionNode);
56  			if (configClass != null) {
57  				configProcessorInst = configClass.newInstance();
58  			}
59  			
60  		}
61  		
62  		assertTrue("should be 1 preProcessor", preProcessors.size() == 1);
63  		assertTrue("should be 1 postProcessor", postProcessors.size() == 1);
64  		assertTrue("should be 1 stateComps", stateComps.size() == 1);
65  		assertTrue("Object made from config proces, arg1", configProcessorInst instanceof TestConfigProcessor);
66  		
67  	}
68  	
69  
70  }