View Javadoc

    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 static org.junit.Assert.assertEquals;
    23  import static org.junit.Assert.assertNotNull;
    24
    25  import org.apache.turbine.test.BaseTestCase;
    26  import org.apache.turbine.test.EnhancedMockHttpServletResponse;
    27  import org.apache.turbine.util.TurbineConfig;
    28  import org.junit.Test;
    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 1606111 2014-06-27 14:46:47Z gk $
    39   */
    40  public class TurbineTest extends BaseTestCase
    41  {
    42
    43      @Test
    44      public void testTurbineAndFirstGet() throws Exception
    45      {
    46          TurbineConfig tc = new TurbineConfig(".",
    47                  "/conf/test/CompleteTurbineResources.properties");
    48          tc.initialize();
    49
    50          assertNotNull(Turbine.getDefaultServerData());
    51          assertEquals("", Turbine.getServerName());
    52          assertEquals("80", Turbine.getServerPort());
    53          assertEquals("", Turbine.getScriptName());
    54          Turbine t = tc.getTurbine();
    55
    56          MockHttpServletRequest request = getMockRequest();
    57          EnhancedMockHttpServletResponse resp = new EnhancedMockHttpServletResponse();
    58
    59          t.doGet(request, resp);
    60
    61          assertEquals("8080", Turbine.getServerPort());
    62          t.destroy();
    63          tc.dispose();
    64      }
    65      @Test
    66      public void testDefaultInputEncoding() throws Exception
    67      {
    68          TurbineConfig tc = new TurbineConfig(".",
    69                  "/conf/test/CompleteTurbineResources.properties");
    70          tc.initialize();
    71          Turbine t = tc.getTurbine();
    72          assertNotNull(t.getDefaultInputEncoding());
    73          assertEquals(TurbineConstants.PARAMETER_ENCODING_DEFAULT, t.getDefaultInputEncoding());
    74          t.destroy();
    75          tc.dispose();
    76      }
    77      @Test
    78      public void testNonDefaultEncoding()
    79      {
    80          TurbineConfig tc = new TurbineConfig(".",
    81                  "/conf/test/CompleteTurbineResourcesWithEncoding.properties");
    82          tc.initialize();
    83          Turbine t = tc.getTurbine();
    84          assertNotNull(t.getDefaultInputEncoding());
    85          assertEquals("UTF-8", t.getDefaultInputEncoding());
    86          tc.dispose();
    87      }
    88  }