1 package org.apache.archiva.repository.maven.metadata.storage;
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
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
21 import junit.framework.TestCase;
22 import org.apache.archiva.maven2.metadata.MavenMetadataReader;
23 import org.apache.archiva.model.ArchivaRepositoryMetadata;
24 import org.apache.archiva.model.Plugin;
25 import org.apache.archiva.repository.metadata.RepositoryMetadataException;
26 import org.apache.archiva.test.utils.ArchivaBlockJUnit4ClassRunner;
27 import org.junit.Before;
28 import org.junit.Test;
29 import org.junit.runner.RunWith;
31 import java.nio.file.Path;
32 import java.nio.file.Paths;
33 import java.util.Arrays;
36 * RepositoryMetadataReaderTest
40 @RunWith( ArchivaBlockJUnit4ClassRunner.class )
41 public class MavenRepositoryMetadataReaderTest
44 private Path defaultRepoDir;
47 public void testGroupMetadata()
48 throws RepositoryMetadataException
50 Path metadataFile = defaultRepoDir.resolve( "org/apache/maven/plugins/maven-metadata.xml" );
52 MavenMetadataReader metadataReader = new MavenMetadataReader( );
53 ArchivaRepositoryMetadata metadata = metadataReader.read( metadataFile );
55 assertNotNull( metadata );
56 assertEquals( "org.apache.maven.plugins", metadata.getGroupId() );
57 assertNull( metadata.getArtifactId() );
58 assertNull( metadata.getReleasedVersion() );
59 assertNull( metadata.getLatestVersion() );
60 assertTrue( metadata.getAvailableVersions().isEmpty() );
61 assertNull( metadata.getSnapshotVersion() );
62 assertNull( metadata.getLastUpdated() );
64 Plugin cleanPlugin = new Plugin();
65 cleanPlugin.setPrefix( "clean" );
66 cleanPlugin.setArtifactId( "maven-clean-plugin" );
67 cleanPlugin.setName( "Maven Clean Plugin" );
69 Plugin compilerPlugin = new Plugin();
70 compilerPlugin.setPrefix( "compiler" );
71 compilerPlugin.setArtifactId( "maven-compiler-plugin" );
72 compilerPlugin.setName( "Maven Compiler Plugin" );
74 Plugin surefirePlugin = new Plugin();
75 surefirePlugin.setPrefix( "surefire" );
76 surefirePlugin.setArtifactId( "maven-surefire-plugin" );
77 surefirePlugin.setName( "Maven Surefire Plugin" );
79 assertEquals( Arrays.asList( cleanPlugin, compilerPlugin, surefirePlugin ), metadata.getPlugins() );
83 public void testProjectMetadata()
84 throws RepositoryMetadataException
86 Path metadataFile = defaultRepoDir.resolve( "org/apache/maven/shared/maven-downloader/maven-metadata.xml" );
88 MavenMetadataReader metadataReader = new MavenMetadataReader( );
89 ArchivaRepositoryMetadata metadata = metadataReader.read( metadataFile );
91 assertNotNull( metadata );
92 assertEquals( "org.apache.maven.shared", metadata.getGroupId() );
93 assertEquals( "maven-downloader", metadata.getArtifactId() );
94 assertEquals( "1.1", metadata.getReleasedVersion() );
95 assertNull( metadata.getLatestVersion() );
96 assertEquals( Arrays.asList( "1.0", "1.1" ), metadata.getAvailableVersions() );
97 assertNull( metadata.getSnapshotVersion() );
98 assertEquals( "20061212214311", metadata.getLastUpdated() );
102 public void testProjectVersionMetadata()
103 throws RepositoryMetadataException
105 Path metadataFile = defaultRepoDir.resolve( "org/apache/apache/5-SNAPSHOT/maven-metadata.xml" );
107 MavenMetadataReader metadataReader = new MavenMetadataReader( );
108 ArchivaRepositoryMetadata metadata = metadataReader.read(metadataFile );
110 assertNotNull( metadata );
111 assertEquals( "org.apache", metadata.getGroupId() );
112 assertEquals( "apache", metadata.getArtifactId() );
113 assertNull( metadata.getReleasedVersion() );
114 assertNull( metadata.getLatestVersion() );
115 assertTrue( metadata.getAvailableVersions().isEmpty() );
116 assertNotNull( metadata.getSnapshotVersion() );
117 assertEquals( "20080801.151215", metadata.getSnapshotVersion().getTimestamp() );
118 assertEquals( 1, metadata.getSnapshotVersion().getBuildNumber() );
119 assertEquals( "20080801151215", metadata.getLastUpdated() );
128 defaultRepoDir = Paths.get("target/test-repository");