    1   package org.apache.turbine;
    2
    3   /*
    4    * Licensed to the Apache Software Foundation (ASF) under one
    5    * or more contributor license agreements.  See the NOTICE file
    6    * distributed with this work for additional information
    7    * regarding copyright ownership.  The ASF licenses this file
    8    * to you under the Apache License, Version 2.0 (the
    9    * "License"); you may not use this file except in compliance
    10   * with the License.  You may obtain a copy of the License at
    11   *
    12   *   http://www.apache.org/licenses/LICENSE-2.0
    13   *
    14   * Unless required by applicable law or agreed to in writing,
    15   * software distributed under the License is distributed on an
    16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    17   * KIND, either express or implied.  See the License for the
    18   * specific language governing permissions and limitations
    19   * under the License.
    20   */
    21
    22  import javax.servlet.ServletConfig;
    23  import javax.servlet.ServletContext;
    24  import javax.servlet.ServletException;
    25
    26  import org.apache.turbine.test.BaseTestCase;
    27  import org.apache.turbine.test.EnhancedMockHttpServletResponse;
    28  import org.apache.turbine.util.TurbineConfig;
    29
    30  import com.mockobjects.servlet.MockHttpServletRequest;
    31
    32  /**
    33   * This testcase verifies that TurbineConfig can be used to startup Turbine in a
    34   * non servlet environment properly.
    35   *
    36   * @author <a href="mailto:epugh@opensourceconnections.com">Eric Pugh </a>
    37   * @author <a href="mailto:peter@courcoux.biz">Peter Courcoux </a>
    38   * @version $Id: TurbineTest.java 1096602 2011-04-25 21:06:57Z ludwig $
    39   */
    40  public class TurbineTest extends BaseTestCase
    41  {
    42
    43      public TurbineTest(String name) throws Exception
    44      {
    45          super(name);
    46      }
    47
    48      public void testTurbineAndFirstGet() throws Exception
    49      {
    50          TurbineConfig tc = new TurbineConfig(".",
    51                  "/conf/test/CompleteTurbineResources.properties");
    52          tc.initialize();
    53
    54          ServletConfig config = (ServletConfig) tc;
    55          ServletContext context = config.getServletContext();
    56          assertNotNull(Turbine.getDefaultServerData());
    57          assertEquals("", Turbine.getServerName());
    58          assertEquals("80", Turbine.getServerPort());
    59          assertEquals("", Turbine.getScriptName());
    60          Turbine t = tc.getTurbine();
    61
    62          MockHttpServletRequest request = getMockRequest();
    63          EnhancedMockHttpServletResponse resp = new EnhancedMockHttpServletResponse();
    64
    65          t.doGet(request, resp);
    66
    67          assertEquals("8080", Turbine.getServerPort());
    68          t.destroy();
    69      }
    70
    71      public void testDefaultInputEncoding() throws Exception
    72      {
    73          TurbineConfig tc = new TurbineConfig(".",
    74                  "/conf/test/CompleteTurbineResources.properties");
    75          tc.initialize();
    76          Turbine t = tc.getTurbine();
    77          assertNotNull(t.getDefaultInputEncoding());
    78          assertEquals(TurbineConstants.PARAMETER_ENCODING_DEFAULT, t.getDefaultInputEncoding());
    79          t.destroy();
    80      }
    81
    82      public void testNonDefaultEncoding() throws ServletException
    83      {
    84          TurbineConfig tc = new TurbineConfig(".",
    85                  "/conf/test/CompleteTurbineResourcesWithEncoding.properties");
    86          tc.initialize();
    87          Turbine t = tc.getTurbine();
    88          assertNotNull(t.getDefaultInputEncoding());
    89          assertEquals("UTF-8", t.getDefaultInputEncoding());
    90      }
    91
    92  }