001package org.apache.turbine.services.template; 002 003 004/* 005 * Licensed to the Apache Software Foundation (ASF) under one 006 * or more contributor license agreements. See the NOTICE file 007 * distributed with this work for additional information 008 * regarding copyright ownership. The ASF licenses this file 009 * to you under the Apache License, Version 2.0 (the 010 * "License"); you may not use this file except in compliance 011 * with the License. You may obtain a copy of the License at 012 * 013 * http://www.apache.org/licenses/LICENSE-2.0 014 * 015 * Unless required by applicable law or agreed to in writing, 016 * software distributed under the License is distributed on an 017 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 018 * KIND, either express or implied. See the License for the 019 * specific language governing permissions and limitations 020 * under the License. 021 */ 022 023 024import static org.junit.Assert.assertEquals; 025import static org.junit.Assert.assertFalse; 026 027 028import org.apache.turbine.services.TurbineServices; 029import org.apache.turbine.test.BaseTestCase; 030import org.apache.turbine.util.TurbineConfig; 031import org.junit.AfterClass; 032import org.junit.BeforeClass; 033import org.junit.Test; 034 035/** 036 * Tests all the various defaults for the Template Service. 037 * 038 * @author <a href="hps@intermeta.de">Henning P. Schmiedehausen</a> 039 * @version $Id: DefaultsTest.java 1616993 2014-08-09 17:03:07Z tv $ 040 */ 041public class DefaultsTest 042 extends BaseTestCase 043{ 044 private static TurbineConfig tc = null; 045 private static TemplateService ts = null; 046 047 048 @BeforeClass 049 public static void setUp() throws Exception { 050 tc = new TurbineConfig(".", "/conf/test/TemplateService.properties"); 051 tc.initialize(); 052 053 ts = (TemplateService) TurbineServices.getInstance().getService(TemplateService.SERVICE_NAME); 054 } 055 056 @AfterClass 057 public static void destroy() throws Exception { 058 ts.shutdown(); 059 tc.dispose(); 060 } 061 062 @Test 063 public void testDefaults() 064 { 065 // Test if the caching property was loaded correctly. (key:module.cache) 066 assertFalse("isCaching failed!", ts.isCaching()); 067 068 // Test if the default values for Template and Extension were loaded correctly 069 assertEquals("Default Extension failed", ts.getDefaultExtension(), ""); 070 assertEquals("Default Template failed", ts.getDefaultTemplate(), TemplateService.DEFAULT_TEMPLATE_VALUE); 071 } 072 073 @Test 074 public void testTemplateDefaults() 075 { 076 // Test if the Default-Values for the Screen, Layout and Navigation classes and the Layout Template are correct. 077 assertEquals("Default Page failed", TemplateService.DEFAULT_TEMPLATE_VALUE, ts.getDefaultPage()); 078 assertEquals("Default Screen failed", TemplateService.DEFAULT_TEMPLATE_VALUE, ts.getDefaultScreen()); 079 assertEquals("Default Layout failed", TemplateService.DEFAULT_TEMPLATE_VALUE, ts.getDefaultLayout()); 080 assertEquals("Default Navigation failed", TemplateService.DEFAULT_TEMPLATE_VALUE, ts.getDefaultNavigation()); 081 assertEquals("Default LayoutTemplate failed", TemplateService.DEFAULT_TEMPLATE_VALUE, ts.getDefaultLayoutTemplate()); 082 } 083 084 @Test 085 public void testVelocityDefaults() 086 { 087 // Test if all the Velocity based Defaults for Page, Screen, Layout, Navigation and Layout Template 088 assertEquals("Default Page failed", "VelocityPage", ts.getDefaultPageName("foo.vm")); 089 assertEquals("Default Screen failed", "VelocityScreen", ts.getDefaultScreenName("foo.vm")); 090 assertEquals("Default Layout failed", "VelocityOnlyLayout", ts.getDefaultLayoutName("foo.vm")); 091 assertEquals("Default Navigation failed", "VelocityNavigation", ts.getDefaultNavigationName("foo.vm")); 092 assertEquals("Default LayoutTemplate failed", "Default.vm", ts.getDefaultLayoutTemplateName("foo.vm")); 093 } 094} 095