View Javadoc
1   package org.apache.maven.repository.legacy;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one or more contributor license
5    * agreements. See the NOTICE file distributed with this work for additional information regarding
6    * copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance with the License. You may obtain a
8    * 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, software distributed under the License
13   * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
14   * or implied. See the License for the specific language governing permissions and limitations under
15   * the License.
16   */
17  
18  import java.io.File;
19  import java.util.Arrays;
20  
21  import org.apache.maven.artifact.repository.ArtifactRepository;
22  import org.apache.maven.artifact.repository.Authentication;
23  import org.apache.maven.repository.RepositorySystem;
24  import org.apache.maven.settings.Server;
25  import org.codehaus.plexus.ContainerConfiguration;
26  import org.codehaus.plexus.PlexusConstants;
27  import org.codehaus.plexus.PlexusTestCase;
28  
29  /**
30   * Tests {@link LegacyRepositorySystem}.
31   *
32   * @author Benjamin Bentmann
33   */
34  public class LegacyRepositorySystemTest
35      extends PlexusTestCase
36  {
37      private RepositorySystem repositorySystem;
38  
39      @Override
40      protected void customizeContainerConfiguration( ContainerConfiguration containerConfiguration )
41      {
42          super.customizeContainerConfiguration( containerConfiguration );
43          containerConfiguration.setAutoWiring( true );
44          containerConfiguration.setClassPathScanning( PlexusConstants.SCANNING_INDEX );
45      }
46  
47      @Override
48      protected void setUp()
49          throws Exception
50      {
51          super.setUp();
52          repositorySystem = lookup( RepositorySystem.class, "default" );
53      }
54  
55      @Override
56      protected void tearDown()
57          throws Exception
58      {
59          repositorySystem = null;
60          super.tearDown();
61      }
62  
63      public void testThatLocalRepositoryWithSpacesIsProperlyHandled()
64          throws Exception
65      {
66          File basedir = new File( "target/spacy path" ).getAbsoluteFile();
67          ArtifactRepository repo = repositorySystem.createLocalRepository( basedir );
68          assertEquals( basedir, new File( repo.getBasedir() ) );
69      }
70  
71      public void testAuthenticationHandling()
72          throws Exception
73      {
74          Server server = new Server();
75          server.setId( "repository" );
76          server.setUsername( "jason" );
77          server.setPassword( "abc123" );
78  
79          ArtifactRepository repository =
80              repositorySystem.createArtifactRepository( "repository", "http://foo", null, null, null );
81          repositorySystem.injectAuthentication( Arrays.asList( repository ), Arrays.asList( server ) );
82          Authentication authentication = repository.getAuthentication();
83          assertNotNull( authentication );
84          assertEquals( "jason", authentication.getUsername() );
85          assertEquals( "abc123", authentication.getPassword() );
86      }
87  
88  }