1 package org.apache.turbine.services.avaloncomponent;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
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 264148 2005-08-29 14:21:04Z henning $
33 */
34 public class TurbineAvalonComponentServiceTest
35 extends BaseTestCase
36 {
37 private static final String 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 name)
48 throws Exception
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
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 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 e)
92 {
93 e.printStackTrace();
94 fail();
95 }
96 }
97 }