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.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   * Tests {@link LegacyRepositorySystem}.
34   *
35   * @author Benjamin Bentmann
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  }