1 package org.apache.maven.archiva.layer;
4 * Copyright 2005-2006 The Apache Software Foundation.
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
19 import org.apache.maven.artifact.Artifact;
20 import org.apache.maven.artifact.factory.ArtifactFactory;
21 import org.apache.maven.artifact.repository.ArtifactRepository;
22 import org.apache.maven.artifact.repository.ArtifactRepositoryFactory;
23 import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
24 import org.codehaus.plexus.PlexusTestCase;
27 import java.util.List;
32 public abstract class AbstractRepositoryQueryLayerTestCase
33 extends PlexusTestCase
35 private ArtifactFactory artifactFactory;
37 protected ArtifactRepository repository;
39 protected RepositoryQueryLayer queryLayer;
41 protected void setUp()
45 File repositoryDirectory = getTestFile( "src/test/repository" );
47 artifactFactory = (ArtifactFactory) lookup( ArtifactFactory.ROLE );
48 ArtifactRepositoryFactory factory = (ArtifactRepositoryFactory) lookup( ArtifactRepositoryFactory.ROLE );
49 ArtifactRepositoryLayout layout = (ArtifactRepositoryLayout) lookup( ArtifactRepositoryLayout.ROLE, "default" );
52 factory.createArtifactRepository( "test", repositoryDirectory.toURL().toString(), layout, null, null );
55 public void testContainsArtifactTrue()
57 Artifact artifact = getArtifact( "groupId", "artifactId", "1.0-alpha-1" );
59 assertTrue( "check artifact", queryLayer.containsArtifact( artifact ) );
62 public void testContainsArtifactFalse()
64 Artifact artifact = getArtifact( "groupId", "artifactId", "1.0-beta-1" );
66 assertFalse( "check non-existent artifact", queryLayer.containsArtifact( artifact ) );
69 public void testContainsSnapshotArtifactTrue()
71 Artifact artifact = getArtifact( "groupId", "snapshot-artifact", "1.0-alpha-1-20050611.202024-1" );
72 assertTrue( "check for snapshot artifact", queryLayer.containsArtifact( artifact ) );
75 public void testContainsSnapshotArtifactFalse()
77 Artifact artifact = getArtifact( "groupId", "snapshot-artifact", "1.0-alpha-1-20050611.202024-2" );
78 assertFalse( "check for non-existent snapshot artifact", queryLayer.containsArtifact( artifact ) );
81 public void testArtifactVersions()
84 Artifact artifact = getArtifact( "groupId", "artifactId", "ignored" );
86 List versions = queryLayer.getVersions( artifact );
88 assertTrue( "check version 1.0-alpha-1", versions.contains( "1.0-alpha-1" ) );
89 assertFalse( "check version 1.0-alpha-2", versions.contains( "1.0-alpha-2" ) );
92 public void testArtifactVersionsError()
94 Artifact artifact = getArtifact( "groupId", "none", "ignored" );
98 queryLayer.getVersions( artifact );
99 fail( "expected error not thrown" );
101 catch ( RepositoryQueryLayerException e )
107 private Artifact getArtifact( String groupId, String artifactId, String version )
109 Artifact projectArtifact = artifactFactory.createProjectArtifact( groupId, artifactId, version );
110 projectArtifact.isSnapshot();
111 return projectArtifact;