1 package org.apache.turbine.services.avaloncomponent;
2
3
4 /*
5 * Licensed to the Apache Software Foundation (ASF) under one
6 * or more contributor license agreements. See the NOTICE file
7 * distributed with this work for additional information
8 * regarding copyright ownership. The ASF licenses this file
9 * to you under the Apache License, Version 2.0 (the
10 * "License"); you may not use this file except in compliance
11 * with the License. You may obtain a copy of the License at
12 *
13 * http://www.apache.org/licenses/LICENSE-2.0
14 *
15 * Unless required by applicable law or agreed to in writing,
16 * software distributed under the License is distributed on an
17 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
18 * KIND, either express or implied. See the License for the
19 * specific language governing permissions and limitations
20 * under the License.
21 */
22
23
24 import static org.junit.Assert.assertTrue;
25 import static org.junit.Assert.fail;
26
27 import org.apache.commons.configuration.BaseConfiguration;
28 import org.apache.commons.configuration.Configuration;
29 import org.apache.turbine.services.ServiceManager;
30 import org.apache.turbine.services.TurbineServices;
31 import org.apache.turbine.test.BaseTestCase;
32 import org.apache.turbine.test.TestComponent;
33 import org.junit.Test;
34
35
36 /**
37 * Simple test to make sure that the AvalonComponentService can be initialized.
38 *
39 * @author <a href="mailto:quintonm@bellsouth.net">Quinton McCombs</a>
40 * @version $Id: TurbineAvalonComponentServiceTest.java 1616993 2014-08-09 17:03:07Z tv $
41 */
42 public class TurbineAvalonComponentServiceTest
43 extends BaseTestCase
44 {
45 private static final String PREFIX = "services." +
46 AvalonComponentService.SERVICE_NAME + '.';
47
48 /**
49 * Initialize the unit test. The AvalonComponentService will be configured
50 * and initialized.*/
51
52
53 /**
54 * Use the service to get an instance of the TestComponent. The test() method will be called to
55 * simply write a log message. The component will then be released.
56 */
57 @Test public void testGetAndUseTestComponent()
58 {
59 ServiceManager serviceManager = TurbineServices.getInstance();
60 serviceManager.setApplicationRoot(".");
61
62 Configuration cfg = new BaseConfiguration();
63
64 // decide here whether to start ECM or YAAFI
65 //cfg.setProperty(PREFIX + "classname", TurbineAvalonComponentService.class.getName());
66 cfg.setProperty(PREFIX + "classname", TurbineYaafiComponentService.class.getName());
67
68 // we want to configure the service to load test TEST configuration files
69 cfg.setProperty(PREFIX + "componentConfiguration",
70 "src/test/componentConfiguration.xml");
71 cfg.setProperty(PREFIX + "componentRoles",
72 "src/test/componentRoles.xml");
73 serviceManager.setConfiguration(cfg);
74
75 try
76 {
77 serviceManager.init();
78 }
79 catch(Exception e)
80 {
81 e.printStackTrace();
82 fail();
83 }
84 try
85 {
86 TestComponent tc = (TestComponent)TurbineServices.getInstance().getService(TestComponent.ROLE);
87 assertTrue( tc != null );
88 tc.test();
89 }
90 catch(Exception e)
91 {
92 e.printStackTrace();
93 fail();
94 }
95 }
96 }