View Javadoc
1   package org.apache.maven.project.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 java.util.Arrays;
23  import java.util.Collections;
24  
25  import org.apache.maven.artifact.Artifact;
26  import org.apache.maven.artifact.repository.ArtifactRepository;
27  import org.apache.maven.artifact.resolver.filter.ExcludesArtifactFilter;
28  import org.apache.maven.project.artifact.DefaultMavenMetadataCache.CacheKey;
29  import org.apache.maven.repository.DelegatingLocalArtifactRepository;
30  import org.apache.maven.repository.RepositorySystem;
31  import org.apache.maven.repository.TestRepositorySystem;
32  
33  import junit.framework.TestCase;
34  
35  /**
36   * @author Igor Fedorenko
37   */
38  public class DefaultMavenMetadataCacheTest
39      extends TestCase
40  {
41      private RepositorySystem repositorySystem;
42  
43      protected void setUp()
44          throws Exception
45      {
46          super.setUp();
47          repositorySystem = new TestRepositorySystem();
48      }
49  
50      @Override
51      protected void tearDown()
52          throws Exception
53      {
54          repositorySystem = null;
55          super.tearDown();
56      }
57  
58      public void testCacheKey()
59          throws Exception
60      {
61          Artifact a1 = repositorySystem.createArtifact( "testGroup", "testArtifact", "1.2.3", "jar" );
62          @SuppressWarnings( "deprecation" )
63          ArtifactRepository lr1 = new DelegatingLocalArtifactRepository( repositorySystem.createDefaultLocalRepository() );
64          ArtifactRepository rr1 = repositorySystem.createDefaultRemoteRepository();
65          a1.setDependencyFilter( new ExcludesArtifactFilter( Arrays.asList( "foo" ) ) );
66  
67          Artifact a2 = repositorySystem.createArtifact( "testGroup", "testArtifact", "1.2.3", "jar" );
68          @SuppressWarnings( "deprecation" )
69          ArtifactRepository lr2 = new DelegatingLocalArtifactRepository( repositorySystem.createDefaultLocalRepository() );
70          ArtifactRepository rr2 = repositorySystem.createDefaultRemoteRepository();
71          a2.setDependencyFilter( new ExcludesArtifactFilter( Arrays.asList( "foo" ) ) );
72  
73          // sanity checks
74          assertNotSame( a1, a2 );
75          assertNotSame( lr1, lr2 );
76          assertNotSame( rr1, rr2 );
77  
78          CacheKey k1 = new CacheKey( a1, false, lr1, Collections.singletonList( rr1 ) );
79          CacheKey k2 = new CacheKey( a2, false, lr2, Collections.singletonList( rr2 ) );
80  
81          assertEquals(k1.hashCode(), k2.hashCode());
82      }
83  }