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.codehaus.plexus.PlexusTestCase;
32  
33  /**
34   * @author Igor Fedorenko
35   */
36  public class DefaultMavenMetadataCacheTest
37      extends PlexusTestCase
38  {
39      private RepositorySystem repositorySystem;
40  
41      protected void setUp()
42          throws Exception
43      {
44          super.setUp();
45          repositorySystem = lookup( RepositorySystem.class );
46      }
47  
48      @Override
49      protected void tearDown()
50          throws Exception
51      {
52          repositorySystem = null;
53          super.tearDown();
54      }
55  
56      public void testCacheKey()
57          throws Exception
58      {
59          Artifact a1 = repositorySystem.createArtifact( "testGroup", "testArtifact", "1.2.3", "jar" );
60          ArtifactRepository lr1 = new DelegatingLocalArtifactRepository( repositorySystem.createDefaultLocalRepository() );
61          ArtifactRepository rr1 = repositorySystem.createDefaultRemoteRepository();
62          a1.setDependencyFilter( new ExcludesArtifactFilter( Arrays.asList( "foo" ) ) );
63  
64          Artifact a2 = repositorySystem.createArtifact( "testGroup", "testArtifact", "1.2.3", "jar" );
65          ArtifactRepository lr2 = new DelegatingLocalArtifactRepository( repositorySystem.createDefaultLocalRepository() );
66          ArtifactRepository rr2 = repositorySystem.createDefaultRemoteRepository();
67          a2.setDependencyFilter( new ExcludesArtifactFilter( Arrays.asList( "foo" ) ) );
68  
69          // sanity checks
70          assertNotSame( a1, a2 );
71          assertNotSame( lr1, lr2 );
72          assertNotSame( rr1, rr2 );
73  
74          CacheKey k1 = new CacheKey( a1, false, lr1, Collections.singletonList( rr1 ) );
75          CacheKey k2 = new CacheKey( a2, false, lr2, Collections.singletonList( rr2 ) );
76          
77          assertEquals(k1.hashCode(), k2.hashCode());
78      }
79  }