You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by og...@apache.org on 2009/04/23 00:57:04 UTC

svn commit: r767705 [17/31] - in /maven/mercury/trunk/mercury-core: ./ src/ src/main/ src/main/java/ src/main/java/org/ src/main/java/org/apache/ src/main/java/org/apache/maven/ src/main/java/org/apache/maven/mercury/ src/main/java/org/apache/maven/mer...

Added: maven/mercury/trunk/mercury-core/src/test/java/org/apache/maven/mercury/metadata/sat/DefaultSatSolverTest.java
URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-core/src/test/java/org/apache/maven/mercury/metadata/sat/DefaultSatSolverTest.java?rev=767705&view=auto
==============================================================================
--- maven/mercury/trunk/mercury-core/src/test/java/org/apache/maven/mercury/metadata/sat/DefaultSatSolverTest.java (added)
+++ maven/mercury/trunk/mercury-core/src/test/java/org/apache/maven/mercury/metadata/sat/DefaultSatSolverTest.java Wed Apr 22 22:56:48 2009
@@ -0,0 +1,566 @@
+/**
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+package org.apache.maven.mercury.metadata.sat;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Comparator;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import junit.framework.TestCase;
+
+import org.apache.maven.mercury.artifact.ArtifactMetadata;
+import org.apache.maven.mercury.artifact.MetadataTreeNode;
+import org.apache.maven.mercury.metadata.ClassicDepthComparator;
+import org.apache.maven.mercury.metadata.ClassicVersionComparator;
+
+/**
+ * @author <a href="oleg@codehaus.org">Oleg Gusakov</a>
+ */
+public class DefaultSatSolverTest
+    extends TestCase
+{
+  DefaultSatSolver ss;
+  String title;
+  
+  MetadataTreeNode tree;
+  
+  ArtifactMetadata a1 = new ArtifactMetadata("t:a:1");
+  ArtifactMetadata b1 = new ArtifactMetadata("t:b:1");
+  ArtifactMetadata b2 = new ArtifactMetadata("t:b:2");
+  ArtifactMetadata b3 = new ArtifactMetadata("t:b:3");
+  ArtifactMetadata c1 = new ArtifactMetadata("t:c:1");
+  ArtifactMetadata c2 = new ArtifactMetadata("t:c:2");
+
+  ArtifactMetadata d1 = new ArtifactMetadata("t:d:1");
+  
+  //----------------------------------------------------------------------
+  protected void setUp()
+  throws Exception
+  {
+    super.setUp();
+  }
+  //----------------------------------------------------------------------
+  public void testDedupe()
+  {
+    List<MetadataTreeNode> list = new ArrayList<MetadataTreeNode>();
+    
+    list.add(  new MetadataTreeNode( new ArtifactMetadata("a:a:1"), null, null ) );
+    list.add(  new MetadataTreeNode( new ArtifactMetadata("a:a:1"), null, null ) );
+    list.add(  new MetadataTreeNode( new ArtifactMetadata("a:a:1"), null, null ) );
+    list.add(  new MetadataTreeNode( new ArtifactMetadata("b:b:1"), null, null ) );
+    list.add(  new MetadataTreeNode( new ArtifactMetadata("b:b:1"), null, null ) );
+    list.add(  new MetadataTreeNode( new ArtifactMetadata("a:a:1"), null, null ) );
+    
+    DefaultSatSolver.removeDuplicateGAVs( list );
+    
+    System.out.println(list);
+    
+    assertEquals( 2, list.size() );
+  }
+  
+  
+  private int f( int a, int b )
+  {
+    return -a + b;
+  }
+  //----------------------------------------------------------------------
+  //       d:d:1 - c:c:[2,4)
+  //      / 
+  // a:a:1
+  //      \     
+  //       b:b:2 - c:c:1
+  //----------------------------------------------------------------------
+  public void testReNumeration()
+  throws SatException, IOException
+  {
+    title = "testReNumeration";
+    System.out.println("\n\n==========================\n"+title+"\n");
+    
+    MetadataTreeNode na1 = new MetadataTreeNode( a1, null, null )
+      .addQuery(d1)
+      .addQuery(b2)
+    ;
+    
+    ArtifactMetadata c2q = new ArtifactMetadata("t:c:[2,4)");
+    
+    MetadataTreeNode nd1 = new MetadataTreeNode( d1, na1, d1 )
+      .addQuery( c2q )
+    ;
+    MetadataTreeNode nb2 = new MetadataTreeNode( b2, na1, b2 )
+      .addQuery( c1 )
+    ;
+    
+    MetadataTreeNode nc2 = new MetadataTreeNode( c2, nd1, c2q );
+
+    MetadataTreeNode nc1 = new MetadataTreeNode( c1, nb2, c1 );
+    
+    na1
+      .addChild(nd1)
+      .addChild(nb2)
+    ;
+    
+    nd1
+      .addChild(nc2)
+    ;
+    
+    nb2
+      .addChild(nc1)
+    ;
+    
+    MetadataTreeNode.reNumber( na1, 1 );
+    
+    assertEquals( 1, na1.getId() );
+    
+    assertEquals( 2, nd1.getId() );
+    
+  }
+  //----------------------------------------------------------------------
+  public void testOptimization()
+  throws SatException
+  {
+    title = "optimization test";
+    System.out.println("\n\n==========================\n"+title+"\n");
+
+    //       b:b:1
+    //      / 
+    // a:a:1       b:b:2
+    //    \     /
+    //     c:c:1
+    //          \ b:b:1
+    
+    ArtifactMetadata mdaa1 = new ArtifactMetadata("a:a:1");
+    ArtifactMetadata mdbb1 = new ArtifactMetadata("b:b:1");
+    ArtifactMetadata mdbb2 = new ArtifactMetadata("b:b:2");
+    ArtifactMetadata mdcc1 = new ArtifactMetadata("c:c:1");
+    
+    MetadataTreeNode aa1;
+    MetadataTreeNode bb1;
+    MetadataTreeNode cc1;
+    MetadataTreeNode cc1bb1;
+    MetadataTreeNode cc1bb2;
+    
+    aa1 = new MetadataTreeNode( mdaa1, null, mdaa1 );
+    bb1 = new MetadataTreeNode( mdbb1, aa1, mdbb1 );
+    aa1.addChild(bb1);
+    cc1 = new MetadataTreeNode( mdcc1, aa1, mdcc1 );
+    aa1.addChild(cc1);
+    cc1bb1 = new MetadataTreeNode( mdbb1, cc1, mdbb1 );
+    cc1.addChild( cc1bb1 );
+    cc1bb2 = new MetadataTreeNode( mdbb2, cc1, mdbb2 );
+    cc1.addChild( cc1bb2 );
+    
+    ss = (DefaultSatSolver) DefaultSatSolver.create( aa1 );
+    
+    List< Comparator<MetadataTreeNode>> comparators = new ArrayList<Comparator<MetadataTreeNode>>(2);
+    comparators.add( new ClassicDepthComparator() );
+    comparators.add( new ClassicVersionComparator() );
+    
+    Map<String, List<MetadataTreeNode>> buckets = new HashMap<String, List<MetadataTreeNode>>(128);
+    DefaultSatSolver.fillBuckets( buckets, aa1 );
+    DefaultSatSolver.sortBuckets( buckets, comparators );
+
+    assertNotNull("no resulting map", buckets ); 
+    assertEquals( "bad map size", 3, buckets.size() ); 
+    
+    System.out.println("optimized buckets: "+buckets);
+    
+    List<MetadataTreeNode> bbl = buckets.get("b:b");
+    assertNotNull("no b:b list", bbl );
+    assertEquals( "bad b:b list size", 2, bbl.size() ); 
+    
+    MetadataTreeNode first = bbl.get(0);
+    assertNotNull("bad first element", first );
+    assertEquals( "bad first element's GAV", "b:b:1::jar", first.getMd().getGAV() );
+    assertEquals( "bad first element's depth", 1, first.getDepth() );
+    
+    MetadataTreeNode second = bbl.get(1);
+    assertNotNull("bad second element", second );
+    assertEquals( "bad second element's GAV", "b:b:2::jar", second.getMd().getGAV() );
+    assertEquals( "bad second element's depth", 2, second.getDepth() );
+  }
+  //----------------------------------------------------------------------
+  //
+  // a1
+  //    and (b1 or b2 or b3)
+  //    and ((c1 and b1) or (c2 and (b2 or b3))
+  //
+  //----------------------------------------------------------------------
+  public void testClassicResolution()
+  throws SatException
+  {
+    title = "simplest 3-node tree";
+    System.out.println("\n\n==========================\n"+title+"\n");
+    
+    MetadataTreeNode na1 = new MetadataTreeNode( a1, null, null )
+      .addQuery(b1)
+      .addQuery(c1)
+    ;
+    
+    MetadataTreeNode nb1 = new MetadataTreeNode( b1, na1, b1 );
+    MetadataTreeNode nb2 = new MetadataTreeNode( b2, na1, b1 );
+    MetadataTreeNode nb3 = new MetadataTreeNode( b3, na1, b1 );
+    
+    MetadataTreeNode nc1 = new MetadataTreeNode( c1, na1, c1 )
+      .addQuery(b1)
+    ;
+    MetadataTreeNode nc2 = new MetadataTreeNode( c2, na1, c1 )
+      .addQuery(b1)
+    ;
+    
+    na1
+      .addChild(nb1)
+      .addChild(nb2)
+      .addChild(nb3)
+      .addChild(nc1)
+      .addChild(nc2)
+    ;
+    
+    nc1
+      .addChild(nb1)
+    ;
+    
+    nc2
+      .addChild(nb2)
+      .addChild(nb3)
+    ;
+
+    ss = (DefaultSatSolver) DefaultSatSolver.create(na1);
+
+    List<ArtifactMetadata> res = ss.solve();
+    
+    int m[] = ss._solver.model();
+
+    System.out.print("model: " );
+    for( int i=0; i<m.length; i++ )
+      System.out.print(" "+m[i]);
+    System.out.println("");
+
+    assertNotNull( res );
+    
+    System.out.print("Result:");
+    for( ArtifactMetadata md : res )
+    {
+      System.out.print(" "+md);
+    }
+    System.out.println("");
+
+    assertEquals( 3, res.size() );
+    
+    assertTrue( res.contains( a1 ) );
+    assertTrue( res.contains( b2 ) );
+    assertTrue( res.contains( c2 ) );
+  }
+  //----------------------------------------------------------------------
+  //       b:b:1 - c:c:2
+  //      / 
+  // a:a:1
+  //      \     
+  //       b:b:2 - c:c:1
+  //----------------------------------------------------------------------
+  public void testSingleVersionResolution()
+  throws SatException
+  {
+    title = "testSingleVersionResolution";
+    System.out.println("\n\n==========================\n"+title+"\n");
+    
+    MetadataTreeNode na1 = new MetadataTreeNode( a1, null, null )
+      .addQuery(b1)
+      .addQuery(b2)
+    ;
+    
+    MetadataTreeNode nb1 = new MetadataTreeNode( b1, na1, b1 )
+      .addQuery( c2 )
+    ;
+    MetadataTreeNode nb2 = new MetadataTreeNode( b2, na1, b2 )
+      .addQuery( c1 )
+    ;
+    
+    MetadataTreeNode nc2 = new MetadataTreeNode( c2, nb1, c2 );
+
+    MetadataTreeNode nc1 = new MetadataTreeNode( c1, nb2, c1 );
+    
+    na1
+      .addChild(nb1)
+      .addChild(nb2)
+    ;
+    
+    nb1
+      .addChild(nc2)
+    ;
+    
+    nb2
+      .addChild(nc1)
+    ;
+    
+    List<Comparator<MetadataTreeNode>> cl = new ArrayList<Comparator<MetadataTreeNode>>(2);
+    cl.add( new ClassicDepthComparator() );
+    cl.add( new ClassicVersionComparator() );
+
+    ss = (DefaultSatSolver) DefaultSatSolver.create(na1);
+    
+    ss.applyPolicies( cl );
+
+    List<ArtifactMetadata> res = ss.solve();
+    
+    int m[] = ss._solver.model();
+
+    System.out.print("model: " );
+
+    for( int i=0; i<m.length; i++ )
+      System.out.print(" "+m[i]);
+    System.out.println("");
+
+    assertNotNull( res );
+    
+    System.out.print("Result:");
+    for( ArtifactMetadata md : res )
+    {
+      System.out.print(" "+md);
+    }
+    System.out.println("");
+    
+    assertEquals( 3, res.size() );
+    
+    assertTrue( res.contains( a1 ) );
+    assertTrue( res.contains( b1 ) );
+    assertTrue( res.contains( c2 ) );
+  }
+  //----------------------------------------------------------------------
+  //       b:b:1 - c:c:[2,4)
+  //      / 
+  // a:a:1
+  //      \     
+  //       b:b:2 - c:c:1
+  //----------------------------------------------------------------------
+  public void testStrictRangeResolution()
+  throws SatException
+  {
+    title = "testStrictRangeResolution";
+    System.out.println("\n\n==========================\n"+title+"\n");
+    
+    MetadataTreeNode na1 = new MetadataTreeNode( a1, null, null )
+      .addQuery(b1)
+      .addQuery(b2)
+    ;
+    
+    ArtifactMetadata c2q = new ArtifactMetadata("t:c:[2,4)");
+    
+    MetadataTreeNode nb1 = new MetadataTreeNode( b1, na1, b1 )
+      .addQuery( c2q )
+    ;
+    MetadataTreeNode nb2 = new MetadataTreeNode( b2, na1, b2 )
+      .addQuery( c1 )
+    ;
+    
+    MetadataTreeNode nc2 = new MetadataTreeNode( c2, nb1, c2q );
+
+    MetadataTreeNode nc1 = new MetadataTreeNode( c1, nb2, c1 );
+    
+    na1
+      .addChild(nb1)
+      .addChild(nb2)
+    ;
+    
+    nb1
+      .addChild(nc2)
+    ;
+    
+    nb2
+      .addChild(nc1)
+    ;
+    
+    List<Comparator<MetadataTreeNode>> cl = new ArrayList<Comparator<MetadataTreeNode>>(2);
+    cl.add( new ClassicDepthComparator() );
+    cl.add( new ClassicVersionComparator() );
+
+    ss = (DefaultSatSolver) DefaultSatSolver.create(na1);
+    
+    ss.applyPolicies( cl );
+
+    List<ArtifactMetadata> res = ss.solve();
+    
+    int m[] = ss._solver.model();
+
+    System.out.print("model: " );
+
+    for( int i=0; i<m.length; i++ )
+      System.out.print(" "+m[i]);
+    System.out.println("");
+
+    assertNotNull( res );
+    
+    System.out.print("Result:");
+    for( ArtifactMetadata md : res )
+    {
+      System.out.print(" "+md);
+    }
+    System.out.println("");
+    
+    assertEquals( 3, res.size() );
+    
+    assertTrue( res.contains( a1 ) );
+    assertTrue( res.contains( b1 ) );
+    assertTrue( res.contains( c2 ) );
+  }
+  //----------------------------------------------------------------------
+  //       d:d:1 - c:c:[2,4)
+  //      / 
+  // a:a:1
+  //      \     
+  //       b:b:2 - c:c:1
+  //----------------------------------------------------------------------
+  public void testStrictRangeResolution2()
+  throws SatException
+  {
+    title = "testStrictRangeResolution2";
+    System.out.println("\n\n==========================\n"+title+"\n");
+    
+    MetadataTreeNode na1 = new MetadataTreeNode( a1, null, null )
+      .addQuery(d1)
+      .addQuery(b2)
+    ;
+    
+    ArtifactMetadata c2q = new ArtifactMetadata("t:c:[2,4)");
+    
+    MetadataTreeNode nd1 = new MetadataTreeNode( d1, na1, d1 )
+      .addQuery( c2q )
+    ;
+    MetadataTreeNode nb2 = new MetadataTreeNode( b2, na1, b2 )
+      .addQuery( c1 )
+    ;
+    
+    MetadataTreeNode nc2 = new MetadataTreeNode( c2, nd1, c2q );
+
+    MetadataTreeNode nc1 = new MetadataTreeNode( c1, nb2, c1 );
+    
+    na1
+      .addChild(nd1)
+      .addChild(nb2)
+    ;
+    
+    nd1
+      .addChild(nc2)
+    ;
+    
+    nb2
+      .addChild(nc1)
+    ;
+    
+    List<Comparator<MetadataTreeNode>> cl = new ArrayList<Comparator<MetadataTreeNode>>(2);
+    cl.add( new ClassicDepthComparator() );
+    cl.add( new ClassicVersionComparator() );
+
+    ss = (DefaultSatSolver) DefaultSatSolver.create(na1);
+    
+    ss.applyPolicies( cl );
+
+    List<ArtifactMetadata> res = ss.solve();
+    
+    int m[] = ss._solver.model();
+
+    System.out.print("model: " );
+
+    for( int i=0; i<m.length; i++ )
+      System.out.print(" "+m[i]);
+    System.out.println("");
+
+    assertNotNull( res );
+    
+    System.out.print("Result:");
+    for( ArtifactMetadata md : res )
+    {
+      System.out.print(" "+md);
+    }
+    System.out.println("");
+    
+    assertEquals( 4, res.size() );
+    
+    assertTrue( res.contains( a1 ) );
+    assertTrue( res.contains( d1 ) );
+    assertTrue( res.contains( b2 ) );
+    assertTrue( res.contains( c2 ) );
+  }
+  
+  //----------------------------------------------------------------------
+  //       d:d:1 - c:c:[2,4)
+  //      / 
+  // a:a:1
+  //      \     
+  //       b:b:2 - c:c:1
+  //----------------------------------------------------------------------
+  public void testSolveAsTree()
+  throws SatException, IOException
+  {
+    title = "testSolveAsTree";
+    System.out.println("\n\n==========================\n"+title+"\n");
+    
+    MetadataTreeNode na1 = new MetadataTreeNode( a1, null, null )
+      .addQuery(d1)
+      .addQuery(b2)
+    ;
+    
+    ArtifactMetadata c2q = new ArtifactMetadata("t:c:[2,4)");
+    
+    MetadataTreeNode nd1 = new MetadataTreeNode( d1, na1, d1 )
+      .addQuery( c2q )
+    ;
+    MetadataTreeNode nb2 = new MetadataTreeNode( b2, na1, b2 )
+      .addQuery( c1 )
+    ;
+    
+    MetadataTreeNode nc2 = new MetadataTreeNode( c2, nd1, c2q );
+
+    MetadataTreeNode nc1 = new MetadataTreeNode( c1, nb2, c1 );
+    
+    na1
+      .addChild(nd1)
+      .addChild(nb2)
+    ;
+    
+    nd1
+      .addChild(nc2)
+    ;
+    
+    nb2
+      .addChild(nc1)
+    ;
+    
+    List<Comparator<MetadataTreeNode>> cl = new ArrayList<Comparator<MetadataTreeNode>>(2);
+    cl.add( new ClassicDepthComparator() );
+    cl.add( new ClassicVersionComparator() );
+
+    ss = (DefaultSatSolver) DefaultSatSolver.create(na1);
+    
+    ss.applyPolicies( cl );
+
+    MetadataTreeNode res = ss.solveAsTree();
+    
+    assertNotNull( res );
+    
+    MetadataTreeNode.showNode( res, 0 );
+    
+    assertEquals( 4, res.countNodes() );
+    
+  }
+  //----------------------------------------------------------------------
+  //----------------------------------------------------------------------
+}

