View Javadoc
1   package org.eclipse.aether.internal.impl;
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 static org.junit.Assert.*;
23  
24  import java.io.File;
25  import java.io.IOException;
26  
27  import org.eclipse.aether.RepositorySystemSession;
28  import org.eclipse.aether.artifact.Artifact;
29  import org.eclipse.aether.artifact.DefaultArtifact;
30  import org.eclipse.aether.internal.impl.SimpleLocalRepositoryManager;
31  import org.eclipse.aether.internal.test.util.TestFileUtils;
32  import org.eclipse.aether.internal.test.util.TestUtils;
33  import org.eclipse.aether.repository.LocalArtifactRequest;
34  import org.eclipse.aether.repository.LocalArtifactResult;
35  import org.eclipse.aether.repository.RemoteRepository;
36  import org.junit.After;
37  import org.junit.Before;
38  import org.junit.Test;
39  
40  /**
41   */
42  public class SimpleLocalRepositoryManagerTest
43  {
44  
45      private File basedir;
46  
47      private SimpleLocalRepositoryManager manager;
48  
49      private RepositorySystemSession session;
50  
51      @Before
52      public void setup()
53          throws IOException
54      {
55          basedir = TestFileUtils.createTempDir( "simple-repo" );
56          manager = new SimpleLocalRepositoryManager( basedir );
57          session = TestUtils.newSession();
58      }
59  
60      @After
61      public void tearDown()
62          throws Exception
63      {
64          TestFileUtils.deleteFile( basedir );
65          manager = null;
66          session = null;
67      }
68  
69      @Test
70      public void testGetPathForLocalArtifact()
71      {
72          Artifact artifact = new DefaultArtifact( "g.i.d:a.i.d:1.0-SNAPSHOT" );
73          assertEquals( "1.0-SNAPSHOT", artifact.getBaseVersion() );
74          assertEquals( "g/i/d/a.i.d/1.0-SNAPSHOT/a.i.d-1.0-SNAPSHOT.jar", manager.getPathForLocalArtifact( artifact ) );
75  
76          artifact = new DefaultArtifact( "g.i.d:a.i.d:1.0-20110329.221805-4" );
77          assertEquals( "1.0-SNAPSHOT", artifact.getBaseVersion() );
78          assertEquals( "g/i/d/a.i.d/1.0-SNAPSHOT/a.i.d-1.0-SNAPSHOT.jar", manager.getPathForLocalArtifact( artifact ) );
79  
80          artifact = new DefaultArtifact( "g.i.d", "a.i.d", "", "", "1.0-SNAPSHOT" );
81          assertEquals( "g/i/d/a.i.d/1.0-SNAPSHOT/a.i.d-1.0-SNAPSHOT", manager.getPathForLocalArtifact( artifact ) );
82      }
83  
84      @Test
85      public void testGetPathForRemoteArtifact()
86      {
87          RemoteRepository remoteRepo = new RemoteRepository.Builder( "repo", "default", "ram:/void" ).build();
88  
89          Artifact artifact = new DefaultArtifact( "g.i.d:a.i.d:1.0-SNAPSHOT" );
90          assertEquals( "1.0-SNAPSHOT", artifact.getBaseVersion() );
91          assertEquals( "g/i/d/a.i.d/1.0-SNAPSHOT/a.i.d-1.0-SNAPSHOT.jar",
92                        manager.getPathForRemoteArtifact( artifact, remoteRepo, "" ) );
93  
94          artifact = new DefaultArtifact( "g.i.d:a.i.d:1.0-20110329.221805-4" );
95          assertEquals( "1.0-SNAPSHOT", artifact.getBaseVersion() );
96          assertEquals( "g/i/d/a.i.d/1.0-SNAPSHOT/a.i.d-1.0-20110329.221805-4.jar",
97                        manager.getPathForRemoteArtifact( artifact, remoteRepo, "" ) );
98      }
99  
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 }