1   package org.apache.turbine.services.avaloncomponent;
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 org.apache.commons.configuration.BaseConfiguration;
23  import org.apache.commons.configuration.Configuration;
24  
25  import org.apache.turbine.services.ServiceManager;
26  import org.apache.turbine.services.TurbineServices;
27  import org.apache.turbine.test.BaseTestCase;
28  import org.apache.turbine.test.TestComponent;
29  
30  
31  /***
32   * Simple test to make sure that the AvalonComponentService can be initialized.
33   *
34   * @author <a href="mailto:quintonm@bellsouth.net">Quinton McCombs</a>
35   * @version $Id: TurbineAvalonComponentServiceTest.java 534527 2007-05-02 16:10:59Z tv $
36   */
37  public class TurbineAvalonComponentServiceTest
38          extends BaseTestCase
39  {
40      private static final String PREFIX = "services." +
41              AvalonComponentService.SERVICE_NAME + '.';
42  
43      /***
44       * Initialize the unit test.  The AvalonComponentService will be configured
45       * and initialized.
46  
47       *
48       * @param name
49       */
50      public TurbineAvalonComponentServiceTest(String name)
51              throws Exception
52      {
53          super(name);
54          ServiceManager serviceManager = TurbineServices.getInstance();
55          serviceManager.setApplicationRoot(".");
56  
57          Configuration cfg = new BaseConfiguration();
58          cfg.setProperty(PREFIX + "classname",
59                  TurbineAvalonComponentService.class.getName());
60  
61          // we want to configure the service to load test TEST configuration files
62          cfg.setProperty(PREFIX + "componentConfiguration",
63                  "src/test/componentConfiguration.xml");
64          cfg.setProperty(PREFIX + "componentRoles",
65                  "src/test/componentRoles.xml");
66          serviceManager.setConfiguration(cfg);
67  
68          try
69          {
70              serviceManager.init();
71          }
72          catch(Exception e)
73          {
74              e.printStackTrace();
75              fail();
76          }
77      }
78  
79      /***
80       * Use the service to get an instance of the TestComponent.  The test() method will be called to
81       * simply write a log message.  The component will then be released.
82       */
83      public void testGetAndUseTestComponent()
84      {
85          try
86          {
87              AvalonComponentService cs = (AvalonComponentService)
88                      TurbineServices.getInstance().getService(AvalonComponentService.SERVICE_NAME);
89  
90              TestComponent tc = (TestComponent) cs.lookup(TestComponent.ROLE);
91              tc.test();
92              cs.release(tc);
93          }
94          catch(Exception e)
95          {
96              e.printStackTrace();
97              fail();
98          }
99      }
100 }