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 java.util.Vector;
    25
    26  import javax.servlet.http.HttpServletResponse;
    27
    28  import org.apache.turbine.om.security.User;
    29  import org.apache.turbine.test.BaseTestCase;
    30  import org.apache.turbine.test.EnhancedMockHttpServletRequest;
    31  import org.apache.turbine.test.EnhancedMockHttpSession;
    32  import org.apache.turbine.util.RunData;
    33  import org.apache.turbine.util.TurbineConfig;
    34  import org.apache.turbine.util.uri.URIConstants;
    35  import org.junit.AfterClass;
    36  import org.junit.Before;
    37  import org.junit.BeforeClass;
    38  import org.junit.Test;
    39
    40  import com.mockobjects.servlet.MockHttpServletResponse;
    41  import com.mockobjects.servlet.MockServletConfig;
    42
    43  import static org.junit.Assert.*;
    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: DetermineTargetValveTest.java 1606111 2014-06-27 14:46:47Z gk $
    51   */
    52  public class DetermineTargetValveTest 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      @BeforeClass
    62      public static void init() {
    63          tc = new TurbineConfig(
    64                              ".",
    65                              "/conf/test/CompleteTurbineResources.properties");
    66          tc.initialize();
    67      }
    68
    69      @Before
    70      public void setUpBefore() throws Exception {
    71          config = new MockServletConfig();
    72          config.setupNoParameters();
    73          request = new EnhancedMockHttpServletRequest();
    74          request.setupServerName("bob");
    75          request.setupGetProtocol("http");
    76          request.setupScheme("scheme");
    77          request.setupPathInfo("damn");
    78          request.setupGetServletPath("damn2");
    79          request.setupGetContextPath("wow");
    80          request.setupGetContentType("html/text");
    81          request.setupAddHeader("Content-type", "html/text");
    82          request.setupAddHeader("Accept-Language", "en-US");
    83
    84          session = new EnhancedMockHttpSession();
    85          response = new MockHttpServletResponse();
    86
    87          session.setupGetAttribute(User.SESSION_KEY, null);
    88          request.setSession(session);
    89      }
    90
    91      /**
    92       * Tests the Valve.
    93       */
    94      @Test public void testScreenSet() throws Exception
    95      {
    96          Vector<String> v = new Vector<String>();
    97          v.add(URIConstants.CGI_SCREEN_PARAM);
    98          request.setupGetParameterNames(v.elements());
    99
    100         request.setupAddParameter(URIConstants.CGI_SCREEN_PARAM,"TestScreen");
    101
    102         RunData runData = getRunData(request,response,config);
    103
    104         Pipeline pipeline = new TurbinePipeline();
    105         PipelineData pipelineData = runData;
    106         DetermineTargetValve valve = new DetermineTargetValve();
    107         pipeline.addValve(valve);
    108
    109         pipeline.invoke(pipelineData);
    110         assertEquals("TestScreen",runData.getScreen());
    111     }
    112
    113     @Test public void testScreenNotSet() throws Exception
    114     {
    115         Vector<String> v = new Vector<String>();
    116         v.add(URIConstants.CGI_SCREEN_PARAM);
    117         request.setupGetParameterNames(v.elements());
    118
    119         String screens[] = new String[1];
    120         screens[0]=null;
    121         request.setupAddParameter(URIConstants.CGI_SCREEN_PARAM,screens);
    122
    123         RunData runData = getRunData(request,response,config);
    124
    125         Pipeline pipeline = new TurbinePipeline();
    126         PipelineData pipelineData = runData;
    127
    128         DetermineTargetValve valve = new DetermineTargetValve();
    129         pipeline.addValve(valve);
    130
    131         pipeline.invoke(pipelineData);
    132         assertEquals("",runData.getScreen());
    133     }
    134
    135     @AfterClass
    136     public static void destroy() {
    137         tc.dispose();
    138     }
    139 }