    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    import java.util.Vector;
    025
    026    import javax.servlet.ServletConfig;
    027    import javax.servlet.http.HttpServletResponse;
    028
    029    import org.apache.turbine.TurbineConstants;
    030    import org.apache.turbine.modules.actions.LoginUser;
    031    import org.apache.turbine.om.security.User;
    032    import org.apache.turbine.services.template.TemplateService;
    033    import org.apache.turbine.test.BaseTestCase;
    034    import org.apache.turbine.test.EnhancedMockHttpServletRequest;
    035    import org.apache.turbine.test.EnhancedMockHttpSession;
    036    import org.apache.turbine.util.RunData;
    037    import org.apache.turbine.util.TurbineConfig;
    038
    039    import com.mockobjects.servlet.MockHttpServletResponse;
    040    import com.mockobjects.servlet.MockServletConfig;
    041
    042    /**
    043     * Tests TurbinePipeline.
    044     *
    045     * @author <a href="mailto:epugh@opensourceConnections.com">Eric Pugh</a>
    046     * @author <a href="mailto:peter@courcoux.biz">Peter Courcoux</a>
    047     * @version $Id: DefaultLoginValveTest.java 757213 2009-03-22 16:43:31Z tv $
    048     */
    049    public class DefaultLoginValveTest extends BaseTestCase
    050    {
    051        private static TurbineConfig tc = null;
    052        private static TemplateService ts = null;
    053        private MockServletConfig config = null;
    054        private EnhancedMockHttpServletRequest request = null;
    055        private EnhancedMockHttpSession session = null;
    056        private HttpServletResponse response = null;
    057        private static ServletConfig sc = null;
    058        /**
    059         * Constructor
    060         */
    061        public DefaultLoginValveTest(String testName) throws Exception
    062        {
    063            super(testName);
    064        }
    065
    066        protected void setUp() throws Exception {
    067            super.setUp();
    068            config = new MockServletConfig();
    069            config.setupNoParameters();
    070            request = new EnhancedMockHttpServletRequest();
    071            request.setupServerName("bob");
    072            request.setupGetProtocol("http");
    073            request.setupScheme("scheme");
    074            request.setupPathInfo("damn");
    075            request.setupGetServletPath("damn2");
    076            request.setupGetContextPath("wow");
    077            request.setupGetContentType("html/text");
    078            request.setupAddHeader("Content-type", "html/text");
    079            request.setupAddHeader("Accept-Language", "en-US");
    080
    081
    082
    083
    084
    085
    086            session = new EnhancedMockHttpSession();
    087            response = new MockHttpServletResponse();
    088
    089            session.setupGetAttribute(User.SESSION_KEY, null);
    090
    091            request.setSession(session);
    092
    093
    094
    095            sc = config;
    096            tc =
    097                new TurbineConfig(
    098                        ".",
    099                "/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    }