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.om.security.User;
030    import org.apache.turbine.services.template.TemplateService;
031    import org.apache.turbine.test.BaseTestCase;
032    import org.apache.turbine.test.EnhancedMockHttpServletRequest;
033    import org.apache.turbine.test.EnhancedMockHttpSession;
034    import org.apache.turbine.util.RunData;
035    import org.apache.turbine.util.TurbineConfig;
036    import org.apache.turbine.util.uri.URIConstants;
037    
038    import com.mockobjects.servlet.MockHttpServletResponse;
039    import com.mockobjects.servlet.MockServletConfig;
040    
041    /**
042     * Tests TurbinePipeline.
043     *
044     * @author <a href="mailto:epugh@opensourceConnections.com">Eric Pugh</a>
045     * @author <a href="mailto:peter@courcoux.biz">Peter Courcoux</a>
046     * @version $Id: DetermineTargetValveTest.java 615328 2008-01-25 20:25:05Z tv $
047     */
048    public class DetermineTargetValveTest extends BaseTestCase
049    {
050        private static TurbineConfig tc = null;
051        private static TemplateService ts = null;
052        private MockServletConfig config = null;
053        private EnhancedMockHttpServletRequest request = null;
054        private EnhancedMockHttpSession session = null;
055        private HttpServletResponse response = null;
056        private static ServletConfig sc = null;
057        /**
058         * Constructor
059         */
060        public DetermineTargetValveTest(String testName) throws Exception
061        {
062            super(testName);
063        }
064    
065        protected void setUp() throws Exception {
066            super.setUp();
067            config = new MockServletConfig();
068            config.setupNoParameters();
069            request = new EnhancedMockHttpServletRequest();
070            request.setupServerName("bob");
071            request.setupGetProtocol("http");
072            request.setupScheme("scheme");
073            request.setupPathInfo("damn");
074            request.setupGetServletPath("damn2");
075            request.setupGetContextPath("wow");
076            request.setupGetContentType("html/text");
077            request.setupAddHeader("Content-type", "html/text");
078            request.setupAddHeader("Accept-Language", "en-US");
079    
080    
081    
082    
083    
084    
085            session = new EnhancedMockHttpSession();
086            response = new MockHttpServletResponse();
087    
088            session.setupGetAttribute(User.SESSION_KEY, null);
089            request.setSession(session);
090    
091    
092    
093            sc = config;
094            tc =
095                new TurbineConfig(
096                        ".",
097                "/conf/test/CompleteTurbineResources.properties");
098            tc.initialize();
099        }
100    
101        /**
102         * Tests the Valve.
103         */
104        public void testScreenSet() throws Exception
105        {
106            Vector v = new Vector();
107            v.add(URIConstants.CGI_SCREEN_PARAM);
108            request.setupGetParameterNames(v.elements());
109    
110            request.setupAddParameter(URIConstants.CGI_SCREEN_PARAM,"TestScreen");
111    
112            RunData runData = getRunData(request,response,config);
113    
114            Pipeline pipeline = new TurbinePipeline();
115            PipelineData pipelineData = runData;
116            DetermineTargetValve valve = new DetermineTargetValve();
117            pipeline.addValve(valve);
118    
119            pipeline.invoke(pipelineData);
120            assertEquals("TestScreen",runData.getScreen());
121    
122    
123        }
124        public void testScreenNotSet() throws Exception
125        {
126            Vector v = new Vector();
127            v.add(URIConstants.CGI_SCREEN_PARAM);
128            request.setupGetParameterNames(v.elements());
129    
130            String screens[] = new String[1];
131            screens[0]=null;
132            request.setupAddParameter(URIConstants.CGI_SCREEN_PARAM,screens);
133    
134            RunData runData = getRunData(request,response,config);
135    
136            Pipeline pipeline = new TurbinePipeline();
137            PipelineData pipelineData = runData;
138    
139            DetermineTargetValve valve = new DetermineTargetValve();
140            pipeline.addValve(valve);
141    
142            pipeline.invoke(pipelineData);
143            assertEquals("",runData.getScreen());
144    
145    
146        }
147    
148    
149    }