    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 org.apache.commons.configuration.BaseConfiguration;
    25  import org.apache.commons.configuration.Configuration;
    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  /**
    34   * Simple test to make sure that the AvalonComponentService can be initialized.
    35   *
    36   * @author <a href="mailto:quintonm@bellsouth.net">Quinton McCombs</a>
    37   * @version $Id: TurbineAvalonComponentServiceTest.java 731294 2009-01-04 16:39:38Z tv $
    38   */
    39  public class TurbineAvalonComponentServiceTest
    40          extends BaseTestCase
    41  {
    42      private static final String PREFIX = "services." +
    43              AvalonComponentService.SERVICE_NAME + '.';
    44
    45      /**
    46       * Initialize the unit test.  The AvalonComponentService will be configured
    47       * and initialized.
    48
    49       *
    50       * @param name
    51       */
    52      public TurbineAvalonComponentServiceTest(String name)
    53              throws Exception
    54      {
    55          super(name);
    56          ServiceManager serviceManager = TurbineServices.getInstance();
    57          serviceManager.setApplicationRoot(".");
    58
    59          Configuration cfg = new BaseConfiguration();
    60
    61          // decide here wether to start ECM or YAAFI
    62          // cfg.setProperty(PREFIX + "classname", TurbineAvalonComponentService.class.getName());
    63          cfg.setProperty(PREFIX + "classname", TurbineYaafiComponentService.class.getName());
    64          cfg.setProperty(PREFIX + "earlyInit", "true");
    65
    66          // we want to configure the service to load test TEST configuration files
    67          cfg.setProperty(PREFIX + "componentConfiguration",
    68                  "src/test/componentConfiguration.xml");
    69          cfg.setProperty(PREFIX + "componentRoles",
    70                  "src/test/componentRoles.xml");
    71          serviceManager.setConfiguration(cfg);
    72
    73          try
    74          {
    75              serviceManager.init();
    76          }
    77          catch(Exception e)
    78          {
    79              e.printStackTrace();
    80              fail();
    81          }
    82      }
    83
    84      /**
    85       * Use the service to get an instance of the TestComponent.  The test() method will be called to
    86       * simply write a log message.  The component will then be released.
    87       */
    88      public void testGetAndUseTestComponent()
    89      {
    90          try
    91          {
    92              TestComponent tc = (TestComponent)TurbineServices.getInstance().getService(TestComponent.ROLE);
    93              tc.test();
    94          }
    95          catch(Exception e)
    96          {
    97              e.printStackTrace();
    98              fail();
    99          }
    100     }
    101 }