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 024import static org.junit.Assert.assertEquals; 025import static org.mockito.Mockito.mock; 026import static org.mockito.Mockito.when; 027 028import java.util.Vector; 029 030import javax.servlet.ServletConfig; 031import javax.servlet.http.HttpServletRequest; 032import javax.servlet.http.HttpServletResponse; 033 034import org.apache.turbine.test.BaseTestCase; 035import org.apache.turbine.util.RunData; 036import org.apache.turbine.util.TurbineConfig; 037import org.apache.turbine.util.uri.URIConstants; 038import org.junit.AfterClass; 039import org.junit.Before; 040import org.junit.BeforeClass; 041import org.junit.Test; 042 043/** 044 * Tests TurbinePipeline. 045 * 046 * @author <a href="mailto:epugh@opensourceConnections.com">Eric Pugh</a> 047 * @author <a href="mailto:peter@courcoux.biz">Peter Courcoux</a> 048 * @version $Id: DetermineTargetValveTest.java 1754909 2016-08-02 12:55:35Z tv $ 049 */ 050public class DetermineTargetValveTest extends BaseTestCase 051{ 052 private static TurbineConfig tc = null; 053 private ServletConfig config = null; 054 private HttpServletRequest request = null; 055 private HttpServletResponse response = null; 056 057 @BeforeClass 058 public static void init() 059 { 060 tc = new TurbineConfig( 061 ".", 062 "/conf/test/CompleteTurbineResources.properties"); 063 tc.initialize(); 064 } 065 066 @Before 067 public void setUpBefore() throws Exception 068 { 069 config = mock(ServletConfig.class); 070 request = getMockRequest(); 071 response = mock(HttpServletResponse.class); 072 } 073 074 /** 075 * Tests the Valve. 076 */ 077 @Test public void testScreenSet() throws Exception 078 { 079 Vector<String> v = new Vector<String>(); 080 v.add(URIConstants.CGI_SCREEN_PARAM); 081 when(request.getParameterNames()).thenReturn(v.elements()); 082 083 when(request.getParameterValues(URIConstants.CGI_SCREEN_PARAM)).thenReturn(new String[] { "TestScreen" }); 084 085 RunData runData = getRunData(request,response,config); 086 087 Pipeline pipeline = new TurbinePipeline(); 088 PipelineData pipelineData = runData; 089 DetermineTargetValve valve = new DetermineTargetValve(); 090 pipeline.addValve(valve); 091 092 pipeline.invoke(pipelineData); 093 assertEquals("TestScreen",runData.getScreen()); 094 } 095 096 @Test public void testScreenNotSet() throws Exception 097 { 098 Vector<String> v = new Vector<String>(); 099 v.add(URIConstants.CGI_SCREEN_PARAM); 100 when(request.getParameterNames()).thenReturn(v.elements()); 101 102 when(request.getParameterValues(URIConstants.CGI_SCREEN_PARAM)).thenReturn(new String[] { null }); 103 104 RunData runData = getRunData(request,response,config); 105 106 Pipeline pipeline = new TurbinePipeline(); 107 PipelineData pipelineData = runData; 108 109 DetermineTargetValve valve = new DetermineTargetValve(); 110 pipeline.addValve(valve); 111 112 pipeline.invoke(pipelineData); 113 assertEquals("",runData.getScreen()); 114 } 115 116 @AfterClass 117 public static void destroy() 118 { 119 tc.dispose(); 120 } 121}