1   package org.apache.turbine.pipeline;
2   
3   
4   /*
5    * Copyright 2001-2004 The Apache Software Foundation.
6    *
7    * Licensed under the Apache License, Version 2.0 (the "License")
8    * you may not use this file except in compliance with the License.
9    * You may obtain a copy of the License at
10   *
11   *     http://www.apache.org/licenses/LICENSE-2.0
12   *
13   * Unless required by applicable law or agreed to in writing, software
14   * distributed under the License is distributed on an "AS IS" BASIS,
15   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16   * See the License for the specific language governing permissions and
17   * limitations under the License.
18   */
19  
20  
21  import java.util.Vector;
22  
23  import javax.servlet.ServletConfig;
24  import javax.servlet.http.HttpServletResponse;
25  
26  import org.apache.turbine.om.security.User;
27  import org.apache.turbine.services.template.TemplateService;
28  import org.apache.turbine.test.BaseTestCase;
29  import org.apache.turbine.test.EnhancedMockHttpServletRequest;
30  import org.apache.turbine.test.EnhancedMockHttpSession;
31  import org.apache.turbine.util.RunData;
32  import org.apache.turbine.util.TurbineConfig;
33  import org.apache.turbine.util.uri.URIConstants;
34  
35  import com.mockobjects.servlet.MockHttpServletResponse;
36  import com.mockobjects.servlet.MockServletConfig;
37  
38  /***
39   * Tests TurbinePipeline.
40   *
41   * @author <a href="mailto:epugh@opensourceConnections.com">Eric Pugh</a>
42   * @author <a href="mailto:peter@courcoux.biz">Peter Courcoux</a>
43   * @version $Id: DetermineActionValveTest.java 222043 2004-12-06 17:47:33Z painter $
44   */
45  public class DetermineActionValveTest extends BaseTestCase
46  {
47      private static TurbineConfig tc = null;
48      private static TemplateService ts = null;
49      private MockServletConfig config = null;
50      private EnhancedMockHttpServletRequest request = null;
51      private EnhancedMockHttpSession session = null;
52      private HttpServletResponse response = null;
53      private static ServletConfig sc = null;
54      /***
55       * Constructor
56       */
57      public DetermineActionValveTest(String testName) throws Exception
58      {
59          super(testName);
60      }
61  
62      protected void setUp() throws Exception {
63          super.setUp();
64          config = new MockServletConfig();
65          config.setupNoParameters();
66          request = new EnhancedMockHttpServletRequest();
67          request.setupServerName("bob");
68          request.setupGetProtocol("http");
69          request.setupScheme("scheme");
70          request.setupPathInfo("damn");
71          request.setupGetServletPath("damn2");
72          request.setupGetContextPath("wow");
73          request.setupGetContentType("html/text");
74          request.setupAddHeader("Content-type", "html/text");
75          request.setupAddHeader("Accept-Language", "en-US");
76          
77         
78          
79          Vector v = new Vector();
80          v.add(URIConstants.CGI_ACTION_PARAM);
81          request.setupGetParameterNames(v.elements());
82          
83          request.setupAddParameter(URIConstants.CGI_ACTION_PARAM,"TestAction");
84          
85          
86          session = new EnhancedMockHttpSession();
87          response = new MockHttpServletResponse();
88          
89          session.setupGetAttribute(User.SESSION_KEY, null);
90          request.setSession(session);
91          
92          
93          
94          sc = config;
95          tc =
96              new TurbineConfig(
97                      ".",
98              "/conf/test/CompleteTurbineResources.properties");
99          tc.initialize();
100     }
101     
102     /***
103      * Tests the Valve.
104      */
105     public void testValve() throws Exception
106     {
107         RunData runData = getRunData(request,response,config);
108         
109         Pipeline pipeline = new TurbinePipeline();
110         PipelineData pipelineData = runData;
111 
112         DetermineActionValve valve = new DetermineActionValve();
113         pipeline.addValve(valve);
114 
115         pipeline.invoke(pipelineData);
116         assertEquals("TestAction",runData.getAction());
117 
118 
119     }
120     
121    
122 }