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  
25  import javax.servlet.http.HttpServletResponse;
26  
27  import org.apache.fulcrum.security.model.turbine.entity.impl.TurbineUserImpl;
28  import org.apache.turbine.om.security.DefaultUserImpl;
29  import org.apache.turbine.om.security.User;
30  import org.apache.turbine.test.BaseTestCase;
31  import org.apache.turbine.test.EnhancedMockHttpServletRequest;
32  import org.apache.turbine.test.EnhancedMockHttpSession;
33  import org.apache.turbine.util.RunData;
34  import org.apache.turbine.util.TurbineConfig;
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: DefaultACLCreationValveTest.java 1606111 2014-06-27 14:46:47Z gk $
51   */
52  public class DefaultACLCreationValveTest 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          session = new EnhancedMockHttpSession();
84          response = new MockHttpServletResponse();
85          request.setSession(session);
86      }
87  
88  
89      @Test public void testLoggedInUser() throws Exception
90      {
91          RunData runData = getRunData(request,response,config);
92          User tu = new DefaultUserImpl(new TurbineUserImpl());
93          tu.setName("username");
94          tu.setHasLoggedIn(Boolean.TRUE);
95          runData.setAction("TestAction");
96          runData.setUser(tu);
97  
98          Pipeline pipeline = new TurbinePipeline();
99          PipelineData pipelineData = runData;
100 
101         DefaultACLCreationValve valve = new DefaultACLCreationValve();
102         pipeline.addValve(valve);
103         pipeline.initialize();
104 
105         pipeline.invoke(pipelineData);
106         User user = runData.getUser();
107         assertNotNull(user);
108         assertEquals("username",user.getName());
109         assertTrue(user.hasLoggedIn());
110         assertNotNull(runData.getACL());
111     }
112     
113     @AfterClass
114     public static void destroy() {
115         tc.dispose();
116     }
117 }