1   package org.apache.maven.plugins.shade.mojo;
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 junit.framework.TestCase;
23  
24  /**
25   * @author Benjamin Bentmann
26   */
27  public class ArtifactIdTest
28      extends TestCase
29  {
30  
31      public void testIdParsing()
32      {
33          ArtifactId id;
34  
35          id = new ArtifactId( (String) null );
36          assertEquals( "", id.getGroupId() );
37  
38          id = new ArtifactId( "" );
39          assertEquals( "", id.getGroupId() );
40  
41          id = new ArtifactId( "gid" );
42          assertEquals( "gid", id.getGroupId() );
43          assertEquals( "*", id.getArtifactId() );
44          assertEquals( "*", id.getType() );
45          assertEquals( "*", id.getClassifier() );
46  
47          id = new ArtifactId( "gid:" );
48          assertEquals( "gid", id.getGroupId() );
49          assertEquals( "", id.getArtifactId() );
50          assertEquals( "*", id.getType() );
51          assertEquals( "*", id.getClassifier() );
52  
53          id = new ArtifactId( ":aid" );
54          assertEquals( "", id.getGroupId() );
55          assertEquals( "aid", id.getArtifactId() );
56          assertEquals( "*", id.getType() );
57          assertEquals( "*", id.getClassifier() );
58  
59          id = new ArtifactId( "gid:aid" );
60          assertEquals( "gid", id.getGroupId() );
61          assertEquals( "aid", id.getArtifactId() );
62          assertEquals( "*", id.getType() );
63          assertEquals( "*", id.getClassifier() );
64  
65          id = new ArtifactId( "gid:aid:" );
66          assertEquals( "gid", id.getGroupId() );
67          assertEquals( "aid", id.getArtifactId() );
68          assertEquals( "*", id.getType() );
69          assertEquals( "", id.getClassifier() );
70  
71          id = new ArtifactId( "gid:aid:cls" );
72          assertEquals( "gid", id.getGroupId() );
73          assertEquals( "aid", id.getArtifactId() );
74          assertEquals( "*", id.getType() );
75          assertEquals( "cls", id.getClassifier() );
76  
77          id = new ArtifactId( "gid:aid:type:cls" );
78          assertEquals( "gid", id.getGroupId() );
79          assertEquals( "aid", id.getArtifactId() );
80          assertEquals( "type", id.getType() );
81          assertEquals( "cls", id.getClassifier() );
82  
83          id = new ArtifactId( "gid:aid::cls" );
84          assertEquals( "gid", id.getGroupId() );
85          assertEquals( "aid", id.getArtifactId() );
86          assertEquals( "", id.getType() );
87          assertEquals( "cls", id.getClassifier() );
88  
89          id = new ArtifactId( "gid:aid::" );
90          assertEquals( "gid", id.getGroupId() );
91          assertEquals( "aid", id.getArtifactId() );
92          assertEquals( "", id.getType() );
93          assertEquals( "", id.getClassifier() );
94  
95          id = new ArtifactId( "*:aid:type:cls" );
96          assertEquals( "*", id.getGroupId() );
97          assertEquals( "aid", id.getArtifactId() );
98          assertEquals( "type", id.getType() );
99          assertEquals( "cls", id.getClassifier() );
100 
101         id = new ArtifactId( "gid:*:type:cls" );
102         assertEquals( "gid", id.getGroupId() );
103         assertEquals( "*", id.getArtifactId() );
104         assertEquals( "type", id.getType() );
105         assertEquals( "cls", id.getClassifier() );
106 
107         id = new ArtifactId( "gid:aid:*:cls" );
108         assertEquals( "gid", id.getGroupId() );
109         assertEquals( "aid", id.getArtifactId() );
110         assertEquals( "*", id.getType() );
111         assertEquals( "cls", id.getClassifier() );
112 
113         id = new ArtifactId( "gid:aid:type:*" );
114         assertEquals( "gid", id.getGroupId() );
115         assertEquals( "aid", id.getArtifactId() );
116         assertEquals( "type", id.getType() );
117         assertEquals( "*", id.getClassifier() );
118     }
119 
120     public void testMatches()
121     {
122         assertTrue( new ArtifactId( "gid", "aid", "type", "cls" ).matches( new ArtifactId( "gid:aid:type:cls" ) ) );
123         assertFalse( new ArtifactId( "Gid", "aid", "type", "cls" ).matches( new ArtifactId( "gid:aid:type:cls" ) ) );
124         assertFalse( new ArtifactId( "gid", "Aid", "type", "cls" ).matches( new ArtifactId( "gid:aid:type:cls" ) ) );
125         assertFalse( new ArtifactId( "gid", "aid", "Type", "cls" ).matches( new ArtifactId( "gid:aid:type:cls" ) ) );
126         assertFalse( new ArtifactId( "gid", "aid", "type", "Cls" ).matches( new ArtifactId( "gid:aid:type:cls" ) ) );
127 
128         assertTrue( new ArtifactId( "gid", "aid", "any", "cls" ).matches( new ArtifactId( "gid:aid:cls" ) ) );
129         assertTrue( new ArtifactId( "gid", "aid", "type", "cls" ).matches( new ArtifactId( "gid:aid:cls" ) ) );
130         assertFalse( new ArtifactId( "id", "aid", "type", "cls" ).matches( new ArtifactId( "gid:aid:cls" ) ) );
131         assertFalse( new ArtifactId( "gid", "id", "type", "cls" ).matches( new ArtifactId( "gid:aid:cls" ) ) );
132         assertFalse( new ArtifactId( "gid", "id", "type", "ls" ).matches( new ArtifactId( "gid:aid:cls" ) ) );
133 
134         assertTrue( new ArtifactId( "gid", "aid", "type", "" ).matches( new ArtifactId( "gid:aid" ) ) );
135         assertTrue( new ArtifactId( "gid", "aid", "any", "tests" ).matches( new ArtifactId( "gid:aid" ) ) );
136         assertFalse( new ArtifactId( "id", "aid", "type", "" ).matches( new ArtifactId( "gid:aid" ) ) );
137         assertFalse( new ArtifactId( "gid", "id", "type", "" ).matches( new ArtifactId( "gid:aid" ) ) );
138 
139         assertTrue( new ArtifactId( "gid", "aid", "type", "" ).matches( new ArtifactId( "gid" ) ) );
140         assertTrue( new ArtifactId( "gid", "id", "any", "any" ).matches( new ArtifactId( "gid" ) ) );
141         assertFalse( new ArtifactId( "id", "aid", "type", "" ).matches( new ArtifactId( "gid" ) ) );
142 
143         assertTrue( new ArtifactId( "gid", "aid", "type", "cls" ).matches( new ArtifactId( "*:aid:type:cls" ) ) );
144         assertTrue( new ArtifactId( "any", "aid", "type", "cls" ).matches( new ArtifactId( "*:aid:type:cls" ) ) );
145         assertFalse( new ArtifactId( "any", "id", "type", "cls" ).matches( new ArtifactId( "*:aid:type:cls" ) ) );
146 
147         assertTrue( new ArtifactId( "gid", "aid", "type", "cls" ).matches( new ArtifactId( "gid:*:type:cls" ) ) );
148         assertTrue( new ArtifactId( "gid", "any", "type", "cls" ).matches( new ArtifactId( "gid:*:type:cls" ) ) );
149         assertFalse( new ArtifactId( "id", "any", "type", "cls" ).matches( new ArtifactId( "gid:*:type:cls" ) ) );
150 
151         assertTrue( new ArtifactId( "gid", "aid", "type", "cls" ).matches( new ArtifactId( "gid:aid:*:cls" ) ) );
152         assertTrue( new ArtifactId( "gid", "aid", "any", "cls" ).matches( new ArtifactId( "gid:aid:*:cls" ) ) );
153         assertFalse( new ArtifactId( "id", "aid", "any", "cls" ).matches( new ArtifactId( "gid:aid:*:cls" ) ) );
154 
155         assertTrue( new ArtifactId( "gid", "aid", "type", "cls" ).matches( new ArtifactId( "gid:aid:type:*" ) ) );
156         assertTrue( new ArtifactId( "gid", "aid", "type", "any" ).matches( new ArtifactId( "gid:aid:type:*" ) ) );
157         assertFalse( new ArtifactId( "id", "aid", "type", "any" ).matches( new ArtifactId( "gid:aid:type:*" ) ) );
158 
159         assertTrue( new ArtifactId( "gid", "aid", "type", "cls" ).matches( new ArtifactId( "gid:a*d" ) ) );
160         assertTrue( new ArtifactId( "gid", "ad", "type", "cls" ).matches( new ArtifactId( "gid:a*d" ) ) );
161         assertTrue( new ArtifactId( "gid", "a---d", "type", "cls" ).matches( new ArtifactId( "gid:a*d" ) ) );
162 
163         assertTrue( new ArtifactId( "gid", "aid", "type", "cls" ).matches( new ArtifactId( "gid:a?d" ) ) );
164         assertTrue( new ArtifactId( "gid", "a-d", "type", "cls" ).matches( new ArtifactId( "gid:a?d" ) ) );
165         assertFalse( new ArtifactId( "gid", "ad", "type", "cls" ).matches( new ArtifactId( "gid:a?d" ) ) );
166         assertFalse( new ArtifactId( "gid", "a---d", "type", "cls" ).matches( new ArtifactId( "gid:a?d" ) ) );
167     }
168 
169 }