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
20
21
22 import org.apache.commons.configuration.BaseConfiguration;
23 import org.apache.commons.configuration.Configuration;
24
25 import org.apache.turbine.services.ServiceManager;
26 import org.apache.turbine.services.TurbineServices;
27 import org.apache.turbine.test.BaseTestCase;
28 import org.apache.turbine.test.TestComponent;
29
30
31 /***
32 * Simple test to make sure that the AvalonComponentService can be initialized.
33 *
34 * @author <a href="mailto:quintonm@bellsouth.net">Quinton McCombs</a>
35 * @version $Id: TurbineAvalonComponentServiceTest.java 534527 2007-05-02 16:10:59Z tv $
36 */
37 public class TurbineAvalonComponentServiceTest
38 extends BaseTestCase
39 {
40 private static final String PREFIX = "services." +
41 AvalonComponentService.SERVICE_NAME + '.';
42
43 /***
44 * Initialize the unit test. The AvalonComponentService will be configured
45 * and initialized.
46
47 *
48 * @param name
49 */
50 public TurbineAvalonComponentServiceTest(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 TurbineAvalonComponentService.class.getName());
60
61
62 cfg.setProperty(PREFIX + "componentConfiguration",
63 "src/test/componentConfiguration.xml");
64 cfg.setProperty(PREFIX + "componentRoles",
65 "src/test/componentRoles.xml");
66 serviceManager.setConfiguration(cfg);
67
68 try
69 {
70 serviceManager.init();
71 }
72 catch(Exception e)
73 {
74 e.printStackTrace();
75 fail();
76 }
77 }
78
79 /***
80 * Use the service to get an instance of the TestComponent. The test() method will be called to
81 * simply write a log message. The component will then be released.
82 */
83 public void testGetAndUseTestComponent()
84 {
85 try
86 {
87 AvalonComponentService cs = (AvalonComponentService)
88 TurbineServices.getInstance().getService(AvalonComponentService.SERVICE_NAME);
89
90 TestComponent tc = (TestComponent) cs.lookup(TestComponent.ROLE);
91 tc.test();
92 cs.release(tc);
93 }
94 catch(Exception e)
95 {
96 e.printStackTrace();
97 fail();
98 }
99 }
100 }