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 static org.junit.Assert.assertEquals; 026import static org.junit.Assert.assertNotNull; 027import static org.junit.Assert.assertTrue; 028import static org.mockito.Mockito.mock; 029 030import javax.servlet.ServletConfig; 031import javax.servlet.http.HttpServletRequest; 032import javax.servlet.http.HttpServletResponse; 033 034import org.apache.fulcrum.security.model.turbine.entity.impl.TurbineUserImpl; 035import org.apache.turbine.om.security.DefaultUserImpl; 036import org.apache.turbine.om.security.User; 037import org.apache.turbine.test.BaseTestCase; 038import org.apache.turbine.util.RunData; 039import org.apache.turbine.util.TurbineConfig; 040import org.junit.AfterClass; 041import org.junit.Before; 042import org.junit.BeforeClass; 043import org.junit.Test; 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 1754909 2016-08-02 12:55:35Z tv $ 051 */ 052public class DefaultACLCreationValveTest extends BaseTestCase 053{ 054 private static TurbineConfig tc = null; 055 private ServletConfig config = null; 056 private HttpServletRequest request = null; 057 private HttpServletResponse response = null; 058 059 @BeforeClass 060 public static void init() 061 { 062 tc = new TurbineConfig( 063 ".", 064 "/conf/test/CompleteTurbineResources.properties"); 065 tc.initialize(); 066 } 067 068 @Before 069 public void setUpBefore() throws Exception 070 { 071 config = mock(ServletConfig.class); 072 request = getMockRequest(); 073 response = mock(HttpServletResponse.class); 074 } 075 076 @Test public void testLoggedInUser() throws Exception 077 { 078 RunData runData = getRunData(request,response,config); 079 User tu = new DefaultUserImpl(new TurbineUserImpl()); 080 tu.setName("username"); 081 tu.setHasLoggedIn(Boolean.TRUE); 082 runData.setAction("TestAction"); 083 runData.setUser(tu); 084 085 Pipeline pipeline = new TurbinePipeline(); 086 PipelineData pipelineData = runData; 087 088 DefaultACLCreationValve valve = new DefaultACLCreationValve(); 089 pipeline.addValve(valve); 090 pipeline.initialize(); 091 092 pipeline.invoke(pipelineData); 093 User user = runData.getUser(); 094 assertNotNull(user); 095 assertEquals("username",user.getName()); 096 assertTrue(user.hasLoggedIn()); 097 assertNotNull(runData.getACL()); 098 } 099 100 @AfterClass 101 public static void destroy() 102 { 103 tc.dispose(); 104 } 105}