View Javadoc
1   package org.apache.archiva.metadata.repository.storage.maven2;
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 junit.framework.TestCase;
23  import org.apache.archiva.maven2.metadata.MavenMetadataReader;
24  import org.apache.archiva.model.ArchivaRepositoryMetadata;
25  import org.apache.archiva.model.Plugin;
26  import org.apache.archiva.xml.XMLException;
27  import org.junit.Before;
28  import org.junit.Test;
29  import org.junit.runner.RunWith;
30  
31  import java.io.File;
32  import java.util.Arrays;
33  import org.apache.archiva.test.utils.ArchivaBlockJUnit4ClassRunner;
34  
35  /**
36   * RepositoryMetadataReaderTest
37   *
38   *
39   */
40  @RunWith( ArchivaBlockJUnit4ClassRunner.class )
41  public class MavenRepositoryMetadataReaderTest
42      extends TestCase
43  {
44      private File defaultRepoDir;
45  
46      @Test
47      public void testGroupMetadata()
48          throws XMLException
49      {
50          File metadataFile = new File( defaultRepoDir, "org/apache/maven/plugins/maven-metadata.xml" );
51  
52          ArchivaRepositoryMetadata metadata = MavenMetadataReader.read( metadataFile );
53  
54          assertNotNull( metadata );
55          assertEquals( "org.apache.maven.plugins", metadata.getGroupId() );
56          assertNull( metadata.getArtifactId() );
57          assertNull( metadata.getReleasedVersion() );
58          assertNull( metadata.getLatestVersion() );
59          assertTrue( metadata.getAvailableVersions().isEmpty() );
60          assertNull( metadata.getSnapshotVersion() );
61          assertNull( metadata.getLastUpdated() );
62  
63          Plugin cleanPlugin = new Plugin();
64          cleanPlugin.setPrefix( "clean" );
65          cleanPlugin.setArtifactId( "maven-clean-plugin" );
66          cleanPlugin.setName( "Maven Clean Plugin" );
67  
68          Plugin compilerPlugin = new Plugin();
69          compilerPlugin.setPrefix( "compiler" );
70          compilerPlugin.setArtifactId( "maven-compiler-plugin" );
71          compilerPlugin.setName( "Maven Compiler Plugin" );
72  
73          Plugin surefirePlugin = new Plugin();
74          surefirePlugin.setPrefix( "surefire" );
75          surefirePlugin.setArtifactId( "maven-surefire-plugin" );
76          surefirePlugin.setName( "Maven Surefire Plugin" );
77  
78          assertEquals( Arrays.asList( cleanPlugin, compilerPlugin, surefirePlugin ), metadata.getPlugins() );
79      }
80  
81      @Test
82      public void testProjectMetadata()
83          throws XMLException
84      {
85          File metadataFile = new File( defaultRepoDir, "org/apache/maven/shared/maven-downloader/maven-metadata.xml" );
86  
87          ArchivaRepositoryMetadata metadata = MavenMetadataReader.read( metadataFile );
88  
89          assertNotNull( metadata );
90          assertEquals( "org.apache.maven.shared", metadata.getGroupId() );
91          assertEquals( "maven-downloader", metadata.getArtifactId() );
92          assertEquals( "1.1", metadata.getReleasedVersion() );
93          assertNull( metadata.getLatestVersion() );
94          assertEquals( Arrays.asList( "1.0", "1.1" ), metadata.getAvailableVersions() );
95          assertNull( metadata.getSnapshotVersion() );
96          assertEquals( "20061212214311", metadata.getLastUpdated() );
97      }
98  
99      @Test
100     public void testProjectVersionMetadata()
101         throws XMLException
102     {
103         File metadataFile = new File( defaultRepoDir, "org/apache/apache/5-SNAPSHOT/maven-metadata.xml" );
104 
105         ArchivaRepositoryMetadata metadata = MavenMetadataReader.read( metadataFile );
106 
107         assertNotNull( metadata );
108         assertEquals( "org.apache", metadata.getGroupId() );
109         assertEquals( "apache", metadata.getArtifactId() );
110         assertNull( metadata.getReleasedVersion() );
111         assertNull( metadata.getLatestVersion() );
112         assertTrue( metadata.getAvailableVersions().isEmpty() );
113         assertNotNull( metadata.getSnapshotVersion() );
114         assertEquals( "20080801.151215", metadata.getSnapshotVersion().getTimestamp() );
115         assertEquals( 1, metadata.getSnapshotVersion().getBuildNumber() );
116         assertEquals( "20080801151215", metadata.getLastUpdated() );
117     }
118 
119     @Before
120     @Override
121     public void setUp()
122         throws Exception
123     {
124         super.setUp();
125         defaultRepoDir = new File( "target/test-repository" );
126     }
127 }