Propchange: maven/mercury/trunk/mercury-core/src/test/java/org/apache/maven/mercury/metadata/sat/DefaultSatSolverTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/mercury/trunk/mercury-core/src/test/java/org/apache/maven/mercury/metadata/sat/DefaultSatSolverTest.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: maven/mercury/trunk/mercury-core/src/test/java/org/apache/maven/mercury/repository/api/AbstractRepositoryTest.java
URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-core/src/test/java/org/apache/maven/mercury/repository/api/AbstractRepositoryTest.java?rev=767705&view=auto
==============================================================================
--- maven/mercury/trunk/mercury-core/src/test/java/org/apache/maven/mercury/repository/api/AbstractRepositoryTest.java (added)
+++ maven/mercury/trunk/mercury-core/src/test/java/org/apache/maven/mercury/repository/api/AbstractRepositoryTest.java Wed Apr 22 22:56:48 2009
@@ -0,0 +1,44 @@
+/*
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements.  See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership.  The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License.  You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied.  See the License for the
+specific language governing permissions and limitations
+under the License.
+*/
+
+package org.apache.maven.mercury.repository.api;
+
+import junit.framework.TestCase;
+
+/**
+ *
+ *
+ * @author Oleg Gusakov
+ * @version $Id$
+ *
+ */
+public class AbstractRepositoryTest
+    extends TestCase
+{
+    public void testIdHash()
+    {
+        String res = AbstractRepository.hashId( "central" );
+        
+        assertEquals( "central", res );
+
+        res = AbstractRepository.hashId( "http://central" );
+        
+        assertEquals( "3e447f03cb543932ff37403fe937841ff58ff788", res );
+    }
+}

