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 2004/01/19 19:12:43 UTC

cvs commit: avalon/merlin/activation/impl/src/test/org/apache/avalon/activation/appliance/grant/components TestComponent.java TestService.java

mcconnell    2004/01/19 10:12:43

  Modified:    merlin/activation/impl maven.xml
               merlin/activation/impl/src/test/conf playground.xml
               merlin/activation/impl/src/test/org/apache/avalon/activation/appliance
                        AbstractTestCase.java PlaygroundTestCase.java
  Added:       merlin/activation/impl/src/test/conf secure.xml
               merlin/activation/impl/src/test/org/apache/avalon/activation/appliance/grant
                        CodeSecurityTestCase.java
               merlin/activation/impl/src/test/org/apache/avalon/activation/appliance/grant/components
                        TestComponent.java TestService.java
  Log:
  Cleanup of existing testcases and add a skeleton testcase for the privs content.
  
  Revision  Changes    Path
  1.2       +1 -0      avalon/merlin/activation/impl/maven.xml
  
  Index: maven.xml
  ===================================================================
  RCS file: /home/cvs/avalon/merlin/activation/impl/maven.xml,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- maven.xml	14 Jan 2004 16:34:55 -0000	1.1
  +++ maven.xml	19 Jan 2004 18:12:43 -0000	1.2
  @@ -9,6 +9,7 @@
       <mkdir dir="${basedir}/target/test-classes/repository/avalon-framework/jars"/>
       <ant:copy toDir="${basedir}/target/test-classes/repository/avalon-framework/jars" 
         file="${pom.getDependencyPath('avalon-framework:avalon-framework-impl')}"/>
  +    <attainGoal name="avalon:meta"/>
     </postGoal>
   
   </project>
  
  
  
  1.2       +2 -0      avalon/merlin/activation/impl/src/test/conf/playground.xml
  
  Index: playground.xml
  ===================================================================
  RCS file: /home/cvs/avalon/merlin/activation/impl/src/test/conf/playground.xml,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- playground.xml	19 Jan 2004 16:20:08 -0000	1.1
  +++ playground.xml	19 Jan 2004 18:12:43 -0000	1.2
  @@ -22,6 +22,8 @@
   
      <container name="subsidiary">
   
  +     <categories priority="WARN"/>
  +
        <component name="complex"
              class="org.apache.avalon.playground.ComplexComponent" activation="startup"/>
   
  
  
  
  1.1                  avalon/merlin/activation/impl/src/test/conf/secure.xml
  
  Index: secure.xml
  ===================================================================
  
  <!--
  Example block deployment descriptor.
  -->
  
  <container name="root">
  
     <classloader>
  
       <classpath>
         <fileset dir="."/>
         <repository>
           <resource id="avalon-framework:avalon-framework-impl" version="4.1.5"/>
         </repository>
       </classpath>
  
       <grant>
         <permission class="java.util.PropertyPermission" name="org.apache" >
           <action>read</action>
           <action>write</action>
         </permission>
         <permission class="java.lang.RuntimePermission" name="getClassLoader" />
       </grant>
  
     </classloader>
  
     <component name="test"
         class="org.apache.avalon.activation.appliance.grant.components.TestComponent"
         activation="startup"/>
  
  </container>
  
  
  
  1.8       +26 -6     avalon/merlin/activation/impl/src/test/org/apache/avalon/activation/appliance/AbstractTestCase.java
  
  Index: AbstractTestCase.java
  ===================================================================
  RCS file: /home/cvs/avalon/merlin/activation/impl/src/test/org/apache/avalon/activation/appliance/AbstractTestCase.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- AbstractTestCase.java	19 Jan 2004 16:20:09 -0000	1.7
  +++ AbstractTestCase.java	19 Jan 2004 18:12:43 -0000	1.8
  @@ -105,7 +105,7 @@
      // setup
      //-------------------------------------------------------
   
  -    public abstract String getPath();
  +    //public abstract String getPath();
   
      /**
       * The setup process covers the establishment of the base
  @@ -116,10 +116,25 @@
       *
       * @exception Exception if things don't work out
       */
  -    public void setUp() throws Exception
  +    public void setUp( String filename ) throws Exception
       {
  -        File base = new File( getTestDir(), "test-classes" );
  +        File base = new File( getTargetDirectory(), "test-classes" );
  +        File conf = new File( getBaseDirectory(), "src/test/conf" );
  +        File block = new File( conf, filename );
  +        setUp( base, block );
  +    }
   
  +   /**
  +    * The setup process covers the establishment of the base
  +    * directory (from which relative references for extension directories
  +    * and fileset base directories are resolved), a file repository (not
  +    * used in this test case at this time), and a class loader model from 
  +    * which a classpath will be established.
  +    *
  +    * @exception Exception if things don't work out
  +    */
  +    public void setUp( File base, File block ) throws Exception
  +    {
           //
           // Next couple of lines are using a convinience operation
           // on DefaultSystemContext to create the system context.  This 
  @@ -138,7 +153,7 @@
           // and establish a containment model for the unit test
           //
   
  -        ContainmentProfile profile = setUpProfile( new File( base, getPath() ) );
  +        ContainmentProfile profile = setUpProfile( block );
           m_model = m_system.getFactory().createContainmentModel( profile );
       }
   
  @@ -151,9 +166,14 @@
           return creator.createContainmentProfile( config );
       }
   
  -    protected static File getTestDir()
  +    protected static File getBaseDirectory()
  +    {
  +        return new File( System.getProperty( "basedir" ) );
  +    }
  +
  +    protected static File getTargetDirectory()
       {
  -        return new File( System.getProperty( "basedir" ), "target" );
  +        return new File( getBaseDirectory(), "target" );
       }
   
       protected Logger getLogger()
  
  
  
  1.2       +11 -4     avalon/merlin/activation/impl/src/test/org/apache/avalon/activation/appliance/PlaygroundTestCase.java
  
  Index: PlaygroundTestCase.java
  ===================================================================
  RCS file: /home/cvs/avalon/merlin/activation/impl/src/test/org/apache/avalon/activation/appliance/PlaygroundTestCase.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- PlaygroundTestCase.java	19 Jan 2004 16:20:09 -0000	1.1
  +++ PlaygroundTestCase.java	19 Jan 2004 18:12:43 -0000	1.2
  @@ -50,6 +50,8 @@
   
   package org.apache.avalon.activation.appliance;
   
  +import org.apache.avalon.util.exception.ExceptionHelper;
  +
   public class PlaygroundTestCase extends AbstractTestCase
   {
      //-------------------------------------------------------
  @@ -70,10 +72,15 @@
      // setup
      //-------------------------------------------------------
   
  -   public String getPath()
  -   {
  -      return "playground.xml";
  -   }
  +   /**
  +    * Setup the model using a source balock in the conf 
  +    * directory.
  +    * @exception Exception if things don't work out
  +    */
  +    public void setUp() throws Exception
  +    {
  +        super.setUp( "playground.xml" );
  +    }
   
      //-------------------------------------------------------
      // test
  
  
  
  1.1                  avalon/merlin/activation/impl/src/test/org/apache/avalon/activation/appliance/grant/CodeSecurityTestCase.java
  
  Index: CodeSecurityTestCase.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.avalon.activation.appliance.grant;
  
  import org.apache.avalon.activation.appliance.Appliance;
  import org.apache.avalon.activation.appliance.Block;
  import org.apache.avalon.activation.appliance.impl.DefaultBlock;
  import org.apache.avalon.activation.appliance.AbstractTestCase;
  import org.apache.avalon.util.exception.ExceptionHelper;
  
  import org.apache.avalon.activation.appliance.grant.components.TestService;
  
  public class CodeSecurityTestCase extends AbstractTestCase
  {
     //-------------------------------------------------------
     // constructor
     //-------------------------------------------------------
  
      public CodeSecurityTestCase( )
      {
          this( "secure" );
      }
  
      public CodeSecurityTestCase( String name )
      {
          super( name );
      }
  
     //-------------------------------------------------------
     // setup
     //-------------------------------------------------------
  
     /**
      * Setup the model using a source balock in the conf 
      * directory.
      * @exception Exception if things don't work out
      */
      public void setUp() throws Exception
      {
          super.setUp( "secure.xml" );
      }
  
     //-------------------------------------------------------
     // test
     //-------------------------------------------------------
  
     /**
      * Create, assembly, deploy and decommission the block 
      * defined by getPath().
      */
      public void testCodeSecurity() throws Exception
      {
          TestService test = setupTestService();
  
          try
          {
              test.doPrimary(); // test something in component
          }
          catch( Throwable e )
          {
              final String error = "CodeSecurityTest primary failure.";
              final String message = ExceptionHelper.packException( error, e, true );
              getLogger().error( message );
              throw new Exception( message );
          }
  
          try
          {
              test.doSecondary(); // test something in component
          }
          catch( Throwable e )
          {
              final String error = "CodeSecurityTest secondary failure.";
              final String message = ExceptionHelper.packException( error, e, true );
              getLogger().error( message );
              throw new Exception( message );
          }
  
      }
  
      private TestService setupTestService() throws Exception
      {
          m_model.assemble();
          Block block = new DefaultBlock( m_model );
          block.deploy();
          Appliance appliance = block.locate( "/test" );
          Object test = appliance.resolve();
          return (TestService) appliance.resolve();
      }
  
  }
  
  
  
  1.1                  avalon/merlin/activation/impl/src/test/org/apache/avalon/activation/appliance/grant/components/TestComponent.java
  
  Index: TestComponent.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2002 The Apache Software Foundation. All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, 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", "Avalon", 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 (INCLUDING, 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.avalon.activation.appliance.grant.components;
  
  import java.io.File;
  
  import org.apache.avalon.framework.logger.AbstractLogEnabled;
  import org.apache.avalon.framework.context.Contextualizable;
  import org.apache.avalon.framework.context.ContextException;
  import org.apache.avalon.framework.context.Context;
  
  /**
   * This is a component that can be tested relative a set of 
   * assigned permissions.
   *
   * @author <a href="mailto:dev@avalon.apache.org">Avalon Development Team</a>
   * @avalon.component name="test" lifestyle="singleton"
   * @avalon.service type="org.apache.avalon.activation.appliance.grant.components.TestService"
   */
  public class TestComponent extends AbstractLogEnabled 
    implements Contextualizable, TestService
  {
      //----------------------------------------------------------------------
      // state
      //----------------------------------------------------------------------
  
      private File m_home;
  
      //----------------------------------------------------------------------
      // Contextualizable
      //----------------------------------------------------------------------
  
     /**
      * @avalon.context type="java.io.File" key="urn:avalon:home"
      */
      public void contextualize( Context context ) throws ContextException
      {
          m_home = (File) context.get( "urn:avalon:home" );
      }
  
      //----------------------------------------------------------------------
      // TestService
      //----------------------------------------------------------------------
  
      /**
       * Does something trivial.
       */
      public void doPrimary()
      {
          m_home.mkdirs();
      }
  
      /**
       * Does something trivial.
       */
      public void doSecondary()
      {
          m_home.delete();
      }
  }
  
  
  
  1.1                  avalon/merlin/activation/impl/src/test/org/apache/avalon/activation/appliance/grant/components/TestService.java
  
  Index: TestService.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2002 The Apache Software Foundation. All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, 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", "Avalon", 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 (INCLUDING, 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.avalon.activation.appliance.grant.components;
  
  import java.io.File;
  
  import org.apache.avalon.framework.logger.AbstractLogEnabled;
  import org.apache.avalon.framework.context.Contextualizable;
  import org.apache.avalon.framework.context.ContextException;
  import org.apache.avalon.framework.context.Context;
  
  /**
   * This is a component that can be tested relative a set of 
   * assigned permissions.
   *
   * @author <a href="mailto:dev@avalon.apache.org">Avalon Development Team</a>
   * @avalon.component name="test" lifestyle="singleton"
   */
  public interface TestService
  {
      /**
       * Does something trivial.
       */
      public void doPrimary();
  
      /**
       * Does something trivial.
       */
      public void doSecondary();
  }
  
  
  

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