View Javadoc

1   /**
2    * Copyright 2005-2011 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.edl.impl;
17  
18  import static org.junit.Assert.assertTrue;
19  
20  import java.io.InputStream;
21  import java.util.Map;
22  
23  import javax.xml.parsers.DocumentBuilderFactory;
24  
25  import org.junit.Test;
26  import org.kuali.rice.kew.test.KEWTestCase;
27  import org.kuali.rice.kew.test.TestUtilities;
28  import org.w3c.dom.Document;
29  import org.w3c.dom.Node;
30  import org.w3c.dom.NodeList;
31  
32  
33  public class EDLGlobalConfigFactoryTest extends KEWTestCase {
34  
35  	/**
36  	 * Test a positive case global parsing..
37  	 * 
38  	 * @throws Exception
39  	 */
40  	@Test public void testEDLGlobalConfigParsing() throws Exception {
41  
42          EDLGlobalConfig edlGlobalConfig = EDLGlobalConfigFactory.createEDLGlobalConfig("classpath:org/kuali/rice/kew/edl/TestEDLConfig.xml");
43  		Map preProcessors = edlGlobalConfig.getPreProcessors();
44  		Map postProcessors = edlGlobalConfig.getPostProcessors();
45  		Map stateComps = edlGlobalConfig.getStateComponents();
46  
47          InputStream fakeyEDL = TestUtilities.loadResource(this.getClass(), "FakeyEDL.xml");
48  		Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(fakeyEDL);
49  		
50  		Object configProcessorInst = null;
51  		NodeList edlDefinitionNodes = doc.getElementsByTagName("fieldDef");
52  		for (int i = 0; i < edlDefinitionNodes.getLength(); i++) {
53  			Node definitionNode = edlDefinitionNodes.item(i);
54  			Class configClass = (Class)edlGlobalConfig.getConfigProcessor(definitionNode, null);
55  			if (configClass != null) {
56  				configProcessorInst = configClass.newInstance();
57  			}
58  			
59  		}
60  		
61  		assertTrue("should be 1 preProcessor", preProcessors.size() == 1);
62  		assertTrue("should be 1 postProcessor", postProcessors.size() == 1);
63  		assertTrue("should be 1 stateComps", stateComps.size() == 1);
64  		assertTrue("Object made from config proces, arg1", configProcessorInst instanceof TestConfigProcessor);
65  		
66  	}
67  	
68  
69  }