maven-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ogusa...@apache.org
Subject svn commit: r769199 [17/19] - in /maven/mercury/trunk: mercury-ant-tasks/src/main/java/org/apache/maven/mercury/ant/tasks/ mercury-ant-tasks/src/test/java/org/apache/maven/mercury/ant/tasks/ mercury-core/src/main/java/org/apache/maven/mercury/artifact/...
Date Mon, 27 Apr 2009 23:12:32 GMT
Modified: maven/mercury/trunk/mercury-it/src/test/java/org/apache/maven/mercury/repository/tests/AbstractRepositoryReaderM2Test.java
URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-it/src/test/java/org/apache/maven/mercury/repository/tests/AbstractRepositoryReaderM2Test.java?rev=769199&r1=769198&r2=769199&view=diff
==============================================================================
--- maven/mercury/trunk/mercury-it/src/test/java/org/apache/maven/mercury/repository/tests/AbstractRepositoryReaderM2Test.java (original)
+++ maven/mercury/trunk/mercury-it/src/test/java/org/apache/maven/mercury/repository/tests/AbstractRepositoryReaderM2Test.java Mon Apr 27 23:12:25 2009
@@ -35,494 +35,506 @@
 import org.apache.maven.mercury.crypto.api.StreamVerifierFactory;
 import org.apache.maven.mercury.crypto.pgp.PgpStreamVerifierFactory;
 import org.apache.maven.mercury.crypto.sha.SHA1VerifierFactory;
-import org.apache.maven.mercury.repository.api.MetadataResults;
 import org.apache.maven.mercury.repository.api.ArtifactResults;
+import org.apache.maven.mercury.repository.api.MetadataResults;
 import org.apache.maven.mercury.repository.api.Repository;
 import org.apache.maven.mercury.repository.api.RepositoryException;
 import org.apache.maven.mercury.repository.api.RepositoryReader;
 import org.apache.maven.mercury.transport.api.Server;
 
 /**
- *
- *
  * @author Oleg Gusakov
  * @version $Id$
- *
  */
 public abstract class AbstractRepositoryReaderM2Test
