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  import static org.mockito.Mockito.mock;
    26  import static org.mockito.Mockito.when;
    27
    28  import java.util.Vector;
    29
    30  import javax.servlet.ServletConfig;
    31  import javax.servlet.http.HttpServletRequest;
    32  import javax.servlet.http.HttpServletResponse;
    33
    34  import org.apache.turbine.test.BaseTestCase;
    35  import org.apache.turbine.util.RunData;
    36  import org.apache.turbine.util.TurbineConfig;
    37  import org.apache.turbine.util.uri.URIConstants;
    38  import org.junit.AfterClass;
    39  import org.junit.Before;
    40  import org.junit.BeforeClass;
    41  import org.junit.Test;
    42
    43  /**
    44   * Tests TurbinePipeline.
    45   *
    46   * @author <a href="mailto:epugh@opensourceConnections.com">Eric Pugh</a>
    47   * @author <a href="mailto:peter@courcoux.biz">Peter Courcoux</a>
    48   * @version $Id: DetermineActionValveTest.java 1754909 2016-08-02 12:55:35Z tv $
    49   */
    50  public class DetermineActionValveTest extends BaseTestCase
    51  {
    52      private static TurbineConfig tc = null;
    53      private ServletConfig config = null;
    54      private HttpServletRequest request = null;
    55      private HttpServletResponse response = null;
    56
    57      @BeforeClass
    58      public static void init()
    59      {
    60          tc = new TurbineConfig(
    61                              ".",
    62                              "/conf/test/CompleteTurbineResources.properties");
    63          tc.initialize();
    64      }
    65
    66      @Before
    67      public void setUpBefore() throws Exception
    68      {
    69          config = mock(ServletConfig.class);
    70          request = getMockRequest();
    71          response = mock(HttpServletResponse.class);
    72
    73          Vector<String> v = new Vector<String>();
    74          v.add(URIConstants.CGI_ACTION_PARAM);
    75          when(request.getParameterNames()).thenReturn(v.elements());
    76
    77          when(request.getParameterValues(URIConstants.CGI_ACTION_PARAM)).thenReturn(new String[] { "TestAction" });
    78      }
    79
    80      /**
    81       * Tests the Valve.
    82       */
    83      @Test public void testValve() throws Exception
    84      {
    85          RunData runData = getRunData(request,response,config);
    86
    87          Pipeline pipeline = new TurbinePipeline();
    88          PipelineData pipelineData = runData;
    89
    90          DetermineActionValve valve = new DetermineActionValve();
    91          pipeline.addValve(valve);
    92
    93          pipeline.invoke(pipelineData);
    94          assertEquals("TestAction",runData.getAction());
    95      }
    96
    97      @AfterClass
    98      public static void destroy() {
    99          tc.dispose();
    100     }
    101 }