KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > turbine > services > avaloncomponent > TurbineAvalonComponentServiceTest


1 package org.apache.turbine.services.avaloncomponent;
2
3 /*
4  * Copyright 2001-2004 The Apache Software Foundation.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License")
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */

18
19 import org.apache.commons.configuration.BaseConfiguration;
20 import org.apache.commons.configuration.Configuration;
21
22 import org.apache.turbine.services.ServiceManager;
23 import org.apache.turbine.services.TurbineServices;
24 import org.apache.turbine.test.BaseTestCase;
25 import org.apache.turbine.test.TestComponent;
26
27
28 /**
29  * Simple test to make sure that the AvalonComponentService can be initialized.
30  *
31  * @author <a HREF="mailto:quintonm@bellsouth.net">Quinton McCombs</a>
32  * @version $Id: TurbineAvalonComponentServiceTest.java,v 1.5.2.2 2004/05/20 03:32:54 seade Exp $
33  */

34 public class TurbineAvalonComponentServiceTest
35         extends BaseTestCase
36 {
37     private static final String JavaDoc PREFIX = "services." +
38             AvalonComponentService.SERVICE_NAME + '.';
39
40     /**
41      * Initialize the unit test. The AvalonComponentService will be configured
42      * and initialized.
43
44      *
45      * @param name
46      */

47     public TurbineAvalonComponentServiceTest(String JavaDoc name)
48             throws Exception JavaDoc
49     {
50         super(name);
51         ServiceManager serviceManager = TurbineServices.getInstance();
52         serviceManager.setApplicationRoot(".");
53
54         Configuration cfg = new BaseConfiguration();
55         cfg.setProperty(PREFIX + "classname",
56                 TurbineAvalonComponentService.class.getName());
57
58         // we want to configure the service to load test TEST configuration files
59
cfg.setProperty(PREFIX + "componentConfiguration",
60                 "src/test/componentConfiguration.xml");
61         cfg.setProperty(PREFIX + "componentRoles",
62                 "src/test/componentRoles.xml");
63         serviceManager.setConfiguration(cfg);
64
65         try
66         {
67             serviceManager.init();
68         }
69         catch(Exception JavaDoc e)
70         {
71             e.printStackTrace();
72             fail();
73         }
74     }
75
76     /**
77      * Use the service to get an instance of the TestComponent. The test() method will be called to
78      * simply write a log message. The component will then be released.
79      */

80     public void testGetAndUseTestComponent()
81     {
82         try
83         {
84             AvalonComponentService cs = (AvalonComponentService)
85                     TurbineServices.getInstance().getService(AvalonComponentService.SERVICE_NAME);
86
87             TestComponent tc = (TestComponent) cs.lookup(TestComponent.ROLE);
88             tc.test();
89             cs.release(tc);
90         }
91         catch(Exception JavaDoc e)
92         {
93             e.printStackTrace();
94             fail();
95         }
96     }
97 }
98
Popular Tags