1 package org.apache.maven.index.locator;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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 }