001package org.eclipse.aether.internal.impl.collect; 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 org.eclipse.aether.DefaultRepositorySystemSession; 023import org.eclipse.aether.artifact.DefaultArtifact; 024import org.eclipse.aether.graph.Dependency; 025import org.eclipse.aether.repository.RemoteRepository; 026import org.eclipse.aether.resolution.ArtifactDescriptorRequest; 027import org.eclipse.aether.resolution.ArtifactDescriptorResult; 028import org.eclipse.aether.resolution.VersionRangeRequest; 029import org.junit.Test; 030 031import java.util.Collections; 032 033import static org.junit.Assert.assertEquals; 034import static org.junit.Assert.assertNotNull; 035 036public class DataPoolTest 037{ 038 039 private DataPool newDataPool() 040 { 041 return new DataPool( new DefaultRepositorySystemSession() ); 042 } 043 044 @Test 045 public void testArtifactDescriptorCaching() 046 { 047 ArtifactDescriptorRequest request = new ArtifactDescriptorRequest(); 048 request.setArtifact( new DefaultArtifact( "gid:aid:1" ) ); 049 ArtifactDescriptorResult result = new ArtifactDescriptorResult( request ); 050 result.setArtifact( new DefaultArtifact( "gid:aid:2" ) ); 051 result.addRelocation( request.getArtifact() ); 052 result.addDependency( new Dependency( new DefaultArtifact( "gid:dep:3" ), "compile" ) ); 053 result.addManagedDependency( new Dependency( new DefaultArtifact( "gid:mdep:3" ), "runtime" ) ); 054 result.addRepository( new RemoteRepository.Builder( "test", "default", "http://localhost" ).build() ); 055 result.addAlias( new DefaultArtifact( "gid:alias:4" ) ); 056 057 DataPool pool = newDataPool(); 058 Object key = pool.toKey( request ); 059 pool.putDescriptor( key, result ); 060 ArtifactDescriptorResult cached = pool.getDescriptor( key, request ); 061 assertNotNull( cached ); 062 assertEquals( result.getArtifact(), cached.getArtifact() ); 063 assertEquals( result.getRelocations(), cached.getRelocations() ); 064 assertEquals( result.getDependencies(), cached.getDependencies() ); 065 assertEquals( result.getManagedDependencies(), cached.getManagedDependencies() ); 066 assertEquals( result.getRepositories(), cached.getRepositories() ); 067 assertEquals( result.getAliases(), cached.getAliases() ); 068 } 069 070 @Test 071 public void testConstraintKey() 072 { 073 VersionRangeRequest request = new VersionRangeRequest(); 074 request.setRepositories( 075 Collections.singletonList( new RemoteRepository.Builder( "some-id", "some-type", "http://www.example.com" ).build() ) 076 ); 077 request.setArtifact( new DefaultArtifact("group:artifact:1.0") ); 078 079 DataPool pool = newDataPool(); 080 081 Object key1 = pool.toKey( request ); 082 Object key2 = pool.toKey( request ); 083 assertEquals(key1, key2); 084 } 085}