001package org.eclipse.aether.internal.impl; 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 static org.junit.Assert.*; 023 024import java.io.File; 025import java.io.IOException; 026 027import org.eclipse.aether.RepositorySystemSession; 028import org.eclipse.aether.artifact.Artifact; 029import org.eclipse.aether.artifact.DefaultArtifact; 030import org.eclipse.aether.internal.impl.SimpleLocalRepositoryManager; 031import org.eclipse.aether.internal.test.util.TestFileUtils; 032import org.eclipse.aether.internal.test.util.TestUtils; 033import org.eclipse.aether.repository.LocalArtifactRequest; 034import org.eclipse.aether.repository.LocalArtifactResult; 035import org.eclipse.aether.repository.RemoteRepository; 036import org.junit.After; 037import org.junit.Before; 038import org.junit.Test; 039 040/** 041 */ 042public class SimpleLocalRepositoryManagerTest 043{ 044 045 private File basedir; 046 047 private SimpleLocalRepositoryManager manager; 048 049 private RepositorySystemSession session; 050 051 @Before 052 public void setup() 053 throws IOException 054 { 055 basedir = TestFileUtils.createTempDir( "simple-repo" ); 056 manager = new SimpleLocalRepositoryManager( basedir ); 057 session = TestUtils.newSession(); 058 } 059 060 @After 061 public void tearDown() 062 throws Exception 063 { 064 TestFileUtils.deleteFile( basedir ); 065 manager = null; 066 session = null; 067 } 068 069 @Test 070 public void testGetPathForLocalArtifact() 071 { 072 Artifact artifact = new DefaultArtifact( "g.i.d:a.i.d:1.0-SNAPSHOT" ); 073 assertEquals( "1.0-SNAPSHOT", artifact.getBaseVersion() ); 074 assertEquals( "g/i/d/a.i.d/1.0-SNAPSHOT/a.i.d-1.0-SNAPSHOT.jar", manager.getPathForLocalArtifact( artifact ) ); 075 076 artifact = new DefaultArtifact( "g.i.d:a.i.d:1.0-20110329.221805-4" ); 077 assertEquals( "1.0-SNAPSHOT", artifact.getBaseVersion() ); 078 assertEquals( "g/i/d/a.i.d/1.0-SNAPSHOT/a.i.d-1.0-SNAPSHOT.jar", manager.getPathForLocalArtifact( artifact ) ); 079 080 artifact = new DefaultArtifact( "g.i.d", "a.i.d", "", "", "1.0-SNAPSHOT" ); 081 assertEquals( "g/i/d/a.i.d/1.0-SNAPSHOT/a.i.d-1.0-SNAPSHOT", manager.getPathForLocalArtifact( artifact ) ); 082 } 083 084 @Test 085 public void testGetPathForRemoteArtifact() 086 { 087 RemoteRepository remoteRepo = new RemoteRepository.Builder( "repo", "default", "ram:/void" ).build(); 088 089 Artifact artifact = new DefaultArtifact( "g.i.d:a.i.d:1.0-SNAPSHOT" ); 090 assertEquals( "1.0-SNAPSHOT", artifact.getBaseVersion() ); 091 assertEquals( "g/i/d/a.i.d/1.0-SNAPSHOT/a.i.d-1.0-SNAPSHOT.jar", 092 manager.getPathForRemoteArtifact( artifact, remoteRepo, "" ) ); 093 094 artifact = new DefaultArtifact( "g.i.d:a.i.d:1.0-20110329.221805-4" ); 095 assertEquals( "1.0-SNAPSHOT", artifact.getBaseVersion() ); 096 assertEquals( "g/i/d/a.i.d/1.0-SNAPSHOT/a.i.d-1.0-20110329.221805-4.jar", 097 manager.getPathForRemoteArtifact( artifact, remoteRepo, "" ) ); 098 } 099 100 @Test 101 public void testFindArtifactUsesTimestampedVersion() 102 throws Exception 103 { 104 Artifact artifact = new DefaultArtifact( "g.i.d:a.i.d:1.0-SNAPSHOT" ); 105 File file = new File( basedir, manager.getPathForLocalArtifact( artifact ) ); 106 TestFileUtils.writeString( file, "test" ); 107 108 artifact = artifact.setVersion( "1.0-20110329.221805-4" ); 109 LocalArtifactRequest request = new LocalArtifactRequest(); 110 request.setArtifact( artifact ); 111 LocalArtifactResult result = manager.find( session, request ); 112 assertNull( result.toString(), result.getFile() ); 113 assertFalse( result.toString(), result.isAvailable() ); 114 } 115 116}