001 package org.apache.turbine;
002
003 /*
004 * Licensed to the Apache Software Foundation (ASF) under one
005 * or more contributor license agreements. See the NOTICE file
006 * distributed with this work for additional information
007 * regarding copyright ownership. The ASF licenses this file
008 * to you under the Apache License, Version 2.0 (the
009 * "License"); you may not use this file except in compliance
010 * with the License. You may obtain a copy of the License at
011 *
012 * http://www.apache.org/licenses/LICENSE-2.0
013 *
014 * Unless required by applicable law or agreed to in writing,
015 * software distributed under the License is distributed on an
016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017 * KIND, either express or implied. See the License for the
018 * specific language governing permissions and limitations
019 * under the License.
020 */
021
022 import javax.servlet.ServletConfig;
023 import javax.servlet.ServletContext;
024 import javax.servlet.ServletException;
025
026 import org.apache.turbine.test.BaseTestCase;
027 import org.apache.turbine.test.EnhancedMockHttpServletResponse;
028 import org.apache.turbine.util.TurbineConfig;
029
030 import com.mockobjects.servlet.MockHttpServletRequest;
031
032 /**
033 * This testcase verifies that TurbineConfig can be used to startup Turbine in a
034 * non servlet environment properly.
035 *
036 * @author <a href="mailto:epugh@opensourceconnections.com">Eric Pugh </a>
037 * @author <a href="mailto:peter@courcoux.biz">Peter Courcoux </a>
038 * @version $Id: TurbineTest.java 1096602 2011-04-25 21:06:57Z ludwig $
039 */
040 public class TurbineTest extends BaseTestCase
041 {
042
043 public TurbineTest(String name) throws Exception
044 {
045 super(name);
046 }
047
048 public void testTurbineAndFirstGet() throws Exception
049 {
050 TurbineConfig tc = new TurbineConfig(".",
051 "/conf/test/CompleteTurbineResources.properties");
052 tc.initialize();
053
054 ServletConfig config = (ServletConfig) tc;
055 ServletContext context = config.getServletContext();
056 assertNotNull(Turbine.getDefaultServerData());
057 assertEquals("", Turbine.getServerName());
058 assertEquals("80", Turbine.getServerPort());
059 assertEquals("", Turbine.getScriptName());
060 Turbine t = tc.getTurbine();
061
062 MockHttpServletRequest request = getMockRequest();
063 EnhancedMockHttpServletResponse resp = new EnhancedMockHttpServletResponse();
064
065 t.doGet(request, resp);
066
067 assertEquals("8080", Turbine.getServerPort());
068 t.destroy();
069 }
070
071 public void testDefaultInputEncoding() throws Exception
072 {
073 TurbineConfig tc = new TurbineConfig(".",
074 "/conf/test/CompleteTurbineResources.properties");
075 tc.initialize();
076 Turbine t = tc.getTurbine();
077 assertNotNull(t.getDefaultInputEncoding());
078 assertEquals(TurbineConstants.PARAMETER_ENCODING_DEFAULT, t.getDefaultInputEncoding());
079 t.destroy();
080 }
081
082 public void testNonDefaultEncoding() throws ServletException
083 {
084 TurbineConfig tc = new TurbineConfig(".",
085 "/conf/test/CompleteTurbineResourcesWithEncoding.properties");
086 tc.initialize();
087 Turbine t = tc.getTurbine();
088 assertNotNull(t.getDefaultInputEncoding());
089 assertEquals("UTF-8", t.getDefaultInputEncoding());
090 }
091
092 }