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.assertNotNull; 026 027import org.apache.turbine.services.TurbineServices; 028import org.apache.turbine.services.velocity.VelocityService; 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 startup of the Template Service and registration of the 037 * Velocity Service. 038 * 039 * @author <a href="hps@intermeta.de">Henning P. Schmiedehausen</a> 040 * @version $Id$ 041 */ 042 043public class InitTest 044 extends BaseTestCase 045{ 046 private static TurbineConfig tc = null; 047 private static TemplateService ts = null; 048 049 050 @BeforeClass 051 public static void setUp() throws Exception 052 { 053 tc = new TurbineConfig(".", "/conf/test/TemplateService.properties"); 054 tc.initialize(); 055 056 ts = (TemplateService) TurbineServices.getInstance().getService(TemplateService.SERVICE_NAME); 057 } 058 059 @AfterClass 060 public static void tearDown() throws Exception 061 { 062 if (tc != null) 063 { 064 tc.dispose(); 065 } 066 } 067 068 @Test public void testService() 069 throws Exception 070 { 071 072 // Can we start the service? 073 assertNotNull("Could not load Service!", ts); 074 075 // Did we register the Velocity Service correctly for "vm" templates? 076 VelocityService vs = (VelocityService) TurbineServices 077 .getInstance().getService(VelocityService.SERVICE_NAME); 078 079 TemplateEngineService tes = ts.getTemplateEngineService("foo.vm"); 080 081 assertEquals("Template Service did not return Velocity Service for .vm Templates", vs, tes); 082 } 083}