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.ServletConfig;
27  import javax.servlet.http.HttpServletResponse;
28  
29  import org.apache.turbine.om.security.User;
30  import org.apache.turbine.services.template.TemplateService;
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  
38  import com.mockobjects.servlet.MockHttpServletResponse;
39  import com.mockobjects.servlet.MockServletConfig;
40  
41  /**
42   * Tests TurbinePipeline.
43   *
44   * @author <a href="mailto:epugh@opensourceConnections.com">Eric Pugh</a>
45   * @author <a href="mailto:peter@courcoux.biz">Peter Courcoux</a>
46   * @version $Id: DetermineTargetValveTest.java 615328 2008-01-25 20:25:05Z tv $
47   */
48  public class DetermineTargetValveTest extends BaseTestCase
49  {
50      private static TurbineConfig tc = null;
51      private static TemplateService ts = null;
52      private MockServletConfig config = null;
53      private EnhancedMockHttpServletRequest request = null;
54      private EnhancedMockHttpSession session = null;
55      private HttpServletResponse response = null;
56      private static ServletConfig sc = null;
57      /**
58       * Constructor
59       */
60      public DetermineTargetValveTest(String testName) throws Exception
61      {
62          super(testName);
63      }
64  
65      protected void setUp() throws Exception {
66          super.setUp();
67          config = new MockServletConfig();
68          config.setupNoParameters();
69          request = new EnhancedMockHttpServletRequest();
70          request.setupServerName("bob");
71          request.setupGetProtocol("http");
72          request.setupScheme("scheme");
73          request.setupPathInfo("damn");
74          request.setupGetServletPath("damn2");
75          request.setupGetContextPath("wow");
76          request.setupGetContentType("html/text");
77          request.setupAddHeader("Content-type", "html/text");
78          request.setupAddHeader("Accept-Language", "en-US");
79  
80  
81  
82  
83  
84  
85          session = new EnhancedMockHttpSession();
86          response = new MockHttpServletResponse();
87  
88          session.setupGetAttribute(User.SESSION_KEY, null);
89          request.setSession(session);
90  
91  
92  
93          sc = config;
94          tc =
95              new TurbineConfig(
96                      ".",
97              "/conf/test/CompleteTurbineResources.properties");
98          tc.initialize();
99      }
100 
101     /**
102      * Tests the Valve.
103      */
104     public void testScreenSet() throws Exception
105     {
106         Vector v = new Vector();
107         v.add(URIConstants.CGI_SCREEN_PARAM);
108         request.setupGetParameterNames(v.elements());
109 
110         request.setupAddParameter(URIConstants.CGI_SCREEN_PARAM,"TestScreen");
111 
112         RunData runData = getRunData(request,response,config);
113 
114         Pipeline pipeline = new TurbinePipeline();
115         PipelineData pipelineData = runData;
116         DetermineTargetValve valve = new DetermineTargetValve();
117         pipeline.addValve(valve);
118 
119         pipeline.invoke(pipelineData);
120         assertEquals("TestScreen",runData.getScreen());
121 
122 
123     }
124     public void testScreenNotSet() throws Exception
125     {
126         Vector v = new Vector();
127         v.add(URIConstants.CGI_SCREEN_PARAM);
128         request.setupGetParameterNames(v.elements());
129 
130         String screens[] = new String[1];
131         screens[0]=null;
132         request.setupAddParameter(URIConstants.CGI_SCREEN_PARAM,screens);
133 
134         RunData runData = getRunData(request,response,config);
135 
136         Pipeline pipeline = new TurbinePipeline();
137         PipelineData pipelineData = runData;
138 
139         DetermineTargetValve valve = new DetermineTargetValve();
140         pipeline.addValve(valve);
141 
142         pipeline.invoke(pipelineData);
143         assertEquals("",runData.getScreen());
144 
145 
146     }
147 
148 
149 }