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.TurbineConstants;
30  import org.apache.turbine.modules.actions.LoginUser;
31  import org.apache.turbine.om.security.User;
32  import org.apache.turbine.services.template.TemplateService;
33  import org.apache.turbine.test.BaseTestCase;
34  import org.apache.turbine.test.EnhancedMockHttpServletRequest;
35  import org.apache.turbine.test.EnhancedMockHttpSession;
36  import org.apache.turbine.util.RunData;
37  import org.apache.turbine.util.TurbineConfig;
38  
39  import com.mockobjects.servlet.MockHttpServletResponse;
40  import com.mockobjects.servlet.MockServletConfig;
41  
42  /**
43   * Tests TurbinePipeline.
44   *
45   * @author <a href="mailto:epugh@opensourceConnections.com">Eric Pugh</a>
46   * @author <a href="mailto:peter@courcoux.biz">Peter Courcoux</a>
47   * @version $Id: DefaultLoginValveTest.java 757213 2009-03-22 16:43:31Z tv $
48   */
49  public class DefaultLoginValveTest extends BaseTestCase
50  {
51      private static TurbineConfig tc = null;
52      private static TemplateService ts = null;
53      private MockServletConfig config = null;
54      private EnhancedMockHttpServletRequest request = null;
55      private EnhancedMockHttpSession session = null;
56      private HttpServletResponse response = null;
57      private static ServletConfig sc = null;
58      /**
59       * Constructor
60       */
61      public DefaultLoginValveTest(String testName) throws Exception
62      {
63          super(testName);
64      }
65  
66      protected void setUp() throws Exception {
67          super.setUp();
68          config = new MockServletConfig();
69          config.setupNoParameters();
70          request = new EnhancedMockHttpServletRequest();
71          request.setupServerName("bob");
72          request.setupGetProtocol("http");
73          request.setupScheme("scheme");
74          request.setupPathInfo("damn");
75          request.setupGetServletPath("damn2");
76          request.setupGetContextPath("wow");
77          request.setupGetContentType("html/text");
78          request.setupAddHeader("Content-type", "html/text");
79          request.setupAddHeader("Accept-Language", "en-US");
80  
81  
82  
83  
84  
85  
86          session = new EnhancedMockHttpSession();
87          response = new MockHttpServletResponse();
88  
89          session.setupGetAttribute(User.SESSION_KEY, null);
90  
91          request.setSession(session);
92  
93  
94  
95          sc = config;
96          tc =
97              new TurbineConfig(
98                      ".",
99              "/conf/test/CompleteTurbineResources.properties");
100         tc.initialize();
101     }
102 
103     /**
104      * Tests the Valve.
105      */
106     public void testDefaults() throws Exception
107     {
108 
109         Vector v = new Vector();
110         v.add(LoginUser.CGI_USERNAME);
111         v.add(LoginUser.CGI_PASSWORD);
112         request.setupGetParameterNames(v.elements());
113 
114         request.setupAddParameter(LoginUser.CGI_USERNAME,"username");
115         request.setupAddParameter(LoginUser.CGI_PASSWORD,"password");
116 
117         RunData runData = getRunData(request,response,config);
118         runData.setAction(TurbineConstants.ACTION_LOGIN_DEFAULT);
119 
120         Pipeline pipeline = new TurbinePipeline();
121         PipelineData pipelineData = runData;
122 
123         DefaultLoginValve valve = new DefaultLoginValve();
124         pipeline.addValve(valve);
125         pipeline.initialize();
126 
127         pipeline.invoke(pipelineData);
128         User user = runData.getUser();
129         assertNotNull(user);
130         assertEquals("username",user.getName());
131         assertTrue(user.hasLoggedIn());
132 
133     }
134 
135 
136 
137 
138 
139 }