001 package org.apache.maven.project.artifact; 002 003 /* 004 * Licensed to the Apache Software Foundation (ASF) under one 005 * or more contributor license agreements. See the NOTICE file 006 * distributed with this work for additional information 007 * regarding copyright ownership. The ASF licenses this file 008 * to you under the Apache License, Version 2.0 (the 009 * "License"); you may not use this file except in compliance 010 * with the License. You may obtain a copy of the License at 011 * 012 * http://www.apache.org/licenses/LICENSE-2.0 013 * 014 * Unless required by applicable law or agreed to in writing, 015 * software distributed under the License is distributed on an 016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 017 * KIND, either express or implied. See the License for the 018 * specific language governing permissions and limitations 019 * under the License. 020 */ 021 022 import java.util.Arrays; 023 import java.util.Collections; 024 025 import org.apache.maven.artifact.Artifact; 026 import org.apache.maven.artifact.repository.ArtifactRepository; 027 import org.apache.maven.artifact.resolver.filter.ExcludesArtifactFilter; 028 import org.apache.maven.project.artifact.DefaultMavenMetadataCache.CacheKey; 029 import org.apache.maven.repository.DelegatingLocalArtifactRepository; 030 import org.apache.maven.repository.RepositorySystem; 031 import org.codehaus.plexus.PlexusTestCase; 032 033 /** 034 * @author Igor Fedorenko 035 */ 036 public class DefaultMavenMetadataCacheTest 037 extends PlexusTestCase 038 { 039 private RepositorySystem repositorySystem; 040 041 protected void setUp() 042 throws Exception 043 { 044 super.setUp(); 045 repositorySystem = lookup( RepositorySystem.class ); 046 } 047 048 @Override 049 protected void tearDown() 050 throws Exception 051 { 052 repositorySystem = null; 053 super.tearDown(); 054 } 055 056 public void testCacheKey() 057 throws Exception 058 { 059 Artifact a1 = repositorySystem.createArtifact( "testGroup", "testArtifact", "1.2.3", "jar" ); 060 ArtifactRepository lr1 = new DelegatingLocalArtifactRepository( repositorySystem.createDefaultLocalRepository() ); 061 ArtifactRepository rr1 = repositorySystem.createDefaultRemoteRepository(); 062 a1.setDependencyFilter( new ExcludesArtifactFilter( Arrays.asList( "foo" ) ) ); 063 064 Artifact a2 = repositorySystem.createArtifact( "testGroup", "testArtifact", "1.2.3", "jar" ); 065 ArtifactRepository lr2 = new DelegatingLocalArtifactRepository( repositorySystem.createDefaultLocalRepository() ); 066 ArtifactRepository rr2 = repositorySystem.createDefaultRemoteRepository(); 067 a2.setDependencyFilter( new ExcludesArtifactFilter( Arrays.asList( "foo" ) ) ); 068 069 // sanity checks 070 assertNotSame( a1, a2 ); 071 assertNotSame( lr1, lr2 ); 072 assertNotSame( rr1, rr2 ); 073 074 CacheKey k1 = new CacheKey( a1, false, lr1, Collections.singletonList( rr1 ) ); 075 CacheKey k2 = new CacheKey( a2, false, lr2, Collections.singletonList( rr2 ) ); 076 077 assertEquals(k1.hashCode(), k2.hashCode()); 078 } 079 }