1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.index.locator;
20
21 import java.io.File;
22
23 import org.apache.maven.index.AbstractNexusIndexerTest;
24 import org.apache.maven.index.ArtifactContext;
25 import org.apache.maven.index.ArtifactContextProducer;
26 import org.apache.maven.index.NexusIndexer;
27 import org.apache.maven.index.artifact.ArtifactPackagingMapper;
28 import org.apache.maven.index.artifact.Gav;
29 import org.apache.maven.index.artifact.M2GavCalculator;
30 import org.junit.Test;
31
32 import static org.junit.Assert.assertTrue;
33
34 public class ArtifactLocatorTest extends AbstractNexusIndexerTest {
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) throws Exception {
43 context = nexusIndexer.addIndexingContext("al-test", "al-test", repo, indexDir, null, null, FULL_CREATORS);
44
45 nexusIndexer.scan(context);
46
47 artifactContextProducer = lookup(ArtifactContextProducer.class);
48
49 artifactPackagingMapper = lookup(ArtifactPackagingMapper.class);
50 }
51
52 @Test
53 public void testContextProducer() {
54 final File pomFile =
55 getTestFile("src/test/repo/ch/marcus-schulte/maven/hivedoc-plugin/1.0.0/hivedoc-plugin-1.0.0.pom");
56
57 final ArtifactContext ac = artifactContextProducer.getArtifactContext(context, pomFile);
58
59 assertTrue("Artifact file was not found!", ac.getArtifact() != null);
60 assertTrue("Artifact file was not found!", ac.getArtifact().exists());
61 }
62
63 @Test
64 public void testArtifactLocator() {
65 ArtifactLocator al = new ArtifactLocator(artifactPackagingMapper);
66
67 final M2GavCalculator gavCalculator = new M2GavCalculator();
68
69 final File pomFile =
70 getTestFile("src/test/repo/ch/marcus-schulte/maven/hivedoc-plugin/1.0.0/hivedoc-plugin-1.0.0.pom");
71
72 final Gav gav =
73 gavCalculator.pathToGav("/ch/marcus-schulte/maven/hivedoc-plugin/1.0.0/hivedoc-plugin-1.0.0.pom");
74
75 File artifactFile = al.locate(pomFile, gavCalculator, gav);
76
77 assertTrue("Artifact file was not located!", artifactFile != null);
78 assertTrue("Artifact file was not located!", artifactFile.exists());
79 }
80 }