Propchange: maven/mercury/trunk/mercury-core/src/test/java/org/apache/maven/mercury/repository/api/AbstractRepositoryTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/mercury/trunk/mercury-core/src/test/java/org/apache/maven/mercury/repository/api/AbstractRepositoryTest.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: maven/mercury/trunk/mercury-core/src/test/java/org/apache/maven/mercury/repository/api/RepositoryUpdatePolicyIntervalTest.java
URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-core/src/test/java/org/apache/maven/mercury/repository/api/RepositoryUpdatePolicyIntervalTest.java?rev=767705&view=auto
==============================================================================
--- maven/mercury/trunk/mercury-core/src/test/java/org/apache/maven/mercury/repository/api/RepositoryUpdatePolicyIntervalTest.java (added)
+++ maven/mercury/trunk/mercury-core/src/test/java/org/apache/maven/mercury/repository/api/RepositoryUpdatePolicyIntervalTest.java Wed Apr 22 22:56:48 2009
@@ -0,0 +1,58 @@
+/**
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+package org.apache.maven.mercury.repository.api;
+
+import junit.framework.TestCase;
+
+/**
+ *
+ *
+ * @author Oleg Gusakov
+ * @version $Id$
+ *
+ */
+public class RepositoryUpdatePolicyIntervalTest
+    extends TestCase
+{
+  RepositoryUpdateIntervalPolicy in;
+  long now;
+  
+  @Override
+  protected void setUp()
+      throws Exception
+  {
+    in = new RepositoryUpdateIntervalPolicy( RepositoryUpdateIntervalPolicy.UPDATE_POLICY_NAME_INTERVAL+"1" );
+    now = System.currentTimeMillis();
+  }
+
+  public void testInterval()
+  {
+    assertFalse( in.timestampExpired( now, null ) );
+    assertTrue( in.timestampExpired( now-80000L, null ) );
+  }
+
+  public void testDayly()
+  {
+    in = new RepositoryUpdateIntervalPolicy( RepositoryUpdateIntervalPolicy.UPDATE_POLICY_NAME_DAILY );
+
+    assertFalse( in.timestampExpired( now, null ) );
+    assertFalse( in.timestampExpired( now-80000L, null ) );
+    assertTrue( in.timestampExpired( now - 24L*3600L*1000L - 80000L, null ) );
+  }
+}

Propchange: maven/mercury/trunk/mercury-core/src/test/java/org/apache/maven/mercury/repository/api/RepositoryUpdatePolicyIntervalTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/mercury/trunk/mercury-core/src/test/java/org/apache/maven/mercury/repository/api/RepositoryUpdatePolicyIntervalTest.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: maven/mercury/trunk/mercury-core/src/test/java/org/apache/maven/mercury/repository/cache/fs/CachedGATest.java
URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-core/src/test/java/org/apache/maven/mercury/repository/cache/fs/CachedGATest.java?rev=767705&view=auto
==============================================================================
--- maven/mercury/trunk/mercury-core/src/test/java/org/apache/maven/mercury/repository/cache/fs/CachedGATest.java (added)
+++ maven/mercury/trunk/mercury-core/src/test/java/org/apache/maven/mercury/repository/cache/fs/CachedGATest.java Wed Apr 22 22:56:48 2009
@@ -0,0 +1,85 @@
+/**
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+package org.apache.maven.mercury.repository.cache.fs;
+
+import java.io.File;
+import java.io.InputStream;
+
+import junit.framework.TestCase;
+
+import org.apache.maven.mercury.repository.api.RepositoryGAMetadata;
+import org.apache.maven.mercury.repository.metadata.Metadata;
+import org.apache.maven.mercury.repository.metadata.MetadataBuilder;
+import org.apache.maven.mercury.util.FileUtil;
+
+/**
+ *
+ *
+ * @author Oleg Gusakov
+ * @version $Id$
+ *
+ */
+public class CachedGATest
+    extends TestCase
+{
+  
+  byte [] mdBytes;
+  
+  CachedGAMetadata gam;
+  
+  Metadata omd;
+
+  @Override
+  protected void setUp()
+  throws Exception
+  {
+    InputStream is = CachedGATest.class.getResourceAsStream( "/ga-metadata.xml" );
+    
+    mdBytes = FileUtil.readRawData( is );
+    
+    omd = MetadataBuilder.getMetadata( mdBytes );
+    
+    gam = new CachedGAMetadata( new RepositoryGAMetadata(omd) );
+  }
+  
+  public void testData()
+  throws Exception
+  {
+    assertEquals( omd.getGroupId(), gam.getGA().getGroupId() );
+    assertEquals( omd.getArtifactId(), gam.getGA().getArtifactId() );
+    
+    assertEquals( omd.getVersioning().getVersions().size(), gam.getVersions().size() );
+  }
+  
+  public void testRead()
+  throws Exception
+  {
+    File mf = File.createTempFile( "test-ga-", ".xml", new File("./target") );
+    gam.cm.save( mf );
+    
+    CachedGAMetadata gam2 = new CachedGAMetadata( mf );
+
+    assertEquals( omd.getGroupId(), gam2.getGA().getGroupId() );
+    assertEquals( omd.getArtifactId(), gam2.getGA().getArtifactId() );
+    
+    assertEquals( omd.getVersioning().getVersions().size(), gam2.getVersions().size() );
+  }
+  
+  
+}

Propchange: maven/mercury/trunk/mercury-core/src/test/java/org/apache/maven/mercury/repository/cache/fs/CachedGATest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/mercury/trunk/mercury-core/src/test/java/org/apache/maven/mercury/repository/cache/fs/CachedGATest.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: maven/mercury/trunk/mercury-core/src/test/java/org/apache/maven/mercury/repository/cache/fs/CachedGAVTest.java
URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-core/src/test/java/org/apache/maven/mercury/repository/cache/fs/CachedGAVTest.java?rev=767705&view=auto
==============================================================================
--- maven/mercury/trunk/mercury-core/src/test/java/org/apache/maven/mercury/repository/cache/fs/CachedGAVTest.java (added)
+++ maven/mercury/trunk/mercury-core/src/test/java/org/apache/maven/mercury/repository/cache/fs/CachedGAVTest.java Wed Apr 22 22:56:48 2009
@@ -0,0 +1,86 @@
+/**
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+package org.apache.maven.mercury.repository.cache.fs;
+
+import java.io.File;
+import java.io.InputStream;
+
+import junit.framework.TestCase;
+
+import org.apache.maven.mercury.repository.api.RepositoryGAVMetadata;
+import org.apache.maven.mercury.repository.metadata.Metadata;
+import org.apache.maven.mercury.repository.metadata.MetadataBuilder;
+import org.apache.maven.mercury.util.FileUtil;
+
+/**
+ *
+ *
+ * @author Oleg Gusakov
+ * @version $Id$
+ *
+ */
+public class CachedGAVTest
+    extends TestCase
+{
+  
+  byte [] mdBytes;
+  
+  CachedGAVMetadata gam;
+  
+  Metadata omd;
+
+  @Override
+  protected void setUp()
+  throws Exception
+  {
+    InputStream is = CachedGAVTest.class.getResourceAsStream( "/gav-metadata.xml" );
+    
+    mdBytes = FileUtil.readRawData( is );
+    
+    omd = MetadataBuilder.getMetadata( mdBytes );
+    
+    gam = new CachedGAVMetadata( new RepositoryGAVMetadata(omd) );
+  }
+  
+  public void testData()
+  throws Exception
+  {
+    assertEquals( omd.getGroupId(), gam.getGAV().getGroupId() );
+    assertEquals( omd.getArtifactId(), gam.getGAV().getArtifactId() );
+    assertEquals( omd.getVersion(), gam.getGAV().getVersion() );
+    
+    assertEquals( omd.getVersioning().getVersions().size(), gam.getSnapshots().size() );
+  }
+  
+  public void testRead()
+  throws Exception
+  {
+    File mf = File.createTempFile( "test-ga-", ".xml", new File("./target") );
+    gam.cm.save( mf );
+    
+    CachedGAVMetadata gam2 = new CachedGAVMetadata( mf );
+
+    assertEquals( omd.getGroupId(), gam2.getGAV().getGroupId() );
+    assertEquals( omd.getArtifactId(), gam2.getGAV().getArtifactId() );
+    assertEquals( omd.getVersion(), gam2.getGAV().getVersion() );
+    
+    assertEquals( omd.getVersioning().getVersions().size(), gam2.getSnapshots().size() );
+  }
+  
+}

