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:
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: * Simple test to make sure that the AvalonComponentService can be initialized.
32: *
33: * @author <a href="mailto:quintonm@bellsouth.net">Quinton McCombs</a>
34: * @version $Id: TurbineAvalonComponentServiceTest.java 534527 2007-05-02 16:10:59Z tv $
35: */
36: public class TurbineAvalonComponentServiceTest extends BaseTestCase {
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: super (name);
50: ServiceManager serviceManager = TurbineServices.getInstance();
51: serviceManager.setApplicationRoot(".");
52:
53: Configuration cfg = new BaseConfiguration();
54: cfg.setProperty(PREFIX + "classname",
55: TurbineAvalonComponentService.class.getName());
56:
57: // we want to configure the service to load test TEST configuration files
58: cfg.setProperty(PREFIX + "componentConfiguration",
59: "src/test/componentConfiguration.xml");
60: cfg.setProperty(PREFIX + "componentRoles",
61: "src/test/componentRoles.xml");
62: serviceManager.setConfiguration(cfg);
63:
64: try {
65: serviceManager.init();
66: } catch (Exception e) {
67: e.printStackTrace();
68: fail();
69: }
70: }
71:
72: /**
73: * Use the service to get an instance of the TestComponent. The test() method will be called to
74: * simply write a log message. The component will then be released.
75: */
76: public void testGetAndUseTestComponent() {
77: try {
78: AvalonComponentService cs = (AvalonComponentService) TurbineServices
79: .getInstance().getService(
80: AvalonComponentService.SERVICE_NAME);
81:
82: TestComponent tc = (TestComponent) cs
83: .lookup(TestComponent.ROLE);
84: tc.test();
85: cs.release(tc);
86: } catch (Exception e) {
87: e.printStackTrace();
88: fail();
89: }
90: }
91: }
|