1 package org.apache.maven.archiva.layer;
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 org.apache.maven.artifact.Artifact;
23 import org.apache.maven.artifact.factory.ArtifactFactory;
24 import org.apache.maven.artifact.repository.ArtifactRepository;
25 import org.apache.maven.artifact.repository.ArtifactRepositoryFactory;
26 import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
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 RepositoryQueryLayer 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 Artifact artifact = getArtifact( "groupId", "snapshot-artifact", "1.0-alpha-1-20050611.202024-1" );
75 assertTrue( "check for snapshot artifact", queryLayer.containsArtifact( artifact ) );
78 public void testContainsSnapshotArtifactFalse()
80 Artifact artifact = getArtifact( "groupId", "snapshot-artifact", "1.0-alpha-1-20050611.202024-2" );
81 assertFalse( "check for non-existent snapshot artifact", queryLayer.containsArtifact( artifact ) );
84 public void testArtifactVersions()
87 Artifact artifact = getArtifact( "groupId", "artifactId", "ignored" );
89 List versions = queryLayer.getVersions( artifact );
91 assertTrue( "check version 1.0-alpha-1", versions.contains( "1.0-alpha-1" ) );
92 assertFalse( "check version 1.0-alpha-2", versions.contains( "1.0-alpha-2" ) );
95 public void testArtifactVersionsError()
97 Artifact artifact = getArtifact( "groupId", "none", "ignored" );
101 queryLayer.getVersions( artifact );
102 fail( "expected error not thrown" );
104 catch ( RepositoryQueryLayerException e )
110 private Artifact getArtifact( String groupId, String artifactId, String version )
112 Artifact projectArtifact = artifactFactory.createProjectArtifact( groupId, artifactId, version );
113 projectArtifact.isSnapshot();
114 return projectArtifact;