1 package org.apache.maven.archiva.reporting;
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.apache.maven.artifact.repository.metadata.Snapshot;
25 import org.codehaus.plexus.PlexusTestCase;
28 import java.util.List;
33 public abstract class AbstractRepositoryQueryLayerTestCase
34 extends PlexusTestCase
36 private ArtifactFactory artifactFactory;
38 protected ArtifactRepository repository;
40 protected CachedRepositoryQueryLayer queryLayer;
42 protected void setUp()
46 File repositoryDirectory = getTestFile( "src/test/repository" );
48 artifactFactory = (ArtifactFactory) lookup( ArtifactFactory.ROLE );
49 ArtifactRepositoryFactory factory = (ArtifactRepositoryFactory) lookup( ArtifactRepositoryFactory.ROLE );
50 ArtifactRepositoryLayout layout = (ArtifactRepositoryLayout) lookup( ArtifactRepositoryLayout.ROLE, "default" );
53 factory.createArtifactRepository( "test", repositoryDirectory.toURL().toString(), layout, null, null );
56 public void testContainsArtifactTrue()
58 Artifact artifact = getArtifact( "groupId", "artifactId", "1.0-alpha-1" );
60 assertTrue( "check artifact", queryLayer.containsArtifact( artifact ) );
63 public void testContainsArtifactFalse()
65 Artifact artifact = getArtifact( "groupId", "artifactId", "1.0-beta-1" );
67 assertFalse( "check non-existent artifact", queryLayer.containsArtifact( artifact ) );
70 public void testContainsSnapshotArtifactTrue()
72 Snapshot snapshot = new Snapshot();
73 snapshot.setTimestamp( "20050611.202024" );
74 snapshot.setBuildNumber( 1 );
76 Artifact artifact = getArtifact( "groupId", "snapshot-artifact", "1.0-alpha-1-SNAPSHOT" );
77 assertTrue( "check for snapshot artifact", queryLayer.containsArtifact( artifact, snapshot ) );
80 public void testContainsSnapshotArtifactFalse()
82 Snapshot snapshot = new Snapshot();
83 snapshot.setTimestamp( "20050611.202024" );
84 snapshot.setBuildNumber( 2 );
86 Artifact artifact = getArtifact( "groupId", "snapshot-artifact", "1.0-alpha-1-SNAPSHOT" );
87 assertFalse( "check for non-existent snapshot artifact", queryLayer.containsArtifact( artifact, snapshot ) );
90 public void testArtifactVersionsTrue()
93 Artifact artifact = getArtifact( "groupId", "artifactId", "ignored" );
95 List versions = queryLayer.getVersions( artifact );
97 assertTrue( "check version 1.0-alpha-1", versions.contains( "1.0-alpha-1" ) );
98 assertTrue( "check version 1.0-alpha-2", versions.contains( "1.0-alpha-2" ) );
99 assertFalse( "check version 1.0-alpha-3", versions.contains( "1.0-alpha-3" ) );
102 public void testArtifactVersionsFalse()
105 Artifact artifact = getArtifact( "groupId", "artifactId", "ignored" );
107 List versions = queryLayer.getVersions( artifact );
109 assertTrue( "check version 1.0-alpha-1", versions.contains( "1.0-alpha-1" ) );
110 assertTrue( "check version 1.0-alpha-2", versions.contains( "1.0-alpha-2" ) );
111 assertFalse( "check version 1.0-alpha-3", versions.contains( "1.0-alpha-3" ) );
114 public void testArtifactVersionsError()
116 Artifact artifact = getArtifact( "groupId", "none", "ignored" );
120 queryLayer.getVersions( artifact );
121 fail( "expected error not thrown" );
123 catch ( RepositoryQueryLayerException e )
129 private Artifact getArtifact( String groupId, String artifactId, String version )
131 return artifactFactory.createBuildArtifact( groupId, artifactId, version, "pom" );
134 protected void tearDown()
137 release( artifactFactory );
139 artifactFactory = null;