    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;
    025import static org.mockito.Mockito.mock;
    026import static org.mockito.Mockito.when;
    027
    028import java.util.Vector;
    029
    030import javax.servlet.ServletConfig;
    031import javax.servlet.http.HttpServletRequest;
    032import javax.servlet.http.HttpServletResponse;
    033
    034import org.apache.turbine.test.BaseTestCase;
    035import org.apache.turbine.util.RunData;
    036import org.apache.turbine.util.TurbineConfig;
    037import org.apache.turbine.util.uri.URIConstants;
    038import org.junit.AfterClass;
    039import org.junit.Before;
    040import org.junit.BeforeClass;
    041import org.junit.Test;
    042
    043/**
    044 * Tests TurbinePipeline.
    045 *
    046 * @author <a href="mailto:epugh@opensourceConnections.com">Eric Pugh</a>
    047 * @author <a href="mailto:peter@courcoux.biz">Peter Courcoux</a>
    048 * @version $Id: DetermineActionValveTest.java 1754909 2016-08-02 12:55:35Z tv $
    049 */
    050public class DetermineActionValveTest extends BaseTestCase
    051{
    052    private static TurbineConfig tc = null;
    053    private ServletConfig config = null;
    054    private HttpServletRequest request = null;
    055    private HttpServletResponse response = null;
    056
    057    @BeforeClass
    058    public static void init()
    059    {
    060        tc = new TurbineConfig(
    061                            ".",
    062                            "/conf/test/CompleteTurbineResources.properties");
    063        tc.initialize();
    064    }
    065
    066    @Before
    067    public void setUpBefore() throws Exception
    068    {
    069        config = mock(ServletConfig.class);
    070        request = getMockRequest();
    071        response = mock(HttpServletResponse.class);
    072
    073        Vector<String> v = new Vector<String>();
    074        v.add(URIConstants.CGI_ACTION_PARAM);
    075        when(request.getParameterNames()).thenReturn(v.elements());
    076
    077        when(request.getParameterValues(URIConstants.CGI_ACTION_PARAM)).thenReturn(new String[] { "TestAction" });
    078    }
    079
    080    /**
    081     * Tests the Valve.
    082     */
    083    @Test public void testValve() throws Exception
    084    {
    085        RunData runData = getRunData(request,response,config);
    086
    087        Pipeline pipeline = new TurbinePipeline();
    088        PipelineData pipelineData = runData;
    089
    090        DetermineActionValve valve = new DetermineActionValve();
    091        pipeline.addValve(valve);
    092
    093        pipeline.invoke(pipelineData);
    094        assertEquals("TestAction",runData.getAction());
    095    }
    096
    097    @AfterClass
    098    public static void destroy() {
    099        tc.dispose();
    100    }
    101}