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 javax.servlet.http.HttpServletRequest;
    26  import javax.servlet.http.HttpServletResponse;
    27
    28  import org.apache.turbine.test.BaseTestCase;
    29  import org.apache.turbine.util.TurbineConfig;
    30  import org.junit.Test;
    31  import org.mockito.Mockito;
    32
    33  /**
    34   * This testcase verifies that TurbineConfig can be used to startup Turbine in a
    35   * non servlet environment properly.
    36   *
    37   * @author <a href="mailto:epugh@opensourceconnections.com">Eric Pugh </a>
    38   * @author <a href="mailto:peter@courcoux.biz">Peter Courcoux </a>
    39   * @version $Id: TurbineTest.java 1754909 2016-08-02 12:55:35Z tv $
    40   */
    41  public class TurbineTest extends BaseTestCase
    42  {
    43
    44      @Test
    45      public void testTurbineAndFirstGet() throws Exception
    46      {
    47          TurbineConfig tc = new TurbineConfig(".",
    48                  "/conf/test/CompleteTurbineResources.properties");
    49          tc.initialize();
    50
    51          assertNotNull(Turbine.getDefaultServerData());
    52          assertEquals("", Turbine.getServerName());
    53          assertEquals("80", Turbine.getServerPort());
    54          assertEquals("", Turbine.getScriptName());
    55          Turbine t = tc.getTurbine();
    56
    57          HttpServletRequest request = getMockRequest();
    58          HttpServletResponse resp = Mockito.mock(HttpServletResponse.class);
    59
    60          t.doGet(request, resp);
    61
    62          assertEquals("8080", Turbine.getServerPort());
    63          t.destroy();
    64          tc.dispose();
    65      }
    66
    67      @Test
    68      public void testDefaultInputEncoding() throws Exception
    69      {
    70          TurbineConfig tc = new TurbineConfig(".",
    71                  "/conf/test/CompleteTurbineResources.properties");
    72          tc.initialize();
    73          Turbine t = tc.getTurbine();
    74          assertNotNull(t.getDefaultInputEncoding());
    75          assertEquals(TurbineConstants.PARAMETER_ENCODING_DEFAULT, t.getDefaultInputEncoding());
    76          t.destroy();
    77          tc.dispose();
    78      }
    79
    80      @Test
    81      public void testNonDefaultEncoding()
    82      {
    83          TurbineConfig tc = new TurbineConfig(".",
    84                  "/conf/test/CompleteTurbineResourcesWithEncoding.properties");
    85          tc.initialize();
    86          Turbine t = tc.getTurbine();
    87          assertNotNull(t.getDefaultInputEncoding());
    88          assertEquals("UTF-8", t.getDefaultInputEncoding());
    89          tc.dispose();
    90      }
    91  }