You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@avalon.apache.org by do...@apache.org on 2002/04/01 13:47:43 UTC

cvs commit: jakarta-avalon-excalibur/extension/src/test/org/apache/avalon/excalibur/extension/test specification-1.mf specification-2.mf specification-3.mf specification-4.mf specification-5.mf specification-6.mf specification-7.mf SpecificationTestCase.java

donaldp     02/04/01 03:47:43

  Added:       extension/src/test/org/apache/avalon/excalibur/extension/test
                        specification-1.mf specification-2.mf
                        specification-3.mf specification-4.mf
                        specification-5.mf specification-6.mf
                        specification-7.mf SpecificationTestCase.java
  Log:
  Do some unit testing with specification
  
  Revision  Changes    Path
  1.1                  jakarta-avalon-excalibur/extension/src/test/org/apache/avalon/excalibur/extension/test/specification-1.mf
  
  Index: specification-1.mf
  ===================================================================
  Manifest-Version: 1.0
  
  Name: org/realityforge/dve
  Specification-Title: org.realityforge.dve
  Specification-Version: 1.0.2
  Specification-Vendor: Peter Donald
  Implementation-Title: DVE vi OS3P
  Implementation-Vendor: Peter Donald
  Implementation-Version: 1.0.2Alpha
  
  
  
  1.1                  jakarta-avalon-excalibur/extension/src/test/org/apache/avalon/excalibur/extension/test/specification-2.mf
  
  Index: specification-2.mf
  ===================================================================
  Manifest-Version: 1.0
  
  Name: org/realityforge/dve
  Specification-Title: org.realityforge.dve
  
  
  
  1.1                  jakarta-avalon-excalibur/extension/src/test/org/apache/avalon/excalibur/extension/test/specification-3.mf
  
  Index: specification-3.mf
  ===================================================================
  Manifest-Version: 1.0
  
  Name: org/realityforge/dve
  Specification-Title: org.realityforge.dve
  Specification-Version: 1.0.2
  
  
  
  1.1                  jakarta-avalon-excalibur/extension/src/test/org/apache/avalon/excalibur/extension/test/specification-4.mf
  
  Index: specification-4.mf
  ===================================================================
  Manifest-Version: 1.0
  
  Name: org/realityforge/dve
  Specification-Title: org.realityforge.dve
  Specification-Version: 1.0.2
  Specification-Vendor: Peter Donald
  
  
  
  1.1                  jakarta-avalon-excalibur/extension/src/test/org/apache/avalon/excalibur/extension/test/specification-5.mf
  
  Index: specification-5.mf
  ===================================================================
  Manifest-Version: 1.0
  
  Name: org/realityforge/dve
  Specification-Title: org.realityforge.dve
  Specification-Version: 1.0.2
  Specification-Vendor: Peter Donald
  Implementation-Title: DVE vi OS3P
  
  
  
  1.1                  jakarta-avalon-excalibur/extension/src/test/org/apache/avalon/excalibur/extension/test/specification-6.mf
  
  Index: specification-6.mf
  ===================================================================
  Manifest-Version: 1.0
  
  Name: org/realityforge/dve
  Specification-Title: org.realityforge.dve
  Specification-Version: 1.0.2
  Specification-Vendor: Peter Donald
  Implementation-Title: DVE vi OS3P
  Implementation-Vendor: Peter Donald
  
  
  
  1.1                  jakarta-avalon-excalibur/extension/src/test/org/apache/avalon/excalibur/extension/test/specification-7.mf
  
  Index: specification-7.mf
  ===================================================================
  Manifest-Version: 1.0
  
  Name: org/realityforge/dve
  Specification-Title: org.realityforge.dve
  Specification-Version: 1.0.2
  Specification-Vendor: Peter Donald
  Implementation-Title: DVE vi OS3P
  Implementation-Vendor: Peter Donald
  Implementation-Version: 1.0.2Alpha
  
  
  
  1.1                  jakarta-avalon-excalibur/extension/src/test/org/apache/avalon/excalibur/extension/test/SpecificationTestCase.java
  
  Index: SpecificationTestCase.java
  ===================================================================
  /*
   * Copyright (C) The Apache Software Foundation. All rights reserved.
   *
   * This software is published under the terms of the Apache Software License
   * version 1.1, a copy of which has been included with this distribution in
   * the LICENSE.txt file.
   */
  package org.apache.avalon.excalibur.extension.test;
  
  import java.io.InputStream;
  import java.util.jar.Manifest;
  import junit.framework.TestCase;
  import org.apache.avalon.excalibur.extension.Specification;
  
  /**
   * TestCases for Specification.
   *
   * @author <a href="mailto:peter@apache.org">Peter Donald</a>
   * @version $Revision: 1.1 $ $Date: 2002/04/01 11:47:43 $
   */
  public class SpecificationTestCase
      extends TestCase
  {
      private static final String MF1_STITLE = "org.realityforge.dve";
      private static final String MF1_SVERSION = "1.0.2";
      private static final String MF1_SVENDOR = "Peter Donald";
      private static final String MF1_ITITLE = "DVE vi OS3P";
      private static final String MF1_IVENDOR = "Peter Donald";
      private static final String MF1_IVERSION = "1.0.2Alpha";
  
      public SpecificationTestCase( String name )
      {
          super( name );
      }
  
      private Manifest getManifest( final String name )
          throws Exception
      {
          final InputStream inputStream = getClass().getResourceAsStream( name );
          return new Manifest( inputStream );
      }
  
      private Specification[] getPackageSpecifcations( final String name )
          throws Exception
      {
          final Manifest manifest = getManifest( name );
          return Specification.getPackageSpecifications( manifest );
      }
  
      private void checkMissing( final int manifestID, final String attribute )
      {
          try
          {
              getPackageSpecifcations( "specification-" + manifestID + ".mf" );
          }
          catch( final Throwable t )
          {
              return;
          }
          fail( "Missing " + attribute + " parsed" );
      }
  
      public void testSpecifications()
          throws Exception
      {
          final Specification[] specifications = getPackageSpecifcations( "specification-1.mf" );
  
          assertEquals( "Count", 1, specifications.length );
          assertEquals( "Name", MF1_STITLE, specifications[ 0 ].getSpecificationTitle() );
          assertEquals( "SpecVendor", MF1_SVENDOR, specifications[ 0 ].getSpecificationVendor() );
          assertEquals( "SpecVersion", MF1_SVERSION,
                        specifications[ 0 ].getSpecificationVersion().toString() );
          assertEquals( "ImpVendor", MF1_IVENDOR, specifications[ 0 ].getImplementationVendor() );
          assertEquals( "ImpTitle", MF1_ITITLE, specifications[ 0 ].getImplementationTitle() );
          assertEquals( "ImpVersion", MF1_IVERSION,
                        specifications[ 0 ].getImplementationVersion().toString() );
      }
  
      public void testSpaceAtEOL()
          throws Exception
      {
          //Note that manifest 7 is just manifest 1 with
          //spaces added to the end of each line
          final Specification[] specifications = getPackageSpecifcations( "specification-7.mf" );
  
          assertEquals( "Count", 1, specifications.length );
          assertEquals( "Name", MF1_STITLE, specifications[ 0 ].getSpecificationTitle() );
          assertEquals( "SpecVendor", MF1_SVENDOR, specifications[ 0 ].getSpecificationVendor() );
          assertEquals( "SpecVersion", MF1_SVERSION,
                        specifications[ 0 ].getSpecificationVersion().toString() );
          assertEquals( "ImpVendor", MF1_IVENDOR, specifications[ 0 ].getImplementationVendor() );
          assertEquals( "ImpTitle", MF1_ITITLE, specifications[ 0 ].getImplementationTitle() );
          assertEquals( "ImpVersion", MF1_IVERSION,
                        specifications[ 0 ].getImplementationVersion().toString() );
      }
  
      public void testMissingSPecVersion()
          throws Exception
      {
          checkMissing( 2, "SpecVersion" );
      }
  
      public void testMissingSpecVendor()
          throws Exception
      {
          checkMissing( 3, "SpecVendor" );
      }
  
      public void testMissingImplTitle()
          throws Exception
      {
          checkMissing( 4, "ImplTitle" );
      }
  
      public void testMissingImplVendor()
          throws Exception
      {
          checkMissing( 5, "ImplVendor" );
      }
  
      public void testMissingImplVersion()
          throws Exception
      {
          checkMissing( 6, "ImplVersion" );
      }
  
      public void testCompatible()
          throws Exception
      {
          final Specification req1 =
              new Specification( MF1_STITLE, MF1_SVERSION, MF1_SVENDOR,
                                 MF1_ITITLE, MF1_IVERSION, MF1_IVENDOR );
          final Specification req2 =
              new Specification( MF1_STITLE, MF1_SVERSION, MF1_SVENDOR,
                                 null, null, null );
          final Specification req3 =
              new Specification( MF1_STITLE, "1.0.1", MF1_SVENDOR,
                                 null, null, null );
          final Specification req4 =
              new Specification( MF1_STITLE, MF1_SVERSION, null,
                                 null, null, null );
          final Specification req5 =
              new Specification( "another title", MF1_SVERSION, MF1_SVENDOR,
                                 MF1_ITITLE, MF1_IVERSION, MF1_IVENDOR );
  
          final Specification avail1 =
              new Specification( MF1_STITLE, MF1_SVERSION, MF1_SVENDOR,
                                 MF1_ITITLE, MF1_IVERSION, MF1_IVENDOR );
          final Specification avail2 =
              new Specification( MF1_STITLE, MF1_SVERSION, MF1_SVENDOR,
                                 MF1_ITITLE, "another version", MF1_IVENDOR );
          final Specification avail3 =
              new Specification( MF1_STITLE, MF1_SVERSION, MF1_SVENDOR,
                                 MF1_ITITLE, MF1_IVERSION, "another vendor" );
  
          assertTrue( "avail1.isCompatibleWith( req1 )", avail1.isCompatibleWith( req1 ) );
          assertTrue( "avail1.isCompatibleWith( req2 )", avail1.isCompatibleWith( req2 ) );
          assertTrue( "avail1.isCompatibleWith( req3 )", avail1.isCompatibleWith( req3 ) );
          assertTrue( "avail1.isCompatibleWith( req4 )", avail1.isCompatibleWith( req4 ) );
          assertTrue( "!avail1.isCompatibleWith( req5 )", !avail1.isCompatibleWith( req5 ) );
  
          assertTrue( "!avail2.isCompatibleWith( req1 )", !avail2.isCompatibleWith( req1 ) );
          assertTrue( "avail2.isCompatibleWith( req2 )", avail2.isCompatibleWith( req2 ) );
          assertTrue( "avail2.isCompatibleWith( req3 )", avail2.isCompatibleWith( req3 ) );
          assertTrue( "avail2.isCompatibleWith( req4 )", avail2.isCompatibleWith( req4 ) );
          assertTrue( "!avail2.isCompatibleWith( req5 )", !avail2.isCompatibleWith( req5 ) );
  
          assertTrue( "!avail3.isCompatibleWith( req1 )", !avail3.isCompatibleWith( req1 ) );
          assertTrue( "avail3.isCompatibleWith( req2 )", avail3.isCompatibleWith( req2 ) );
          assertTrue( "avail3.isCompatibleWith( req3 )", avail3.isCompatibleWith( req3 ) );
          assertTrue( "avail3.isCompatibleWith( req4 )", avail3.isCompatibleWith( req4 ) );
          assertTrue( "!avail3.isCompatibleWith( req5 )", !avail3.isCompatibleWith( req5 ) );
      }
  }
  
  
  

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>