001package 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 022import static org.junit.Assert.assertEquals; 023import static org.junit.Assert.assertNotNull; 024 025import org.apache.turbine.test.BaseTestCase; 026import org.apache.turbine.test.EnhancedMockHttpServletResponse; 027import org.apache.turbine.util.TurbineConfig; 028import org.junit.Test; 029 030import 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 1606111 2014-06-27 14:46:47Z gk $ 039 */ 040public class TurbineTest extends BaseTestCase 041{ 042 043 @Test 044 public void testTurbineAndFirstGet() throws Exception 045 { 046 TurbineConfig tc = new TurbineConfig(".", 047 "/conf/test/CompleteTurbineResources.properties"); 048 tc.initialize(); 049 050 assertNotNull(Turbine.getDefaultServerData()); 051 assertEquals("", Turbine.getServerName()); 052 assertEquals("80", Turbine.getServerPort()); 053 assertEquals("", Turbine.getScriptName()); 054 Turbine t = tc.getTurbine(); 055 056 MockHttpServletRequest request = getMockRequest(); 057 EnhancedMockHttpServletResponse resp = new EnhancedMockHttpServletResponse(); 058 059 t.doGet(request, resp); 060 061 assertEquals("8080", Turbine.getServerPort()); 062 t.destroy(); 063 tc.dispose(); 064 } 065 @Test 066 public void testDefaultInputEncoding() throws Exception 067 { 068 TurbineConfig tc = new TurbineConfig(".", 069 "/conf/test/CompleteTurbineResources.properties"); 070 tc.initialize(); 071 Turbine t = tc.getTurbine(); 072 assertNotNull(t.getDefaultInputEncoding()); 073 assertEquals(TurbineConstants.PARAMETER_ENCODING_DEFAULT, t.getDefaultInputEncoding()); 074 t.destroy(); 075 tc.dispose(); 076 } 077 @Test 078 public void testNonDefaultEncoding() 079 { 080 TurbineConfig tc = new TurbineConfig(".", 081 "/conf/test/CompleteTurbineResourcesWithEncoding.properties"); 082 tc.initialize(); 083 Turbine t = tc.getTurbine(); 084 assertNotNull(t.getDefaultInputEncoding()); 085 assertEquals("UTF-8", t.getDefaultInputEncoding()); 086 tc.dispose(); 087 } 088}