1 package org.apache.archiva.repository.maven.metadata;
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.metadata.maven.MavenMetadataReader;
23 import org.apache.archiva.model.ArchivaRepositoryMetadata;
24 import org.apache.archiva.repository.metadata.RepositoryMetadataException;
25 import org.apache.archiva.test.utils.ArchivaBlockJUnit4ClassRunner;
26 import org.junit.Test;
27 import org.junit.runner.RunWith;
29 import java.net.URISyntaxException;
30 import java.nio.file.Path;
31 import java.nio.file.Paths;
34 * RepositoryMetadataReaderTest
38 @RunWith( ArchivaBlockJUnit4ClassRunner.class )
39 public class RepositoryMetadataReaderTest
43 private Path getRepositoryPath(String repoName) {
46 return Paths.get( Thread.currentThread( ).getContextClassLoader( ).getResource( "repositories/" + repoName ).toURI( ) );
48 catch ( URISyntaxException e )
50 throw new RuntimeException( "Could not resolve repository path " + e.getMessage( ), e );
55 public void testLoadSimple()
56 throws RepositoryMetadataException
58 Path defaultRepoDir = getRepositoryPath( "default-repository" );
59 Path metadataFile = defaultRepoDir.resolve( "org/apache/maven/shared/maven-downloader/maven-metadata.xml" );
61 MavenMetadataReader metadataReader = new MavenMetadataReader( );
63 ArchivaRepositoryMetadata metadata = metadataReader.read( metadataFile );
65 assertNotNull( metadata );
66 assertEquals( "Group Id", "org.apache.maven.shared", metadata.getGroupId() );
67 assertEquals( "Artifact Id", "maven-downloader", metadata.getArtifactId() );
68 assertEquals( "Released Version", "1.1", metadata.getReleasedVersion() );
69 assertEquals( "List of Available Versions", 2, metadata.getAvailableVersions().size() );
70 assertTrue( "Available version 1.0", metadata.getAvailableVersions().contains( "1.0" ) );
71 assertTrue( "Available version 1.1", metadata.getAvailableVersions().contains( "1.1" ) );
75 public void testLoadComplex()
76 throws RepositoryMetadataException
78 Path defaultRepoDir = getRepositoryPath( "default-repository" );
79 Path metadataFile = defaultRepoDir.resolve( "org/apache/maven/samplejar/maven-metadata.xml" );
80 MavenMetadataReader metadataReader = new MavenMetadataReader( );
82 ArchivaRepositoryMetadata metadata = metadataReader.read( metadataFile );
84 assertNotNull( metadata );
85 assertEquals( "Group Id", "org.apache.maven", metadata.getGroupId() );
86 assertEquals( "Artifact Id", "samplejar", metadata.getArtifactId() );
87 assertEquals( "Released Version", "2.0", metadata.getReleasedVersion() );
88 assertEquals( "Latest Version", "6.0-SNAPSHOT", metadata.getLatestVersion() );
89 assertEquals( "List of Available Versions", 18, metadata.getAvailableVersions().size() );
90 assertTrue( "Available version 6.0-20060311.183228-10",
91 metadata.getAvailableVersions().contains( "6.0-20060311.183228-10" ) );
92 assertTrue( "Available version 6.0-SNAPSHOT", metadata.getAvailableVersions().contains( "6.0-SNAPSHOT" ) );