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 javax.servlet.http.HttpServletRequest; 026import javax.servlet.http.HttpServletResponse; 027 028import org.apache.turbine.test.BaseTestCase; 029import org.apache.turbine.util.TurbineConfig; 030import org.junit.Test; 031import org.mockito.Mockito; 032 033/** 034 * This testcase verifies that TurbineConfig can be used to startup Turbine in a 035 * non servlet environment properly. 036 * 037 * @author <a href="mailto:epugh@opensourceconnections.com">Eric Pugh </a> 038 * @author <a href="mailto:peter@courcoux.biz">Peter Courcoux </a> 039 * @version $Id: TurbineTest.java 1754909 2016-08-02 12:55:35Z tv $ 040 */ 041public class TurbineTest extends BaseTestCase 042{ 043 044 @Test 045 public void testTurbineAndFirstGet() throws Exception 046 { 047 TurbineConfig tc = new TurbineConfig(".", 048 "/conf/test/CompleteTurbineResources.properties"); 049 tc.initialize(); 050 051 assertNotNull(Turbine.getDefaultServerData()); 052 assertEquals("", Turbine.getServerName()); 053 assertEquals("80", Turbine.getServerPort()); 054 assertEquals("", Turbine.getScriptName()); 055 Turbine t = tc.getTurbine(); 056 057 HttpServletRequest request = getMockRequest(); 058 HttpServletResponse resp = Mockito.mock(HttpServletResponse.class); 059 060 t.doGet(request, resp); 061 062 assertEquals("8080", Turbine.getServerPort()); 063 t.destroy(); 064 tc.dispose(); 065 } 066 067 @Test 068 public void testDefaultInputEncoding() throws Exception 069 { 070 TurbineConfig tc = new TurbineConfig(".", 071 "/conf/test/CompleteTurbineResources.properties"); 072 tc.initialize(); 073 Turbine t = tc.getTurbine(); 074 assertNotNull(t.getDefaultInputEncoding()); 075 assertEquals(TurbineConstants.PARAMETER_ENCODING_DEFAULT, t.getDefaultInputEncoding()); 076 t.destroy(); 077 tc.dispose(); 078 } 079 080 @Test 081 public void testNonDefaultEncoding() 082 { 083 TurbineConfig tc = new TurbineConfig(".", 084 "/conf/test/CompleteTurbineResourcesWithEncoding.properties"); 085 tc.initialize(); 086 Turbine t = tc.getTurbine(); 087 assertNotNull(t.getDefaultInputEncoding()); 088 assertEquals("UTF-8", t.getDefaultInputEncoding()); 089 tc.dispose(); 090 } 091}