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