    001package 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
    024import static org.junit.Assert.assertTrue;
    025import static org.junit.Assert.fail;
    026
    027import org.apache.commons.configuration.BaseConfiguration;
    028import org.apache.commons.configuration.Configuration;
    029import org.apache.turbine.services.ServiceManager;
    030import org.apache.turbine.services.TurbineServices;
    031import org.apache.turbine.test.BaseTestCase;
    032import org.apache.turbine.test.TestComponent;
    033import org.junit.Test;
    034
    035
    036/**
    037 * Simple test to make sure that the AvalonComponentService can be initialized.
    038 *
    039 * @author <a href="mailto:quintonm@bellsouth.net">Quinton McCombs</a>
    040 * @version $Id: TurbineAvalonComponentServiceTest.java 1616993 2014-08-09 17:03:07Z tv $
    041 */
    042public class TurbineAvalonComponentServiceTest
    043        extends BaseTestCase
    044{
    045    private static final String PREFIX = "services." +
    046            AvalonComponentService.SERVICE_NAME + '.';
    047
    048    /**
    049     * Initialize the unit test.  The AvalonComponentService will be configured
    050     * and initialized.*/
    051
    052
    053    /**
    054     * Use the service to get an instance of the TestComponent.  The test() method will be called to
    055     * simply write a log message.  The component will then be released.
    056     */
    057    @Test public void testGetAndUseTestComponent()
    058    {
    059        ServiceManager serviceManager = TurbineServices.getInstance();
    060        serviceManager.setApplicationRoot(".");
    061
    062        Configuration cfg = new BaseConfiguration();
    063
    064        // decide here whether to start ECM or YAAFI
    065        //cfg.setProperty(PREFIX + "classname", TurbineAvalonComponentService.class.getName());
    066        cfg.setProperty(PREFIX + "classname", TurbineYaafiComponentService.class.getName());
    067
    068        // we want to configure the service to load test TEST configuration files
    069        cfg.setProperty(PREFIX + "componentConfiguration",
    070                "src/test/componentConfiguration.xml");
    071        cfg.setProperty(PREFIX + "componentRoles",
    072                "src/test/componentRoles.xml");
    073        serviceManager.setConfiguration(cfg);
    074
    075        try
    076        {
    077            serviceManager.init();
    078        }
    079        catch(Exception e)
    080        {
    081            e.printStackTrace();
    082            fail();
    083        }
    084        try
    085        {
    086            TestComponent tc = (TestComponent)TurbineServices.getInstance().getService(TestComponent.ROLE);
    087            assertTrue( tc != null );
    088            tc.test();
    089        }
    090        catch(Exception e)
    091        {
    092            e.printStackTrace();
    093            fail();
    094        }
    095    }
    096}