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.jupiter.api.Assertions.assertEquals; 026import static org.junit.jupiter.api.Assertions.assertNotNull; 027import static org.junit.jupiter.api.Assertions.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.jupiter.api.AfterAll; 041import org.junit.jupiter.api.BeforeAll; 042import org.junit.jupiter.api.BeforeEach; 043import org.junit.jupiter.api.Test; 044/** 045 * Tests TurbinePipeline. 046 * 047 * @author <a href="mailto:epugh@opensourceConnections.com">Eric Pugh</a> 048 * @author <a href="mailto:peter@courcoux.biz">Peter Courcoux</a> 049 * @version $Id$ 050 */ 051public class DefaultACLCreationValveTest extends BaseTestCase 052{ 053 private static TurbineConfig tc = null; 054 private ServletConfig config = null; 055 private HttpServletRequest request = null; 056 private HttpServletResponse response = null; 057 058 @BeforeAll 059 public static void init() 060 { 061 tc = new TurbineConfig( 062 ".", 063 "/conf/test/CompleteTurbineResources.properties"); 064 tc.initialize(); 065 } 066 067 @BeforeEach 068 public void setUpBefore() throws Exception 069 { 070 config = mock(ServletConfig.class); 071 request = getMockRequest(); 072 response = mock(HttpServletResponse.class); 073 } 074 075 @Test public void testLoggedInUser() throws Exception 076 { 077 RunData runData = getRunData(request,response,config); 078 User tu = new DefaultUserImpl(new TurbineUserImpl()); 079 tu.setName("username"); 080 tu.setHasLoggedIn(Boolean.TRUE); 081 runData.setAction("TestAction"); 082 runData.setUser(tu); 083 084 Pipeline pipeline = new TurbinePipeline(); 085 PipelineData pipelineData = runData; 086 087 DefaultACLCreationValve valve = new DefaultACLCreationValve(); 088 pipeline.addValve(valve); 089 pipeline.initialize(); 090 091 pipeline.invoke(pipelineData); 092 User user = runData.getUser(); 093 assertNotNull(user); 094 assertEquals("username",user.getName()); 095 assertTrue(user.hasLoggedIn()); 096 assertNotNull(runData.getACL()); 097 } 098 099 @AfterAll 100 public static void destroy() 101 { 102 tc.dispose(); 103 } 104}