001package 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
025import javax.servlet.http.HttpServletResponse;
026
027import org.apache.fulcrum.security.model.turbine.entity.impl.TurbineUserImpl;
028import org.apache.turbine.om.security.DefaultUserImpl;
029import org.apache.turbine.om.security.User;
030import org.apache.turbine.test.BaseTestCase;
031import org.apache.turbine.test.EnhancedMockHttpServletRequest;
032import org.apache.turbine.test.EnhancedMockHttpSession;
033import org.apache.turbine.util.RunData;
034import org.apache.turbine.util.TurbineConfig;
035import org.junit.AfterClass;
036import org.junit.Before;
037import org.junit.BeforeClass;
038import org.junit.Test;
039
040import com.mockobjects.servlet.MockHttpServletResponse;
041import com.mockobjects.servlet.MockServletConfig;
042
043import static org.junit.Assert.*;
044
045/**
046 * Tests TurbinePipeline.
047 *
048 * @author <a href="mailto:epugh@opensourceConnections.com">Eric Pugh</a>
049 * @author <a href="mailto:peter@courcoux.biz">Peter Courcoux</a>
050 * @version $Id: DefaultACLCreationValveTest.java 1606111 2014-06-27 14:46:47Z gk $
051 */
052public class DefaultACLCreationValveTest extends BaseTestCase
053{
054    private static TurbineConfig tc = null;
055    private MockServletConfig config = null;
056    private EnhancedMockHttpServletRequest request = null;
057    private EnhancedMockHttpSession session = null;
058    private HttpServletResponse response = null;
059
060
061    @BeforeClass
062    public static void init() {
063        tc = new TurbineConfig(
064                            ".",
065                            "/conf/test/CompleteTurbineResources.properties");
066        tc.initialize();
067    }
068
069    @Before
070    public void setUpBefore() throws Exception {
071        config = new MockServletConfig();
072        config.setupNoParameters();
073        request = new EnhancedMockHttpServletRequest();
074        request.setupServerName("bob");
075        request.setupGetProtocol("http");
076        request.setupScheme("scheme");
077        request.setupPathInfo("damn");
078        request.setupGetServletPath("damn2");
079        request.setupGetContextPath("wow");
080        request.setupGetContentType("html/text");
081        request.setupAddHeader("Content-type", "html/text");
082        request.setupAddHeader("Accept-Language", "en-US");
083        session = new EnhancedMockHttpSession();
084        response = new MockHttpServletResponse();
085        request.setSession(session);
086    }
087
088
089    @Test public void testLoggedInUser() throws Exception
090    {
091        RunData runData = getRunData(request,response,config);
092        User tu = new DefaultUserImpl(new TurbineUserImpl());
093        tu.setName("username");
094        tu.setHasLoggedIn(Boolean.TRUE);
095        runData.setAction("TestAction");
096        runData.setUser(tu);
097
098        Pipeline pipeline = new TurbinePipeline();
099        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}