-extends TestCase
+    extends TestCase
 {
-  Repository repo;
-  DependencyProcessor mdProcessor;
-  RepositoryReader reader;
-  List<ArtifactMetadata> query;
-  
-  ArtifactMetadata bmd;
-  
-  private static final String publicKeyFile = "/pgp/pubring.gpg";
-  private static final String secretKeyFile = "/pgp/secring.gpg";
-  
-  boolean goodOs = false;
-  
-  Server server;
-  HashSet<StreamVerifierFactory> factories;
-  
-  
-  @Override
-  protected void setUp()
-  throws Exception
-  {
-    String os = System.getProperty("os.name");
-    
-    if( "Mac OS X".equals( os ) )
-      goodOs = true;
-    
-    File sn = new File("target/test-classes/repo/a/a/5-SNAPSHOT/a-5-SNAPSHOT.jar");
-    
-    sn.setLastModified( new Date().getTime() + 10000L );
-    
-  }
-  
+    Repository repo;
+
+    DependencyProcessor mdProcessor;
+
+    RepositoryReader reader;
+
+    List<ArtifactMetadata> query;
+
+    ArtifactMetadata bmd;
+
+    private static final String publicKeyFile = "/pgp/pubring.gpg";
+
+    private static final String secretKeyFile = "/pgp/secring.gpg";
+
+    boolean goodOs = false;
+
+    Server server;
+
+    HashSet<StreamVerifierFactory> factories;
+
+    @Override
+    protected void setUp()
+        throws Exception
+    {
+        String os = System.getProperty( "os.name" );
+
+        if ( "Mac OS X".equals( os ) )
+            goodOs = true;
+
+        File sn = new File( "target/test-classes/repo/a/a/5-SNAPSHOT/a-5-SNAPSHOT.jar" );
+
+        sn.setLastModified( new Date().getTime() + 10000L );
+
+    }
+
     @Override
     protected void tearDown()
         throws Exception
     {
-        if( query != null )
+        if ( query != null )
             query.clear();
     }
-  //------------------------------------------------------------------------------
-  public void testReadReleaseVersion()
-  throws IllegalArgumentException, RepositoryException
-  {
-    bmd = new ArtifactMetadata("a:a:[3,3]");
-    query.add( bmd );
-    
-    MetadataResults res = reader.readVersions( query );
-    
-    assertNotNull( res );
-    assertFalse( res.hasExceptions() );
-    assertTrue( res.hasResults() );
-    
-    assertEquals( 1, res.getResults().size() );
-    
-    List<ArtifactMetadata> ror = res.getResult( bmd );
-    
-    assertNotNull( ror );
-    
-    if( res.hasExceptions() )
-      System.out.println( res.getExceptions() );
-
-    assertEquals( 1, ror.size() );
-    
-//    System.out.println(qr);
-  }
-  //------------------------------------------------------------------------------
-  public void testReadReleaseRange()
-  throws IllegalArgumentException, RepositoryException
-  {
-    repo.setRepositoryQualityRange( QualityRange.RELEASES_ONLY );
-  
-    bmd = new ArtifactMetadata("a:a:[3,)");
-    query.add( bmd );
-    
-    MetadataResults res = reader.readVersions( query );
-    
-    assertNotNull( res );
-    
-    if( res.hasExceptions() )
-      System.out.println( res.getExceptions() );
-
-    assertFalse( res.hasExceptions() );
-    assertTrue( res.hasResults() );
-    
-    assertEquals( 1, res.getResults().size() );
-    
-    List<ArtifactMetadata> qr = res.getResult( bmd );
-    
-    assertNotNull( qr );
-    assertTrue( qr.size() > 1 );
-    
-    assertFalse( qr.contains( new ArtifactMetadata("a:a:5-SNAPSHOT") ) );
-    
-    System.out.println("query "+bmd+"->"+qr);
-    
-    MetadataResults depRes = reader.readDependencies( qr );
-    
-    assertNotNull( depRes );
-    assertFalse( depRes.hasExceptions() );
-    assertTrue( depRes.hasResults() );
-    
-    ArtifactMetadata a3 = new ArtifactMetadata("a:a:3");
-    
-    assertTrue( depRes.hasResults( a3 ) );
-    
-    List<ArtifactMetadata> deps = depRes.getResult( a3 );
-    assertNotNull( deps );
-    assertFalse( deps.isEmpty() );
-
-    System.out.println(deps);
-
-    assertTrue( deps.contains( new ArtifactMetadata("b:b:2") ) );
-    assertTrue( deps.contains( new ArtifactMetadata("c:c:(1,)") ) );
-    
-  }
-  //------------------------------------------------------------------------------
-  public void testReadArtifacts()
-  throws IllegalArgumentException, RepositoryException
-  {
-    bmd = new ArtifactMetadata("a:a:3");
-    query.add( bmd );
-
-    ArtifactResults ror = reader.readArtifacts( query );
-    
-    assertNotNull( ror );
-    
-    if( ror.hasExceptions() )
-      System.out.println( ror.getExceptions() );
-    
-    assertFalse( ror.hasExceptions() );
-    assertTrue( ror.hasResults() );
-    
-    List<Artifact> res = ror.getResults(bmd);
-    
-    assertNotNull( res );
-    assertEquals( 1, res.size() );
-    
-    Artifact da = res.get( 0 );
-    
-    assertNotNull( da );
-    assertNotNull( da.getFile() );
-    assertTrue( da.getFile().exists() );
-    assertNotNull( da.getPomBlob() );
-  }
-  //------------------------------------------------------------------------------
-  public void testReadSnapshot()
-  throws IllegalArgumentException, RepositoryException
-  {
-    bmd = new ArtifactMetadata("a:a:5-SNAPSHOT");
-    query.add( bmd );
-
-    ArtifactResults ror = reader.readArtifacts( query );
-    
-    assertNotNull( ror );
-    
-    if( ror.hasExceptions() )
-      System.out.println( ror.getExceptions() );
-    
-    assertFalse( ror.hasExceptions() );
-    assertTrue( ror.hasResults() );
-    
-    List<Artifact> res = ror.getResults(bmd);
-    
-    assertNotNull( res );
-    assertEquals( 1, res.size() );
-    
-    Artifact da = res.get( 0 );
-    
-    assertNotNull( da );
-    assertNotNull( da.getFile() );
-    assertTrue( da.getFile().exists() );
-    assertEquals( 159630, da.getFile().length() );
-    assertNotNull( da.getPomBlob() );
-  }
-  //------------------------------------------------------------------------------
-  public void testReadSnapshotTS()
-  throws IllegalArgumentException, RepositoryException
-  {
-    bmd = new ArtifactMetadata("a:a:5-20080807.234713-11");
-    query.add( bmd );
-
-    ArtifactResults ror = reader.readArtifacts( query );
-    
-    assertNotNull( ror );
-    
-    if( ror.hasExceptions() )
-      System.out.println( ror.getExceptions() );
-    
-    assertFalse( ror.hasExceptions() );
-    assertTrue( ror.hasResults() );
-    
-    List<Artifact> res = ror.getResults(bmd);
-    
-    assertNotNull( res );
-    assertEquals( 1, res.size() );
-    
-    Artifact da = res.get( 0 );
-    
-    assertNotNull( da );
-    assertNotNull( da.getFile() );
-    assertTrue( da.getFile().exists() );
-    assertEquals( 14800, da.getFile().length() );
-    assertNotNull( da.getPomBlob() );
-  }
-  //------------------------------------------------------------------------------
-  public void testReadVersionsLatest()
-  throws IllegalArgumentException, RepositoryException
-  {
-    bmd = new ArtifactMetadata("a:a:LATEST");
-    query.add( bmd );
-
-    MetadataResults ror = reader.readVersions( query );
-    
-    assertNotNull( ror );
-    
-    if( ror.hasExceptions() )
-    {
-      Map<ArtifactMetadata, Exception> exs = ror.getExceptions();
-      
-      for( ArtifactMetadata bmd : exs.keySet() )
-      {
-        System.out.println( "\n==========> "+bmd.toString());
-        exs.get( bmd ).printStackTrace();
-      }
-    }
-    
-    assertFalse( ror.hasExceptions() );
-    assertTrue( ror.hasResults() );
-    
-    List<ArtifactMetadata> deps = ror.getResult(bmd);
-    
-    assertNotNull( deps );
-    assertEquals( 1, deps.size() );
-    assertTrue( deps.contains( new ArtifactMetadata("a:a:5-SNAPSHOT") ) );
-    
-  }
-  //------------------------------------------------------------------------------
-  public void testReadVersionsRelease()
-  throws IllegalArgumentException, RepositoryException
-  {
-    bmd = new ArtifactMetadata("a:a:RELEASE");
-    query.add( bmd );
-
-    MetadataResults ror = reader.readVersions( query );
-    
-    assertNotNull( ror );
-    
-    if( ror.hasExceptions() )
-      System.out.println( ror.getExceptions() );
-    
-    assertFalse( ror.hasExceptions() );
-    assertTrue( ror.hasResults() );
-    
-    List<ArtifactMetadata> deps = ror.getResult(bmd);
-    
-    assertNotNull( deps );
-    assertEquals( 1, deps.size() );
-    assertTrue( deps.contains( new ArtifactMetadata("a:a:4") ) );
-    
-  }
-  //------------------------------------------------------------------------------
-  public void testReadLatest()
-  throws IllegalArgumentException, RepositoryException
-  {
-    bmd = new ArtifactMetadata("a:a:LATEST");
-    query.add( bmd );
-
-    ArtifactResults ror = reader.readArtifacts( query );
-    
-    assertNotNull( ror );
-    
-    if( ror.hasExceptions() )
-      System.out.println( ror.getExceptions() );
-  
-    assertFalse( ror.hasExceptions() );
-    assertTrue( ror.hasResults() );
-    
-    List<Artifact> res = ror.getResults(bmd);
-    
-    assertNotNull( res );
-    assertEquals( 1, res.size() );
-    
-    Artifact da = res.get( 0 );
-    
-    assertNotNull( da );
-    assertEquals( "5-SNAPSHOT", da.getVersion() );
-    
-    assertNotNull( da.getFile() );
-    assertTrue( da.getFile().exists() );
-    assertEquals( 159630, da.getFile().length() );
-    assertNotNull( da.getPomBlob() );
-    
-  }
-  //------------------------------------------------------------------------------
-  public void testReadRelease()
-  throws IllegalArgumentException, RepositoryException
-  {
-    bmd = new ArtifactMetadata("a:a:RELEASE");
-    query.add( bmd );
-
-    ArtifactResults ror = reader.readArtifacts( query );
-    
-    assertNotNull( ror );
-    
-    if( ror.hasExceptions() )
-      System.out.println( ror.getExceptions() );
-    
-    assertFalse( ror.hasExceptions() );
-    assertTrue( ror.hasResults() );
-    
-    List<Artifact> res = ror.getResults(bmd);
-    
-    assertNotNull( res );
-    assertEquals( 1, res.size() );
-    
-    Artifact da = res.get( 0 );
-    
-    assertNotNull( da );
-    assertEquals( "4", da.getVersion() );
-    
-    assertNotNull( da.getFile() );
-    assertTrue( da.getFile().exists() );
-    assertEquals( 14800, da.getFile().length() );
-    assertNotNull( da.getPomBlob() );
-  }
-  //------------------------------------------------------------------------------
-  public void testReadAndVerifyGoodArtifact()
-  throws IllegalArgumentException, RepositoryException, StreamVerifierException
-  {
-    // verifiers
-    factories = new HashSet<StreamVerifierFactory>();       
-    factories.add( 
-        new PgpStreamVerifierFactory(
-                new StreamVerifierAttributes( PgpStreamVerifierFactory.DEFAULT_EXTENSION, false, true )
-                , getClass().getResourceAsStream( publicKeyFile )
-                                    )
-                  );
-    factories.add( new SHA1VerifierFactory( true, false ) );
-    
-    if( goodOs )
-      server.setReaderStreamVerifierFactories(factories);
-
-    bmd = new ArtifactMetadata("a:a:4");
-    query.add( bmd );
-
-    ArtifactResults ror = reader.readArtifacts( query );
-    
-    assertNotNull( ror );
-    
-    if( ror.hasExceptions() )
-    {
-      System.out.println("===> unexpected Exceptions");
-      for( Exception e : ror.getExceptions().values() )
-        System.out.println( e.getClass().getName()+": "+e.getMessage() );
-      System.out.println("<=== unexpected Exceptions");
-    }
-    
-    assertFalse( ror.hasExceptions() );
-    assertTrue( ror.hasResults() );
-    
-    List<Artifact> res = ror.getResults(bmd);
-    
-    assertNotNull( res );
-    assertEquals( 1, res.size() );
-    
-    Artifact da = res.get( 0 );
-    
-    assertNotNull( da );
-    assertNotNull( da.getFile() );
-    assertTrue( da.getFile().exists() );
-    assertNotNull( da.getPomBlob() );
-  }
-  //------------------------------------------------------------------------------
-  public void testReadAndVerifyArtifactNoSig()
-  throws IllegalArgumentException, StreamVerifierException
-  {
-    // verifiers
-    factories = new HashSet<StreamVerifierFactory>();       
-    factories.add( 
-        new PgpStreamVerifierFactory(
-                new StreamVerifierAttributes( PgpStreamVerifierFactory.DEFAULT_EXTENSION, false, true )
-                , getClass().getResourceAsStream( publicKeyFile )
-                                    )
-                  );
-    
-    server.setReaderStreamVerifierFactories(factories);
-
-    bmd = new ArtifactMetadata("a:a:3");
-    query.add( bmd );
-
-    ArtifactResults ror = null;
-    try
-    {
-      ror = reader.readArtifacts( query );
-    }
-    catch( RepositoryException e )
-    {
-      System.out.println( "Expected exception: "+e.getMessage() );
-      return;
-    }
-    assertNotNull( ror );
-    if( !ror.hasExceptions() )
-      fail( "Artifact a:a:3 does not have .asc signature, PGP verifier is not lenient, but this did not cause a RepositoryException" );
-
-    System.out.println("Expected Exceptions: "+ror.getExceptions() );
-  }
-  //------------------------------------------------------------------------------
-  public void testReadAndVerifyArtifactBadSig()
-  throws IllegalArgumentException, StreamVerifierException
-  {
-    // verifiers
-    factories = new HashSet<StreamVerifierFactory>();       
-    factories.add( 
-        new PgpStreamVerifierFactory(
-                new StreamVerifierAttributes( PgpStreamVerifierFactory.DEFAULT_EXTENSION, false, true )
-                , getClass().getResourceAsStream( publicKeyFile )
-                                    )
-                  );
-    server.setReaderStreamVerifierFactories(factories);
-
-    bmd = new ArtifactMetadata("a:a:2");
-    query.add( bmd );
-
-    ArtifactResults ror = null;
-    try
-    {
-      ror = reader.readArtifacts( query );
-    }
-    catch( RepositoryException e )
-    {
-      System.out.println( "Expected exception: "+e.getMessage() );
-      return;
-    }
-    assertNotNull( ror );
-    if( !ror.hasExceptions() )
-      fail( "Artifact a:a:2 does have a bad .asc (PGP) signature, PGP verifier is not lenient, but this did not cause a RepositoryException" );
-
-    System.out.println("Expected Exceptions: "+ror.getExceptions() );
-  }
-  //------------------------------------------------------------------------------
-  public void testReadAndVerifyArtifactNoSigLenientVerifier()
-  throws IllegalArgumentException, StreamVerifierException
-  {
-    // verifiers
-    factories = new HashSet<StreamVerifierFactory>();       
-    factories.add( 
-        new PgpStreamVerifierFactory(
-                new StreamVerifierAttributes( PgpStreamVerifierFactory.DEFAULT_EXTENSION, true, true )
-                , getClass().getResourceAsStream( publicKeyFile )
-                                    )
-                  );
-    if( goodOs )
-    {
-      factories.add( new SHA1VerifierFactory(true,false) );
-      server.setReaderStreamVerifierFactories(factories);
-    }
-
-    bmd = new ArtifactMetadata("a:a:3");
-    query.add( bmd );
-
-    ArtifactResults ror = null;
-    try
-    {
-      ror = reader.readArtifacts( query );
-    }
-    catch( RepositoryException e )
-    {
-      fail( "Artifact a:a:3 does not have .asc signature, PGP verifier is lenient, but still caused a RepositoryException: "+e.getMessage() );
-    }
-    if( ror.hasExceptions() )
-      fail( "Artifact a:a:3 does not have .asc signature, PGP verifier is lenient, but still caused exceptions: "+ror.getExceptions() );
-  }
-  //------------------------------------------------------------------------------
-  //------------------------------------------------------------------------------
+
+    // ------------------------------------------------------------------------------
+    public void testReadReleaseVersion()
+        throws IllegalArgumentException, RepositoryException
+    {
+        bmd = new ArtifactMetadata( "a:a:[3,3]" );
+        query.add( bmd );
+
+        MetadataResults res = reader.readVersions( query );
+
+        assertNotNull( res );
+        assertFalse( res.hasExceptions() );
+        assertTrue( res.hasResults() );
+
+        assertEquals( 1, res.getResults().size() );
+
+        List<ArtifactMetadata> ror = res.getResult( bmd );
+
+        assertNotNull( ror );
+
+        if ( res.hasExceptions() )
+            System.out.println( res.getExceptions() );
+
+        assertEquals( 1, ror.size() );
+
+        // System.out.println(qr);
+    }
+
+    // ------------------------------------------------------------------------------
+    public void testReadReleaseRange()
+        throws IllegalArgumentException, RepositoryException
+    {
+        repo.setRepositoryQualityRange( QualityRange.RELEASES_ONLY );
+
+        bmd = new ArtifactMetadata( "a:a:[3,)" );
+        query.add( bmd );
+
+        MetadataResults res = reader.readVersions( query );
+
+        assertNotNull( res );
+
+        if ( res.hasExceptions() )
+            System.out.println( res.getExceptions() );
+
+        assertFalse( res.hasExceptions() );
+        assertTrue( res.hasResults() );
+
+        assertEquals( 1, res.getResults().size() );
+
+        List<ArtifactMetadata> qr = res.getResult( bmd );
+
+        assertNotNull( qr );
+        assertTrue( qr.size() > 1 );
+
+        assertFalse( qr.contains( new ArtifactMetadata( "a:a:5-SNAPSHOT" ) ) );
+
+        System.out.println( "query " + bmd + "->" + qr );
+
+        MetadataResults depRes = reader.readDependencies( qr );
+
+        assertNotNull( depRes );
+        assertFalse( depRes.hasExceptions() );
+        assertTrue( depRes.hasResults() );
+
+        ArtifactMetadata a3 = new ArtifactMetadata( "a:a:3" );
+
+        assertTrue( depRes.hasResults( a3 ) );
+
+        List<ArtifactMetadata> deps = depRes.getResult( a3 );
+        assertNotNull( deps );
+        assertFalse( deps.isEmpty() );
+
+        System.out.println( deps );
+
+        assertTrue( deps.contains( new ArtifactMetadata( "b:b:2" ) ) );
+        assertTrue( deps.contains( new ArtifactMetadata( "c:c:(1,)" ) ) );
+
+    }
+
+    // ------------------------------------------------------------------------------
+    public void testReadArtifacts()
+        throws IllegalArgumentException, RepositoryException
+    {
+        bmd = new ArtifactMetadata( "a:a:3" );
+        query.add( bmd );
+
+        ArtifactResults ror = reader.readArtifacts( query );
+
+        assertNotNull( ror );
+
+        if ( ror.hasExceptions() )
+            System.out.println( ror.getExceptions() );
+
+        assertFalse( ror.hasExceptions() );
+        assertTrue( ror.hasResults() );
+
+        List<Artifact> res = ror.getResults( bmd );
+
+        assertNotNull( res );
+        assertEquals( 1, res.size() );
+
+        Artifact da = res.get( 0 );
+
+        assertNotNull( da );
+        assertNotNull( da.getFile() );
+        assertTrue( da.getFile().exists() );
+        assertNotNull( da.getPomBlob() );
+    }
+
+    // ------------------------------------------------------------------------------
+    public void testReadSnapshot()
+        throws IllegalArgumentException, RepositoryException
+    {
+        bmd = new ArtifactMetadata( "a:a:5-SNAPSHOT" );
+        query.add( bmd );
+
+        ArtifactResults ror = reader.readArtifacts( query );
+
+        assertNotNull( ror );
+
+        if ( ror.hasExceptions() )
+            System.out.println( ror.getExceptions() );
+
+        assertFalse( ror.hasExceptions() );
+        assertTrue( ror.hasResults() );
+
+        List<Artifact> res = ror.getResults( bmd );
+
+        assertNotNull( res );
+        assertEquals( 1, res.size() );
+
+        Artifact da = res.get( 0 );
+
+        assertNotNull( da );
+        assertNotNull( da.getFile() );
+        assertTrue( da.getFile().exists() );
+        assertEquals( 159630, da.getFile().length() );
+        assertNotNull( da.getPomBlob() );
+    }
+
+    // ------------------------------------------------------------------------------
+    public void testReadSnapshotTS()
+        throws IllegalArgumentException, RepositoryException
+    {
+        bmd = new ArtifactMetadata( "a:a:5-20080807.234713-11" );
+        query.add( bmd );
+
+        ArtifactResults ror = reader.readArtifacts( query );
+
+        assertNotNull( ror );
+
+        if ( ror.hasExceptions() )
+            System.out.println( ror.getExceptions() );
+
+        assertFalse( ror.hasExceptions() );
+        assertTrue( ror.hasResults() );
+
+        List<Artifact> res = ror.getResults( bmd );
+
+        assertNotNull( res );
+        assertEquals( 1, res.size() );
+
+        Artifact da = res.get( 0 );
+
+        assertNotNull( da );
+        assertNotNull( da.getFile() );
+        assertTrue( da.getFile().exists() );
+        assertEquals( 14800, da.getFile().length() );
+        assertNotNull( da.getPomBlob() );
+    }
+
+    // ------------------------------------------------------------------------------
+    public void testReadVersionsLatest()
+        throws IllegalArgumentException, RepositoryException
+    {
+        bmd = new ArtifactMetadata( "a:a:LATEST" );
+        query.add( bmd );
+
+        MetadataResults ror = reader.readVersions( query );
+
+        assertNotNull( ror );
+
+        if ( ror.hasExceptions() )
+        {
+            Map<ArtifactMetadata, Exception> exs = ror.getExceptions();
+
+            for ( ArtifactMetadata bmd : exs.keySet() )
+            {
+                System.out.println( "\n==========> " + bmd.toString() );
+                exs.get( bmd ).printStackTrace();
+            }
+        }
+
+        assertFalse( ror.hasExceptions() );
+        assertTrue( ror.hasResults() );
+
+        List<ArtifactMetadata> deps = ror.getResult( bmd );
+
+        assertNotNull( deps );
+        assertEquals( 1, deps.size() );
+        assertTrue( deps.contains( new ArtifactMetadata( "a:a:5-SNAPSHOT" ) ) );
+
+    }
+
+    // ------------------------------------------------------------------------------
+    public void testReadVersionsRelease()
+        throws IllegalArgumentException, RepositoryException
+    {
+        bmd = new ArtifactMetadata( "a:a:RELEASE" );
+        query.add( bmd );
+
+        MetadataResults ror = reader.readVersions( query );
+
+        assertNotNull( ror );
+
+        if ( ror.hasExceptions() )
+            System.out.println( ror.getExceptions() );
+
+        assertFalse( ror.hasExceptions() );
+        assertTrue( ror.hasResults() );
+
+        List<ArtifactMetadata> deps = ror.getResult( bmd );
+
+        assertNotNull( deps );
+        assertEquals( 1, deps.size() );
+        assertTrue( deps.contains( new ArtifactMetadata( "a:a:4" ) ) );
+
+    }
+
+    // ------------------------------------------------------------------------------
+    public void testReadLatest()
+        throws IllegalArgumentException, RepositoryException
+    {
+        bmd = new ArtifactMetadata( "a:a:LATEST" );
+        query.add( bmd );
+
+        ArtifactResults ror = reader.readArtifacts( query );
+
+        assertNotNull( ror );
+
+        if ( ror.hasExceptions() )
+            System.out.println( ror.getExceptions() );
+
+        assertFalse( ror.hasExceptions() );
+        assertTrue( ror.hasResults() );
+
+        List<Artifact> res = ror.getResults( bmd );
+
+        assertNotNull( res );
+        assertEquals( 1, res.size() );
+
+        Artifact da = res.get( 0 );
+
+        assertNotNull( da );
+        assertEquals( "5-SNAPSHOT", da.getVersion() );
+
+        assertNotNull( da.getFile() );
+        assertTrue( da.getFile().exists() );
+        assertEquals( 159630, da.getFile().length() );
+        assertNotNull( da.getPomBlob() );
+
+    }
+
+    // ------------------------------------------------------------------------------
+    public void testReadRelease()
+        throws IllegalArgumentException, RepositoryException
+    {
+        bmd = new ArtifactMetadata( "a:a:RELEASE" );
+        query.add( bmd );
+
+        ArtifactResults ror = reader.readArtifacts( query );
+
+        assertNotNull( ror );
+
+        if ( ror.hasExceptions() )
+            System.out.println( ror.getExceptions() );
+
+        assertFalse( ror.hasExceptions() );
+        assertTrue( ror.hasResults() );
+
+        List<Artifact> res = ror.getResults( bmd );
+
+        assertNotNull( res );
+        assertEquals( 1, res.size() );
+
+        Artifact da = res.get( 0 );
+
+        assertNotNull( da );
+        assertEquals( "4", da.getVersion() );
+
+        assertNotNull( da.getFile() );
+        assertTrue( da.getFile().exists() );
+        assertEquals( 14800, da.getFile().length() );
+        assertNotNull( da.getPomBlob() );
+    }
+
+    // ------------------------------------------------------------------------------
+    public void testReadAndVerifyGoodArtifact()
+        throws IllegalArgumentException, RepositoryException, StreamVerifierException
+    {
+        // verifiers
+        factories = new HashSet<StreamVerifierFactory>();
+        factories.add( new PgpStreamVerifierFactory(
+                                                     new StreamVerifierAttributes(
+                                                                                   PgpStreamVerifierFactory.DEFAULT_EXTENSION,
+                                                                                   false, true ),
+                                                     getClass().getResourceAsStream( publicKeyFile ) ) );
+        factories.add( new SHA1VerifierFactory( true, false ) );
+
+        if ( goodOs )
+            server.setReaderStreamVerifierFactories( factories );
+
+        bmd = new ArtifactMetadata( "a:a:4" );
+        query.add( bmd );
+
+        ArtifactResults ror = reader.readArtifacts( query );
+
+        assertNotNull( ror );
+
+        if ( ror.hasExceptions() )
+        {
+            System.out.println( "===> unexpected Exceptions" );
+            for ( Exception e : ror.getExceptions().values() )
+                System.out.println( e.getClass().getName() + ": " + e.getMessage() );
+            System.out.println( "<=== unexpected Exceptions" );
+        }
+
+        assertFalse( ror.hasExceptions() );
+        assertTrue( ror.hasResults() );
+
+        List<Artifact> res = ror.getResults( bmd );
+
+        assertNotNull( res );
+        assertEquals( 1, res.size() );
+
+        Artifact da = res.get( 0 );
+
+        assertNotNull( da );
+        assertNotNull( da.getFile() );
+        assertTrue( da.getFile().exists() );
+        assertNotNull( da.getPomBlob() );
+    }
+
+    // ------------------------------------------------------------------------------
+    public void testReadAndVerifyArtifactNoSig()
+        throws IllegalArgumentException, StreamVerifierException
+    {
+        // verifiers
+        factories = new HashSet<StreamVerifierFactory>();
+        factories.add( new PgpStreamVerifierFactory(
+                                                     new StreamVerifierAttributes(
+                                                                                   PgpStreamVerifierFactory.DEFAULT_EXTENSION,
+                                                                                   false, true ),
+                                                     getClass().getResourceAsStream( publicKeyFile ) ) );
+
+        server.setReaderStreamVerifierFactories( factories );
+
+        bmd = new ArtifactMetadata( "a:a:3" );
+        query.add( bmd );
+
+        ArtifactResults ror = null;
+        try
+        {
+            ror = reader.readArtifacts( query );
+        }
+        catch ( RepositoryException e )
+        {
+            System.out.println( "Expected exception: " + e.getMessage() );
+            return;
+        }
+        assertNotNull( ror );
+        if ( !ror.hasExceptions() )
+            fail( "Artifact a:a:3 does not have .asc signature, PGP verifier is not lenient, but this did not cause a RepositoryException" );
+
+        System.out.println( "Expected Exceptions: " + ror.getExceptions() );
+    }
+
+    // ------------------------------------------------------------------------------
+    public void testReadAndVerifyArtifactBadSig()
+        throws IllegalArgumentException, StreamVerifierException
+    {
+        // verifiers
+        factories = new HashSet<StreamVerifierFactory>();
+        factories.add( new PgpStreamVerifierFactory(
+                                                     new StreamVerifierAttributes(
+                                                                                   PgpStreamVerifierFactory.DEFAULT_EXTENSION,
+                                                                                   false, true ),
+                                                     getClass().getResourceAsStream( publicKeyFile ) ) );
+        server.setReaderStreamVerifierFactories( factories );
+
+        bmd = new ArtifactMetadata( "a:a:2" );
+        query.add( bmd );
+
+        ArtifactResults ror = null;
+        try
+        {
+            ror = reader.readArtifacts( query );
+        }
+        catch ( RepositoryException e )
+        {
+            System.out.println( "Expected exception: " + e.getMessage() );
+            return;
+        }
+        assertNotNull( ror );
+        if ( !ror.hasExceptions() )
+            fail( "Artifact a:a:2 does have a bad .asc (PGP) signature, PGP verifier is not lenient, but this did not cause a RepositoryException" );
+
+        System.out.println( "Expected Exceptions: " + ror.getExceptions() );
+    }
+
+    // ------------------------------------------------------------------------------
+    public void testReadAndVerifyArtifactNoSigLenientVerifier()
+        throws IllegalArgumentException, StreamVerifierException
+    {
+        // verifiers
+        factories = new HashSet<StreamVerifierFactory>();
+        factories.add( new PgpStreamVerifierFactory(
+                                                     new StreamVerifierAttributes(
+                                                                                   PgpStreamVerifierFactory.DEFAULT_EXTENSION,
+                                                                                   true, true ),
+                                                     getClass().getResourceAsStream( publicKeyFile ) ) );
+        if ( goodOs )
+        {
+            factories.add( new SHA1VerifierFactory( true, false ) );
+            server.setReaderStreamVerifierFactories( factories );
+        }
+
+        bmd = new ArtifactMetadata( "a:a:3" );
+        query.add( bmd );
+
+        ArtifactResults ror = null;
+        try
+        {
+            ror = reader.readArtifacts( query );
+        }
+        catch ( RepositoryException e )
+        {
+            fail( "Artifact a:a:3 does not have .asc signature, PGP verifier is lenient, but still caused a RepositoryException: "
+                + e.getMessage() );
+        }
+        if ( ror.hasExceptions() )
+            fail( "Artifact a:a:3 does not have .asc signature, PGP verifier is lenient, but still caused exceptions: "
+                + ror.getExceptions() );
+    }
+    // ------------------------------------------------------------------------------
+    // ------------------------------------------------------------------------------
 }

