01: package org.apache.turbine.services.avaloncomponent;
02:
03: /*
04: * Licensed to the Apache Software Foundation (ASF) under one
05: * or more contributor license agreements. See the NOTICE file
06: * distributed with this work for additional information
07: * regarding copyright ownership. The ASF licenses this file
08: * to you under the Apache License, Version 2.0 (the
09: * "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 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 extends BaseTestCase {
39: private static final String PREFIX = "services."
40: + ACSYaafiComponentService.SERVICE_NAME + '.';
41:
42: /**
43: * Initialize the unit test. The YaafiComponentService will be configured
44: * and initialized.
45: *
46: * @param name
47: */
48: public ACSYaafiComponentServiceTest(String name) throws Exception {
49: super (name);
50: ServiceManager serviceManager = TurbineServices.getInstance();
51: serviceManager.setApplicationRoot(".");
52:
53: Configuration cfg = new BaseConfiguration();
54: cfg.setProperty(PREFIX + "classname",
55: ACSYaafiComponentService.class.getName());
56: cfg.setProperty(PREFIX + "earlyInit", "true");
57:
58: // Configure the service to load test TEST configuration files
59: cfg.setProperty(PREFIX + "containerConfiguration",
60: "src/test/yaafiContainerConfiguration.xml");
61: serviceManager.setConfiguration(cfg);
62:
63: try {
64: serviceManager.init();
65: } catch (Exception e) {
66: e.printStackTrace();
67: fail();
68: }
69: }
70:
71: /**
72: * Use the service to get an instance of the TestComponent. The test()
73: * method will be called to simply write a log message. The component will
74: * then be released.
75: */
76: public void testGetAndUseTestComponent() {
77: try {
78: ServiceManagerService serviceManagerService = ServiceManagerServiceImpl
79: .getInstance();
80: assertNotNull(serviceManagerService);
81:
82: assertTrue(serviceManagerService
83: .hasService(TestComponent.ROLE));
84: TestComponent tc = (TestComponent) serviceManagerService
85: .lookup(TestComponent.ROLE);
86: tc.test();
87: serviceManagerService.release(tc);
88: } catch (Exception e) {
89: e.printStackTrace();
90: fail();
91: }
92: }
93: }
|