1 package org.apache.archiva.metadata.repository.storage.maven2;
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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
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;
32 import java.util.Arrays;
33 import org.apache.archiva.test.utils.ArchivaBlockJUnit4ClassRunner;
36 * RepositoryMetadataReaderTest
40 @RunWith( ArchivaBlockJUnit4ClassRunner.class )
41 public class MavenRepositoryMetadataReaderTest
44 private File defaultRepoDir;
47 public void testGroupMetadata()
50 File metadataFile = new File( defaultRepoDir, "org/apache/maven/plugins/maven-metadata.xml" );
52 ArchivaRepositoryMetadata metadata = MavenMetadataReader.read( metadataFile );
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() );
63 Plugin cleanPlugin = new Plugin();
64 cleanPlugin.setPrefix( "clean" );
65 cleanPlugin.setArtifactId( "maven-clean-plugin" );
66 cleanPlugin.setName( "Maven Clean Plugin" );
68 Plugin compilerPlugin = new Plugin();
69 compilerPlugin.setPrefix( "compiler" );
70 compilerPlugin.setArtifactId( "maven-compiler-plugin" );
71 compilerPlugin.setName( "Maven Compiler Plugin" );
73 Plugin surefirePlugin = new Plugin();
74 surefirePlugin.setPrefix( "surefire" );
75 surefirePlugin.setArtifactId( "maven-surefire-plugin" );
76 surefirePlugin.setName( "Maven Surefire Plugin" );
78 assertEquals( Arrays.asList( cleanPlugin, compilerPlugin, surefirePlugin ), metadata.getPlugins() );
82 public void testProjectMetadata()
85 File metadataFile = new File( defaultRepoDir, "org/apache/maven/shared/maven-downloader/maven-metadata.xml" );
87 ArchivaRepositoryMetadata metadata = MavenMetadataReader.read( metadataFile );
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() );
100 public void testProjectVersionMetadata()
103 File metadataFile = new File( defaultRepoDir, "org/apache/apache/5-SNAPSHOT/maven-metadata.xml" );
105 ArchivaRepositoryMetadata metadata = MavenMetadataReader.read( metadataFile );
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() );
124 defaultRepoDir = new File( "target/test-repository" );