View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
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  }