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