001    package org.apache.turbine.services.avaloncomponent;
002    
003    
004    /*
005     * Licensed to the Apache Software Foundation (ASF) under one
006     * or more contributor license agreements.  See the NOTICE file
007     * distributed with this work for additional information
008     * regarding copyright ownership.  The ASF licenses this file
009     * to you under the Apache License, Version 2.0 (the
010     * "License"); you may not use this file except in compliance
011     * with the License.  You may obtain a copy of the License at
012     *
013     *   http://www.apache.org/licenses/LICENSE-2.0
014     *
015     * Unless required by applicable law or agreed to in writing,
016     * software distributed under the License is distributed on an
017     * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
018     * KIND, either express or implied.  See the License for the
019     * specific language governing permissions and limitations
020     * under the License.
021     */
022    
023    
024    import org.apache.commons.configuration.BaseConfiguration;
025    import org.apache.commons.configuration.Configuration;
026    
027    import org.apache.turbine.services.ServiceManager;
028    import org.apache.turbine.services.TurbineServices;
029    import org.apache.turbine.test.BaseTestCase;
030    import org.apache.turbine.test.TestComponent;
031    
032    
033    /**
034     * Simple test to make sure that the AvalonComponentService can be initialized.
035     *
036     * @author <a href="mailto:quintonm@bellsouth.net">Quinton McCombs</a>
037     * @version $Id: TurbineAvalonComponentServiceTest.java 731294 2009-01-04 16:39:38Z tv $
038     */
039    public class TurbineAvalonComponentServiceTest
040            extends BaseTestCase
041    {
042        private static final String PREFIX = "services." +
043                AvalonComponentService.SERVICE_NAME + '.';
044    
045        /**
046         * Initialize the unit test.  The AvalonComponentService will be configured
047         * and initialized.
048    
049         *
050         * @param name
051         */
052        public TurbineAvalonComponentServiceTest(String name)
053                throws Exception
054        {
055            super(name);
056            ServiceManager serviceManager = TurbineServices.getInstance();
057            serviceManager.setApplicationRoot(".");
058    
059            Configuration cfg = new BaseConfiguration();
060    
061            // decide here wether to start ECM or YAAFI
062            // cfg.setProperty(PREFIX + "classname", TurbineAvalonComponentService.class.getName());
063            cfg.setProperty(PREFIX + "classname", TurbineYaafiComponentService.class.getName());
064            cfg.setProperty(PREFIX + "earlyInit", "true");
065    
066            // we want to configure the service to load test TEST configuration files
067            cfg.setProperty(PREFIX + "componentConfiguration",
068                    "src/test/componentConfiguration.xml");
069            cfg.setProperty(PREFIX + "componentRoles",
070                    "src/test/componentRoles.xml");
071            serviceManager.setConfiguration(cfg);
072    
073            try
074            {
075                serviceManager.init();
076            }
077            catch(Exception e)
078            {
079                e.printStackTrace();
080                fail();
081            }
082        }
083    
084        /**
085         * Use the service to get an instance of the TestComponent.  The test() method will be called to
086         * simply write a log message.  The component will then be released.
087         */
088        public void testGetAndUseTestComponent()
089        {
090            try
091            {
092                TestComponent tc = (TestComponent)TurbineServices.getInstance().getService(TestComponent.ROLE);
093                tc.test();
094            }
095            catch(Exception e)
096            {
097                e.printStackTrace();
098                fail();
099            }
100        }
101    }