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 static org.junit.Assert.assertEquals;
26  import static org.junit.Assert.assertNotNull;
27  import static org.junit.Assert.assertTrue;
28  import static org.mockito.Mockito.mock;
29  
30  import javax.servlet.ServletConfig;
31  import javax.servlet.http.HttpServletRequest;
32  import javax.servlet.http.HttpServletResponse;
33  
34  import org.apache.fulcrum.security.model.turbine.entity.impl.TurbineUserImpl;
35  import org.apache.turbine.om.security.DefaultUserImpl;
36  import org.apache.turbine.om.security.User;
37  import org.apache.turbine.test.BaseTestCase;
38  import org.apache.turbine.util.RunData;
39  import org.apache.turbine.util.TurbineConfig;
40  import org.junit.AfterClass;
41  import org.junit.Before;
42  import org.junit.BeforeClass;
43  import org.junit.Test;
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 1754909 2016-08-02 12:55:35Z tv $
51   */
52  public class DefaultACLCreationValveTest extends BaseTestCase
53  {
54      private static TurbineConfig tc = null;
55      private ServletConfig config = null;
56      private HttpServletRequest request = null;
57      private HttpServletResponse response = null;
58  
59      @BeforeClass
60      public static void init()
61      {
62          tc = new TurbineConfig(
63                              ".",
64                              "/conf/test/CompleteTurbineResources.properties");
65          tc.initialize();
66      }
67  
68      @Before
69      public void setUpBefore() throws Exception
70      {
71          config = mock(ServletConfig.class);
72          request = getMockRequest();
73          response = mock(HttpServletResponse.class);
74      }
75  
76      @Test public void testLoggedInUser() throws Exception
77      {
78          RunData runData = getRunData(request,response,config);
79          User tu = new DefaultUserImpl(new TurbineUserImpl());
80          tu.setName("username");
81          tu.setHasLoggedIn(Boolean.TRUE);
82          runData.setAction("TestAction");
83          runData.setUser(tu);
84  
85          Pipeline pipeline = new TurbinePipeline();
86          PipelineData pipelineData = runData;
87  
88          DefaultACLCreationValve valve = new DefaultACLCreationValve();
89          pipeline.addValve(valve);
90          pipeline.initialize();
91  
92          pipeline.invoke(pipelineData);
93          User user = runData.getUser();
94          assertNotNull(user);
95          assertEquals("username",user.getName());
96          assertTrue(user.hasLoggedIn());
97          assertNotNull(runData.getACL());
98      }
99  
100     @AfterClass
101     public static void destroy()
102     {
103         tc.dispose();
104     }
105 }