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