Propchange: maven/mercury/trunk/mercury-core/src/test/java/org/apache/maven/mercury/repository/cache/fs/CachedGAVTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/mercury/trunk/mercury-core/src/test/java/org/apache/maven/mercury/repository/cache/fs/CachedGAVTest.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: maven/mercury/trunk/mercury-core/src/test/java/org/apache/maven/mercury/repository/local/flat/LocalRepositoryFlatTest.java
URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-core/src/test/java/org/apache/maven/mercury/repository/local/flat/LocalRepositoryFlatTest.java?rev=767705&view=auto
==============================================================================
--- maven/mercury/trunk/mercury-core/src/test/java/org/apache/maven/mercury/repository/local/flat/LocalRepositoryFlatTest.java (added)
+++ maven/mercury/trunk/mercury-core/src/test/java/org/apache/maven/mercury/repository/local/flat/LocalRepositoryFlatTest.java Wed Apr 22 22:56:48 2009
@@ -0,0 +1,216 @@
+/**
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+package org.apache.maven.mercury.repository.local.flat;
+
+import java.io.File;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.List;
+
+import junit.framework.TestCase;
+
+import org.apache.maven.mercury.artifact.Artifact;
+import org.apache.maven.mercury.artifact.ArtifactMetadata;
+import org.apache.maven.mercury.artifact.DefaultArtifact;
+import org.apache.maven.mercury.logging.IMercuryLogger;
+import org.apache.maven.mercury.logging.MercuryLoggerManager;
+import org.apache.maven.mercury.repository.api.RepositoryWriter;
+import org.apache.maven.mercury.util.FileUtil;
+
+/**
+ *
+ *
+ * @author Oleg Gusakov
+ * @version $Id$
+ *
+ */
+public class LocalRepositoryFlatTest
+    extends TestCase
+{
+  private static final IMercuryLogger LOG = MercuryLoggerManager.getLogger( LocalRepositoryFlatTest.class ); 
+
+  File _dir;
+  LocalRepositoryFlat _repo;
+  
+  String repoUrl = "http://repo1.sonatype.org";
+//  String repoUrl = "http://repository.sonatype.org/content/groups/public";
+  
+  Artifact a;
+  Artifact b;
+
+  @Override
+  protected void setUp()
+      throws Exception
+  {
+    _dir = File.createTempFile( "test-flat-", "-repo" );
+    _dir.delete();
+    _dir.mkdirs();
+    
+    _repo = new LocalRepositoryFlat("testFlatRepo", _dir, false, false );
+    
+    byte [] pomBlob = "pomblob".getBytes();
+    
+    a = new DefaultArtifact( new ArtifactMetadata("a:a:1.0.0") );
+    
+    File ant = File.createTempFile( "test-flat", "-repo" );
+    ant.deleteOnExit();
+    InputStream in = LocalRepositoryFlatTest.class.getResourceAsStream( "/ant-1.6.5.jar" );
+    FileUtil.writeRawData( in, ant );
+    a.setFile( ant );
+    a.setPomBlob( pomBlob );
+    
+    b = new DefaultArtifact( new ArtifactMetadata("b:b:1.0.0") );
+    
+    File antlr = File.createTempFile( "test-flat", "-repo" );
+    antlr.deleteOnExit();
+    in = LocalRepositoryFlatTest.class.getResourceAsStream( "/antlr-2.7.7.jar" );
+    FileUtil.writeRawData( in, antlr );
+    b.setFile( antlr );
+    b.setPomBlob( pomBlob );
+  }
+
+  @Override
+  protected void tearDown()
+      throws Exception
+  {
+    FileUtil.delete( _dir );
+  }  
+
+  public void testWriteFlat()
+  throws Exception
+  {
+    String test = "testWriteFlat()";
+    
+    System.out.println(test+": test repo is in "+_repo.getDirectory());
+
+    List<Artifact> artifacts = new ArrayList<Artifact>();
+    artifacts.add( a );
+    artifacts.add( b );
+    
+    RepositoryWriter rw = _repo.getWriter();
+    rw.writeArtifacts( artifacts );
+    
+    File af = new File ( _dir, "a-1.0.0.jar" );
+    
+    assertTrue( af.exists() );
+    assertEquals( 1034049L, af.length() );
+    
+    File bf = new File ( _dir, "b-1.0.0.jar" );
+
+    assertTrue( bf.exists() );
+    assertEquals( 445288L, bf.length() );
+  }
+  
+  
+  public void testWriteFlatWithPom()
+  throws Exception
+  {
+    String test = "testWriteFlatWithPom()";
+    
+    _repo.setCreatePoms( true );
+    
+    System.out.println(test+": test repo is in "+_repo.getDirectory());
+
+    List<Artifact> artifacts = new ArrayList<Artifact>();
+    artifacts.add( a );
+    artifacts.add( b );
+    
+    RepositoryWriter rw = _repo.getWriter();
+    rw.writeArtifacts( artifacts );
+    
+    File af = new File ( _dir, "a-1.0.0.jar" );
+    
+    assertTrue( af.exists() );
+    assertEquals( 1034049L, af.length() );
+    
+    File ap = new File ( _dir, "a-1.0.0.pom" );
+    assertTrue( ap.exists() );
+    
+    File bf = new File ( _dir, "b-1.0.0.jar" );
+
+    assertTrue( bf.exists() );
+    assertEquals( 445288L, bf.length() );
+    
+    File bp = new File ( _dir, "b-1.0.0.pom" );
+    assertTrue( bp.exists() );
+  }
+  
+  public void testWriteFlatWithGroup()
+  throws Exception
+  {
+    String test = "testWriteFlatWithGroup()";
+    
+    _repo.setCreateGroupFolders( true );
+    
+    System.out.println(test+": test repo is in "+_repo.getDirectory());
+
+    List<Artifact> artifacts = new ArrayList<Artifact>();
+    artifacts.add( a );
+    artifacts.add( b );
+    
+    RepositoryWriter rw = _repo.getWriter();
+    rw.writeArtifacts( artifacts );
+    
+    File af = new File ( _dir, "a/a-1.0.0.jar" );
+    
+    assertTrue( af.exists() );
+    assertEquals( 1034049L, af.length() );
+    
+    File bf = new File ( _dir, "b/b-1.0.0.jar" );
+
+    assertTrue( bf.exists() );
+    assertEquals( 445288L, bf.length() );
+  }
+  
+  public void testWriteFlatWithGroupAndPom()
+  throws Exception
+  {
+    String test = "testWriteFlatWithGroupAndPom()";
+    
+    _repo.setCreateGroupFolders( true );
+    _repo.setCreatePoms( true );
+    
+    System.out.println(test+": test repo is in "+_repo.getDirectory());
+
+    List<Artifact> artifacts = new ArrayList<Artifact>();
+    artifacts.add( a );
+    artifacts.add( b );
+    
+    RepositoryWriter rw = _repo.getWriter();
+    rw.writeArtifacts( artifacts );
+    
+    File af = new File ( _dir, "a/a-1.0.0.jar" );
+    
+    assertTrue( af.exists() );
+    assertEquals( 1034049L, af.length() );
+    
+    File ap = new File ( _dir, "a/a-1.0.0.pom" );
+    assertTrue( ap.exists() );
+    
+    File bf = new File ( _dir, "b/b-1.0.0.jar" );
+
+    assertTrue( bf.exists() );
+    assertEquals( 445288L, bf.length() );
+    
+    File bp = new File ( _dir, "b/b-1.0.0.pom" );
+    assertTrue( bp.exists() );
+  }
+  
+
+}

Propchange: maven/mercury/trunk/mercury-core/src/test/java/org/apache/maven/mercury/repository/local/flat/LocalRepositoryFlatTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/mercury/trunk/mercury-core/src/test/java/org/apache/maven/mercury/repository/local/flat/LocalRepositoryFlatTest.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: maven/mercury/trunk/mercury-core/src/test/java/org/apache/maven/mercury/repository/local/m2/ArtifactLocationtest.java
URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-core/src/test/java/org/apache/maven/mercury/repository/local/m2/ArtifactLocationtest.java?rev=767705&view=auto
==============================================================================
--- maven/mercury/trunk/mercury-core/src/test/java/org/apache/maven/mercury/repository/local/m2/ArtifactLocationtest.java (added)
+++ maven/mercury/trunk/mercury-core/src/test/java/org/apache/maven/mercury/repository/local/m2/ArtifactLocationtest.java Wed Apr 22 22:56:48 2009
@@ -0,0 +1,96 @@
+/*
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements.  See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership.  The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License.  You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied.  See the License for the
+specific language governing permissions and limitations
+under the License.
+*/
+
+package org.apache.maven.mercury.repository.local.m2;
+
+import junit.framework.TestCase;
+
+import org.apache.maven.mercury.artifact.ArtifactMetadata;
+
+/**
+ *
+ *
+ * @author Oleg Gusakov
+ * @version $Id$
+ *
+ */
+public class ArtifactLocationtest
+    extends TestCase
+{
+
+    protected void setUp()
+        throws Exception
+    {
+    }
+    
+    public void testChopTS()
+    throws Exception
+    {
+        ArtifactLocation loc = new ArtifactLocation( "test", new ArtifactMetadata("a:a:3.0-alpha-1-20080920.015600-7") );
+        
+        String chop = loc.getVersionWithoutTS();
+        
+        assertEquals( "3.0-alpha-1", chop );
+
+        
+        loc = new ArtifactLocation( "test", new ArtifactMetadata("a:a:3.0-20080920.015600-7") );
+        
+        chop = loc.getVersionWithoutTS();
+        
+        assertEquals( "3.0", chop );
+
+
+        loc = new ArtifactLocation( "test", new ArtifactMetadata("a:a:3.0-20080920.0156007") );
+        
+        chop = loc.getVersionWithoutTS();
+        
+        assertEquals( "3.0-20080920.0156007", chop );
+    }
+    
+    public void testChopTSstatic()
+    throws Exception
+    {
+        String chop = ArtifactLocation.calculateVersionDir( "3.0-alpha-1-20080920.015600-7" );
+        
+        assertEquals( "3.0-alpha-1-SNAPSHOT", chop );
+
+        
+        chop = ArtifactLocation.calculateVersionDir( "3.0-20080920.015600-7" );
+        
+        assertEquals( "3.0-SNAPSHOT", chop );
+        
+
+        chop = ArtifactLocation.calculateVersionDir( "3.0-20080920.01560-7" );
+        
+        assertEquals( "3.0-20080920.01560-7", chop );
+
+        
+        chop = ArtifactLocation.calculateVersionDir( "3.0-20080920.015600" );
+        
+        assertEquals( "3.0-20080920.015600", chop );
+
+        
+        chop = ArtifactLocation.calculateVersionDir( "3.0" );
+        
+        assertEquals( "3.0", chop );
+
+    }
+
+
+}

