1 package org.eclipse.aether.internal.impl;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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 throws Exception
72 {
73 Artifact artifact = new DefaultArtifact( "g.i.d:a.i.d:1.0-SNAPSHOT" );
74 assertEquals( "1.0-SNAPSHOT", artifact.getBaseVersion() );
75 assertEquals( "g/i/d/a.i.d/1.0-SNAPSHOT/a.i.d-1.0-SNAPSHOT.jar", manager.getPathForLocalArtifact( artifact ) );
76
77 artifact = new DefaultArtifact( "g.i.d:a.i.d:1.0-20110329.221805-4" );
78 assertEquals( "1.0-SNAPSHOT", artifact.getBaseVersion() );
79 assertEquals( "g/i/d/a.i.d/1.0-SNAPSHOT/a.i.d-1.0-SNAPSHOT.jar", manager.getPathForLocalArtifact( artifact ) );
80
81 artifact = new DefaultArtifact( "g.i.d", "a.i.d", "", "", "1.0-SNAPSHOT" );
82 assertEquals( "g/i/d/a.i.d/1.0-SNAPSHOT/a.i.d-1.0-SNAPSHOT", manager.getPathForLocalArtifact( artifact ) );
83 }
84
85 @Test
86 public void testGetPathForRemoteArtifact()
87 throws Exception
88 {
89 RemoteRepository remoteRepo = new RemoteRepository.Builder( "repo", "default", "ram:/void" ).build();
90
91 Artifact artifact = new DefaultArtifact( "g.i.d:a.i.d:1.0-SNAPSHOT" );
92 assertEquals( "1.0-SNAPSHOT", artifact.getBaseVersion() );
93 assertEquals( "g/i/d/a.i.d/1.0-SNAPSHOT/a.i.d-1.0-SNAPSHOT.jar",
94 manager.getPathForRemoteArtifact( artifact, remoteRepo, "" ) );
95
96 artifact = new DefaultArtifact( "g.i.d:a.i.d:1.0-20110329.221805-4" );
97 assertEquals( "1.0-SNAPSHOT", artifact.getBaseVersion() );
98 assertEquals( "g/i/d/a.i.d/1.0-SNAPSHOT/a.i.d-1.0-20110329.221805-4.jar",
99 manager.getPathForRemoteArtifact( artifact, remoteRepo, "" ) );
100 }
101
102 @Test
103 public void testFindArtifactUsesTimestampedVersion()
104 throws Exception
105 {
106 Artifact artifact = new DefaultArtifact( "g.i.d:a.i.d:1.0-SNAPSHOT" );
107 File file = new File( basedir, manager.getPathForLocalArtifact( artifact ) );
108 TestFileUtils.writeString( file, "test" );
109
110 artifact = artifact.setVersion( "1.0-20110329.221805-4" );
111 LocalArtifactRequest request = new LocalArtifactRequest();
112 request.setArtifact( artifact );
113 LocalArtifactResult result = manager.find( session, request );
114 assertNull( result.toString(), result.getFile() );
115 assertFalse( result.toString(), result.isAvailable() );
116 }
117
118 }