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.archiva.layer.CachedRepositoryQueryLayer;
20 import org.apache.maven.archiva.layer.RepositoryQueryLayerException;
21 import org.apache.maven.artifact.Artifact;
22 import org.apache.maven.artifact.factory.ArtifactFactory;
23 import org.apache.maven.artifact.repository.ArtifactRepository;
24 import org.apache.maven.artifact.repository.ArtifactRepositoryFactory;
25 import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
26 import org.apache.maven.artifact.repository.metadata.Snapshot;
27 import org.codehaus.plexus.PlexusTestCase;
30 import java.util.List;
35 public abstract class AbstractRepositoryQueryLayerTestCase
36 extends PlexusTestCase
38 private ArtifactFactory artifactFactory;
40 protected ArtifactRepository repository;
42 protected CachedRepositoryQueryLayer queryLayer;
44 protected void setUp()
48 File repositoryDirectory = getTestFile( "src/test/repository" );
50 artifactFactory = (ArtifactFactory) lookup( ArtifactFactory.ROLE );
51 ArtifactRepositoryFactory factory = (ArtifactRepositoryFactory) lookup( ArtifactRepositoryFactory.ROLE );
52 ArtifactRepositoryLayout layout = (ArtifactRepositoryLayout) lookup( ArtifactRepositoryLayout.ROLE, "default" );
55 factory.createArtifactRepository( "test", repositoryDirectory.toURL().toString(), layout, null, null );
58 public void testContainsArtifactTrue()
60 Artifact artifact = getArtifact( "groupId", "artifactId", "1.0-alpha-1" );
62 assertTrue( "check artifact", queryLayer.containsArtifact( artifact ) );
65 public void testContainsArtifactFalse()
67 Artifact artifact = getArtifact( "groupId", "artifactId", "1.0-beta-1" );
69 assertFalse( "check non-existent artifact", queryLayer.containsArtifact( artifact ) );
72 public void testContainsSnapshotArtifactTrue()
74 Snapshot snapshot = new Snapshot();
75 snapshot.setTimestamp( "20050611.202024" );
76 snapshot.setBuildNumber( 1 );
78 Artifact artifact = getArtifact( "groupId", "snapshot-artifact", "1.0-alpha-1-SNAPSHOT" );
79 assertTrue( "check for snapshot artifact", queryLayer.containsArtifact( artifact, snapshot ) );
82 public void testContainsSnapshotArtifactFalse()
84 Snapshot snapshot = new Snapshot();
85 snapshot.setTimestamp( "20050611.202024" );
86 snapshot.setBuildNumber( 2 );
88 Artifact artifact = getArtifact( "groupId", "snapshot-artifact", "1.0-alpha-1-SNAPSHOT" );
89 assertFalse( "check for non-existent snapshot artifact", queryLayer.containsArtifact( artifact, snapshot ) );
92 public void testArtifactVersionsTrue()
95 Artifact artifact = getArtifact( "groupId", "artifactId", "ignored" );
97 List versions = queryLayer.getVersions( artifact );
99 assertTrue( "check version 1.0-alpha-1", versions.contains( "1.0-alpha-1" ) );
100 assertTrue( "check version 1.0-alpha-2", versions.contains( "1.0-alpha-2" ) );
101 assertFalse( "check version 1.0-alpha-3", versions.contains( "1.0-alpha-3" ) );
104 public void testArtifactVersionsFalse()
107 Artifact artifact = getArtifact( "groupId", "artifactId", "ignored" );
109 List versions = queryLayer.getVersions( artifact );
111 assertTrue( "check version 1.0-alpha-1", versions.contains( "1.0-alpha-1" ) );
112 assertTrue( "check version 1.0-alpha-2", versions.contains( "1.0-alpha-2" ) );
113 assertFalse( "check version 1.0-alpha-3", versions.contains( "1.0-alpha-3" ) );
116 public void testArtifactVersionsError()
118 Artifact artifact = getArtifact( "groupId", "none", "ignored" );
122 queryLayer.getVersions( artifact );
123 fail( "expected error not thrown" );
125 catch ( RepositoryQueryLayerException e )
131 private Artifact getArtifact( String groupId, String artifactId, String version )
133 return artifactFactory.createBuildArtifact( groupId, artifactId, version, "pom" );
136 protected void tearDown()
139 release( artifactFactory );
141 artifactFactory = null;