1   package org.apache.maven.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  
23  import org.apache.maven.artifact.handler.ArtifactHandlerMock;
24  import org.apache.maven.artifact.versioning.VersionRange;
25  
26  import junit.framework.TestCase;
27  
28  public class DefaultArtifactTest
29      extends TestCase
30  {
31  
32      private DefaultArtifact artifact;
33  
34      private DefaultArtifact snapshotArtifact;
35  
36      private String groupId = "groupid", artifactId = "artifactId", version = "1.0", scope = "scope", type = "type",
37          classifier = "classifier";
38  
39      private String snapshotSpecVersion = "1.0-SNAPSHOT";
40      private String snapshotResolvedVersion = "1.0-20070606.010101-1";
41  
42      private VersionRange versionRange;
43      private VersionRange snapshotVersionRange;
44  
45      private ArtifactHandlerMock artifactHandler;
46  
47      protected void setUp()
48          throws Exception
49      {
50          super.setUp();
51          artifactHandler = new ArtifactHandlerMock();
52          versionRange = VersionRange.createFromVersion( version );
53          artifact = new DefaultArtifact( groupId, artifactId, versionRange, scope, type, classifier, artifactHandler );
54  
55          snapshotVersionRange = VersionRange.createFromVersion( snapshotResolvedVersion );
56          snapshotArtifact = new DefaultArtifact( groupId, artifactId, snapshotVersionRange, scope, type, classifier, artifactHandler );
57      }
58  
59      public void testGetVersionReturnsResolvedVersionOnSnapshot()
60      {
61          assertEquals( snapshotResolvedVersion, snapshotArtifact.getVersion() );
62  
63          // this is FOUL!
64  //        snapshotArtifact.isSnapshot();
65  
66          assertEquals( snapshotSpecVersion, snapshotArtifact.getBaseVersion() );
67      }
68  
69      public void testGetDependencyConflictId()
70      {
71          assertEquals( groupId + ":" + artifactId + ":" + type + ":" + classifier, artifact.getDependencyConflictId() );
72      }
73  
74      public void testGetDependencyConflictIdNullGroupId()
75      {
76          artifact.setGroupId( null );
77          assertEquals( null + ":" + artifactId + ":" + type + ":" + classifier, artifact.getDependencyConflictId() );
78      }
79  
80      public void testGetDependencyConflictIdNullClassifier()
81      {
82          artifact = new DefaultArtifact( groupId, artifactId, versionRange, scope, type, null, artifactHandler );
83          assertEquals( groupId + ":" + artifactId + ":" + type, artifact.getDependencyConflictId() );
84      }
85  
86      public void testGetDependencyConflictIdNullScope()
87      {
88          artifact.setScope( null );
89          assertEquals( groupId + ":" + artifactId + ":" + type + ":" + classifier, artifact.getDependencyConflictId() );
90      }
91  
92      public void testToString()
93      {
94          assertEquals( groupId + ":" + artifactId + ":" + type + ":" + classifier + ":" + version + ":" + scope,
95                        artifact.toString() );
96      }
97  
98      public void testToStringNullGroupId()
99      {
100         artifact.setGroupId( null );
101         assertEquals( artifactId + ":" + type + ":" + classifier + ":" + version + ":" + scope, artifact.toString() );
102     }
103 
104     public void testToStringNullClassifier()
105     {
106         artifact = new DefaultArtifact( groupId, artifactId, versionRange, scope, type, null, artifactHandler );
107         assertEquals( groupId + ":" + artifactId + ":" + type + ":" + version + ":" + scope, artifact.toString() );
108     }
109 
110     public void testToStringNullScope()
111     {
112         artifact.setScope( null );
113         assertEquals( groupId + ":" + artifactId + ":" + type + ":" + classifier + ":" + version, artifact.toString() );
114     }
115 
116 }