View Javadoc

    1   package org.apache.turbine.pipeline;
    2
    3
    4   /*
    5    * Licensed to the Apache Software Foundation (ASF) under one
    6    * or more contributor license agreements.  See the NOTICE file
    7    * distributed with this work for additional information
    8    * regarding copyright ownership.  The ASF licenses this file
    9    * to you under the Apache License, Version 2.0 (the
    10   * "License"); you may not use this file except in compliance
    11   * with the License.  You may obtain a copy of the License at
    12   *
    13   *   http://www.apache.org/licenses/LICENSE-2.0
    14   *
    15   * Unless required by applicable law or agreed to in writing,
    16   * software distributed under the License is distributed on an
    17   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    18   * KIND, either express or implied.  See the License for the
    19   * specific language governing permissions and limitations
    20   * under the License.
    21   */
    22
    23
    24  import static org.junit.Assert.assertEquals;
    25
    26  import java.util.Vector;
    27
    28  import javax.servlet.http.HttpServletResponse;
    29
    30  import org.apache.turbine.om.security.User;
    31  import org.apache.turbine.test.BaseTestCase;
    32  import org.apache.turbine.test.EnhancedMockHttpServletRequest;
    33  import org.apache.turbine.test.EnhancedMockHttpSession;
    34  import org.apache.turbine.util.RunData;
    35  import org.apache.turbine.util.TurbineConfig;
    36  import org.apache.turbine.util.uri.URIConstants;
    37  import org.junit.AfterClass;
    38  import org.junit.Before;
    39  import org.junit.BeforeClass;
    40  import org.junit.Test;
    41
    42  import com.mockobjects.servlet.MockHttpServletResponse;
    43  import com.mockobjects.servlet.MockServletConfig;
    44
    45  /**
    46   * Tests TurbinePipeline.
    47   *
    48   * @author <a href="mailto:epugh@opensourceConnections.com">Eric Pugh</a>
    49   * @author <a href="mailto:peter@courcoux.biz">Peter Courcoux</a>
    50   * @version $Id: DetermineActionValveTest.java 1606111 2014-06-27 14:46:47Z gk $
    51   */
    52  public class DetermineActionValveTest extends BaseTestCase
    53  {
    54      private static TurbineConfig tc = null;
    55      private MockServletConfig config = null;
    56      private EnhancedMockHttpServletRequest request = null;
    57      private EnhancedMockHttpSession session = null;
    58      private HttpServletResponse response = null;
    59
    60
    61
    62      @BeforeClass
    63      public static void init() {
    64          tc = new TurbineConfig(
    65                              ".",
    66                              "/conf/test/CompleteTurbineResources.properties");
    67          tc.initialize();
    68      }
    69
    70      @Before
    71      public void setUpBefore() throws Exception {
    72          config = new MockServletConfig();
    73          config.setupNoParameters();
    74          request = new EnhancedMockHttpServletRequest();
    75          request.setupServerName("bob");
    76          request.setupGetProtocol("http");
    77          request.setupScheme("scheme");
    78          request.setupPathInfo("damn");
    79          request.setupGetServletPath("damn2");
    80          request.setupGetContextPath("wow");
    81          request.setupGetContentType("html/text");
    82          request.setupAddHeader("Content-type", "html/text");
    83          request.setupAddHeader("Accept-Language", "en-US");
    84
    85          Vector<String> v = new Vector<String>();
    86          v.add(URIConstants.CGI_ACTION_PARAM);
    87          request.setupGetParameterNames(v.elements());
    88
    89          request.setupAddParameter(URIConstants.CGI_ACTION_PARAM,"TestAction");
    90
    91          session = new EnhancedMockHttpSession();
    92          response = new MockHttpServletResponse();
    93
    94          session.setupGetAttribute(User.SESSION_KEY, null);
    95          request.setSession(session);
    96      }
    97
    98      /**
    99       * 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 }