1 package org.apache.maven.archiva.repository.project.resolvers;
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
24 import org.apache.maven.archiva.configuration.FileTypes;
25 import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
26 import org.apache.maven.archiva.model.ArchivaProjectModel;
27 import org.apache.maven.archiva.model.VersionedReference;
28 import org.apache.maven.archiva.repository.content.ManagedDefaultRepositoryContent;
29 import org.apache.maven.archiva.repository.project.ProjectModelException;
30 import org.apache.maven.archiva.repository.project.readers.ProjectModel400Reader;
31 import org.codehaus.plexus.spring.PlexusInSpringTestCase;
33 public class ManagedRepositoryProjectResolverTest
34 extends PlexusInSpringTestCase
36 private ManagedRepositoryProjectResolver resolver;
38 public void setUp() throws Exception
42 FileTypes fileTypes = new MockFileTypes();
44 ManagedRepositoryConfiguration repoConfig = new ManagedRepositoryConfiguration();
45 repoConfig.setId( "test-repo" );
46 repoConfig.setLocation( new File( getBasedir(), "target/test-classes/test-repo" ).getPath() );
47 repoConfig.setName( "Test Repository" );
49 ManagedDefaultRepositoryContent repository = new ManagedDefaultRepositoryContent();
50 repository.setRepository( repoConfig );
51 repository.setFiletypes( fileTypes );
53 resolver = new ManagedRepositoryProjectResolver( repository, new ProjectModel400Reader() );
56 public void testResolveSnapshotUniqueVersionPresent()
59 VersionedReference ref = new VersionedReference();
60 ref.setGroupId( "org.apache.archiva" );
61 ref.setArtifactId( "unique-version" );
62 ref.setVersion( "1.0-SNAPSHOT" );
66 ArchivaProjectModel model = resolver.resolveProjectModel( ref );
68 assertNotNull( model );
69 assertEquals( "org.apache.archiva", model.getGroupId() );
70 assertEquals( "unique-version", model.getArtifactId() );
71 assertEquals( "1.0-SNAPSHOT", model.getVersion() );
72 assertEquals( "Unique Version Snapshot - Build 3", model.getName() );
76 if( e instanceof ProjectModelException )
78 fail( "A ProjectModelException should not have occurred. Instead, the latest timestamp should have been found!" );
87 public void testResolveSnapshotGenericVersionPresent()
90 VersionedReference ref = new VersionedReference();
91 ref.setGroupId( "org.apache.archiva" );
92 ref.setArtifactId( "generic-version" );
93 ref.setVersion( "1.0-SNAPSHOT" );
95 ArchivaProjectModel model = resolver.resolveProjectModel( ref );
97 assertNotNull( model );
98 assertEquals( "org.apache.archiva", model.getGroupId() );
99 assertEquals( "generic-version", model.getArtifactId() );
100 assertEquals( "1.0-SNAPSHOT", model.getVersion() );
103 public void testResolveSuccessful()
106 VersionedReference ref = new VersionedReference();
107 ref.setGroupId( "org.apache.archiva" );
108 ref.setArtifactId( "released-version" );
109 ref.setVersion( "1.0" );
111 ArchivaProjectModel model = resolver.resolveProjectModel( ref );
113 assertNotNull( model );
114 assertEquals( "org.apache.archiva", model.getGroupId() );
115 assertEquals( "released-version", model.getArtifactId() );
116 assertEquals( "1.0", model.getVersion() );
119 public void testResolveNotFound()
122 VersionedReference ref = new VersionedReference();
123 ref.setGroupId( "org.apache.archiva" );
124 ref.setArtifactId( "non-existant" );
125 ref.setVersion( "2.0" );
129 resolver.resolveProjectModel( ref );
130 fail( "A ProjectModelException should have been thrown." );
134 assertTrue( e instanceof ProjectModelException );
141 public boolean matchesArtifactPattern( String relativePath )