1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.repository.legacy;
20
21 import java.io.File;
22 import java.util.Arrays;
23
24 import org.apache.maven.artifact.repository.ArtifactRepository;
25 import org.apache.maven.artifact.repository.Authentication;
26 import org.apache.maven.repository.RepositorySystem;
27 import org.apache.maven.settings.Server;
28 import org.codehaus.plexus.ContainerConfiguration;
29 import org.codehaus.plexus.PlexusConstants;
30 import org.codehaus.plexus.PlexusTestCase;
31
32
33
34
35
36
37 public class LegacyRepositorySystemTest extends PlexusTestCase {
38 private RepositorySystem repositorySystem;
39
40 @Override
41 protected void customizeContainerConfiguration(ContainerConfiguration containerConfiguration) {
42 super.customizeContainerConfiguration(containerConfiguration);
43 containerConfiguration.setAutoWiring(true);
44 containerConfiguration.setClassPathScanning(PlexusConstants.SCANNING_INDEX);
45 }
46
47 @Override
48 protected void setUp() throws Exception {
49 super.setUp();
50 repositorySystem = lookup(RepositorySystem.class, "default");
51 }
52
53 @Override
54 protected void tearDown() throws Exception {
55 repositorySystem = null;
56 super.tearDown();
57 }
58
59 public void testThatLocalRepositoryWithSpacesIsProperlyHandled() throws Exception {
60 File basedir = new File("target/spacy path").getAbsoluteFile();
61 ArtifactRepository repo = repositorySystem.createLocalRepository(basedir);
62 assertEquals(basedir, new File(repo.getBasedir()));
63 }
64
65 public void testAuthenticationHandling() throws Exception {
66 Server server = new Server();
67 server.setId("repository");
68 server.setUsername("jason");
69 server.setPassword("abc123");
70
71 ArtifactRepository repository =
72 repositorySystem.createArtifactRepository("repository", "http://foo", null, null, null);
73 repositorySystem.injectAuthentication(Arrays.asList(repository), Arrays.asList(server));
74 Authentication authentication = repository.getAuthentication();
75 assertNotNull(authentication);
76 assertEquals("jason", authentication.getUsername());
77 assertEquals("abc123", authentication.getPassword());
78 }
79 }