View Javadoc

1   package org.apache.maven.index.locator;
2   
3   /*
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
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0    
13   *
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
19   * under the License.
20   */
21  
22  import java.io.File;
23  
24  import org.apache.maven.index.AbstractNexusIndexerTest;
25  import org.apache.maven.index.ArtifactContext;
26  import org.apache.maven.index.ArtifactContextProducer;
27  import org.apache.maven.index.NexusIndexer;
28  import org.apache.maven.index.artifact.ArtifactPackagingMapper;
29  import org.apache.maven.index.artifact.Gav;
30  import org.apache.maven.index.artifact.M2GavCalculator;
31  
32  public class ArtifactLocatorTest
33      extends AbstractNexusIndexerTest
34  {
35      protected File repo = new File( getBasedir(), "src/test/repo" );
36  
37      private ArtifactContextProducer artifactContextProducer;
38  
39      private ArtifactPackagingMapper artifactPackagingMapper;
40  
41      @Override
42      protected void prepareNexusIndexer( NexusIndexer nexusIndexer )
43          throws Exception
44      {
45          context = nexusIndexer.addIndexingContext( "al-test", "al-test", repo, indexDir, null, null, FULL_CREATORS );
46  
47          nexusIndexer.scan( context );
48  
49          artifactContextProducer = lookup( ArtifactContextProducer.class );
50  
51          artifactPackagingMapper = lookup( ArtifactPackagingMapper.class );
52      }
53  
54      public void testContextProducer()
55      {
56          final File pomFile =
57              getTestFile( "src/test/repo/ch/marcus-schulte/maven/hivedoc-plugin/1.0.0/hivedoc-plugin-1.0.0.pom" );
58  
59          final ArtifactContext ac = artifactContextProducer.getArtifactContext( context, pomFile );
60  
61          assertTrue( "Artifact file was not found!", ac.getArtifact() != null );
62          assertTrue( "Artifact file was not found!", ac.getArtifact().exists() );
63      }
64  
65      public void testArtifactLocator()
66      {
67          ArtifactLocator al = new ArtifactLocator( artifactPackagingMapper );
68  
69          final M2GavCalculator gavCalculator = new M2GavCalculator();
70  
71          final File pomFile =
72              getTestFile( "src/test/repo/ch/marcus-schulte/maven/hivedoc-plugin/1.0.0/hivedoc-plugin-1.0.0.pom" );
73  
74          final Gav gav =
75              gavCalculator.pathToGav( "/ch/marcus-schulte/maven/hivedoc-plugin/1.0.0/hivedoc-plugin-1.0.0.pom" );
76  
77          File artifactFile = al.locate( pomFile, gavCalculator, gav );
78  
79          assertTrue( "Artifact file was not located!", artifactFile != null );
80          assertTrue( "Artifact file was not located!", artifactFile.exists() );
81      }
82  }