Modified: maven/mercury/trunk/mercury-it/src/test/java/org/apache/maven/mercury/repository/tests/AbstractRepositoryWriterM2Test.java
URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-it/src/test/java/org/apache/maven/mercury/repository/tests/AbstractRepositoryWriterM2Test.java?rev=769199&r1=769198&r2=769199&view=diff
==============================================================================
--- maven/mercury/trunk/mercury-it/src/test/java/org/apache/maven/mercury/repository/tests/AbstractRepositoryWriterM2Test.java (original)
+++ maven/mercury/trunk/mercury-it/src/test/java/org/apache/maven/mercury/repository/tests/AbstractRepositoryWriterM2Test.java Mon Apr 27 23:12:25 2009
@@ -43,405 +43,456 @@
 import org.codehaus.plexus.PlexusTestCase;
 
 /**
- *
- *
  * @author Oleg Gusakov
  * @version $Id$
- *
  */
 public abstract class AbstractRepositoryWriterM2Test
-extends PlexusTestCase
+    extends PlexusTestCase
 {
-  Repository repo;
-  
-  File targetDirectory; 
-  
-  DependencyProcessor mdProcessor;
-  
-  RepositoryReader reader;
-  RepositoryWriter writer;
-
-  List<ArtifactMetadata> query;
-  
-  ArtifactMetadata bmd;
-  
-  String pomBlob;
-  
-  protected static final String keyId   = "0EDB5D91141BC4F2";
-
-  protected static final String secretKeyFile = "/pgp/secring.gpg";
-  protected static final String publicKeyFile = "/pgp/pubring.gpg";
-  protected static final String secretKeyPass = "testKey82";
-  
-  PgpStreamVerifierFactory pgpF;
-  SHA1VerifierFactory      sha1F;
-  HashSet<StreamVerifierFactory> vFacPgp;
-  HashSet<StreamVerifierFactory> vFacSha1;
-  
-  Server server;
-  HashSet<StreamVerifierFactory> factories;
-  
-  File f;
-  
-  File artifactBinary;
-  long binarySize = -1L;
-
-  File artifactPom;
-  long pomSize = -1L;
-  byte [] pomBytes;
-
-  static PlexusContainer plexus;
-  
-  /** current test works with snapshots 
-   * @throws Exception */
-  abstract void setReleases() throws Exception;
-  /** current test works with releases */
-  abstract void setSnapshots() throws Exception;
-  
-  static final boolean differentEOL = File.pathSeparatorChar == ';';
-  
-  
-  @Override
-  protected void setUp()
-  throws Exception
-  {
-    super.setUp();
-
-    if( plexus == null )
-      plexus = getContainer();
-
-    pgpF = new PgpStreamVerifierFactory(
-        new StreamVerifierAttributes( PgpStreamVerifierFactory.DEFAULT_EXTENSION, false, true )
-        , getClass().getResourceAsStream( publicKeyFile )
-                            );
-    sha1F = new SHA1VerifierFactory( false, false );
+    Repository repo;
 
-    vFacPgp  = new HashSet<StreamVerifierFactory>(1);
-    vFacSha1 = new HashSet<StreamVerifierFactory>(1);
+    File targetDirectory;
 
-//    if( ! differentEOL )
-//    {
+    DependencyProcessor mdProcessor;
+
+    RepositoryReader reader;
+
+    RepositoryWriter writer;
+
+    List<ArtifactMetadata> query;
+
+    ArtifactMetadata bmd;
+
+    String pomBlob;
+
+    protected static final String keyId = "0EDB5D91141BC4F2";
+
+    protected static final String secretKeyFile = "/pgp/secring.gpg";
+
+    protected static final String publicKeyFile = "/pgp/pubring.gpg";
+
+    protected static final String secretKeyPass = "testKey82";
+
+    PgpStreamVerifierFactory pgpF;
+
+    SHA1VerifierFactory sha1F;
+
+    HashSet<StreamVerifierFactory> vFacPgp;
+
+    HashSet<StreamVerifierFactory> vFacSha1;
+
+    Server server;
+
+    HashSet<StreamVerifierFactory> factories;
+
+    File f;
+
+    File artifactBinary;
+
+    long binarySize = -1L;
+
+    File artifactPom;
+
+    long pomSize = -1L;
+
+    byte[] pomBytes;
+
+    static PlexusContainer plexus;
+
+    /**
+     * current test works with snapshots
+     * 
+     * @throws Exception
+     */
+    abstract void setReleases()
+        throws Exception;
+
+    /** current test works with releases */
+    abstract void setSnapshots()
+        throws Exception;
+
+    static final boolean differentEOL = File.pathSeparatorChar == ';';
+
+    @Override
+    protected void setUp()
+        throws Exception
+    {
+        super.setUp();
+
+        if ( plexus == null )
+            plexus = getContainer();
+
+        pgpF =
+            new PgpStreamVerifierFactory( new StreamVerifierAttributes( PgpStreamVerifierFactory.DEFAULT_EXTENSION,
+                                                                        false, true ),
+                                          getClass().getResourceAsStream( publicKeyFile ) );
+        sha1F = new SHA1VerifierFactory( false, false );
+
+        vFacPgp = new HashSet<StreamVerifierFactory>( 1 );
+        vFacSha1 = new HashSet<StreamVerifierFactory>( 1 );
+
+        // if( ! differentEOL )
+        // {
         vFacPgp.add( pgpF );
         vFacSha1.add( sha1F );
-//    }
+        // }
 
-    artifactBinary = File.createTempFile( "test-repo-writer", "bin" );
-    artifactBinary.deleteOnExit();
-    FileUtil.writeRawData( getClass().getResourceAsStream( "/maven-core-2.0.9.jar" ), artifactBinary );
-    binarySize = artifactBinary.length();
-
-    System.out.println( "Binary size is "+binarySize+" bytes" );
-
-    artifactPom = File.createTempFile( "test-repo-writer", "pom" );
-    artifactPom.deleteOnExit();
-    FileUtil.writeRawData( getClass().getResourceAsStream( "/maven-core-2.0.9.pom" ), artifactPom );
-    pomSize = artifactPom.length();
-    pomBytes = FileUtil.readRawData( artifactPom );
-  }
-  
-  @Override
-  protected void tearDown()
-  throws Exception
-  {
-    super.tearDown();
-  }
-
-  public void testWriteArtifact()
-  throws Exception
-  {
-    setReleases();
-    
-    File af = new File( targetDirectory, "/org/apache/maven/maven-core/2.0.9/maven-core-2.0.9.jar");
-
-    assertFalse( af.exists() );
-    assertFalse( new File( targetDirectory, "/org/apache/maven/maven-core/2.0.9/maven-core-2.0.9.jar.asc").exists() );
-    assertFalse( new File( targetDirectory, "/org/apache/maven/maven-core/2.0.9/maven-core-2.0.9.jar.sha1").exists() );
-    
-    File ap = new File( targetDirectory, "/org/apache/maven/maven-core/2.0.9/maven-core-2.0.9.pom");
-    assertFalse( ap.exists() );
-    assertFalse( new File( targetDirectory, "/org/apache/maven/maven-core/2.0.9/maven-core-2.0.9.pom.asc").exists() );
-    assertFalse( new File( targetDirectory, "/org/apache/maven/maven-core/2.0.9/maven-core-2.0.9.pom.sha1").exists() );
-    
-    assertFalse( new File( targetDirectory, "/org/apache/maven/maven-core/"+repo.getMetadataName()).exists() );
-    assertFalse( new File( targetDirectory, "/org/apache/maven/maven-core/"+repo.getMetadataName()+".asc").exists() );
-    assertFalse( new File( targetDirectory, "/org/apache/maven/maven-core/"+repo.getMetadataName()+".sha1").exists() );
-
-    assertFalse( new File( targetDirectory, "/org/apache/maven/maven-core/2.0.9/"+repo.getMetadataName()).exists() );
-    assertFalse( new File( targetDirectory, "/org/apache/maven/maven-core/2.0.9/"+repo.getMetadataName()+".asc").exists() );
-    assertFalse( new File( targetDirectory, "/org/apache/maven/maven-core/2.0.9/"+repo.getMetadataName()+".sha1").exists() );
-
-    Set<Artifact> artifacts = new HashSet<Artifact>(3);
-    DefaultArtifact da = new DefaultArtifact( new ArtifactMetadata("org.apache.maven:maven-core:2.0.9") );
-    
-    da.setPomBlob( pomBytes );
-    da.setFile( artifactBinary );
-    artifacts.add( da );
-    
-    writer.writeArtifacts( artifacts );
-    Thread.sleep( 2000L );
-    
-    f = new File( targetDirectory, "/org/apache/maven/maven-core/"+repo.getMetadataName());
-    assertTrue( f.exists() );
-    
-//  [MERCURY-83] - should not verify repo metadata, it's repository's business    
-//    assertTrue( new File( targetDirectory, "/org/apache/maven/maven-core/"+repo.getMetadataName()+".asc").exists() );
-//    FileUtil.verify( f, vFacPgp, false, true );
-//    assertTrue( new File( targetDirectory, "/org/apache/maven/maven-core/"+repo.getMetadataName()+".sha1").exists() );
-//    FileUtil.verify( f, vFacSha1, false, true );
-
-    f = new File( targetDirectory, "/org/apache/maven/maven-core/2.0.9/"+repo.getMetadataName());
-    assertTrue( f.exists() );
-//    [MERCURY-83] - should not verify repo metadata, it's repository's business    
-//    assertTrue( new File( targetDirectory, "/org/apache/maven/maven-core/2.0.9/"+repo.getMetadataName()+".asc").exists() );
-//    FileUtil.verify( f, vFacPgp, false, true );
-//    assertTrue( new File( targetDirectory, "/org/apache/maven/maven-core/2.0.9/"+repo.getMetadataName()+".sha1").exists() );
-//    FileUtil.verify( f, vFacSha1, false, true );
-    
-    assertTrue( af.exists() );
-    assertEquals( binarySize, af.length() );
-    assertTrue( new File( targetDirectory, "/org/apache/maven/maven-core/2.0.9/maven-core-2.0.9.jar.asc").exists() );
-    FileUtil.verify( af, vFacPgp, false, true );
-    assertTrue( new File( targetDirectory, "/org/apache/maven/maven-core/2.0.9/maven-core-2.0.9.jar.sha1").exists() );
-    FileUtil.verify( af, vFacSha1, false, true );
-    
-    assertTrue( ap.exists() );
-    assertEquals( pomSize, ap.length() );  
-    assertTrue( new File( targetDirectory, "/org/apache/maven/maven-core/2.0.9/maven-core-2.0.9.pom.asc").exists() );
-    FileUtil.verify( ap, vFacPgp, false, true );
-    assertTrue( new File( targetDirectory, "/org/apache/maven/maven-core/2.0.9/maven-core-2.0.9.pom.sha1").exists() );
-    FileUtil.verify( ap, vFacSha1, false, true );
-  }
-  
-  public void testWriteSnapshotAsTS()
-  throws Exception
-  {
-    setSnapshots();
-    
-    Set<Artifact> artifacts = new HashSet<Artifact>(3);
-    DefaultArtifact da = new DefaultArtifact( new ArtifactMetadata("org.apache.maven:maven-core:2.0.9-20080805.215925-8") );
-    da.setPomBlob( pomBytes );
-    da.setFile( artifactBinary );
-    artifacts.add( da );
-    
-    writer.writeArtifacts( artifacts );
-    
-    File af = new File( targetDirectory, "/org/apache/maven/maven-core/2.0.9-SNAPSHOT/maven-core-2.0.9-20080805.215925-8.jar");
-    assertTrue( af.exists() );
-    assertEquals( binarySize, af.length() );
-    
-    File ap = new File( targetDirectory, "/org/apache/maven/maven-core/2.0.9-SNAPSHOT/maven-core-2.0.9-20080805.215925-8.pom");
-    assertTrue( ap.exists() );
-    assertEquals( pomSize, ap.length() );  
-  }
-  
-  public void testWriteSnapshot()
-  throws Exception
-  {
-    setSnapshots();
-    
-    Set<Artifact> set = new HashSet<Artifact>(3);
-    DefaultArtifact da = new DefaultArtifact( new ArtifactMetadata("org.apache.maven:maven-core:2.0.9-SNAPSHOT") );
-    da.setPomBlob( pomBytes );
-    da.setFile( artifactBinary );
-    set.add( da );
-    
-    writer.writeArtifacts( set );
-    
-    File af = new File( targetDirectory, "/org/apache/maven/maven-core/2.0.9-SNAPSHOT/maven-core-2.0.9-SNAPSHOT.jar");
-    assertTrue( af.exists() );
-    assertEquals( binarySize, af.length() );
-    
-    File ap = new File( targetDirectory, "/org/apache/maven/maven-core/2.0.9-SNAPSHOT/maven-core-2.0.9-SNAPSHOT.pom");
-    assertTrue( ap.exists() );
-    assertEquals( pomSize, ap.length() );  
-  }
-  
-  public void testWriteClassifier()
-  throws Exception
-  {
-    setSnapshots();
-    
-    Set<Artifact> set = new HashSet<Artifact>(3);
-    DefaultArtifact da = new DefaultArtifact( new ArtifactMetadata("org.apache.maven:maven-core:2.0.9:all") );
-    da.setFile( artifactBinary );
-    set.add( da );
-    
-    writer.writeArtifacts( set );
-    
-    File af = new File( targetDirectory, "/org/apache/maven/maven-core/2.0.9/maven-core-2.0.9-all.jar");
-    assertTrue( af.exists() );
-    assertEquals( binarySize, af.length() );
-  }
-  
-  public void testWriteContentionSingleArtifact()
-  throws Exception
-  {
-    setSnapshots();
-    
-    Set<Artifact> set = new HashSet<Artifact>(40);
+        artifactBinary = File.createTempFile( "test-repo-writer", "bin" );
+        artifactBinary.deleteOnExit();
+        FileUtil.writeRawData( getClass().getResourceAsStream( "/maven-core-2.0.9.jar" ), artifactBinary );
+        binarySize = artifactBinary.length();
+
+        System.out.println( "Binary size is " + binarySize + " bytes" );
+
+        artifactPom = File.createTempFile( "test-repo-writer", "pom" );
+        artifactPom.deleteOnExit();
+        FileUtil.writeRawData( getClass().getResourceAsStream( "/maven-core-2.0.9.pom" ), artifactPom );
+        pomSize = artifactPom.length();
+        pomBytes = FileUtil.readRawData( artifactPom );
+    }
 
-    // prep. artifacts
-    for( int i=0; i<20; i++ )
+    @Override
+    protected void tearDown()
+        throws Exception
     {
-      String si = ""+i;
-      
-      DefaultArtifact da = new DefaultArtifact( new ArtifactMetadata("org.apache.maven:maven-core:2.0.9-20080805.215925-"+si) );
-      da.setPomBlob( pomBytes );
-      File ab = File.createTempFile( "test-core-", "-bin" );
-      FileUtil.writeRawData( getClass().getResourceAsStream( "/maven-core-2.0.9.jar" ), ab );
-      da.setFile( ab );
-      set.add( da );
+        super.tearDown();
     }
-    
-    assertEquals( 20, set.size() );
-    
-    long start = System.currentTimeMillis();
-    // write 'em
-    writer.writeArtifacts( set );
-    
-    System.out.println("Took "+(System.currentTimeMillis()-start)+" millis to write "+set.size()+" artifacts");
-    System.out.flush();
-    
-    // check if the showed up in the repo
-    for( int i=0; i<20; i++ )
+
+    public void testWriteArtifact()
+        throws Exception
     {
-      String si = ""+i;
+        setReleases();
 
-      String fn = targetDirectory.getAbsolutePath()+"/org/apache/maven/maven-core/2.0.9-SNAPSHOT/maven-core-2.0.9-20080805.215925-"+si+".jar";
-      File af = new File( fn );
-      assertTrue( fn+" does not exist", af.exists() );
-      assertEquals( binarySize, af.length() );
-      
-      // is pom there also?
-      fn = targetDirectory.getAbsolutePath()+"/org/apache/maven/maven-core/2.0.9-SNAPSHOT/maven-core-2.0.9-20080805.215925-"+si+".pom";
-      File ap = new File( fn );
-      assertTrue( fn+" does not exist", ap.exists() );
-      assertEquals( pomSize, ap.length() );
+        File af = new File( targetDirectory, "/org/apache/maven/maven-core/2.0.9/maven-core-2.0.9.jar" );
+
+        assertFalse( af.exists() );
+        assertFalse( new File( targetDirectory, "/org/apache/maven/maven-core/2.0.9/maven-core-2.0.9.jar.asc" ).exists() );
+        assertFalse( new File( targetDirectory, "/org/apache/maven/maven-core/2.0.9/maven-core-2.0.9.jar.sha1" ).exists() );
+
+        File ap = new File( targetDirectory, "/org/apache/maven/maven-core/2.0.9/maven-core-2.0.9.pom" );
+        assertFalse( ap.exists() );
+        assertFalse( new File( targetDirectory, "/org/apache/maven/maven-core/2.0.9/maven-core-2.0.9.pom.asc" ).exists() );
+        assertFalse( new File( targetDirectory, "/org/apache/maven/maven-core/2.0.9/maven-core-2.0.9.pom.sha1" ).exists() );
+
+        assertFalse( new File( targetDirectory, "/org/apache/maven/maven-core/" + repo.getMetadataName() ).exists() );
+        assertFalse( new File( targetDirectory, "/org/apache/maven/maven-core/" + repo.getMetadataName() + ".asc" ).exists() );
+        assertFalse( new File( targetDirectory, "/org/apache/maven/maven-core/" + repo.getMetadataName() + ".sha1" ).exists() );
+
+        assertFalse( new File( targetDirectory, "/org/apache/maven/maven-core/2.0.9/" + repo.getMetadataName() ).exists() );
+        assertFalse( new File( targetDirectory, "/org/apache/maven/maven-core/2.0.9/" + repo.getMetadataName() + ".asc" ).exists() );
+        assertFalse( new File( targetDirectory, "/org/apache/maven/maven-core/2.0.9/" + repo.getMetadataName()
+            + ".sha1" ).exists() );
+
+        Set<Artifact> artifacts = new HashSet<Artifact>( 3 );
+        DefaultArtifact da = new DefaultArtifact( new ArtifactMetadata( "org.apache.maven:maven-core:2.0.9" ) );
+
+        da.setPomBlob( pomBytes );
+        da.setFile( artifactBinary );
+        artifacts.add( da );
+
+        writer.writeArtifacts( artifacts );
+        Thread.sleep( 2000L );
+
+        f = new File( targetDirectory, "/org/apache/maven/maven-core/" + repo.getMetadataName() );
+        assertTrue( f.exists() );
+
+        // [MERCURY-83] - should not verify repo metadata, it's repository's business
+        // assertTrue( new File( targetDirectory,
+        // "/org/apache/maven/maven-core/"+repo.getMetadataName()+".asc").exists() );
+        // FileUtil.verify( f, vFacPgp, false, true );
+        // assertTrue( new File( targetDirectory,
+        // "/org/apache/maven/maven-core/"+repo.getMetadataName()+".sha1").exists() );
+        // FileUtil.verify( f, vFacSha1, false, true );
+
+        f = new File( targetDirectory, "/org/apache/maven/maven-core/2.0.9/" + repo.getMetadataName() );
+        assertTrue( f.exists() );
+        // [MERCURY-83] - should not verify repo metadata, it's repository's business
+        // assertTrue( new File( targetDirectory,
+        // "/org/apache/maven/maven-core/2.0.9/"+repo.getMetadataName()+".asc").exists() );
+        // FileUtil.verify( f, vFacPgp, false, true );
+        // assertTrue( new File( targetDirectory,
+        // "/org/apache/maven/maven-core/2.0.9/"+repo.getMetadataName()+".sha1").exists() );
+        // FileUtil.verify( f, vFacSha1, false, true );
+
+        assertTrue( af.exists() );
+        assertEquals( binarySize, af.length() );
+        assertTrue( new File( targetDirectory, "/org/apache/maven/maven-core/2.0.9/maven-core-2.0.9.jar.asc" ).exists() );
+        FileUtil.verify( af, vFacPgp, false, true );
+        assertTrue( new File( targetDirectory, "/org/apache/maven/maven-core/2.0.9/maven-core-2.0.9.jar.sha1" ).exists() );
+        FileUtil.verify( af, vFacSha1, false, true );
+
+        assertTrue( ap.exists() );
+        assertEquals( pomSize, ap.length() );
+        assertTrue( new File( targetDirectory, "/org/apache/maven/maven-core/2.0.9/maven-core-2.0.9.pom.asc" ).exists() );
+        FileUtil.verify( ap, vFacPgp, false, true );
+        assertTrue( new File( targetDirectory, "/org/apache/maven/maven-core/2.0.9/maven-core-2.0.9.pom.sha1" ).exists() );
+        FileUtil.verify( ap, vFacSha1, false, true );
     }
-    
-    // check GAV metadata has all versions
-    String mdFile = targetDirectory.getAbsolutePath()+"/org/apache/maven/maven-core/2.0.9-SNAPSHOT/"+repo.getMetadataName();
-    byte [] mdBytes = FileUtil.readRawData( new File(mdFile) );
-    Metadata md = MetadataBuilder.read( new ByteArrayInputStream(mdBytes) );
-    
-    assertNotNull( md );
-    assertNotNull( md.getVersioning() );
-    assertNotNull( md.getVersioning().getVersions() );
-    assertFalse( md.getVersioning().getVersions().isEmpty() );
-    
-    List<String> versions = md.getVersioning().getVersions();
-    System.out.println( versions.size()+" versions: " + versions );
-
-    assertEquals( 20, versions.size() );
-    
-    for( int i=0; i<20;i++ )
+
+    public void testWriteSnapshotAsTS()
+        throws Exception
     {
-      String v = "2.0.9-20080805.215925-"+i;
-      assertTrue( "Did not find "+v+" in GAV metadata "+mdFile+"\n"+new String(mdBytes), versions.contains( v ) );
+        setSnapshots();
+
+        Set<Artifact> artifacts = new HashSet<Artifact>( 3 );
+        DefaultArtifact da =
+            new DefaultArtifact( new ArtifactMetadata( "org.apache.maven:maven-core:2.0.9-20080805.215925-8" ) );
+        da.setPomBlob( pomBytes );
+        da.setFile( artifactBinary );
+        artifacts.add( da );
+
+        writer.writeArtifacts( artifacts );
+
+        File af =
+            new File( targetDirectory,
+                      "/org/apache/maven/maven-core/2.0.9-SNAPSHOT/maven-core-2.0.9-20080805.215925-8.jar" );
+        assertTrue( af.exists() );
+        assertEquals( binarySize, af.length() );
+
+        File ap =
+            new File( targetDirectory,
+                      "/org/apache/maven/maven-core/2.0.9-SNAPSHOT/maven-core-2.0.9-20080805.215925-8.pom" );
+        assertTrue( ap.exists() );
+        assertEquals( pomSize, ap.length() );
     }
-  }
-  
-  
-  public void testWriteContentionMultipleArtifacts()
-  throws Exception
-  {
-    setSnapshots();
-    
-    Set<Artifact> set = new HashSet<Artifact>(40);
 
-    // prep. artifacts
-    for( int i=0; i<20; i++ )
+    public void testWriteSnapshot()
+        throws Exception
     {
-      String si = ""+i;
-      
-      DefaultArtifact da = new DefaultArtifact( new ArtifactMetadata("org.apache.maven:maven-core:2.0."+si+"-SNAPSHOT") );
-      da.setPomBlob( pomBytes );
-      File ab = File.createTempFile( "test-core-", "-bin" );
-      FileUtil.writeRawData( getClass().getResourceAsStream( "/maven-core-2.0.9.jar" ), ab );
-      da.setFile( ab );
-      set.add( da );
-
-      da = new DefaultArtifact( new ArtifactMetadata("org.apache.maven:maven-mercury:2.0."+si+"-SNAPSHOT") );
-      da.setPomBlob( pomBytes );
-      ab = File.createTempFile( "test-mercury-", "-bin" );
-      FileUtil.writeRawData( getClass().getResourceAsStream( "/maven-core-2.0.9.jar" ), ab );
-      da.setFile( ab );
-      set.add( da );
+        setSnapshots();
+
+        Set<Artifact> set = new HashSet<Artifact>( 3 );
+        DefaultArtifact da = new DefaultArtifact( new ArtifactMetadata( "org.apache.maven:maven-core:2.0.9-SNAPSHOT" ) );
+        da.setPomBlob( pomBytes );
+        da.setFile( artifactBinary );
+        set.add( da );
+
+        writer.writeArtifacts( set );
+
+        File af =
+            new File( targetDirectory, "/org/apache/maven/maven-core/2.0.9-SNAPSHOT/maven-core-2.0.9-SNAPSHOT.jar" );
+        assertTrue( af.exists() );
+        assertEquals( binarySize, af.length() );
+
+        File ap =
+            new File( targetDirectory, "/org/apache/maven/maven-core/2.0.9-SNAPSHOT/maven-core-2.0.9-SNAPSHOT.pom" );
+        assertTrue( ap.exists() );
+        assertEquals( pomSize, ap.length() );
     }
-    
-    assertEquals( 40, set.size() );
-    
-    long start = System.currentTimeMillis();
-    // write 'em
-    writer.writeArtifacts( set );
-    
-    System.out.println("Took "+(System.currentTimeMillis()-start)+" millis to write "+set.size()+" artifacts");
-    System.out.flush();
-    
-    // check if the showed up in the repo
-    for( int i=0; i<20; i++ )
+
+    public void testWriteClassifier()
+        throws Exception
     {
-      String si = ""+i;
+        setSnapshots();
 
-      String fn = targetDirectory.getAbsolutePath()+"/org/apache/maven/maven-core/2.0."+si+"-SNAPSHOT/maven-core-2.0."+si+"-SNAPSHOT.jar";
-      File af = new File( targetDirectory, "/org/apache/maven/maven-core/2.0."+si+"-SNAPSHOT/maven-core-2.0."+si+"-SNAPSHOT.jar" );
-      assertTrue( fn+" does not exist", af.exists() );
-      assertEquals( binarySize, af.length() );
-      
-      fn = targetDirectory.getAbsolutePath()+"/org/apache/maven/maven-core/2.0."+si+"-SNAPSHOT/maven-core-2.0."+si+"-SNAPSHOT.pom";
-      File ap = new File( targetDirectory, "/org/apache/maven/maven-core/2.0."+si+"-SNAPSHOT/maven-core-2.0."+si+"-SNAPSHOT.pom");
-      assertTrue( fn+" does not exist", ap.exists() );
-      assertEquals( pomSize, ap.length() );
-
-      fn = targetDirectory.getAbsolutePath()+"/org/apache/maven/maven-mercury/2.0."+si+"-SNAPSHOT/maven-mercury-2.0."+i+"-SNAPSHOT.jar";
-      af = new File( targetDirectory, "/org/apache/maven/maven-mercury/2.0."+si+"-SNAPSHOT/maven-mercury-2.0."+i+"-SNAPSHOT.jar");
-      assertTrue( fn+" does not xist", af.exists() );
-      assertEquals( binarySize, af.length() );
-      
-      fn = targetDirectory.getAbsolutePath()+"/org/apache/maven/maven-mercury/2.0."+si+"-SNAPSHOT/maven-mercury-2.0."+i+"-SNAPSHOT.pom";
-      ap = new File( targetDirectory, "/org/apache/maven/maven-mercury/2.0."+si+"-SNAPSHOT/maven-mercury-2.0."+i+"-SNAPSHOT.pom");
-      assertTrue( ap.exists() );
-      assertEquals( pomSize, ap.length() );
+        Set<Artifact> set = new HashSet<Artifact>( 3 );
+        DefaultArtifact da = new DefaultArtifact( new ArtifactMetadata( "org.apache.maven:maven-core:2.0.9:all" ) );
+        da.setFile( artifactBinary );
+        set.add( da );
+
+        writer.writeArtifacts( set );
+
+        File af = new File( targetDirectory, "/org/apache/maven/maven-core/2.0.9/maven-core-2.0.9-all.jar" );
+        assertTrue( af.exists() );
+        assertEquals( binarySize, af.length() );
     }
-    
-    // check GA metadata has all versions
-    String mdFile = targetDirectory.getAbsolutePath()+"/org/apache/maven/maven-mercury/"+repo.getMetadataName();
-    byte [] mdBytes = FileUtil.readRawData( new File(mdFile) );
-    Metadata md = MetadataBuilder.read( new ByteArrayInputStream(mdBytes) );
-    
-    assertNotNull( md );
-    assertNotNull( md.getVersioning() );
-    assertNotNull( md.getVersioning().getVersions() );
-    assertFalse( md.getVersioning().getVersions().isEmpty() );
-    
-    List<String> versions = md.getVersioning().getVersions();
-
-    assertEquals( 20, versions.size() );
-    
-    for( int i=0; i<20;i++ )
+
+    public void testWriteContentionSingleArtifact()
+        throws Exception
     {
-      String v = "2.0."+i+"-SNAPSHOT";
-      assertTrue( "Did not find "+v+" in GA metadata "+mdFile+"\n"+new String(mdBytes), versions.contains( v ) );
+        setSnapshots();
+
+        Set<Artifact> set = new HashSet<Artifact>( 40 );
+
+        // prep. artifacts
+        for ( int i = 0; i < 20; i++ )
+        {
+            String si = "" + i;
+
+            DefaultArtifact da =
+                new DefaultArtifact( new ArtifactMetadata( "org.apache.maven:maven-core:2.0.9-20080805.215925-" + si ) );
+            da.setPomBlob( pomBytes );
+            File ab = File.createTempFile( "test-core-", "-bin" );
+            FileUtil.writeRawData( getClass().getResourceAsStream( "/maven-core-2.0.9.jar" ), ab );
+            da.setFile( ab );
+            set.add( da );
+        }
+
+        assertEquals( 20, set.size() );
+
+        long start = System.currentTimeMillis();
+        // write 'em
+        writer.writeArtifacts( set );
+
+        System.out.println( "Took " + ( System.currentTimeMillis() - start ) + " millis to write " + set.size()
+            + " artifacts" );
+        System.out.flush();
+
+        // check if the showed up in the repo
+        for ( int i = 0; i < 20; i++ )
+        {
+            String si = "" + i;
+
+            String fn =
+                targetDirectory.getAbsolutePath()
+                    + "/org/apache/maven/maven-core/2.0.9-SNAPSHOT/maven-core-2.0.9-20080805.215925-" + si + ".jar";
+            File af = new File( fn );
+            assertTrue( fn + " does not exist", af.exists() );
+            assertEquals( binarySize, af.length() );
+
+            // is pom there also?
+            fn =
+                targetDirectory.getAbsolutePath()
+                    + "/org/apache/maven/maven-core/2.0.9-SNAPSHOT/maven-core-2.0.9-20080805.215925-" + si + ".pom";
+            File ap = new File( fn );
+            assertTrue( fn + " does not exist", ap.exists() );
+            assertEquals( pomSize, ap.length() );
+        }
+
+        // check GAV metadata has all versions
+        String mdFile =
+            targetDirectory.getAbsolutePath() + "/org/apache/maven/maven-core/2.0.9-SNAPSHOT/" + repo.getMetadataName();
+        byte[] mdBytes = FileUtil.readRawData( new File( mdFile ) );
+        Metadata md = MetadataBuilder.read( new ByteArrayInputStream( mdBytes ) );
+
+        assertNotNull( md );
+        assertNotNull( md.getVersioning() );
+        assertNotNull( md.getVersioning().getVersions() );
+        assertFalse( md.getVersioning().getVersions().isEmpty() );
+
+        List<String> versions = md.getVersioning().getVersions();
+        System.out.println( versions.size() + " versions: " + versions );
+
+        assertEquals( 20, versions.size() );
+
+        for ( int i = 0; i < 20; i++ )
+        {
+            String v = "2.0.9-20080805.215925-" + i;
+            assertTrue( "Did not find " + v + " in GAV metadata " + mdFile + "\n" + new String( mdBytes ),
+                        versions.contains( v ) );
+        }
     }
-    
-    mdFile = targetDirectory.getAbsolutePath()+"/org/apache/maven/maven-core/"+repo.getMetadataName();
-    mdBytes = FileUtil.readRawData( new File(mdFile) );
-    md = MetadataBuilder.read( new ByteArrayInputStream(mdBytes) );
-    
-    assertNotNull( md );
-    assertNotNull( md.getVersioning() );
-    assertNotNull( md.getVersioning().getVersions() );
-    assertFalse( md.getVersioning().getVersions().isEmpty() );
-    
-    versions = md.getVersioning().getVersions();
-    
-    assertEquals( 20, versions.size() );
 
-    for( int i=0; i<20;i++ )
+    public void testWriteContentionMultipleArtifacts()
+        throws Exception
     {
-      String v = "2.0."+i+"-SNAPSHOT";
-      assertTrue( "Did not find "+v+" in GA metadata "+mdFile+"\n"+new String(mdBytes), versions.contains( v ) );
+        setSnapshots();
+
+        Set<Artifact> set = new HashSet<Artifact>( 40 );
+
+        // prep. artifacts
+        for ( int i = 0; i < 20; i++ )
+        {
+            String si = "" + i;
+
+            DefaultArtifact da =
+                new DefaultArtifact( new ArtifactMetadata( "org.apache.maven:maven-core:2.0." + si + "-SNAPSHOT" ) );
+            da.setPomBlob( pomBytes );
+            File ab = File.createTempFile( "test-core-", "-bin" );
+            FileUtil.writeRawData( getClass().getResourceAsStream( "/maven-core-2.0.9.jar" ), ab );
+            da.setFile( ab );
+            set.add( da );
+
+            da = new DefaultArtifact( new ArtifactMetadata( "org.apache.maven:maven-mercury:2.0." + si + "-SNAPSHOT" ) );
+            da.setPomBlob( pomBytes );
+            ab = File.createTempFile( "test-mercury-", "-bin" );
+            FileUtil.writeRawData( getClass().getResourceAsStream( "/maven-core-2.0.9.jar" ), ab );
+            da.setFile( ab );
+            set.add( da );
+        }
+
+        assertEquals( 40, set.size() );
+
+        long start = System.currentTimeMillis();
+        // write 'em
+        writer.writeArtifacts( set );
+
+        System.out.println( "Took " + ( System.currentTimeMillis() - start ) + " millis to write " + set.size()
+            + " artifacts" );
+        System.out.flush();
+
+        // check if the showed up in the repo
+        for ( int i = 0; i < 20; i++ )
+        {
+            String si = "" + i;
+
+            String fn =
+                targetDirectory.getAbsolutePath() + "/org/apache/maven/maven-core/2.0." + si
+                    + "-SNAPSHOT/maven-core-2.0." + si + "-SNAPSHOT.jar";
+            File af =
+                new File( targetDirectory, "/org/apache/maven/maven-core/2.0." + si + "-SNAPSHOT/maven-core-2.0." + si
+                    + "-SNAPSHOT.jar" );
+            assertTrue( fn + " does not exist", af.exists() );
+            assertEquals( binarySize, af.length() );
+
+            fn =
+                targetDirectory.getAbsolutePath() + "/org/apache/maven/maven-core/2.0." + si
+                    + "-SNAPSHOT/maven-core-2.0." + si + "-SNAPSHOT.pom";
+            File ap =
+                new File( targetDirectory, "/org/apache/maven/maven-core/2.0." + si + "-SNAPSHOT/maven-core-2.0." + si
+                    + "-SNAPSHOT.pom" );
+            assertTrue( fn + " does not exist", ap.exists() );
+            assertEquals( pomSize, ap.length() );
+
+            fn =
+                targetDirectory.getAbsolutePath() + "/org/apache/maven/maven-mercury/2.0." + si
+                    + "-SNAPSHOT/maven-mercury-2.0." + i + "-SNAPSHOT.jar";
+            af =
+                new File( targetDirectory, "/org/apache/maven/maven-mercury/2.0." + si + "-SNAPSHOT/maven-mercury-2.0."
+                    + i + "-SNAPSHOT.jar" );
+            assertTrue( fn + " does not xist", af.exists() );
+            assertEquals( binarySize, af.length() );
+
+            fn =
+                targetDirectory.getAbsolutePath() + "/org/apache/maven/maven-mercury/2.0." + si
+                    + "-SNAPSHOT/maven-mercury-2.0." + i + "-SNAPSHOT.pom";
+            ap =
+                new File( targetDirectory, "/org/apache/maven/maven-mercury/2.0." + si + "-SNAPSHOT/maven-mercury-2.0."
+                    + i + "-SNAPSHOT.pom" );
+            assertTrue( ap.exists() );
+            assertEquals( pomSize, ap.length() );
+        }
+
+        // check GA metadata has all versions
+        String mdFile = targetDirectory.getAbsolutePath() + "/org/apache/maven/maven-mercury/" + repo.getMetadataName();
+        byte[] mdBytes = FileUtil.readRawData( new File( mdFile ) );
+        Metadata md = MetadataBuilder.read( new ByteArrayInputStream( mdBytes ) );
+
+        assertNotNull( md );
+        assertNotNull( md.getVersioning() );
+        assertNotNull( md.getVersioning().getVersions() );
+        assertFalse( md.getVersioning().getVersions().isEmpty() );
+
+        List<String> versions = md.getVersioning().getVersions();
+
+        assertEquals( 20, versions.size() );
+
+        for ( int i = 0; i < 20; i++ )
+        {
+            String v = "2.0." + i + "-SNAPSHOT";
+            assertTrue( "Did not find " + v + " in GA metadata " + mdFile + "\n" + new String( mdBytes ),
+                        versions.contains( v ) );
+        }
+
+        mdFile = targetDirectory.getAbsolutePath() + "/org/apache/maven/maven-core/" + repo.getMetadataName();
+        mdBytes = FileUtil.readRawData( new File( mdFile ) );
+        md = MetadataBuilder.read( new ByteArrayInputStream( mdBytes ) );
+
+        assertNotNull( md );
+        assertNotNull( md.getVersioning() );
+        assertNotNull( md.getVersioning().getVersions() );
+        assertFalse( md.getVersioning().getVersions().isEmpty() );
+
+        versions = md.getVersioning().getVersions();
+
+        assertEquals( 20, versions.size() );
+
+        for ( int i = 0; i < 20; i++ )
+        {
+            String v = "2.0." + i + "-SNAPSHOT";
+            assertTrue( "Did not find " + v + " in GA metadata " + mdFile + "\n" + new String( mdBytes ),
+                        versions.contains( v ) );
+        }
     }
-  }
-  
+
 }



Mime
View raw message