    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.ServletConfig;
    26  import javax.servlet.http.HttpServletResponse;
    27
    28  import org.apache.turbine.om.security.TurbineUser;
    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
    37  import com.mockobjects.servlet.MockHttpServletResponse;
    38  import com.mockobjects.servlet.MockServletConfig;
    39
    40  /**
    41   * Tests TurbinePipeline.
    42   *
    43   * @author <a href="mailto:epugh@opensourceConnections.com">Eric Pugh</a>
    44   * @author <a href="mailto:peter@courcoux.biz">Peter Courcoux</a>
    45   * @version $Id: DefaultACLCreationValveTest.java 757213 2009-03-22 16:43:31Z tv $
    46   */
    47  public class DefaultACLCreationValveTest extends BaseTestCase
    48  {
    49      private static TurbineConfig tc = null;
    50      private static TemplateService ts = null;
    51      private MockServletConfig config = null;
    52      private EnhancedMockHttpServletRequest request = null;
    53      private EnhancedMockHttpSession session = null;
    54      private HttpServletResponse response = null;
    55      private static ServletConfig sc = null;
    56      /**
    57       * Constructor
    58       */
    59      public DefaultACLCreationValveTest(String testName) throws Exception
    60      {
    61          super(testName);
    62      }
    63
    64      protected void setUp() throws Exception {
    65          super.setUp();
    66          config = new MockServletConfig();
    67          config.setupNoParameters();
    68          request = new EnhancedMockHttpServletRequest();
    69          request.setupServerName("bob");
    70          request.setupGetProtocol("http");
    71          request.setupScheme("scheme");
    72          request.setupPathInfo("damn");
    73          request.setupGetServletPath("damn2");
    74          request.setupGetContextPath("wow");
    75          request.setupGetContentType("html/text");
    76          request.setupAddHeader("Content-type", "html/text");
    77          request.setupAddHeader("Accept-Language", "en-US");
    78
    79
    80
    81
    82
    83
    84          session = new EnhancedMockHttpSession();
    85          response = new MockHttpServletResponse();
    86
    87
    88
    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     public void testLoggedInUser() throws Exception
    103     {
    104
    105
    106
    107         RunData runData = getRunData(request,response,config);
    108         TurbineUser tu = new TurbineUser();
    109         tu.setName("username");
    110         tu.setHasLoggedIn(Boolean.TRUE);
    111         runData.setAction("TestAction");
    112         runData.setUser(tu);
    113
    114
    115         Pipeline pipeline = new TurbinePipeline();
    116         PipelineData pipelineData = runData;
    117
    118         DefaultACLCreationValve valve = new DefaultACLCreationValve();
    119         pipeline.addValve(valve);
    120         pipeline.initialize();
    121
    122         pipeline.invoke(pipelineData);
    123         User user = runData.getUser();
    124         assertNotNull(user);
    125         assertEquals("username",user.getName());
    126         assertTrue(user.hasLoggedIn());
    127         assertNotNull(runData.getACL());
    128
    129     }
    130
    131
    132
    133
    134
    135 }