Propchange: maven/mercury/trunk/mercury-core/src/test/java/org/apache/maven/mercury/repository/local/m2/ArtifactLocationtest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/mercury/trunk/mercury-core/src/test/java/org/apache/maven/mercury/repository/local/m2/ArtifactLocationtest.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: maven/mercury/trunk/mercury-core/src/test/java/org/apache/maven/mercury/repository/local/m2/LocalRepositoryM2Test.java
URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-core/src/test/java/org/apache/maven/mercury/repository/local/m2/LocalRepositoryM2Test.java?rev=767705&view=auto
==============================================================================
--- maven/mercury/trunk/mercury-core/src/test/java/org/apache/maven/mercury/repository/local/m2/LocalRepositoryM2Test.java (added)
+++ maven/mercury/trunk/mercury-core/src/test/java/org/apache/maven/mercury/repository/local/m2/LocalRepositoryM2Test.java Wed Apr 22 22:56:48 2009
@@ -0,0 +1,129 @@
+/**
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+package org.apache.maven.mercury.repository.local.m2;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.List;
+
+import junit.framework.TestCase;
+
+import org.apache.maven.mercury.artifact.Artifact;
+import org.apache.maven.mercury.artifact.ArtifactMetadata;
+import org.apache.maven.mercury.repository.api.ArtifactResults;
+
+/**
+ *
+ *
+ * @author Oleg Gusakov
+ * @version $Id$
+ *
+ */
+public class LocalRepositoryM2Test
+    extends TestCase
+{
+  File dir;
+  LocalRepositoryM2 repo;
+
+  /* (non-Javadoc)
+   * @see junit.framework.TestCase#setUp()
+   */
+  protected void setUp()
+      throws Exception
+  {
+    dir = new File("./target/test-classes/repoLocalM2");
+    
+    repo = new LocalRepositoryM2( "test", dir, new MetadataProcessorMock() );
+    
+  }
+  
+  
+  /**
+   * this does not fully test this use case, full test belongs to ITs. See http://jira.codehaus.org/browse/MERCURY-47
+   * 
+   * @throws Exception
+   */
+  public void testReadTwice()
+  throws Exception
+  {
+    String artifactId = "a:a:4";
+    
+    ArtifactMetadata bmd = new ArtifactMetadata(artifactId);
+    
+    ArrayList<ArtifactMetadata> q = new ArrayList<ArtifactMetadata>();
+    
+    q.add( bmd );
+    
+    ArtifactResults res = repo.getReader().readArtifacts( q );
+    
+    assertNotNull( res );
+    
+   assertFalse( res.hasExceptions() );
+   
+   assertTrue( res.hasResults() );
+   
+   List<Artifact> arts = res.getResults( bmd );
+   
+   assertNotNull( arts );
+   
+   assertEquals( 1, arts.size() );
+   
+   Artifact a = arts.get( 0 );
+   
+   assertNotNull( a );
+   
+   File f = a.getFile();
+   
+   assertNotNull( f );
+   
+   assertTrue( f.exists() );
+   
+   assertEquals( 14800, f.length() );
+   
+   // second time
+   
+   res = repo.getReader().readArtifacts( q );
+   
+   assertNotNull( res );
+   
+  assertFalse( res.hasExceptions() );
+  
+  assertTrue( res.hasResults() );
+  
+  arts = res.getResults( bmd );
+  
+  assertNotNull( arts );
+  
+  assertEquals( 1, arts.size() );
+  
+  a = arts.get( 0 );
+  
+  assertNotNull( a );
+  
+  f = a.getFile();
+  
+  assertNotNull( f );
+  
+  assertTrue( f.exists() );
+  
+  assertEquals( 14800, f.length() );
+  
+  }
+
+}

Propchange: maven/mercury/trunk/mercury-core/src/test/java/org/apache/maven/mercury/repository/local/m2/LocalRepositoryM2Test.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/mercury/trunk/mercury-core/src/test/java/org/apache/maven/mercury/repository/local/m2/LocalRepositoryM2Test.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: maven/mercury/trunk/mercury-core/src/test/java/org/apache/maven/mercury/repository/local/m2/MetadataProcessorMock.java
URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-core/src/test/java/org/apache/maven/mercury/repository/local/m2/MetadataProcessorMock.java?rev=767705&view=auto
==============================================================================
--- maven/mercury/trunk/mercury-core/src/test/java/org/apache/maven/mercury/repository/local/m2/MetadataProcessorMock.java (added)
+++ maven/mercury/trunk/mercury-core/src/test/java/org/apache/maven/mercury/repository/local/m2/MetadataProcessorMock.java Wed Apr 22 22:56:48 2009
@@ -0,0 +1,110 @@
+/**
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+package org.apache.maven.mercury.repository.local.m2;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.commons.digester.Digester;
+import org.apache.maven.mercury.artifact.ArtifactMetadata;
+import org.apache.maven.mercury.builder.api.DependencyProcessor;
+import org.apache.maven.mercury.builder.api.MetadataReader;
+import org.apache.maven.mercury.builder.api.MetadataReaderException;
+import org.xml.sax.SAXException;
+
+/**
+ * 
+ * a temporary thing to be replaced with real projectBuilder implementation
+ *
+ * @author Oleg Gusakov
+ * @version $Id$
+ *
+ */
+public class MetadataProcessorMock
+implements DependencyProcessor
+{
+
+  public List<ArtifactMetadata> getDependencies( ArtifactMetadata bmd, MetadataReader mdReader, Map env, Map sysProps )
+  throws MetadataReaderException
+  {
+    List<ArtifactMetadata> deps = null;
+    
+    try
+    {
+      byte [] pomBytes = mdReader.readMetadata( bmd, false );
+      if( pomBytes == null )
+      {
+        throw new MetadataReaderException("no metadata found for "+bmd);
+      }
+      deps = getDeps(  pomBytes );
+      
+      return deps;
+    }
+    catch( Exception e )
+    {
+      throw new MetadataReaderException( e );
+    }
+  }
+  
+  private static final List<ArtifactMetadata> getDeps( byte [] pom )
+  throws IOException, SAXException
+  {
+    if( pom == null )
+      return null;
+    
+    DependencyCreator dc = new DependencyCreator();
+    Digester digester = new Digester();
+    digester.push( dc );
+    
+    digester.addCallMethod("project/dependencies/dependency", "addMD", 6 );
+    digester.addCallParam("project/dependencies/dependency/groupId",0);
+    digester.addCallParam("project/dependencies/dependency/artifactId",1);
+    digester.addCallParam("project/dependencies/dependency/version",2);
+    digester.addCallParam("project/dependencies/dependency/type",3);
+    digester.addCallParam("project/dependencies/dependency/scope",4);
+    digester.addCallParam("project/dependencies/dependency/optional",5);
+    
+    digester.parse( new ByteArrayInputStream(pom) );
+    
+    return dc.mds;
+  }
+
+}
+//==============================================================================================
+class DependencyCreator
+{
+  List<ArtifactMetadata> mds = new ArrayList<ArtifactMetadata>(8);
+  
+  public void addMD( String g, String a, String v, String t, String s, String o)
+  {
+    ArtifactMetadata md = new ArtifactMetadata();
+    md.setGroupId(g);
+    md.setArtifactId(a);
+    md.setVersion(v);
+    md.setType(t);
+    md.setScope(s);
+    md.setOptional(o);
+
+    mds.add(md);
+  }
+}
+//==============================================================================================

Propchange: maven/mercury/trunk/mercury-core/src/test/java/org/apache/maven/mercury/repository/local/m2/MetadataProcessorMock.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/mercury/trunk/mercury-core/src/test/java/org/apache/maven/mercury/repository/local/m2/MetadataProcessorMock.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: maven/mercury/trunk/mercury-core/src/test/java/org/apache/maven/mercury/repository/local/map/LocalRepositoryMapTest.java
URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-core/src/test/java/org/apache/maven/mercury/repository/local/map/LocalRepositoryMapTest.java?rev=767705&view=auto
==============================================================================
--- maven/mercury/trunk/mercury-core/src/test/java/org/apache/maven/mercury/repository/local/map/LocalRepositoryMapTest.java (added)
+++ maven/mercury/trunk/mercury-core/src/test/java/org/apache/maven/mercury/repository/local/map/LocalRepositoryMapTest.java Wed Apr 22 22:56:48 2009
@@ -0,0 +1,114 @@
+/**
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+package org.apache.maven.mercury.repository.local.map;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import java.util.Map;
+
+import junit.framework.TestCase;
+
+import org.apache.maven.mercury.artifact.ArtifactMetadata;
+import org.apache.maven.mercury.builder.api.DependencyProcessor;
+import org.apache.maven.mercury.repository.api.MetadataResults;
+import org.apache.maven.mercury.repository.api.RepositoryReader;
+import org.apache.maven.mercury.repository.local.m2.MetadataProcessorMock;
+import org.apache.maven.mercury.util.FileUtil;
+
+/**
+ * @author Oleg Gusakov
+ * @version $Id$
+ */
+public class LocalRepositoryMapTest
+    extends TestCase
+{
+    Storage _storage;
+
+    File _dir;
+
+    LocalRepositoryMap _repo;
+    
+    RepositoryReader _rr;
+    
+    ArtifactMetadata bmd;
+    
+    File _pom;
+
+    @Override
+    protected void setUp()
+        throws Exception
+    {
+        bmd = new ArtifactMetadata("t:t:1.0::pom");
+        
+        _pom = new File("./target/test-classes/t-1.0.pom");
+
+        _dir = File.createTempFile( "temp-", "-mercury-default-storage" );
+        _dir.delete();
+        _storage = new DefaultStorage( _dir );
+        
+        _storage.add( bmd.getGAV(), _pom );
+        
+        DependencyProcessor dp = new MetadataProcessorMock();
+        
+        _repo = new LocalRepositoryMap("testMapRepo", dp, _storage );
+        
+        _rr = _repo.getReader();
+        
+    }
+
+    @Override
+    protected void tearDown()
+        throws Exception
+    {
+        FileUtil.delete( _dir );
+    }
+
+    public void testReadMap()
+        throws Exception
+    {
+        Collection<ArtifactMetadata> query = new ArrayList<ArtifactMetadata>(1);
+        
+        query.add( bmd );
+        
+        MetadataResults res = _rr.readDependencies( query  );
+        
+        assertNotNull( res );
+        
+        assertFalse( res.hasExceptions() );
+        
+        assertTrue( res.hasResults() );
+        
+        Map<ArtifactMetadata, List<ArtifactMetadata>>  deps = res.getResults();
+        
+        assertNotNull( deps );
+        
+        assertEquals( 1, deps.size() );
+        
+        List<ArtifactMetadata> myDeps = deps.get( bmd );
+        
+        assertNotNull( myDeps );
+        
+        assertEquals( 3, myDeps.size() );
+        
+        System.out.println( res.getResults() );
+    }
+
+}

