    1   package org.apache.stratum.component;
    2
    3   /*
    4    * Copyright 2001-2005 The Apache Software Foundation or its licensors,
    5    * as applicable.
    6    *
    7    * Licensed under the Apache License, Version 2.0 (the "License");
    8    * you may not use this file except in compliance with the License.
    9    * You may obtain a copy of the License at
    10   *
    11   *     http://www.apache.org/licenses/LICENSE-2.0
    12   *
    13   * Unless required by applicable law or agreed to in writing, software
    14   * distributed under the License is distributed on an "AS IS" BASIS,
    15   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    16   * See the License for the specific language governing permissions and
    17   * limitations under the License.
    18   */
    19
    20  import junit.framework.Assert;
    21
    22  import org.apache.commons.configuration.Configuration;
    23  import org.apache.commons.lang.exception.NestableException;
    24  import org.apache.log4j.Category;
    25  import org.apache.stratum.lifecycle.Configurable;
    26  import org.apache.stratum.lifecycle.Initializable;
    27
    28  /***
    29   * This class is used by TestComponentLoader to test some assertions about the behvior of ComponentLoader.
    30   *
    31   * @author <a href="mailto:eric NOSPAM dobbse.net">Eric Dobbs</a>
    32   * @version $Id: MockComponent.java 264191 2005-08-29 18:07:52Z henning $
    33   */
    34  public class MockComponent
    35          extends Assert
    36          implements Configurable, Initializable
    37  {
    38      /*** TODO: DOCUMENT ME! */
    39      private static Category log = Category.getInstance(MockComponent.class);
    40
    41      /*** TODO: DOCUMENT ME! */
    42      private int callsToConfigure = 0;
    43
    44      /*** TODO: DOCUMENT ME! */
    45      private int callsToInitialize = 0;
    46
    47      /*** TODO: DOCUMENT ME! */
    48      private int expectedCallsToConfigure = 1;
    49
    50      /*** TODO: DOCUMENT ME! */
    51      private int expectedCallsToInitialize = 1;
    52
    53      /*** TODO: DOCUMENT ME! */
    54      private Configuration config = null;
    55
    56      /***
    57       * Verify that the given Configuration is not null and that configure() is called only once.
    58       *
    59       * @param configuration TODO: DOCUMENT ME!
    60       *
    61       * @throws NestableException TODO: DOCUMENT ME!
    62       */
    63      public void configure(Configuration configuration)
    64              throws NestableException
    65      {
    66          log.debug("MockComponent.configure() called");
    67
    68          config = configuration;
    69
    70          assertNotNull(configuration);
    71          log.debug("good news!  configuration not null");
    72
    73          callsToConfigure++;
    74
    75          if (callsToConfigure > expectedCallsToConfigure)
    76          {
    77              log.debug("bad news!  configure() called too many times");
    78              fail("configure() called too many times");
    79          }
    80
    81          log.debug("good news!  configure() called successfully");
    82      }
    83
    84      /***
    85       * Verify that initialize() is called only once.
    86       *
    87       * @throws Exception TODO: DOCUMENT ME!
    88       */
    89      public void initialize()
    90              throws Exception
    91      {
    92          log.debug("MockComponent.initialize() called");
    93
    94          callsToInitialize++;
    95
    96          if (callsToInitialize > expectedCallsToInitialize)
    97          {
    98              log.debug("bad news!  initialize() called too many times");
    99              fail("initialize() called too many times");
    100         }
    101
    102         log.debug("good news!  initialize() called successfully");
    103     }
    104
    105     /***
    106      * TODO: DOCUMENT ME!
    107      *
    108      * @return TODO: DOCUMENT ME!
    109      */
    110     public Configuration getConfiguration()
    111     {
    112         return config;
    113     }
    114 }