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.edl.impl;
017    
018    import static org.junit.Assert.assertEquals;
019    import static org.junit.Assert.assertNotNull;
020    import static org.junit.Assert.assertTrue;
021    
022    import java.util.Map;
023    
024    import org.junit.Test;
025    import org.kuali.rice.core.api.config.property.Config;
026    import org.kuali.rice.core.api.config.property.ConfigContext;
027    import org.kuali.rice.edl.impl.service.EDocLiteService;
028    import org.kuali.rice.edl.impl.service.EdlServiceLocator;
029    import org.kuali.rice.kew.test.KEWTestCase;
030    import org.springframework.mock.web.MockHttpServletRequest;
031    import org.w3c.dom.Element;
032    
033    
034    public class EDLControllerTest extends KEWTestCase {
035    
036            protected void loadTestData() throws Exception {
037                    super.loadXmlFile("widgets.xml");
038                    super.loadXmlFile("edlstyle.xml");
039                    super.loadXmlFile("FakeyEDL.xml");
040            }
041    
042            @Test public void testEDLControllerCreation() throws Exception {
043                    ConfigContext.getCurrentContextConfig().putProperty(Config.EDL_CONFIG_LOCATION, "classpath:org/kuali/rice/kew/edl/TestEDLConfig.xml");
044    
045    
046                    EDLController edlController = getEDLService().getEDLControllerUsingEdlName("FakeyEDL");
047                    edlController.setEdlContext(getEDLcontext());
048                    assertNotNull("There should be a default dom in the edlcontoller", edlController.getDefaultDOM());
049                    edlController.notifyComponents();
050    
051                    assertTrue("PreProcess component should have been notified", TestPreProcessor.isContacted());
052                    assertTrue("PostProcessor component should have been notified", TestPostProcessor.isContacted());
053                    assertTrue("State component should have been notified", TestStateComponent.isContacted());
054                    assertTrue("ConfigProcess component should have been notified", TestConfigProcessor.isContacted());
055    
056                    //make sure they all have the correct config element passed in
057                    Element preProcessorConfigElement = (Element) ((Map.Entry)edlController.getEdlGlobalConfig().getPreProcessors().entrySet().iterator().next()).getKey();
058                    assertEquals("PreProcessor config element is of the wrong class", "org.kuali.rice.edl.impl.TestPreProcessor", preProcessorConfigElement.getFirstChild().getNodeValue());
059    
060                    Element postProcessorConfigElement = (Element) ((Map.Entry)edlController.getEdlGlobalConfig().getPostProcessors().entrySet().iterator().next()).getKey();
061                    assertEquals("PostProcessor config element is of the wrong class", "org.kuali.rice.edl.impl.TestPostProcessor", postProcessorConfigElement.getFirstChild().getNodeValue());
062    
063                    Element stateConfigElement = (Element) ((Map.Entry)edlController.getEdlGlobalConfig().getStateComponents().entrySet().iterator().next()).getKey();
064                    assertEquals("State config element is of the wrong class", "org.kuali.rice.edl.impl.TestStateComponent", stateConfigElement.getFirstChild().getNodeValue());
065    
066                    Element configProcessorConfigElement = (Element) ((Map.Entry)edlController.getConfigProcessors().entrySet().iterator().next()).getKey();
067                    assertEquals("Config processor element should be fielDef", "fieldDef", configProcessorConfigElement.getNodeName());
068    
069            }
070    
071            private EDLContext getEDLcontext() {
072                    EDLContext edlContext = new EDLContext();
073                    edlContext.setRequestParser(new RequestParser(new MockHttpServletRequest()));
074                    return edlContext;
075            }
076    
077            private EDocLiteService getEDLService() {
078                    return EdlServiceLocator.getEDocLiteService();
079            }
080    
081    }