View Javadoc

    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 static org.junit.Assert.assertEquals;
    25  import static org.junit.Assert.assertFalse;
    26
    27
    28  import org.apache.turbine.services.TurbineServices;
    29  import org.apache.turbine.test.BaseTestCase;
    30  import org.apache.turbine.util.TurbineConfig;
    31  import org.junit.AfterClass;
    32  import org.junit.BeforeClass;
    33  import org.junit.Test;
    34
    35  /**
    36   * Tests all the various defaults for the Template Service.
    37   *
    38   * @author <a href="hps@intermeta.de">Henning P. Schmiedehausen</a>
    39   * @version $Id: DefaultsTest.java 1616993 2014-08-09 17:03:07Z tv $
    40   */
    41  public class DefaultsTest
    42      extends BaseTestCase
    43  {
    44      private static TurbineConfig tc = null;
    45      private static TemplateService ts = null;
    46
    47
    48      @BeforeClass
    49      public static void setUp() throws Exception {
    50          tc = new TurbineConfig(".", "/conf/test/TemplateService.properties");
    51          tc.initialize();
    52
    53          ts = (TemplateService) TurbineServices.getInstance().getService(TemplateService.SERVICE_NAME);
    54      }
    55
    56      @AfterClass
    57      public static void destroy() throws Exception {
    58          ts.shutdown();
    59          tc.dispose();
    60      }
    61
    62      @Test
    63      public void testDefaults()
    64      {
    65          // Test if the caching property was loaded correctly. (key:module.cache)
    66          assertFalse("isCaching failed!", ts.isCaching());
    67
    68          // Test if the default values for Template and Extension were loaded correctly
    69          assertEquals("Default Extension failed",      ts.getDefaultExtension(), "");
    70          assertEquals("Default Template failed",       ts.getDefaultTemplate(), TemplateService.DEFAULT_TEMPLATE_VALUE);
    71      }
    72
    73      @Test
    74      public void testTemplateDefaults()
    75      {
    76          // Test if the Default-Values for the Screen, Layout and Navigation classes and the Layout Template are correct.
    77          assertEquals("Default Page failed",           TemplateService.DEFAULT_TEMPLATE_VALUE, ts.getDefaultPage());
    78          assertEquals("Default Screen failed",         TemplateService.DEFAULT_TEMPLATE_VALUE, ts.getDefaultScreen());
    79          assertEquals("Default Layout failed",         TemplateService.DEFAULT_TEMPLATE_VALUE, ts.getDefaultLayout());
    80          assertEquals("Default Navigation failed",     TemplateService.DEFAULT_TEMPLATE_VALUE, ts.getDefaultNavigation());
    81          assertEquals("Default LayoutTemplate failed", TemplateService.DEFAULT_TEMPLATE_VALUE, ts.getDefaultLayoutTemplate());
    82      }
    83
    84      @Test
    85      public void testVelocityDefaults()
    86      {
    87          // Test if all the Velocity based Defaults for Page, Screen, Layout, Navigation and Layout Template
    88          assertEquals("Default Page failed",           "VelocityPage",       ts.getDefaultPageName("foo.vm"));
    89          assertEquals("Default Screen failed",         "VelocityScreen",     ts.getDefaultScreenName("foo.vm"));
    90          assertEquals("Default Layout failed",         "VelocityOnlyLayout", ts.getDefaultLayoutName("foo.vm"));
    91          assertEquals("Default Navigation failed",     "VelocityNavigation", ts.getDefaultNavigationName("foo.vm"));
    92          assertEquals("Default LayoutTemplate failed", "Default.vm",         ts.getDefaultLayoutTemplateName("foo.vm"));
    93      }
    94  }
    95