Propchange: maven/mercury/trunk/mercury-core/src/test/java/org/apache/maven/mercury/repository/local/map/LocalRepositoryMapTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/mercury/trunk/mercury-core/src/test/java/org/apache/maven/mercury/repository/local/map/LocalRepositoryMapTest.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: maven/mercury/trunk/mercury-core/src/test/java/org/apache/maven/mercury/repository/metadata/MetadataBuilderTest.java
URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-core/src/test/java/org/apache/maven/mercury/repository/metadata/MetadataBuilderTest.java?rev=767705&view=auto
==============================================================================
--- maven/mercury/trunk/mercury-core/src/test/java/org/apache/maven/mercury/repository/metadata/MetadataBuilderTest.java (added)
+++ maven/mercury/trunk/mercury-core/src/test/java/org/apache/maven/mercury/repository/metadata/MetadataBuilderTest.java Wed Apr 22 22:56:48 2009
@@ -0,0 +1,497 @@
+/**
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+package org.apache.maven.mercury.repository.metadata;
+
+import java.io.ByteArrayInputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+import junit.framework.Assert;
+import junit.framework.TestCase;
+
+import org.apache.maven.mercury.util.FileUtil;
+import org.apache.maven.mercury.util.TimeUtil;
+import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
+
+/**
+ *
+ *
+ * @author Oleg Gusakov
+ * @version $Id$
+ *
+ */
+public class MetadataBuilderTest
+extends TestCase
+{
+  MetadataBuilder mb;
+  File testBase = new File("./target/test-classes/controlledRepoMd");
+
+  //-------------------------------------------------------------------------
+  @Override
+  protected void setUp()
+  throws Exception
+  {
+    File temp = new File( testBase, "group-maven-metadata-write.xml");
+    if( temp.exists() )
+      temp.delete();
+  }
+  //-------------------------------------------------------------------------
+  protected void tearDown()
+  throws Exception
+  {
+  }
+  
+	protected Metadata getMetadata(File file) 
+		throws Exception 
+	{
+		byte[] targetBytes = FileUtil.readRawData(file);
+
+		return MetadataBuilder.getMetadata(targetBytes);
+	}
+
+	protected Metadata applyOpsAndGetMetadata(Metadata metadata,
+			List<MetadataOperation> ops, File file) 
+		throws Exception 
+	{
+		byte[] resBytes = MetadataBuilder.changeMetadata(metadata, ops);
+
+		FileUtil.writeRawData(file, resBytes);
+
+		return MetadataBuilder.read(new FileInputStream(file));
+	}
+  
+  //-------------------------------------------------------------------------
+  public void testReadGroupMd()
+  throws FileNotFoundException, IOException, XmlPullParserException, MetadataException
+  {
+    File groupMd = new File( testBase, "group-maven-metadata.xml");
+     Metadata mmd = MetadataBuilder.read(  new FileInputStream( groupMd ) );
+
+     assertNotNull( mmd );
+     assertEquals("a", mmd.getGroupId() );
+     assertEquals("a", mmd.getArtifactId() );
+
+     assertNotNull( mmd.getVersioning() );
+    
+     List<String> versions = mmd.getVersioning().getVersions();
+    
+     assertNotNull( versions );
+     assertEquals( 4, versions.size() );
+  }
+  //-------------------------------------------------------------------------
+  public void testWriteGroupMd()
+  throws FileNotFoundException, IOException, XmlPullParserException, MetadataException
+  {
+    File groupMd = new File( testBase, "group-maven-metadata-write.xml");
+    Metadata md = new Metadata();
+    md.setGroupId( "a" );
+    md.setArtifactId( "a" );
+    md.setVersion( "1.0.0" );
+    Versioning v = new Versioning();
+    v.addVersion( "1.0.0" );
+    v.addVersion( "2.0.0" );
+    md.setVersioning( v );
+    
+     MetadataBuilder.write(  md, new FileOutputStream( groupMd ) );
+     Metadata mmd = MetadataBuilder.read( new FileInputStream(groupMd) );
+
+     assertNotNull( mmd );
+     assertEquals("a", mmd.getGroupId() );
+     assertEquals("a", mmd.getArtifactId() );
+     assertEquals("1.0.0", mmd.getVersion() );
+
+     assertNotNull( mmd.getVersioning() );
+    
+     List<String> versions = mmd.getVersioning().getVersions();
+    
+     assertNotNull( versions );
+     assertEquals( 2, versions.size() );
+  }
+  //-------------------------------------------------------------------------
+    public void testAddPluginOperation()
+        throws Exception
+    {
+        File mdFileBefore = new File( testBase, "group-maven-metadata.xml" );
+        Metadata mdBefore = getMetadata( mdFileBefore );
+
+        Plugin pluginA = new Plugin();
+        pluginA.setArtifactId( "maven-testa-plugin" );
+        pluginA.setName( "Some Plugin A" );
+        pluginA.setPrefix( "testa" );
+        Plugin pluginB = new Plugin();
+        pluginB.setArtifactId( "maven-testb-plugin" );
+        pluginB.setName( "Some Plugin B" );
+        pluginB.setPrefix( "testb" );
+        Plugin pluginC = new Plugin();
+        pluginC.setArtifactId( "maven-testc-plugin" );
+        pluginC.setName( "Some Plugin C" );
+        pluginC.setPrefix( "testc" );
+
+        List<MetadataOperation> opsAdd = new ArrayList<MetadataOperation>();
+
+        opsAdd.add( new AddPluginOperation( new PluginOperand( pluginC ) ) );
+        opsAdd.add( new AddPluginOperation( new PluginOperand( pluginB ) ) );
+        opsAdd.add( new AddPluginOperation( new PluginOperand( pluginA ) ) );
+
+        File mdFileAfter = new File( testBase, "group-maven-metadata-write.xml" );
+        Metadata mdAfterAdd = applyOpsAndGetMetadata( mdBefore, opsAdd, mdFileAfter );
+
+        assertEquals( 3, mdAfterAdd.getPlugins().size() );
+        assertEquals( "maven-testa-plugin", ( (Plugin) mdAfterAdd.getPlugins().get( 0 ) ).getArtifactId() );
+        assertEquals( "testa", ( (Plugin) mdAfterAdd.getPlugins().get( 0 ) ).getPrefix() );
+        assertEquals( "Some Plugin A", ( (Plugin) mdAfterAdd.getPlugins().get( 0 ) ).getName() );
+        assertEquals( "maven-testb-plugin", ( (Plugin) mdAfterAdd.getPlugins().get( 1 ) ).getArtifactId() );
+        assertEquals( "maven-testc-plugin", ( (Plugin) mdAfterAdd.getPlugins().get( 2 ) ).getArtifactId() );
+
+        List<MetadataOperation> opsRemove = new ArrayList<MetadataOperation>();
+
+        opsRemove.add( new RemovePluginOperation( new PluginOperand( pluginA ) ) );
+        opsRemove.add( new RemovePluginOperation( new PluginOperand( pluginB ) ) );
+        opsRemove.add( new RemovePluginOperation( new PluginOperand( pluginC ) ) );
+
+        Metadata mdAfterRemove = applyOpsAndGetMetadata( mdAfterAdd, opsRemove, mdFileAfter );
+
+        assertEquals( 0, mdAfterRemove.getPlugins().size() );
+    }
+    
+  //-------------------------------------------------------------------------
+  public void testMergeOperation()
+  throws FileNotFoundException, IOException, XmlPullParserException, MetadataException
+  {
+    File groupMd = new File( testBase, "group-maven-metadata.xml");
+    byte [] targetBytes = FileUtil.readRawData( groupMd );
+
+    Metadata source = new Metadata();
+    source.setGroupId( "a" );
+    source.setArtifactId( "a" );
+    source.setVersion( "1.0.0" );
+    Versioning v = new Versioning();
+    v.addVersion( "1.0.0" );
+    v.addVersion( "2.0.0" );
+    source.setVersioning( v );
+    
+    byte [] resBytes = MetadataBuilder.changeMetadata( targetBytes, new MergeOperation( new MetadataOperand(source) ) );
+    
+    File resFile = new File( testBase, "group-maven-metadata-write.xml");
+
+    FileUtil.writeRawData( resFile, resBytes );
+    
+     Metadata mmd = MetadataBuilder.read( new FileInputStream(resFile) );
+
+     assertNotNull( mmd );
+     assertEquals("a", mmd.getGroupId() );
+     assertEquals("a", mmd.getArtifactId() );
+     assertEquals("4", mmd.getVersion() );
+
+     assertNotNull( mmd.getVersioning() );
+    
+     List<String> versions = mmd.getVersioning().getVersions();
+    
+     assertNotNull( versions );
+     assertEquals( 6, versions.size() );
+     assertTrue( versions.contains("1") );
+     assertTrue( versions.contains("2") );
+     assertTrue( versions.contains("3") );
+     assertTrue( versions.contains("4") );
+     assertTrue( versions.contains("1.0.0") );
+     assertTrue( versions.contains("2.0.0") );
+  }
+  
+  public void testAddVersionOperationOrdered() throws Exception 
+  {
+    File mdFileBefore = new File(testBase, "group-maven-metadata.xml");
+    Metadata mdBefore = getMetadata( mdFileBefore );
+    
+    List<MetadataOperation> ops = new ArrayList<MetadataOperation>();
+    ops.add(new AddVersionOperation( new StringOperand("1.3.0-SNAPSHOT") ));
+    ops.add(new AddVersionOperation( new StringOperand("1.2.0-SNAPSHOT") ));
+    ops.add(new AddVersionOperation( new StringOperand("1.2.0.5-SNAPSHOT") ));
+    ops.add(new AddVersionOperation( new StringOperand("1.0.1") ));
+    ops.add(new AddVersionOperation( new StringOperand("1.0.3-SNAPSHOT") ));
+    ops.add(new AddVersionOperation( new StringOperand("1.1-M1") ));
+    ops.add(new AddVersionOperation( new StringOperand("1.0.0-alpha-5") ));
+    ops.add(new AddVersionOperation( new StringOperand("1.2.0") ));
+    ops.add(new AddVersionOperation( new StringOperand("1.2.0-beta-1") ));
+    ops.add(new AddVersionOperation( new StringOperand("1.0.0.1") ));
+    ops.add(new AddVersionOperation( new StringOperand("1.0.0-beta-3") ));
+    ops.add(new AddVersionOperation( new StringOperand("4.1.0") ));
+    ops.add(new AddVersionOperation( new StringOperand("1.0.0-beta-6-SNAPSHOT") ));
+    ops.add(new AddVersionOperation( new StringOperand("5.0-SNAPSHOT") ));
+
+    List<String> orderedVersions = new ArrayList<String>();
+    orderedVersions.add( "1.0.0-alpha-5" );
+    orderedVersions.add( "1.0.0-beta-3" );
+    orderedVersions.add( "1.0.0-beta-6-SNAPSHOT" );
+    orderedVersions.add( "1" );
+    orderedVersions.add( "1.0.0.1" );
+    orderedVersions.add( "1.0.1" );
+    orderedVersions.add( "1.0.3-SNAPSHOT" );
+    orderedVersions.add( "1.1-M1" );
+    orderedVersions.add( "1.2.0-SNAPSHOT" );
+    orderedVersions.add( "1.2.0-beta-1" );
+    orderedVersions.add( "1.2.0" );
+    orderedVersions.add( "1.2.0.5-SNAPSHOT" );
+    orderedVersions.add( "1.3.0-SNAPSHOT" );
+    orderedVersions.add( "2" );
+    orderedVersions.add( "3" );
+    orderedVersions.add( "4" );
+    orderedVersions.add( "4.1.0" );
+    orderedVersions.add( "5.0-SNAPSHOT" );
+    
+    File mdFileAfter = new File( testBase, "group-maven-metadata-write.xml");
+    Metadata mdAfter = applyOpsAndGetMetadata( mdBefore, ops, mdFileAfter );
+    
+    Assert.assertEquals(orderedVersions, mdAfter.getVersioning().getVersions());
+    Assert.assertEquals("5.0-SNAPSHOT", mdAfter.getVersioning().getLatest());
+    Assert.assertEquals("4.1.0", mdAfter.getVersioning().getRelease());
+    
+  }
+  
+  //-------------------------------------------------------------------------
+  public void testAddVersionOperation()
+  throws Exception
+  {
+	 // prepare
+	 File groupMd = new File( testBase, "group-maven-metadata.xml");
+	    
+	 Metadata md = getMetadata(groupMd);
+	    
+	 List<MetadataOperation> ops = new ArrayList<MetadataOperation>();
+	    
+	 ops.add(new AddVersionOperation( new StringOperand("5")));
+   
+     File resFile = new File( testBase, "group-maven-metadata-write.xml");
+    
+     // do
+     Metadata mmd = applyOpsAndGetMetadata( md, ops, resFile);
+
+     // assert
+     assertNotNull( mmd );
+     assertEquals("a", mmd.getGroupId() );
+     assertEquals("a", mmd.getArtifactId() );
+     assertEquals("4", mmd.getVersion() );
+
+     assertNotNull( mmd.getVersioning() );
+    
+     List<String> versions = mmd.getVersioning().getVersions();
+    
+     assertNotNull( versions );
+     assertEquals( 5, versions.size() );
+     assertTrue( versions.contains("1") );
+     assertTrue( versions.contains("2") );
+     assertTrue( versions.contains("3") );
+     assertTrue( versions.contains("4") );
+     assertTrue( versions.contains("5") );
+  }
+  //-------------------------------------------------------------------------
+  public void testAddVersionTwiceOperation()
+  throws Exception
+  {
+    File groupMd = new File( testBase, "group-maven-metadata.xml");
+    
+    Metadata checkMd = getMetadata(groupMd);
+
+    assertNotNull( checkMd );
+    assertEquals("a", checkMd.getGroupId() );
+    assertEquals("a", checkMd.getArtifactId() );
+    assertEquals("4", checkMd.getVersion() );
+
+    assertNotNull( checkMd.getVersioning() );
+    
+    List<String> checkVersions = checkMd.getVersioning().getVersions();
+   
+    assertNotNull( checkVersions );
+    assertEquals( 4, checkVersions.size() );
+    assertTrue( checkVersions.contains("1") );
+    assertTrue( checkVersions.contains("2") );
+    assertTrue( checkVersions.contains("3") );
+    assertTrue( checkVersions.contains("4") );
+    assertFalse( checkVersions.contains("5") );
+    
+    List<MetadataOperation> ops = new ArrayList<MetadataOperation>();
+    ops.add( new AddVersionOperation( new StringOperand("5") ) );
+    ops.add( new AddVersionOperation( new StringOperand("5") ) );
+
+    
+    File resFile = new File( testBase, "group-maven-metadata-write.xml");
+
+     Metadata mmd = applyOpsAndGetMetadata(checkMd, ops, resFile);
+
+     assertNotNull( mmd );
+     assertEquals("a", mmd.getGroupId() );
+     assertEquals("a", mmd.getArtifactId() );
+     assertEquals("4", mmd.getVersion() );
+
+     assertNotNull( mmd.getVersioning() );
+    
+     List<String> versions = mmd.getVersioning().getVersions();
+    
+     assertNotNull( versions );
+     assertEquals( 5, versions.size() );
+     assertTrue( versions.contains("1") );
+     assertTrue( versions.contains("2") );
+     assertTrue( versions.contains("3") );
+     assertTrue( versions.contains("4") );
+     assertTrue( versions.contains("5") );
+  }
+  //-------------------------------------------------------------------------
+  public void testRemoveVersionOperation()
+  throws FileNotFoundException, IOException, XmlPullParserException, MetadataException
+  {
+    File groupMd = new File( testBase, "group-maven-metadata.xml");
+    byte [] targetBytes = FileUtil.readRawData( groupMd );
+
+    byte [] resBytes = MetadataBuilder.changeMetadata( targetBytes, new RemoveVersionOperation( new StringOperand("1") ) );
+    
+    File resFile = new File( testBase, "group-maven-metadata-write.xml");
+
+    FileUtil.writeRawData( resFile, resBytes );
+    
+     Metadata mmd = MetadataBuilder.read( new FileInputStream(resFile) );
+
+     assertNotNull( mmd );
+     assertEquals("a", mmd.getGroupId() );
+     assertEquals("a", mmd.getArtifactId() );
+     assertEquals("4", mmd.getVersion() );
+
+     assertNotNull( mmd.getVersioning() );
+    
+     List<String> versions = mmd.getVersioning().getVersions();
+    
+     assertNotNull( versions );
+     assertEquals( 3, versions.size() );
+     assertTrue( !versions.contains("1") );
+     assertTrue( versions.contains("2") );
+     assertTrue( versions.contains("3") );
+     assertTrue( versions.contains("4") );
+  }
+  
+  public void testSetSnapshotVersionOperation()
+  throws Exception
+  {
+	  File mdFileBefore = new File(testBase, "group-maven-metadata.xml");
+	  Metadata mdBefore = getMetadata( mdFileBefore );
+	  
+	  mdBefore.setVersion("1.3.0-SNAPSHOT");
+	  
+	  List<MetadataOperation> ops = new ArrayList<MetadataOperation>();
+	  ops.add( new SetSnapshotOperation( new StringOperand( "a-1.3.0-20090210.041603-374.pom" ) ) );
+	  ops.add( new SetSnapshotOperation( new StringOperand( "a-1.3.0-20090210.030701-373.pom" ) ) );
+	  ops.add( new SetSnapshotOperation( new StringOperand( "a-1.3.0-20090210.090218-375.pom" ) ) );
+	  ops.add( new SetSnapshotOperation( new StringOperand( "a-1.3.0-20090210.095716-376.pom" ) ) );
+	  
+	  File mdFileAfter = new File( testBase, "group-maven-metadata-write.xml");
+	  Metadata mdAfter = applyOpsAndGetMetadata( mdBefore, ops, mdFileAfter );
+	  
+	  Assert.assertEquals("20090210.095716", mdAfter.getVersioning().getSnapshot().getTimestamp());
+	  Assert.assertEquals(376, mdAfter.getVersioning().getSnapshot().getBuildNumber());
+  }
+  
+  
+  //-------------------------------------------------------------------------
+  public void testSetSnapshotOperation()
+  throws FileNotFoundException, IOException, XmlPullParserException, MetadataException
+  {
+    File groupMd = new File( testBase, "group-maven-metadata.xml");
+    byte [] targetBytes = FileUtil.readRawData( groupMd );
+    
+    Snapshot sn = new Snapshot();
+    sn.setLocalCopy( false );
+    sn.setBuildNumber( 35 );
+    String ts = TimeUtil.getUTCTimestamp();
+    sn.setTimestamp( ts );
+
+    byte [] resBytes = MetadataBuilder.changeMetadata( targetBytes, new SetSnapshotOperation( new SnapshotOperand(sn) ) );
+    
+    File resFile = new File( testBase, "group-maven-metadata-write.xml");
+
+    FileUtil.writeRawData( resFile, resBytes );
+    
+     Metadata mmd = MetadataBuilder.read( new FileInputStream(resFile) );
+
+     assertNotNull( mmd );
+     assertEquals("a", mmd.getGroupId() );
+     assertEquals("a", mmd.getArtifactId() );
+     assertEquals("4", mmd.getVersion() );
+
+     assertNotNull( mmd.getVersioning() );
+     Snapshot snapshot = mmd.getVersioning().getSnapshot();
+     assertNotNull( snapshot );
+     assertEquals( ts, snapshot.getTimestamp() );
+     
+     // now let's drop sn
+     targetBytes = FileUtil.readRawData( resFile );
+     resBytes = MetadataBuilder.changeMetadata( targetBytes, new SetSnapshotOperation( new SnapshotOperand(null) ) );
+     
+     Metadata mmd2 = MetadataBuilder.read( new ByteArrayInputStream(resBytes) );
+
+     assertNotNull( mmd2 );
+     assertEquals("a", mmd2.getGroupId() );
+     assertEquals("a", mmd2.getArtifactId() );
+     assertEquals("4", mmd2.getVersion() );
+
+     assertNotNull( mmd2.getVersioning() );
+     
+     snapshot = mmd2.getVersioning().getSnapshot();
+     assertNull( snapshot );
+  }
+  //-------------------------------------------------------------------------
+  public void testMultipleOperations()
+  throws FileNotFoundException, IOException, XmlPullParserException, MetadataException
+  {
+    File groupMd = new File( testBase, "group-maven-metadata.xml");
+    byte [] targetBytes = FileUtil.readRawData( groupMd );
+
+    ArrayList<MetadataOperation> ops = new ArrayList<MetadataOperation>(2);
+    ops.add( new RemoveVersionOperation( new StringOperand("1") ) );
+    ops.add( new AddVersionOperation( new StringOperand("8") ) );
+    
+    byte [] resBytes = MetadataBuilder.changeMetadata( targetBytes, ops  );
+    
+    File resFile = new File( testBase, "group-maven-metadata-write.xml");
+
+    FileUtil.writeRawData( resFile, resBytes );
+    
+     Metadata mmd = MetadataBuilder.read( new FileInputStream(resFile) );
+
+     assertNotNull( mmd );
+     assertEquals("a", mmd.getGroupId() );
+     assertEquals("a", mmd.getArtifactId() );
+     assertEquals("4", mmd.getVersion() );
+
+     assertNotNull( mmd.getVersioning() );
+    
+     List<String> versions = mmd.getVersioning().getVersions();
+    
+     assertNotNull( versions );
+     assertEquals( 4, versions.size() );
+     assertTrue( !versions.contains("1") );
+     assertTrue( versions.contains("2") );
+     assertTrue( versions.contains("3") );
+     assertTrue( versions.contains("4") );
+     assertTrue( versions.contains("8") );
+  }
+  //-------------------------------------------------------------------------
+  //-------------------------------------------------------------------------
+}

