001package org.apache.turbine.pipeline;
002
003
004/*
005 * Licensed to the Apache Software Foundation (ASF) under one
006 * or more contributor license agreements.  See the NOTICE file
007 * distributed with this work for additional information
008 * regarding copyright ownership.  The ASF licenses this file
009 * to you under the Apache License, Version 2.0 (the
010 * "License"); you may not use this file except in compliance
011 * with the License.  You may obtain a copy of the License at
012 *
013 *   http://www.apache.org/licenses/LICENSE-2.0
014 *
015 * Unless required by applicable law or agreed to in writing,
016 * software distributed under the License is distributed on an
017 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
018 * KIND, either express or implied.  See the License for the
019 * specific language governing permissions and limitations
020 * under the License.
021 */
022
023
024import static org.junit.Assert.assertEquals;
025
026import java.util.Vector;
027
028import javax.servlet.http.HttpServletResponse;
029
030import org.apache.turbine.om.security.User;
031import org.apache.turbine.test.BaseTestCase;
032import org.apache.turbine.test.EnhancedMockHttpServletRequest;
033import org.apache.turbine.test.EnhancedMockHttpSession;
034import org.apache.turbine.util.RunData;
035import org.apache.turbine.util.TurbineConfig;
036import org.apache.turbine.util.uri.URIConstants;
037import org.junit.AfterClass;
038import org.junit.Before;
039import org.junit.BeforeClass;
040import org.junit.Test;
041
042import com.mockobjects.servlet.MockHttpServletResponse;
043import com.mockobjects.servlet.MockServletConfig;
044
045/**
046 * Tests TurbinePipeline.
047 *
048 * @author <a href="mailto:epugh@opensourceConnections.com">Eric Pugh</a>
049 * @author <a href="mailto:peter@courcoux.biz">Peter Courcoux</a>
050 * @version $Id: DetermineActionValveTest.java 1606111 2014-06-27 14:46:47Z gk $
051 */
052public class DetermineActionValveTest extends BaseTestCase
053{
054    private static TurbineConfig tc = null;
055    private MockServletConfig config = null;
056    private EnhancedMockHttpServletRequest request = null;
057    private EnhancedMockHttpSession session = null;
058    private HttpServletResponse response = null;
059
060
061    
062    @BeforeClass
063    public static void init() {
064        tc = new TurbineConfig(
065                            ".",
066                            "/conf/test/CompleteTurbineResources.properties");
067        tc.initialize();
068    }
069
070    @Before
071    public void setUpBefore() throws Exception {
072        config = new MockServletConfig();
073        config.setupNoParameters();
074        request = new EnhancedMockHttpServletRequest();
075        request.setupServerName("bob");
076        request.setupGetProtocol("http");
077        request.setupScheme("scheme");
078        request.setupPathInfo("damn");
079        request.setupGetServletPath("damn2");
080        request.setupGetContextPath("wow");
081        request.setupGetContentType("html/text");
082        request.setupAddHeader("Content-type", "html/text");
083        request.setupAddHeader("Accept-Language", "en-US");
084
085        Vector<String> v = new Vector<String>();
086        v.add(URIConstants.CGI_ACTION_PARAM);
087        request.setupGetParameterNames(v.elements());
088
089        request.setupAddParameter(URIConstants.CGI_ACTION_PARAM,"TestAction");
090
091        session = new EnhancedMockHttpSession();
092        response = new MockHttpServletResponse();
093
094        session.setupGetAttribute(User.SESSION_KEY, null);
095        request.setSession(session);
096    }
097
098    /**
099     * Tests the Valve.
100     */
101    @Test public void testValve() throws Exception
102    {
103        RunData runData = getRunData(request,response,config);
104
105        Pipeline pipeline = new TurbinePipeline();
106        PipelineData pipelineData = runData;
107
108        DetermineActionValve valve = new DetermineActionValve();
109        pipeline.addValve(valve);
110
111        pipeline.invoke(pipelineData);
112        assertEquals("TestAction",runData.getAction());
113    }
114    
115    @AfterClass
116    public static void destroy() {
117        tc.dispose();
118    }
119}