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.resolver.internal.ant;
20  
21  import java.io.File;
22  import java.io.IOException;
23  
24  import junit.framework.JUnit4TestAdapter;
25  import org.eclipse.aether.artifact.Artifact;
26  import org.eclipse.aether.artifact.DefaultArtifact;
27  import org.junit.Test;
28  
29  import static org.junit.Assert.*;
30  
31  public class ReactorTest extends AntBuildsTest {
32      public static junit.framework.Test suite() {
33          return new JUnit4TestAdapter(ReactorTest.class);
34      }
35  
36      private Artifact artifact(String coords) {
37          return new DefaultArtifact(coords);
38      }
39  
40      @Test
41      public void testPom() throws IOException {
42          executeTarget("testPom");
43          ProjectWorkspaceReader reader = ProjectWorkspaceReader.getInstance();
44          File found = reader.findArtifact(artifact("test:test:pom:0.1-SNAPSHOT"));
45          assertNotNull(found);
46          assertEquals(new File(projectDir, "pom1.xml"), found.getAbsoluteFile());
47      }
48  
49      @Test
50      public void testArtifact() throws IOException {
51          executeTarget("testArtifact");
52          ProjectWorkspaceReader reader = ProjectWorkspaceReader.getInstance();
53          File found = reader.findArtifact(artifact("test:test:pom:0.1-SNAPSHOT"));
54          assertNotNull(found);
55          assertEquals(new File(projectDir, "pom1.xml"), found.getAbsoluteFile());
56  
57          found = reader.findArtifact(artifact("test:test:xml:0.1-SNAPSHOT"));
58          assertNotNull(found);
59          assertEquals(new File(projectDir, "pom1.xml"), found.getAbsoluteFile());
60      }
61  
62      @Test
63      public void testArtifactInMemoryPom() throws IOException {
64          executeTarget("testArtifactInMemoryPom");
65          ProjectWorkspaceReader reader = ProjectWorkspaceReader.getInstance();
66          File found = reader.findArtifact(artifact("test:test:pom:0.1-SNAPSHOT"));
67          assertNull(found);
68  
69          found = reader.findArtifact(artifact("test:test:xml:0.1-SNAPSHOT"));
70          assertNotNull(found);
71          assertEquals(new File(projectDir, "pom1.xml"), found.getAbsoluteFile());
72      }
73  
74      @Test
75      public void testResolveArtifact() throws IOException {
76          executeTarget("testResolveArtifact");
77          String prop = getProject().getProperty("resolve.test:test:jar");
78          assertEquals(new File(projectDir, "pom1.xml").getAbsolutePath(), prop);
79      }
80  
81      @Test
82      public void testResolveArtifactInMemoryPom() throws IOException {
83          executeTarget("testResolveArtifactInMemoryPom");
84          String prop = getProject().getProperty("resolve.test:test:jar");
85          assertEquals(new File(projectDir, "pom1.xml").getAbsolutePath(), prop);
86          assertLogContaining("The POM for test:test:jar:0.1-SNAPSHOT is missing, no dependency information available");
87      }
88  
89      @Test
90      public void testResolveVersionRange() throws IOException {
91          executeTarget("testResolveVersionRange");
92          String prop = getProject().getProperty("resolve.test:test:jar");
93          assertEquals(new File(projectDir, "pom1.xml").getAbsolutePath(), prop);
94      }
95  }