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 import org.apache.fulcrum.yaafi.service.servicemanager.ServiceManagerService;
25 import org.apache.fulcrum.yaafi.service.servicemanager.ServiceManagerServiceImpl;
26
27 import org.apache.turbine.services.ServiceManager;
28 import org.apache.turbine.services.TurbineServices;
29 import org.apache.turbine.test.BaseTestCase;
30 import org.apache.turbine.test.TestComponent;
31
32 /***
33 * Simple test to make sure that the YaafiComponentService can be initialized.
34 *
35 * @author <a href="mailto:seade@backstagetech.com.au">Scott Eade</a>
36 * @version $Id$
37 */
38 public class ACSYaafiComponentServiceTest
39 extends BaseTestCase
40 {
41 private static final String PREFIX = "services."
42 + ACSYaafiComponentService.SERVICE_NAME + '.';
43
44 /***
45 * Initialize the unit test. The YaafiComponentService will be configured
46 * and initialized.
47 *
48 * @param name
49 */
50 public ACSYaafiComponentServiceTest(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 ACSYaafiComponentService.class.getName());
60 cfg.setProperty(PREFIX + "earlyInit", "true");
61
62
63 cfg.setProperty(PREFIX + "containerConfiguration",
64 "src/test/yaafiContainerConfiguration.xml");
65 serviceManager.setConfiguration(cfg);
66
67 try
68 {
69 serviceManager.init();
70 }
71 catch(Exception e)
72 {
73 e.printStackTrace();
74 fail();
75 }
76 }
77
78 /***
79 * Use the service to get an instance of the TestComponent. The test()
80 * method will be called to simply write a log message. The component will
81 * then be released.
82 */
83 public void testGetAndUseTestComponent()
84 {
85 try
86 {
87 ServiceManagerService serviceManagerService
88 = ServiceManagerServiceImpl.getInstance();
89 assertNotNull(serviceManagerService);
90
91 assertTrue(serviceManagerService.hasService(TestComponent.ROLE));
92 TestComponent tc = (TestComponent)
93 serviceManagerService.lookup(TestComponent.ROLE);
94 tc.test();
95 serviceManagerService.release(tc);
96 }
97 catch(Exception e)
98 {
99 e.printStackTrace();
100 fail();
101 }
102 }
103 }