001 package org.apache.turbine.pipeline;
002
003
004 /*
005 * Licensed to the Apache Software Foundation (ASF) under one
006 * or more contributor license agreements. See the NOTICE file
007 * distributed with this work for additional information
008 * regarding copyright ownership. The ASF licenses this file
009 * to you under the Apache License, Version 2.0 (the
010 * "License"); you may not use this file except in compliance
011 * with the License. You may obtain a copy of the License at
012 *
013 * http://www.apache.org/licenses/LICENSE-2.0
014 *
015 * Unless required by applicable law or agreed to in writing,
016 * software distributed under the License is distributed on an
017 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
018 * KIND, either express or implied. See the License for the
019 * specific language governing permissions and limitations
020 * under the License.
021 */
022
023
024
025 import javax.servlet.ServletConfig;
026 import javax.servlet.http.HttpServletResponse;
027
028 import org.apache.turbine.om.security.TurbineUser;
029 import org.apache.turbine.om.security.User;
030 import org.apache.turbine.services.template.TemplateService;
031 import org.apache.turbine.test.BaseTestCase;
032 import org.apache.turbine.test.EnhancedMockHttpServletRequest;
033 import org.apache.turbine.test.EnhancedMockHttpSession;
034 import org.apache.turbine.util.RunData;
035 import org.apache.turbine.util.TurbineConfig;
036
037 import com.mockobjects.servlet.MockHttpServletResponse;
038 import com.mockobjects.servlet.MockServletConfig;
039
040 /**
041 * Tests TurbinePipeline.
042 *
043 * @author <a href="mailto:epugh@opensourceConnections.com">Eric Pugh</a>
044 * @author <a href="mailto:peter@courcoux.biz">Peter Courcoux</a>
045 * @version $Id: DefaultACLCreationValveTest.java 757213 2009-03-22 16:43:31Z tv $
046 */
047 public class DefaultACLCreationValveTest extends BaseTestCase
048 {
049 private static TurbineConfig tc = null;
050 private static TemplateService ts = null;
051 private MockServletConfig config = null;
052 private EnhancedMockHttpServletRequest request = null;
053 private EnhancedMockHttpSession session = null;
054 private HttpServletResponse response = null;
055 private static ServletConfig sc = null;
056 /**
057 * Constructor
058 */
059 public DefaultACLCreationValveTest(String testName) throws Exception
060 {
061 super(testName);
062 }
063
064 protected void setUp() throws Exception {
065 super.setUp();
066 config = new MockServletConfig();
067 config.setupNoParameters();
068 request = new EnhancedMockHttpServletRequest();
069 request.setupServerName("bob");
070 request.setupGetProtocol("http");
071 request.setupScheme("scheme");
072 request.setupPathInfo("damn");
073 request.setupGetServletPath("damn2");
074 request.setupGetContextPath("wow");
075 request.setupGetContentType("html/text");
076 request.setupAddHeader("Content-type", "html/text");
077 request.setupAddHeader("Accept-Language", "en-US");
078
079
080
081
082
083
084 session = new EnhancedMockHttpSession();
085 response = new MockHttpServletResponse();
086
087
088
089 request.setSession(session);
090
091
092
093 sc = config;
094 tc =
095 new TurbineConfig(
096 ".",
097 "/conf/test/CompleteTurbineResources.properties");
098 tc.initialize();
099 }
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 }