View Javadoc
1   package org.apache.maven.plugins.stage;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import org.codehaus.plexus.PlexusTestCase;
23  import org.codehaus.plexus.util.FileUtils;
24  import org.codehaus.plexus.util.IOUtil;
25  import org.apache.maven.artifact.repository.metadata.io.xpp3.MetadataXpp3Reader;
26  import org.apache.maven.artifact.repository.metadata.Metadata;
27  import org.apache.maven.wagon.repository.Repository;
28  
29  import java.io.File;
30  import java.io.Reader;
31  import java.io.FileReader;
32  import java.util.List;
33  
34  /** @author Jason van Zyl */
35  public class RepositoryCopierTest
36      extends PlexusTestCase
37  {
38      private String version = "2.0.6";
39  
40      private MetadataXpp3Reader reader = new MetadataXpp3Reader();
41  
42      public void testCopy()
43          throws Exception
44      {
45          RepositoryCopier copier = (RepositoryCopier) lookup( RepositoryCopier.ROLE );
46  
47          File targetRepoSource = new File( getBasedir(), "src/test/target-repository" );
48  
49          File targetRepo = new File( getBasedir(), "target/target-repository" );
50  
51          System.out.println( "Copying target stage for tests ..." );
52  
53          FileUtils.copyDirectoryStructure( targetRepoSource, targetRepo );
54  
55          File stagingRepo = new File( getBasedir(), "src/test/staging-repository" );
56  
57          Repository sourceRepository = new Repository( "source", "file://" + stagingRepo );
58          Repository targetRepository = new Repository( "target", "scp://localhost/" + targetRepo );
59  
60          copier.copy( sourceRepository, targetRepository, version );
61  
62          String s[] = {
63              "maven",
64              "maven-artifact",
65              "maven-artifact-manager",
66              "maven-artifact-test",
67              "maven-core",
68              "maven-error-diagnostics",
69              "maven-model",
70              "maven-monitor",
71              "maven-plugin-api",
72              "maven-plugin-descriptor",
73              "maven-plugin-parameter-documenter",
74              "maven-plugin-registry",
75              "maven-profile",
76              "maven-project",
77              "maven-repository-metadata",
78              "maven-script",
79              "maven-script-ant",
80              "maven-script-beanshell",
81              "maven-settings" };
82  
83          for (String value : s) {
84              testMavenArtifact(targetRepo, value);
85          }
86  
87          // leave something behind to clean it up.
88  
89          // Test merging
90  
91          // Test MD5
92  
93          // Test SHA1
94  
95          // Test new artifacts are present
96      }
97  
98      private void testMavenArtifact( File repo, String artifact )
99          throws Exception
100     {
101         File basedir = new File( repo, "org/apache/maven/" + artifact );
102 
103         File versionDir = new File( basedir, version );
104 
105         assertTrue( versionDir.exists() );
106 
107         Reader r = new FileReader( new File( basedir, RepositoryCopier.MAVEN_METADATA) );
108 
109         Metadata metadata = reader.read( r );
110 
111         // Make sure our new versions has been setup as the release.
112         assertEquals( version, metadata.getVersioning().getRelease() );
113 
114         assertEquals( "20070327020553", metadata.getVersioning().getLastUpdated() );
115 
116         // Make sure we didn't whack old versions.
117         List versions = metadata.getVersioning().getVersions();
118 
119         assertTrue( versions.contains( "2.0.1" ) );
120 
121         assertTrue( versions.contains( "2.0.2" ) );
122 
123         assertTrue( versions.contains( "2.0.3" ) );
124         
125         assertTrue( versions.contains( "2.0.4" ) );
126 
127         assertTrue( versions.contains( "2.0.5" ) );
128 
129         IOUtil.close( r );
130     }
131 }