001/**
002 * Copyright 2005-2014 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 */
016package org.kuali.rice.edl.impl;
017
018import static org.junit.Assert.assertTrue;
019
020import java.io.InputStream;
021import java.util.Map;
022
023import javax.xml.parsers.DocumentBuilderFactory;
024
025import org.junit.Test;
026import org.kuali.rice.kew.test.KEWTestCase;
027import org.kuali.rice.kew.test.TestUtilities;
028import org.w3c.dom.Document;
029import org.w3c.dom.Node;
030import org.w3c.dom.NodeList;
031
032
033public class EDLGlobalConfigFactoryTest extends KEWTestCase {
034
035        /**
036         * Test a positive case global parsing..
037         * 
038         * @throws Exception
039         */
040        @Test public void testEDLGlobalConfigParsing() throws Exception {
041
042        EDLGlobalConfig edlGlobalConfig = EDLGlobalConfigFactory.createEDLGlobalConfig("classpath:org/kuali/rice/kew/edl/TestEDLConfig.xml");
043                Map preProcessors = edlGlobalConfig.getPreProcessors();
044                Map postProcessors = edlGlobalConfig.getPostProcessors();
045                Map stateComps = edlGlobalConfig.getStateComponents();
046
047        InputStream fakeyEDL = TestUtilities.loadResource(this.getClass(), "FakeyEDL.xml");
048                Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(fakeyEDL);
049                
050                Object configProcessorInst = null;
051                NodeList edlDefinitionNodes = doc.getElementsByTagName("fieldDef");
052                for (int i = 0; i < edlDefinitionNodes.getLength(); i++) {
053                        Node definitionNode = edlDefinitionNodes.item(i);
054                        Class configClass = (Class)edlGlobalConfig.getConfigProcessor(definitionNode, null);
055                        if (configClass != null) {
056                                configProcessorInst = configClass.newInstance();
057                        }
058                        
059                }
060                
061                assertTrue("should be 1 preProcessor", preProcessors.size() == 1);
062                assertTrue("should be 1 postProcessor", postProcessors.size() == 1);
063                assertTrue("should be 1 stateComps", stateComps.size() == 1);
064                assertTrue("Object made from config proces, arg1", configProcessorInst instanceof TestConfigProcessor);
065                
066        }
067        
068
069}