You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@avalon.apache.org by mc...@apache.org on 2003/04/10 06:38:08 UTC

cvs commit: avalon-sandbox/merlin/merlin-smp/src/examples/afs/simple/src/test/org/apache AbstractTestCase.java

mcconnell    2003/04/09 21:38:08

  Added:       merlin/merlin-smp/src/examples/afs/simple project.properties
               merlin/merlin-smp/src/examples/afs/simple/src/java/org/apache/bank/impl
                        ActionSimulator.java ActionSimulator.xinfo
               merlin/merlin-smp/src/examples/afs/simple/src/test/org/apache
                        AbstractTestCase.java
  Removed:     merlin/merlin-smp/src/examples/afs/simple build.xml
  Log:
  Updates to the simple bank examples.
  
  Revision  Changes    Path
  1.1                  avalon-sandbox/merlin/merlin-smp/src/examples/afs/simple/project.properties
  
  Index: project.properties
  ===================================================================
  
  maven.junit.fork = true
  
  
  
  1.1                  avalon-sandbox/merlin/merlin-smp/src/examples/afs/simple/src/java/org/apache/bank/impl/ActionSimulator.java
  
  Index: ActionSimulator.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2002 The Apache Software Foundation. All rights reserved.
  
   Redistribution and use in source and binary forms, with or without modifica-
   tion, are permitted provided that the following conditions are met:
  
   1. Redistributions of  source code must  retain the above copyright  notice,
      this list of conditions and the following disclaimer.
  
   2. Redistributions in binary form must reproduce the above copyright notice,
      this list of conditions and the following disclaimer in the documentation
      and/or other materials provided with the distribution.
  
   3. The end-user documentation included with the redistribution, if any, must
      include  the following  acknowledgment:  "This product includes  software
      developed  by the  Apache Software Foundation  (http://www.apache.org/)."
      Alternately, this  acknowledgment may  appear in the software itself,  if
      and wherever such third-party acknowledgments normally appear.
  
   4. The names "Jakarta", "Apache Avalon", "Avalon Framework" and
      "Apache Software Foundation"  must not be used to endorse or promote
      products derived  from this  software without  prior written
      permission. For written permission, please contact apache@apache.org.
  
   5. Products  derived from this software may not  be called "Apache", nor may
      "Apache" appear  in their name,  without prior written permission  of the
      Apache Software Foundation.
  
   THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
   INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
   FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
   APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
   INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
   DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
   OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
   ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
   (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
   THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  
   This software  consists of voluntary contributions made  by many individuals
   on  behalf of the Apache Software  Foundation. For more  information on the
   Apache Software Foundation, please see <http://www.apache.org/>.
  
  */
  
  package org.apache.bank.impl;
  
  import java.io.File;
  import java.io.InputStream;
  import java.io.FileInputStream;
  import java.io.FileOutputStream;
  import java.io.ObjectInputStream;
  import java.io.ObjectOutputStream;
  import java.io.OutputStream;
  import java.net.URL;
  
  import org.apache.avalon.framework.logger.AbstractLogEnabled;
  import org.apache.avalon.framework.service.Serviceable;
  import org.apache.avalon.framework.service.ServiceManager;
  import org.apache.avalon.framework.service.ServiceException;
  import org.apache.avalon.framework.activity.Initializable;
  import org.apache.avalon.framework.activity.Disposable;
  
  import org.apache.bank.Bank;
  import org.apache.bank.Account;
  import org.apache.bank.PolicyException;
  import org.apache.bank.NoSuchAccountException;
  
  
  public class ActionSimulator extends AbstractLogEnabled 
    implements Serviceable, Initializable, Disposable
  {
      private ServiceManager m_manager;
      private Bank m_bank;
  
      public void service( ServiceManager manager ) throws ServiceException
      {
          m_manager = manager;
          m_bank = (Bank) manager.lookup( "bank" );
      }
  
     /**
      * Initialization of the component by the container.
      * @exception if an initialization error occurs
      */
      public void initialize() throws Exception
      {
          getLogger().info( "initialize" );
          try
          {
  
              //
              // create an account
              //
  
              Account account = m_bank.createAccount( "simulation" );
              getLogger().info( "balance: " + account.getBalance() );
  
              //
              // deposit some funds
              //
  
              float deposit = new Float( 60000 ).floatValue();
              account.deposit( deposit );
              getLogger().info( "balance: " + account.getBalance() );
  
              //
              // make a partial withdrawl
              //
  
              float withdrawl = new Float( 40000 ).floatValue();
              account.withdraw( withdrawl );
              getLogger().info( "balance: " + account.getBalance() );
  
              //
              // withdrawl the balance and close the account
              //
  
              account.withdraw( account.getBalance() );
              getLogger().info( "balance: " + account.getBalance() );
              m_bank.closeAccount( account.getID() );
          }
          catch( Throwable e )
          {
              final String msg = "Bank runtime failure.";
              getLogger().error( msg, e );
          }
      }
  
     /**
      * Disposal of the bank by the container.
      */
      public void dispose()
      {
          getLogger().info( "disposal" );
          m_manager.release( m_bank );
          m_bank = null;
          m_manager = null;
      }
  
  }
  
  
  
  1.1                  avalon-sandbox/merlin/merlin-smp/src/examples/afs/simple/src/java/org/apache/bank/impl/ActionSimulator.xinfo
  
  Index: ActionSimulator.xinfo
  ===================================================================
  <?xml version="1.0"?>
  <!DOCTYPE type
        PUBLIC "-//AVALON/Type DTD Version 1.0//EN"
               "http://avalon.apache.org/dtds/meta/type_1_1.dtd" >
  <type>
    <info>
      <name>simulator</name>
      <version>1.0</version>
    </info>
    <dependencies>
      <dependency type="org.apache.bank.Bank" key="bank"/>
    </dependencies>
  </type>
  
  
  
  1.1                  avalon-sandbox/merlin/merlin-smp/src/examples/afs/simple/src/test/org/apache/AbstractTestCase.java
  
  Index: AbstractTestCase.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2002 The Apache Software Foundation. All rights reserved.
  
   Redistribution and use in source and binary forms, with or without modifica-
   tion, are permitted provided that the following conditions are met:
  
   1. Redistributions of  source code must  retain the above copyright  notice,
      this list of conditions and the following disclaimer.
  
   2. Redistributions in binary form must reproduce the above copyright notice,
      this list of conditions and the following disclaimer in the documentation
      and/or other materials provided with the distribution.
  
   3. The end-user documentation included with the redistribution, if any, must
      include  the following  acknowledgment:  "This product includes  software
      developed  by the  Apache Software Foundation  (http://www.apache.org/)."
      Alternately, this  acknowledgment may  appear in the software itself,  if
      and wherever such third-party acknowledgments normally appear.
  
   4. The names "Jakarta", "Apache Avalon", "Avalon Framework" and
      "Apache Software Foundation"  must not be used to endorse or promote
      products derived  from this  software without  prior written
      permission. For written permission, please contact apache@apache.org.
  
   5. Products  derived from this software may not  be called "Apache", nor may
      "Apache" appear  in their name,  without prior written permission  of the
      Apache Software Foundation.
  
   THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
   INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
   FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
   APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
   INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
   DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
   OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
   ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
   (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
   THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  
   This software  consists of voluntary contributions made  by many individuals
   on  behalf of the Apache Software  Foundation. For more  information on the
   Apache Software Foundation, please see <http://www.apache.org/>.
  
  */
  
  package org.apache;
  
  import java.io.File;
  import junit.framework.TestCase;
  import org.apache.avalon.assembly.locator.DefaultLocator;
  import org.apache.avalon.assembly.logging.LoggingManager;
  import org.apache.avalon.assembly.logging.TargetDescriptor;
  import org.apache.avalon.assembly.logging.LoggingDescriptor;
  import org.apache.avalon.assembly.logging.DefaultLoggingManager;
  import org.apache.avalon.assembly.locator.DefaultLocator;
  import org.apache.avalon.framework.context.Context;
  import org.apache.avalon.framework.context.ContextException;
  import org.apache.avalon.framework.context.DefaultContext;
  import org.apache.avalon.framework.logger.Logger;
  import org.apache.avalon.meta.model.Category;
  import org.apache.avalon.merlin.block.Block;
  import org.apache.avalon.merlin.kernel.impl.DefaultKernel;
  import org.apache.avalon.merlin.kernel.KernelException;
  import org.apache.avalon.merlin.kernel.Kernel;
  
  /**
   * A testcase for the @link{StandardTypeManager}.
   *
   * @author <a href="mailto:dev@avalon.apache.org">Avalon Development Team</a>
   */
  public abstract class AbstractTestCase extends TestCase implements Kernel
  {
  
      private DefaultKernel m_kernel;
  
      public AbstractTestCase( String name )
      {
          super( name );
      }
  
      protected void setUp() throws Exception
      {
          ClassLoader loader = Thread.currentThread().getContextClassLoader();
          File base = new File( System.getProperty( "user.dir" ) );
          File classes = new File( base, "target/classes" );
  
          DefaultLocator context = new DefaultLocator();
          context.put( "urn:merlin:home", base );
          context.put( "urn:merlin:system", base );
          context.put( "urn:merlin:classloader.common", loader );
          context.put( "urn:merlin:classloader.system", loader );
          context.put( "urn:merlin:debug", "WARN" );
          context.put( "urn:merlin:logging.priority", "INFO" );
          context.put( "urn:merlin:block.url", classes.toURL() );
          context.makeReadOnly();
  
          m_kernel = new DefaultKernel();
          m_kernel.contextualize( context );
          m_kernel.initialize();
      }
  
      public void tearDown() throws Exception
      {
          if( m_kernel != null )
          { 
              m_kernel.shutdown();
          }
      }
  
      //--------------------------------------------------
      // Kernel
      //--------------------------------------------------
  
     /**
      * Return the root block.
      * @return the root block
      */
      public Block getRootBlock()
      {
          if( m_kernel == null ) 
          {
              final String message = 
                "Kernel has not been initialized.";
              throw new IllegalStateException( message );
          }
          return m_kernel.getRootBlock();
      }
  
     /**
      * Initiate an orderly shutdown of the kernel.
      */
      public void shutdown()
      {
          if( m_kernel == null ) 
          {
              final String message = 
                "Kernel has not been initialized.";
              throw new IllegalStateException( message );
          }
          m_kernel.shutdown();
      }
  
  }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: cvs-unsubscribe@avalon.apache.org
For additional commands, e-mail: cvs-help@avalon.apache.org