Propchange: maven/mercury/trunk/mercury-core/src/test/java/org/apache/maven/mercury/repository/metadata/MetadataBuilderTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/mercury/trunk/mercury-core/src/test/java/org/apache/maven/mercury/repository/metadata/MetadataBuilderTest.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: maven/mercury/trunk/mercury-core/src/test/java/org/apache/maven/mercury/repository/remote/m2/RemoteRepositoryUtilM2Test.java
URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-core/src/test/java/org/apache/maven/mercury/repository/remote/m2/RemoteRepositoryUtilM2Test.java?rev=767705&view=auto
==============================================================================
--- maven/mercury/trunk/mercury-core/src/test/java/org/apache/maven/mercury/repository/remote/m2/RemoteRepositoryUtilM2Test.java (added)
+++ maven/mercury/trunk/mercury-core/src/test/java/org/apache/maven/mercury/repository/remote/m2/RemoteRepositoryUtilM2Test.java Wed Apr 22 22:56:48 2009
@@ -0,0 +1,48 @@
+/**
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+package org.apache.maven.mercury.repository.remote.m2;
+
+import java.io.File;
+
+import junit.framework.TestCase;
+
+/**
+ *
+ *
+ * @author Oleg Gusakov
+ * @version $Id$
+ *
+ */
+public class RemoteRepositoryUtilM2Test
+    extends TestCase
+{
+  public void testFlipFolder()
+  {
+    File repo = new File("./target/test-classes/localTestRepoRemoteM2");
+    
+    RepositoryUtilM2.flipLocalFolderToRemoteRepository( repo );
+    
+    File ga = new File( repo, "org/apache/maven/mercury/mercury-pom/maven-metadata.xml");
+    
+    assertTrue( ga.exists() );
+    
+    File gav = new File( repo, "org/apache/maven/mercury/mercury-pom/1.0.0-alpha-2-SNAPSHOT/maven-metadata.xml");
+    
+  }
+}

