View Javadoc
1   package org.eclipse.aether.util.artifact;
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.junit.Assert.*;
23  
24  import org.eclipse.aether.artifact.Artifact;
25  import org.eclipse.aether.artifact.DefaultArtifact;
26  import org.junit.Test;
27  
28  /**
29   */
30  public class ArtifactIdUtilsTest
31  {
32  
33      @Test
34      public void testToIdArtifact()
35      {
36          Artifact artifact = null;
37          assertSame( null, ArtifactIdUtils.toId( artifact ) );
38  
39          artifact = new DefaultArtifact( "gid", "aid", "ext", "1.0-20110205.132618-23" );
40          assertEquals( "gid:aid:ext:1.0-20110205.132618-23", ArtifactIdUtils.toId( artifact ) );
41  
42          artifact = new DefaultArtifact( "gid", "aid", "cls", "ext", "1.0-20110205.132618-23" );
43          assertEquals( "gid:aid:ext:cls:1.0-20110205.132618-23", ArtifactIdUtils.toId( artifact ) );
44      }
45  
46      @Test
47      public void testToIdStrings()
48      {
49          assertEquals( ":::", ArtifactIdUtils.toId( null, null, null, null, null ) );
50  
51          assertEquals( "gid:aid:ext:1", ArtifactIdUtils.toId( "gid", "aid", "ext", "", "1" ) );
52  
53          assertEquals( "gid:aid:ext:cls:1", ArtifactIdUtils.toId( "gid", "aid", "ext", "cls", "1" ) );
54      }
55  
56      @Test
57      public void testToBaseIdArtifact()
58      {
59          Artifact artifact = null;
60          assertSame( null, ArtifactIdUtils.toBaseId( artifact ) );
61  
62          artifact = new DefaultArtifact( "gid", "aid", "ext", "1.0-20110205.132618-23" );
63          assertEquals( "gid:aid:ext:1.0-SNAPSHOT", ArtifactIdUtils.toBaseId( artifact ) );
64  
65          artifact = new DefaultArtifact( "gid", "aid", "cls", "ext", "1.0-20110205.132618-23" );
66          assertEquals( "gid:aid:ext:cls:1.0-SNAPSHOT", ArtifactIdUtils.toBaseId( artifact ) );
67      }
68  
69      @Test
70      public void testToVersionlessIdArtifact()
71      {
72          Artifact artifact = null;
73          assertSame( null, ArtifactIdUtils.toId( artifact ) );
74  
75          artifact = new DefaultArtifact( "gid", "aid", "ext", "1" );
76          assertEquals( "gid:aid:ext", ArtifactIdUtils.toVersionlessId( artifact ) );
77  
78          artifact = new DefaultArtifact( "gid", "aid", "cls", "ext", "1" );
79          assertEquals( "gid:aid:ext:cls", ArtifactIdUtils.toVersionlessId( artifact ) );
80      }
81  
82      @Test
83      public void testToVersionlessIdStrings()
84      {
85          assertEquals( "::", ArtifactIdUtils.toVersionlessId( null, null, null, null ) );
86  
87          assertEquals( "gid:aid:ext", ArtifactIdUtils.toVersionlessId( "gid", "aid", "ext", "" ) );
88  
89          assertEquals( "gid:aid:ext:cls", ArtifactIdUtils.toVersionlessId( "gid", "aid", "ext", "cls" ) );
90      }
91  
92      @Test
93      public void testEqualsId()
94      {
95          Artifact artifact1 = null;
96          Artifact artifact2 = null;
97          assertFalse( ArtifactIdUtils.equalsId( artifact1, artifact2 ) );
98          assertFalse( ArtifactIdUtils.equalsId( artifact2, artifact1 ) );
99  
100         artifact1 = new DefaultArtifact( "gid", "aid", "ext", "1.0-20110205.132618-23" );
101         assertFalse( ArtifactIdUtils.equalsId( artifact1, artifact2 ) );
102         assertFalse( ArtifactIdUtils.equalsId( artifact2, artifact1 ) );
103 
104         artifact2 = new DefaultArtifact( "gidX", "aid", "ext", "1.0-20110205.132618-23" );
105         assertFalse( ArtifactIdUtils.equalsId( artifact1, artifact2 ) );
106         assertFalse( ArtifactIdUtils.equalsId( artifact2, artifact1 ) );
107 
108         artifact2 = new DefaultArtifact( "gid", "aidX", "ext", "1.0-20110205.132618-23" );
109         assertFalse( ArtifactIdUtils.equalsId( artifact1, artifact2 ) );
110         assertFalse( ArtifactIdUtils.equalsId( artifact2, artifact1 ) );
111 
112         artifact2 = new DefaultArtifact( "gid", "aid", "extX", "1.0-20110205.132618-23" );
113         assertFalse( ArtifactIdUtils.equalsId( artifact1, artifact2 ) );
114         assertFalse( ArtifactIdUtils.equalsId( artifact2, artifact1 ) );
115 
116         artifact2 = new DefaultArtifact( "gid", "aid", "ext", "1.0-20110205.132618-24" );
117         assertFalse( ArtifactIdUtils.equalsId( artifact1, artifact2 ) );
118         assertFalse( ArtifactIdUtils.equalsId( artifact2, artifact1 ) );
119 
120         artifact2 = new DefaultArtifact( "gid", "aid", "ext", "1.0-20110205.132618-23" );
121         assertTrue( ArtifactIdUtils.equalsId( artifact1, artifact2 ) );
122         assertTrue( ArtifactIdUtils.equalsId( artifact2, artifact1 ) );
123 
124         assertTrue( ArtifactIdUtils.equalsId( artifact1, artifact1 ) );
125     }
126 
127     @Test
128     public void testEqualsBaseId()
129     {
130         Artifact artifact1 = null;
131         Artifact artifact2 = null;
132         assertFalse( ArtifactIdUtils.equalsBaseId( artifact1, artifact2 ) );
133         assertFalse( ArtifactIdUtils.equalsBaseId( artifact2, artifact1 ) );
134 
135         artifact1 = new DefaultArtifact( "gid", "aid", "ext", "1.0-20110205.132618-23" );
136         assertFalse( ArtifactIdUtils.equalsBaseId( artifact1, artifact2 ) );
137         assertFalse( ArtifactIdUtils.equalsBaseId( artifact2, artifact1 ) );
138 
139         artifact2 = new DefaultArtifact( "gidX", "aid", "ext", "1.0-20110205.132618-23" );
140         assertFalse( ArtifactIdUtils.equalsBaseId( artifact1, artifact2 ) );
141         assertFalse( ArtifactIdUtils.equalsBaseId( artifact2, artifact1 ) );
142 
143         artifact2 = new DefaultArtifact( "gid", "aidX", "ext", "1.0-20110205.132618-23" );
144         assertFalse( ArtifactIdUtils.equalsBaseId( artifact1, artifact2 ) );
145         assertFalse( ArtifactIdUtils.equalsBaseId( artifact2, artifact1 ) );
146 
147         artifact2 = new DefaultArtifact( "gid", "aid", "extX", "1.0-20110205.132618-23" );
148         assertFalse( ArtifactIdUtils.equalsBaseId( artifact1, artifact2 ) );
149         assertFalse( ArtifactIdUtils.equalsBaseId( artifact2, artifact1 ) );
150 
151         artifact2 = new DefaultArtifact( "gid", "aid", "ext", "X.0-20110205.132618-23" );
152         assertFalse( ArtifactIdUtils.equalsBaseId( artifact1, artifact2 ) );
153         assertFalse( ArtifactIdUtils.equalsBaseId( artifact2, artifact1 ) );
154 
155         artifact2 = new DefaultArtifact( "gid", "aid", "ext", "1.0-20110205.132618-24" );
156         assertTrue( ArtifactIdUtils.equalsBaseId( artifact1, artifact2 ) );
157         assertTrue( ArtifactIdUtils.equalsBaseId( artifact2, artifact1 ) );
158 
159         artifact2 = new DefaultArtifact( "gid", "aid", "ext", "1.0-20110205.132618-23" );
160         assertTrue( ArtifactIdUtils.equalsBaseId( artifact1, artifact2 ) );
161         assertTrue( ArtifactIdUtils.equalsBaseId( artifact2, artifact1 ) );
162 
163         assertTrue( ArtifactIdUtils.equalsBaseId( artifact1, artifact1 ) );
164     }
165 
166     @Test
167     public void testEqualsVersionlessId()
168     {
169         Artifact artifact1 = null;
170         Artifact artifact2 = null;
171         assertFalse( ArtifactIdUtils.equalsVersionlessId( artifact1, artifact2 ) );
172         assertFalse( ArtifactIdUtils.equalsVersionlessId( artifact2, artifact1 ) );
173 
174         artifact1 = new DefaultArtifact( "gid", "aid", "ext", "1.0-20110205.132618-23" );
175         assertFalse( ArtifactIdUtils.equalsVersionlessId( artifact1, artifact2 ) );
176         assertFalse( ArtifactIdUtils.equalsVersionlessId( artifact2, artifact1 ) );
177 
178         artifact2 = new DefaultArtifact( "gidX", "aid", "ext", "1.0-20110205.132618-23" );
179         assertFalse( ArtifactIdUtils.equalsVersionlessId( artifact1, artifact2 ) );
180         assertFalse( ArtifactIdUtils.equalsVersionlessId( artifact2, artifact1 ) );
181 
182         artifact2 = new DefaultArtifact( "gid", "aidX", "ext", "1.0-20110205.132618-23" );
183         assertFalse( ArtifactIdUtils.equalsVersionlessId( artifact1, artifact2 ) );
184         assertFalse( ArtifactIdUtils.equalsVersionlessId( artifact2, artifact1 ) );
185 
186         artifact2 = new DefaultArtifact( "gid", "aid", "extX", "1.0-20110205.132618-23" );
187         assertFalse( ArtifactIdUtils.equalsVersionlessId( artifact1, artifact2 ) );
188         assertFalse( ArtifactIdUtils.equalsVersionlessId( artifact2, artifact1 ) );
189 
190         artifact2 = new DefaultArtifact( "gid", "aid", "ext", "1.0-20110205.132618-24" );
191         assertTrue( ArtifactIdUtils.equalsVersionlessId( artifact1, artifact2 ) );
192         assertTrue( ArtifactIdUtils.equalsVersionlessId( artifact2, artifact1 ) );
193 
194         artifact2 = new DefaultArtifact( "gid", "aid", "ext", "1.0-20110205.132618-23" );
195         assertTrue( ArtifactIdUtils.equalsVersionlessId( artifact1, artifact2 ) );
196         assertTrue( ArtifactIdUtils.equalsVersionlessId( artifact2, artifact1 ) );
197 
198         assertTrue( ArtifactIdUtils.equalsVersionlessId( artifact1, artifact1 ) );
199     }
200 
201 }