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.ServiceException;
25  import org.apache.fulcrum.yaafi.TestComponent;
26  import org.apache.fulcrum.yaafi.framework.container.ServiceContainer;
27  import org.apache.fulcrum.yaafi.framework.factory.ServiceContainerConfiguration;
28  import org.apache.fulcrum.yaafi.framework.factory.ServiceContainerFactory;
29  import org.apache.fulcrum.yaafi.service.reconfiguration.ReconfigurationService;
30  
31  /**
32   * Test suite for the ReconfigurationService. This test doesn't do
33   * anything apart from running a minute so you have some time to tinker
34   * with the component configuration file.
35   *
36   * @author <a href="mailto:siegfried.goeschl@it20one.at">Siegfried Goeschl</a>
37   */
38  
39  public class ReconfigurationTest extends TestCase
40  {
41      private ServiceContainer container = null;
42  
43      /**
44       * Constructor
45       * @param name the name of the test case
46       */
47      public ReconfigurationTest( String name )
48      {
49          super(name);
50      }
51  
52      /**
53       * @see junit.framework.TestCase#tearDown()
54       */
55      protected void tearDown() throws Exception
56      {
57          ServiceContainerFactory.dispose(this.container);
58          super.tearDown();
59      }
60  
61      /**
62       * @return get our simple test component
63       */
64      private TestComponent getTestComponent() throws ServiceException
65      {
66          return (TestComponent) container.lookup(
67              TestComponent.ROLE
68              );
69      }
70  
71      /**
72       * Trigger the ReconfigurationService by instantiating it manually.
73       */
74      public void testReconfigurationService() throws Exception
75      {
76          // instantiate a YAAFI container
77  
78          ServiceContainerConfiguration config = new ServiceContainerConfiguration();
79          config.loadContainerConfiguration( "./src/test/TestYaafiContainerConfig.xml" );
80          this.container = ServiceContainerFactory.create( config );
81  
82          // the ReconfigurationService is configured to be instantiated on demand
83          // get an instance to start monitoring ...
84  
85          ReconfigurationService reconfigurationService = null;
86  
87          reconfigurationService = (ReconfigurationService) this.container.lookup(
88              ReconfigurationService.class.getName()
89              );
90  
91          assertNotNull(reconfigurationService);
92  
93          // comment out if you want to tinker with componentConfiguration manually
94  
95          // Thread.sleep(60000);
96  
97          this.getTestComponent().test();
98      }
99  }