Propchange: maven/mercury/trunk/mercury-core/src/test/java/org/apache/maven/mercury/repository/remote/m2/RemoteRepositoryUtilM2Test.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/mercury/trunk/mercury-core/src/test/java/org/apache/maven/mercury/repository/remote/m2/RemoteRepositoryUtilM2Test.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: maven/mercury/trunk/mercury-core/src/test/java/org/apache/maven/mercury/repository/virtual/VirtualRepositoryReaderTest.java
URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-core/src/test/java/org/apache/maven/mercury/repository/virtual/VirtualRepositoryReaderTest.java?rev=767705&view=auto
==============================================================================
--- maven/mercury/trunk/mercury-core/src/test/java/org/apache/maven/mercury/repository/virtual/VirtualRepositoryReaderTest.java (added)
+++ maven/mercury/trunk/mercury-core/src/test/java/org/apache/maven/mercury/repository/virtual/VirtualRepositoryReaderTest.java Wed Apr 22 22:56:48 2009
@@ -0,0 +1,280 @@
+/**
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+package org.apache.maven.mercury.repository.virtual;
+
+import java.io.File;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+import junit.framework.TestCase;
+
+import org.apache.maven.mercury.artifact.Artifact;
+import org.apache.maven.mercury.artifact.ArtifactMetadata;
+import org.apache.maven.mercury.artifact.DefaultArtifact;
+import org.apache.maven.mercury.event.EventManager;
+import org.apache.maven.mercury.event.MercuryEvent;
+import org.apache.maven.mercury.event.MercuryEventListener;
+import org.apache.maven.mercury.event.MercuryEvent.EventMask;
+import org.apache.maven.mercury.repository.api.MetadataResults;
+import org.apache.maven.mercury.repository.api.ArtifactResults;
+import org.apache.maven.mercury.repository.api.LocalRepository;
+import org.apache.maven.mercury.repository.api.RemoteRepository;
+import org.apache.maven.mercury.repository.api.Repository;
+import org.apache.maven.mercury.repository.local.m2.LocalRepositoryM2;
+import org.apache.maven.mercury.repository.local.m2.MetadataProcessorMock;
+import org.apache.maven.mercury.repository.remote.m2.RemoteRepositoryM2;
+import org.apache.maven.mercury.spi.http.server.HttpTestServer;
+import org.apache.maven.mercury.transport.api.Server;
+import org.apache.maven.mercury.util.FileUtil;
+import org.apache.maven.mercury.util.Util;
+
+/**
+ * @author Oleg Gusakov
+ * @version $Id$
+ */
+public class VirtualRepositoryReaderTest
+    extends TestCase
+{
+    File _testBase;
+
+    LocalRepository _localRepo;
+
+    RemoteRepository _remoteRepo;
+
+    VirtualRepositoryReader _vr;
+
+    // String _remoteUrl; // = "http://people.apache.org/~ogusakov/repos/test";
+    String _artifactCoordSn = "org.apache.maven.mercury:mercury-repo-virtual:1.0.0-alpha-2-SNAPSHOT";
+
+    String _artifactCoordLatest = "org.apache.maven.mercury:mercury-repo-virtual:1.0.0-alpha-2-LATEST";
+
+    String _artifactCoordRelease = "ant:ant:1.6.5";
+    
+    String LOCAL_REPO_ID = "localRepo";
+
+    String _localRepoId;
+
+    String REMOTE_REPO_ID = "remoteRepo";
+
+    String _remoteRepoId;
+
+    HttpTestServer _jetty;
+
+    String _port;
+
+    File _remoteRepoBase = new File( "./target/test-classes/remoteRepoVirtual" );
+
+    @Override
+    protected void setUp()
+        throws Exception
+    {
+
+        if ( Util.isWindows() )
+        {
+            Thread.sleep( 2000L );
+        }
+
+        _testBase = new File( "./target/repoVirtual" );
+        FileUtil.delete( _testBase );
+
+        // windows does not like it
+        if ( !Util.isWindows() && _testBase.exists() )
+        {
+            throw new Exception( "cannot clean folder " + _testBase.getAbsolutePath() );
+        }
+
+        _testBase.mkdirs();
+        FileUtil.copy( new File( "./src/test/resources/repoVirtual" ), _testBase, false );
+
+        if ( !_testBase.exists() || !_testBase.isDirectory() )
+        {
+            throw new Exception( "cannot create clean folder " + _testBase.getAbsolutePath() );
+        }
+
+        _localRepo = new LocalRepositoryM2( LOCAL_REPO_ID, _testBase, new MetadataProcessorMock() );
+        
+        _localRepoId = _localRepo.getId();
+
+        _jetty = new HttpTestServer( _remoteRepoBase, "/repo" );
+        _jetty.start();
+        _port = String.valueOf( _jetty.getPort() );
+        Server server = new Server( REMOTE_REPO_ID, new URL( "http://localhost:" + _port + "/repo" ) );
+
+        _remoteRepo = new RemoteRepositoryM2( server, new MetadataProcessorMock() );
+        
+        _remoteRepoId = _remoteRepo.getId();
+
+        if ( Util.isWindows() )
+        {
+            Thread.sleep( 2000L );
+        }
+
+        List<Repository> rl = new ArrayList<Repository>();
+        rl.add( _localRepo );
+        rl.add( _remoteRepo );
+
+        _vr = new VirtualRepositoryReader( rl );
+        
+        
+    }
+
+    @Override
+    protected void tearDown()
+        throws Exception
+    {
+        super.tearDown();
+        if ( _jetty != null )
+        {
+        }
+        if ( _vr != null )
+        {
+            _vr.close();
+        }
+    }
+
+    public void testReadSnapshot()
+        throws Exception
+    {
+        ArtifactMetadata bmd = new ArtifactMetadata( _artifactCoordSn );
+        List<ArtifactMetadata> q = new ArrayList<ArtifactMetadata>();
+        q.add( bmd );
+
+        ArtifactResults res = _vr.readArtifacts( q );
+
+        assertNotNull( res );
+
+        assertFalse( res.hasExceptions() );
+
+        assertTrue( res.hasResults() );
+
+        assertTrue( res.hasResults( bmd ) );
+
+        Map<ArtifactMetadata, List<Artifact>> m = res.getResults();
+
+        List<Artifact> al = m.get( bmd );
+
+        Artifact a = al.get( 0 );
+
+        assertTrue( bmd.getGroupId().equals( a.getGroupId() ) );
+        assertTrue( bmd.getArtifactId().equals( a.getArtifactId() ) );
+
+        assertTrue( a.getVersion().matches( Artifact.SNAPSHOT_TS_REGEX ) );
+
+        byte[] pomBytes = a.getPomBlob();
+
+        assertTrue( pomBytes != null );
+
+        assertEquals( 795, pomBytes.length );
+
+        File ab = a.getFile();
+
+        assertNotNull( ab );
+
+        assertTrue( ab.exists() );
+
+        assertEquals( 6162, ab.length() );
+    }
+
+    public void testWrite()
+        throws Exception
+    {
+        Artifact a = new DefaultArtifact( new ArtifactMetadata( "a:a:1.0:text:txt" ) );
+        File bin = File.createTempFile( "vr-", "-test.txt" );
+        bin.deleteOnExit();
+        FileUtil.writeRawData( bin, "test" );
+        a.setFile( bin );
+
+        List<Artifact> arts = new ArrayList<Artifact>();
+        arts.add( a );
+
+        _localRepo.getWriter().writeArtifacts( arts );
+
+        File af = new File( _testBase, "a/a/1.0/a-1.0-text.txt" );
+
+        assertTrue( af.exists() );
+
+        assertEquals( 4, af.length() );
+
+    }
+
+    public void testReadRelease()
+        throws Exception
+    {
+        ArtifactMetadata bmd = new ArtifactMetadata( _artifactCoordRelease );
+        List<ArtifactMetadata> q = new ArrayList<ArtifactMetadata>();
+        q.add( bmd );
+
+        Listener l = new Listener();
+        _vr.register( l );
+
+        MetadataResults res = _vr.readVersions( q );
+
+        assertNotNull( res );
+
+        assertFalse( res.hasExceptions() );
+
+        assertTrue( res.hasResults() );
+
+        assertTrue( res.hasResults( bmd ) );
+
+        // let events propagate
+        Thread.sleep( 2000L );
+
+        assertTrue( l.localEventCount > 0 );
+
+        assertEquals( 0, l.remoteEventCount );
+
+    }
+
+    // ========================================================================
+    class Listener
+        implements MercuryEventListener
+    {
+
+        int localEventCount = 0;
+
+        int remoteEventCount = 0;
+
+        public void fire( MercuryEvent event )
+        {
+            String tag = event.getInfo();
+
+            if ( _localRepoId.equals( tag ) )
+            {
+                ++localEventCount;
+            }
+            else if ( _remoteRepoId.equals( tag ) )
+            {
+                ++remoteEventCount;
+            }
+
+ System.out.println(EventManager.toString( event ));
+ System.out.flush();
+        }
+
+        public EventMask getMask()
+        {
+            return null;
+        }
+
+    }
+
+}

Propchange: maven/mercury/trunk/mercury-core/src/test/java/org/apache/maven/mercury/repository/virtual/VirtualRepositoryReaderTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/mercury/trunk/mercury-core/src/test/java/org/apache/maven/mercury/repository/virtual/VirtualRepositoryReaderTest.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision