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: DetermineTargetValveTest.java 1754909 2016-08-02 12:55:35Z tv $
49   */
50  public class DetermineTargetValveTest 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  
74      /**
75       * Tests the Valve.
76       */
77      @Test public void testScreenSet() throws Exception
78      {
79          Vector<String> v = new Vector<String>();
80          v.add(URIConstants.CGI_SCREEN_PARAM);
81          when(request.getParameterNames()).thenReturn(v.elements());
82  
83          when(request.getParameterValues(URIConstants.CGI_SCREEN_PARAM)).thenReturn(new String[] { "TestScreen" });
84  
85          RunData runData = getRunData(request,response,config);
86  
87          Pipeline pipeline = new TurbinePipeline();
88          PipelineData pipelineData = runData;
89          DetermineTargetValve valve = new DetermineTargetValve();
90          pipeline.addValve(valve);
91  
92          pipeline.invoke(pipelineData);
93          assertEquals("TestScreen",runData.getScreen());
94      }
95  
96      @Test public void testScreenNotSet() throws Exception
97      {
98          Vector<String> v = new Vector<String>();
99          v.add(URIConstants.CGI_SCREEN_PARAM);
100         when(request.getParameterNames()).thenReturn(v.elements());
101 
102         when(request.getParameterValues(URIConstants.CGI_SCREEN_PARAM)).thenReturn(new String[] { null });
103 
104         RunData runData = getRunData(request,response,config);
105 
106         Pipeline pipeline = new TurbinePipeline();
107         PipelineData pipelineData = runData;
108 
109         DetermineTargetValve valve = new DetermineTargetValve();
110         pipeline.addValve(valve);
111 
112         pipeline.invoke(pipelineData);
113         assertEquals("",runData.getScreen());
114     }
115 
116     @AfterClass
117     public static void destroy()
118     {
119         tc.dispose();
120     }
121 }