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 static org.hamcrest.Matchers.*;
23  import static org.junit.Assert.*;
24  
25  import java.io.File;
26  
27  import org.apache.maven.resolver.internal.ant.ProjectWorkspaceReader;
28  import org.apache.maven.resolver.internal.ant.types.Pom;
29  import org.apache.tools.ant.Project;
30  import org.junit.Before;
31  import org.junit.Test;
32  import org.eclipse.aether.artifact.Artifact;
33  import org.eclipse.aether.artifact.DefaultArtifact;
34  
35  public class ProjectWorkspaceReaderTest
36  {
37  
38      private ProjectWorkspaceReader reader;
39  
40      private Project project;
41  
42      @Before
43      public void setUp()
44          throws Exception
45      {
46          this.reader = new ProjectWorkspaceReader();
47  
48          this.project = new Project();
49          project.setProperty( "user.home", System.getProperty( "user.home" ) );
50      }
51  
52      private Artifact artifact( String coords )
53      {
54          return new DefaultArtifact( coords );
55      }
56  
57      private File getFile( String name )
58      {
59          return new File( "src/test/resources/ProjectWorkspaceReader", name );
60      }
61  
62      @Test
63      public void testFindPom()
64      {
65          Pom pom = new Pom();
66          pom.setProject( project );
67          pom.setFile( getFile( "dummy-pom.xml" ) );
68  
69          reader.addPom( pom );
70  
71          assertEquals( pom.getFile(), reader.findArtifact( artifact( "test:dummy:pom:0.1-SNAPSHOT" ) ) );
72          assertNull( reader.findArtifact( artifact( "unavailable:test:pom:0.1-SNAPSHOT" ) ) );
73      }
74  
75      @Test
76      public void testFindArtifact()
77      {
78          Pom pom = new Pom();
79          pom.setProject( project );
80          pom.setFile( getFile( "dummy-pom.xml" ) );
81  
82          reader.addPom( pom );
83  
84          org.apache.maven.resolver.internal.ant.types.Artifact artifact = new org.apache.maven.resolver.internal.ant.types.Artifact();
85          artifact.setProject( project );
86          artifact.addPom( pom );
87          artifact.setFile( getFile( "dummy-file.txt" ) );
88  
89          reader.addArtifact( artifact );
90  
91          assertEquals( artifact.getFile(), reader.findArtifact( artifact( "test:dummy:txt:0.1-SNAPSHOT" ) ) );
92          assertNull( reader.findArtifact( artifact( "unavailable:test:jar:0.1-SNAPSHOT" ) ) );
93      }
94  
95      @Test
96      public void testFindVersions()
97      {
98          Pom pom1 = new Pom();
99          pom1.setProject( project );
100         pom1.setCoords( "test:dummy:1-SNAPSHOT" );
101 
102         org.apache.maven.resolver.internal.ant.types.Artifact artifact1 = new org.apache.maven.resolver.internal.ant.types.Artifact();
103         artifact1.setProject( project );
104         artifact1.addPom( pom1 );
105         artifact1.setFile( getFile( "dummy-file.txt" ) );
106 
107         reader.addArtifact( artifact1 );
108 
109         Pom pom2 = new Pom();
110         pom2.setProject( project );
111         pom2.setCoords( "test:dummy:2-SNAPSHOT" );
112 
113         org.apache.maven.resolver.internal.ant.types.Artifact artifact2 = new org.apache.maven.resolver.internal.ant.types.Artifact();
114         artifact2.setProject( project );
115         artifact2.addPom( pom2 );
116         artifact2.setFile( getFile( "dummy-file.txt" ) );
117 
118         reader.addArtifact( artifact2 );
119 
120         assertThat( reader.findVersions( artifact( "test:dummy:txt:[0,)" ) ),
121                     containsInAnyOrder( "1-SNAPSHOT", "2-SNAPSHOT" ) );
122     }
123 
124 }