1   package org.apache.fulcrum.yaafi.service;
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.TestCase;
23  
24  import org.apache.avalon.framework.service.ServiceManager;
25  import org.apache.fulcrum.yaafi.framework.container.ServiceContainer;
26  import org.apache.fulcrum.yaafi.framework.factory.ServiceContainerConfiguration;
27  import org.apache.fulcrum.yaafi.framework.factory.ServiceContainerFactory;
28  import org.apache.fulcrum.yaafi.service.servicemanager.ServiceManagerService;
29  import org.apache.fulcrum.yaafi.service.servicemanager.ServiceManagerServiceImpl;
30  
31  /**
32   * Test suite for the ServiceManagereService.
33   *
34   * @author <a href="mailto:siegfried.goeschl@it20one.at">Siegfried Goeschl</a>
35   */
36  
37  public class ServiceManagerServiceTest extends TestCase
38  {
39      private ServiceContainer container = null;
40  
41      /**
42       * Constructor
43       * @param name the name of the test case
44       */
45      public ServiceManagerServiceTest( String name )
46      {
47          super(name);
48      }
49  
50      /**
51       * @see junit.framework.TestCase#setUp()
52       */
53      protected void setUp() throws Exception
54      {
55          super.setUp();
56          ServiceContainerConfiguration config = new ServiceContainerConfiguration();
57          config.loadContainerConfiguration( "./src/test/TestYaafiContainerConfig.xml" );
58          this.container = ServiceContainerFactory.create( config );
59      }
60  
61      /**
62       * @see junit.framework.TestCase#tearDown()
63       */
64      protected void tearDown() throws Exception
65      {
66          ServiceContainerFactory.dispose(this.container);
67          super.tearDown();
68      }
69  
70      /**
71       * Access the ServiceManagerService
72       */
73      public void testServiceManagerService() throws Exception
74      {
75          ServiceManagerService serviceManagerService = ServiceManagerServiceImpl.getInstance();
76          assertNotNull(serviceManagerService);
77  
78          assertNotNull( serviceManagerService.getAvalonLogger() );
79          assertNotNull( serviceManagerService.getContext().get("urn:avalon:home") );
80          assertNotNull( serviceManagerService.getContext().get("urn:avalon:temp") );
81  
82          // get the parameters
83          serviceManagerService.getParameters();
84  
85          // lookup the service
86          serviceManagerService = (ServiceManagerService) serviceManagerService.lookup( ServiceManagerService.class.getName() );
87          assertTrue( serviceManagerService.hasService( ServiceManagerService.class.getName() ) );
88          assertTrue( serviceManagerService.getServiceManager() instanceof ServiceManager );
89          serviceManagerService.release(serviceManagerService);
90      }
91  }