001package 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 022import java.util.Arrays; 023import java.util.Collections; 024 025import org.apache.maven.artifact.Artifact; 026import org.apache.maven.artifact.repository.ArtifactRepository; 027import org.apache.maven.artifact.resolver.filter.ExcludesArtifactFilter; 028import org.apache.maven.project.artifact.DefaultMavenMetadataCache.CacheKey; 029import org.apache.maven.repository.DelegatingLocalArtifactRepository; 030import org.apache.maven.repository.RepositorySystem; 031import org.codehaus.plexus.PlexusTestCase; 032 033/** 034 * @author Igor Fedorenko 035 */ 036public 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 @SuppressWarnings( "deprecation" ) 061 ArtifactRepository lr1 = new DelegatingLocalArtifactRepository( repositorySystem.createDefaultLocalRepository() ); 062 ArtifactRepository rr1 = repositorySystem.createDefaultRemoteRepository(); 063 a1.setDependencyFilter( new ExcludesArtifactFilter( Arrays.asList( "foo" ) ) ); 064 065 Artifact a2 = repositorySystem.createArtifact( "testGroup", "testArtifact", "1.2.3", "jar" ); 066 @SuppressWarnings( "deprecation" ) 067 ArtifactRepository lr2 = new DelegatingLocalArtifactRepository( repositorySystem.createDefaultLocalRepository() ); 068 ArtifactRepository rr2 = repositorySystem.createDefaultRemoteRepository(); 069 a2.setDependencyFilter( new ExcludesArtifactFilter( Arrays.asList( "foo" ) ) ); 070 071 // sanity checks 072 assertNotSame( a1, a2 ); 073 assertNotSame( lr1, lr2 ); 074 assertNotSame( rr1, rr2 ); 075 076 CacheKey k1 = new CacheKey( a1, false, lr1, Collections.singletonList( rr1 ) ); 077 CacheKey k2 = new CacheKey( a2, false, lr2, Collections.singletonList( rr2 ) ); 078 079 assertEquals(k1.hashCode(), k2.hashCode()); 080 } 081}