    1   package org.apache.turbine.services.template;
    2
    3
    4   /*
    5    * Licensed to the Apache Software Foundation (ASF) under one
    6    * or more contributor license agreements.  See the NOTICE file
    7    * distributed with this work for additional information
    8    * regarding copyright ownership.  The ASF licenses this file
    9    * to you under the Apache License, Version 2.0 (the
    10   * "License"); you may not use this file except in compliance
    11   * with the License.  You may obtain a copy of the License at
    12   *
    13   *   http://www.apache.org/licenses/LICENSE-2.0
    14   *
    15   * Unless required by applicable law or agreed to in writing,
    16   * software distributed under the License is distributed on an
    17   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    18   * KIND, either express or implied.  See the License for the
    19   * specific language governing permissions and limitations
    20   * under the License.
    21   */
    22
    23
    24  import org.apache.turbine.services.TurbineServices;
    25  import org.apache.turbine.test.BaseTestCase;
    26  import org.apache.turbine.util.TurbineConfig;
    27
    28  /**
    29   * Tests all the various defaults for the Template Service.
    30   *
    31   * @author <a href="hps@intermeta.de">Henning P. Schmiedehausen</a>
    32   * @version $Id: DefaultsTest.java 615328 2008-01-25 20:25:05Z tv $
    33   */
    34  public class DefaultsTest
    35      extends BaseTestCase
    36  {
    37      private static TurbineConfig tc = null;
    38      private static TemplateService ts = null;
    39
    40      public DefaultsTest(String name)
    41              throws Exception
    42      {
    43          super(name);
    44          tc = new TurbineConfig(".", "/conf/test/TemplateService.properties");
    45          tc.initialize();
    46
    47          ts = (TemplateService) TurbineServices.getInstance().getService(TemplateService.SERVICE_NAME);
    48      }
    49
    50      public void testDefaults()
    51      {
    52          // Test if the caching property was loaded correctly.
    53          assertEquals("isCaching failed!",             ts.isCaching(), false);
    54
    55          // Test if the default values for Template and Extension were loaded correctly
    56          assertEquals("Default Extension failed",      ts.getDefaultExtension(), "");
    57          assertEquals("Default Template failed",       ts.getDefaultTemplate(), TemplateService.DEFAULT_TEMPLATE_VALUE);
    58      }
    59
    60      public void testTemplateDefaults()
    61      {
    62          // Test if the Default-Values for the Screen, Layout and Navigation classes and the Layout Template are correct.
    63          assertEquals("Default Page failed",           TemplateService.DEFAULT_TEMPLATE_VALUE, ts.getDefaultPage());
    64          assertEquals("Default Screen failed",         TemplateService.DEFAULT_TEMPLATE_VALUE, ts.getDefaultScreen());
    65          assertEquals("Default Layout failed",         TemplateService.DEFAULT_TEMPLATE_VALUE, ts.getDefaultLayout());
    66          assertEquals("Default Navigation failed",     TemplateService.DEFAULT_TEMPLATE_VALUE, ts.getDefaultNavigation());
    67          assertEquals("Default LayoutTemplate failed", TemplateService.DEFAULT_TEMPLATE_VALUE, ts.getDefaultLayoutTemplate());
    68      }
    69
    70      public void testVelocityDefaults()
    71      {
    72          // Test if all the Velocity based Defaults for Page, Screen, Layout, Navigation and Layout Template
    73          assertEquals("Default Page failed",           "VelocityPage",       ts.getDefaultPageName("foo.vm"));
    74          assertEquals("Default Screen failed",         "VelocityScreen",     ts.getDefaultScreenName("foo.vm"));
    75          assertEquals("Default Layout failed",         "VelocityOnlyLayout", ts.getDefaultLayoutName("foo.vm"));
    76          assertEquals("Default Navigation failed",     "VelocityNavigation", ts.getDefaultNavigationName("foo.vm"));
    77          assertEquals("Default LayoutTemplate failed", "Default.vm",         ts.getDefaultLayoutTemplateName("foo.vm"));
    78      }
    79  }
    80