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  import org.apache.fulcrum.yaafi.service.servicemanager.ServiceManagerService;
25  import org.apache.fulcrum.yaafi.service.servicemanager.ServiceManagerServiceImpl;
26  
27  import org.apache.turbine.services.ServiceManager;
28  import org.apache.turbine.services.TurbineServices;
29  import org.apache.turbine.test.BaseTestCase;
30  import org.apache.turbine.test.TestComponent;
31  
32  /***
33   * Simple test to make sure that the YaafiComponentService can be initialized.
34   *
35   * @author <a href="mailto:seade@backstagetech.com.au">Scott Eade</a>
36   * @version $Id$
37   */
38  public class ACSYaafiComponentServiceTest
39          extends BaseTestCase
40  {
41      private static final String PREFIX = "services."
42              + ACSYaafiComponentService.SERVICE_NAME + '.';
43  
44      /***
45       * Initialize the unit test.  The YaafiComponentService will be configured
46       * and initialized.
47       *
48       * @param name
49       */
50      public ACSYaafiComponentServiceTest(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                  ACSYaafiComponentService.class.getName());
60          cfg.setProperty(PREFIX + "earlyInit", "true");
61  
62          // Configure the service to load test TEST configuration files
63          cfg.setProperty(PREFIX + "containerConfiguration",
64                  "src/test/yaafiContainerConfiguration.xml");
65          serviceManager.setConfiguration(cfg);
66  
67          try
68          {
69              serviceManager.init();
70          }
71          catch(Exception e)
72          {
73              e.printStackTrace();
74              fail();
75          }
76      }
77  
78      /***
79       * Use the service to get an instance of the TestComponent.  The test()
80       * method will be called to simply write a log message.  The component will
81       * then be released.
82       */
83      public void testGetAndUseTestComponent()
84      {
85          try
86          {
87              ServiceManagerService serviceManagerService
88                      = ServiceManagerServiceImpl.getInstance();
89              assertNotNull(serviceManagerService);
90  
91              assertTrue(serviceManagerService.hasService(TestComponent.ROLE));
92              TestComponent tc = (TestComponent)
93                      serviceManagerService.lookup(TestComponent.ROLE);
94              tc.test();
95              serviceManagerService.release(tc);
96          }
97          catch(Exception e)
98          {
99              e.printStackTrace();
100             fail();
101         }
102     }
103 }