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.repository.metadata.RepositoryMetadataException;
27 import org.apache.archiva.test.utils.ArchivaBlockJUnit4ClassRunner;
28 import org.junit.Before;
29 import org.junit.Test;
30 import org.junit.runner.RunWith;
32 import java.nio.file.Path;
33 import java.nio.file.Paths;
34 import java.util.Arrays;
37 * RepositoryMetadataReaderTest
41 @RunWith( ArchivaBlockJUnit4ClassRunner.class )
42 public class MavenRepositoryMetadataReaderTest
45 private Path defaultRepoDir;
48 public void testGroupMetadata()
49 throws RepositoryMetadataException
51 Path metadataFile = defaultRepoDir.resolve( "org/apache/maven/plugins/maven-metadata.xml" );
53 MavenMetadataReader metadataReader = new MavenMetadataReader( );
54 ArchivaRepositoryMetadata metadata = metadataReader.read( metadataFile );
56 assertNotNull( metadata );
57 assertEquals( "org.apache.maven.plugins", metadata.getGroupId() );
58 assertNull( metadata.getArtifactId() );
59 assertNull( metadata.getReleasedVersion() );
60 assertNull( metadata.getLatestVersion() );
61 assertTrue( metadata.getAvailableVersions().isEmpty() );
62 assertNull( metadata.getSnapshotVersion() );
63 assertNull( metadata.getLastUpdated() );
65 Plugin cleanPlugin = new Plugin();
66 cleanPlugin.setPrefix( "clean" );
67 cleanPlugin.setArtifactId( "maven-clean-plugin" );
68 cleanPlugin.setName( "Maven Clean Plugin" );
70 Plugin compilerPlugin = new Plugin();
71 compilerPlugin.setPrefix( "compiler" );
72 compilerPlugin.setArtifactId( "maven-compiler-plugin" );
73 compilerPlugin.setName( "Maven Compiler Plugin" );
75 Plugin surefirePlugin = new Plugin();
76 surefirePlugin.setPrefix( "surefire" );
77 surefirePlugin.setArtifactId( "maven-surefire-plugin" );
78 surefirePlugin.setName( "Maven Surefire Plugin" );
80 assertEquals( Arrays.asList( cleanPlugin, compilerPlugin, surefirePlugin ), metadata.getPlugins() );
84 public void testProjectMetadata()
85 throws RepositoryMetadataException
87 Path metadataFile = defaultRepoDir.resolve( "org/apache/maven/shared/maven-downloader/maven-metadata.xml" );
89 MavenMetadataReader metadataReader = new MavenMetadataReader( );
90 ArchivaRepositoryMetadata metadata = metadataReader.read( metadataFile );
92 assertNotNull( metadata );
93 assertEquals( "org.apache.maven.shared", metadata.getGroupId() );
94 assertEquals( "maven-downloader", metadata.getArtifactId() );
95 assertEquals( "1.1", metadata.getReleasedVersion() );
96 assertNull( metadata.getLatestVersion() );
97 assertEquals( Arrays.asList( "1.0", "1.1" ), metadata.getAvailableVersions() );
98 assertNull( metadata.getSnapshotVersion() );
99 assertEquals( "20061212214311", metadata.getLastUpdated() );
103 public void testProjectVersionMetadata()
104 throws RepositoryMetadataException
106 Path metadataFile = defaultRepoDir.resolve( "org/apache/apache/5-SNAPSHOT/maven-metadata.xml" );
108 MavenMetadataReader metadataReader = new MavenMetadataReader( );
109 ArchivaRepositoryMetadata metadata = metadataReader.read(metadataFile );
111 assertNotNull( metadata );
112 assertEquals( "org.apache", metadata.getGroupId() );
113 assertEquals( "apache", metadata.getArtifactId() );
114 assertNull( metadata.getReleasedVersion() );
115 assertNull( metadata.getLatestVersion() );
116 assertTrue( metadata.getAvailableVersions().isEmpty() );
117 assertNotNull( metadata.getSnapshotVersion() );
118 assertEquals( "20080801.151215", metadata.getSnapshotVersion().getTimestamp() );
119 assertEquals( 1, metadata.getSnapshotVersion().getBuildNumber() );
120 assertEquals( "20080801151215", metadata.getLastUpdated() );
129 defaultRepoDir = Paths.get("target/test-repository");