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.test.utils.ArchivaBlockJUnit4ClassRunner;
27 import org.apache.archiva.xml.XMLException;
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()
51 Path metadataFile = defaultRepoDir.resolve( "org/apache/maven/plugins/maven-metadata.xml" );
53 ArchivaRepositoryMetadata metadata = MavenMetadataReader.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()
86 Path metadataFile = defaultRepoDir.resolve( "org/apache/maven/shared/maven-downloader/maven-metadata.xml" );
88 ArchivaRepositoryMetadata metadata = MavenMetadataReader.read( metadataFile);
90 assertNotNull( metadata );
91 assertEquals( "org.apache.maven.shared", metadata.getGroupId() );
92 assertEquals( "maven-downloader", metadata.getArtifactId() );
93 assertEquals( "1.1", metadata.getReleasedVersion() );
94 assertNull( metadata.getLatestVersion() );
95 assertEquals( Arrays.asList( "1.0", "1.1" ), metadata.getAvailableVersions() );
96 assertNull( metadata.getSnapshotVersion() );
97 assertEquals( "20061212214311", metadata.getLastUpdated() );
101 public void testProjectVersionMetadata()
104 Path metadataFile = defaultRepoDir.resolve( "org/apache/apache/5-SNAPSHOT/maven-metadata.xml" );
106 ArchivaRepositoryMetadata metadata = MavenMetadataReader.read( metadataFile );
108 assertNotNull( metadata );
109 assertEquals( "org.apache", metadata.getGroupId() );
110 assertEquals( "apache", metadata.getArtifactId() );
111 assertNull( metadata.getReleasedVersion() );
112 assertNull( metadata.getLatestVersion() );
113 assertTrue( metadata.getAvailableVersions().isEmpty() );
114 assertNotNull( metadata.getSnapshotVersion() );
115 assertEquals( "20080801.151215", metadata.getSnapshotVersion().getTimestamp() );
116 assertEquals( 1, metadata.getSnapshotVersion().getBuildNumber() );
117 assertEquals( "20080801151215", metadata.getLastUpdated() );
126 defaultRepoDir = Paths.get("target/test-repository");