View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.eclipse.aether.internal.impl;
20  
21  import java.io.File;
22  import java.io.IOException;
23  
24  import org.eclipse.aether.RepositorySystemSession;
25  import org.eclipse.aether.artifact.Artifact;
26  import org.eclipse.aether.artifact.DefaultArtifact;
27  import org.eclipse.aether.internal.test.util.TestFileUtils;
28  import org.eclipse.aether.internal.test.util.TestUtils;
29  import org.eclipse.aether.repository.LocalArtifactRequest;
30  import org.eclipse.aether.repository.LocalArtifactResult;
31  import org.eclipse.aether.repository.RemoteRepository;
32  import org.junit.After;
33  import org.junit.Before;
34  import org.junit.Test;
35  
36  import static org.junit.Assert.*;
37  
38  /**
39   */
40  public class SimpleLocalRepositoryManagerTest {
41  
42      private File basedir;
43  
44      private SimpleLocalRepositoryManager manager;
45  
46      private RepositorySystemSession session;
47  
48      @Before
49      public void setup() throws IOException {
50          basedir = TestFileUtils.createTempDir("simple-repo");
51          manager = new SimpleLocalRepositoryManager(basedir, "simple", new DefaultLocalPathComposer());
52          session = TestUtils.newSession();
53      }
54  
55      @After
56      public void tearDown() throws Exception {
57          TestFileUtils.deleteFile(basedir);
58          manager = null;
59          session = null;
60      }
61  
62      @Test
63      public void testGetPathForLocalArtifact() {
64          Artifact artifact = new DefaultArtifact("g.i.d:a.i.d:1.0-SNAPSHOT");
65          assertEquals("1.0-SNAPSHOT", artifact.getBaseVersion());
66          assertEquals("g/i/d/a.i.d/1.0-SNAPSHOT/a.i.d-1.0-SNAPSHOT.jar", manager.getPathForLocalArtifact(artifact));
67  
68          artifact = new DefaultArtifact("g.i.d:a.i.d:1.0-20110329.221805-4");
69          assertEquals("1.0-SNAPSHOT", artifact.getBaseVersion());
70          assertEquals("g/i/d/a.i.d/1.0-SNAPSHOT/a.i.d-1.0-SNAPSHOT.jar", manager.getPathForLocalArtifact(artifact));
71  
72          artifact = new DefaultArtifact("g.i.d", "a.i.d", "", "", "1.0-SNAPSHOT");
73          assertEquals("g/i/d/a.i.d/1.0-SNAPSHOT/a.i.d-1.0-SNAPSHOT", manager.getPathForLocalArtifact(artifact));
74      }
75  
76      @Test
77      public void testGetPathForRemoteArtifact() {
78          RemoteRepository remoteRepo = new RemoteRepository.Builder("repo", "default", "ram:/void").build();
79  
80          Artifact artifact = new DefaultArtifact("g.i.d:a.i.d:1.0-SNAPSHOT");
81          assertEquals("1.0-SNAPSHOT", artifact.getBaseVersion());
82          assertEquals(
83                  "g/i/d/a.i.d/1.0-SNAPSHOT/a.i.d-1.0-SNAPSHOT.jar",
84                  manager.getPathForRemoteArtifact(artifact, remoteRepo, ""));
85  
86          artifact = new DefaultArtifact("g.i.d:a.i.d:1.0-20110329.221805-4");
87          assertEquals("1.0-SNAPSHOT", artifact.getBaseVersion());
88          assertEquals(
89                  "g/i/d/a.i.d/1.0-SNAPSHOT/a.i.d-1.0-20110329.221805-4.jar",
90                  manager.getPathForRemoteArtifact(artifact, remoteRepo, ""));
91      }
92  
93      @Test
94      public void testFindArtifactUsesTimestampedVersion() throws Exception {
95          Artifact artifact = new DefaultArtifact("g.i.d:a.i.d:1.0-SNAPSHOT");
96          File file = new File(basedir, manager.getPathForLocalArtifact(artifact));
97          TestFileUtils.writeString(file, "test");
98  
99          artifact = artifact.setVersion("1.0-20110329.221805-4");
100         LocalArtifactRequest request = new LocalArtifactRequest();
101         request.setArtifact(artifact);
102         LocalArtifactResult result = manager.find(session, request);
103         assertNull(result.toString(), result.getFile());
104         assertFalse(result.toString(), result.isAvailable());
105     }
106 }