1   package org.apache.turbine.services.template;
2   
3   /*
4    * Copyright 2001-2005 The Apache Software Foundation.
5    *
6    * Licensed under the Apache License, Version 2.0 (the "License")
7    * you may not use this file except in compliance with the License.
8    * You may obtain a copy of the License at
9    *
10   *     http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18  
19  import junit.framework.Test;
20  import junit.framework.TestSuite;
21  
22  import org.apache.turbine.services.TurbineServices;
23  import org.apache.turbine.services.template.TemplateEngineService;
24  import org.apache.turbine.services.template.TemplateService;
25  import org.apache.turbine.services.velocity.VelocityService;
26  import org.apache.turbine.test.BaseTestCase;
27  import org.apache.turbine.util.TurbineConfig;
28  
29  /***
30   * Tests startup of the Template Service and registration of the
31   * Velocity Service.
32   *
33   * @author <a href="hps@intermeta.de">Henning P. Schmiedehausen</a>
34   * @version $Id: InitTest.java 264148 2005-08-29 14:21:04Z henning $
35   */
36  
37  public class InitTest
38      extends BaseTestCase
39  {
40      private static TurbineConfig tc = null;
41      private static TemplateService ts = null;
42  
43      public InitTest(String name)
44              throws Exception
45      {
46          super(name);
47          tc = new TurbineConfig(".", "/conf/test/TemplateService.properties");
48          tc.initialize();
49  
50          ts = (TemplateService) TurbineServices.getInstance().getService(TemplateService.SERVICE_NAME);
51      }
52  
53      public static Test suite()
54      {
55          return new TestSuite(InitTest.class);
56      }
57  
58      public void testService()
59          throws Exception
60      {
61  
62          // Can we start the service?
63          assertNotNull("Could not load Service!", ts);
64  
65          // Did we register the Velocity Service correctly for "vm" templates?
66          VelocityService vs = (VelocityService) TurbineServices
67              .getInstance().getService(VelocityService.SERVICE_NAME);
68  
69          TemplateEngineService tes = ts.getTemplateEngineService("foo.vm");
70  
71          assertEquals("Template Service did not return Velocity Service for .vm Templates", vs, tes);
72      }
73  }