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.PlexusTestCase;
27  
28  /**
29   * Tests {@link LegacyRepositorySystem}.
30   * 
31   * @author Benjamin Bentmann
32   */
33  public class LegacyRepositorySystemTest
34      extends PlexusTestCase
35  {
36      private RepositorySystem repositorySystem;
37  
38      @Override
39      protected void customizeContainerConfiguration( ContainerConfiguration containerConfiguration )
40      {
41          super.customizeContainerConfiguration( containerConfiguration );
42          containerConfiguration.setAutoWiring( true );
43      }
44  
45      @Override
46      protected void setUp()
47          throws Exception
48      {
49          super.setUp();
50          repositorySystem = lookup( RepositorySystem.class, "default" );
51      }
52  
53      @Override
54      protected void tearDown()
55          throws Exception
56      {
57          repositorySystem = null;
58          super.tearDown();
59      }
60  
61      public void testThatLocalRepositoryWithSpacesIsProperlyHandled()
62          throws Exception
63      {
64          File basedir = new File( "target/spacy path" ).getAbsoluteFile();
65          ArtifactRepository repo = repositorySystem.createLocalRepository( basedir );
66          assertEquals( basedir, new File( repo.getBasedir() ) );
67      }
68  
69      public void testAuthenticationHandling()
70          throws Exception
71      {
72          Server server = new Server();
73          server.setId( "repository" );
74          server.setUsername( "jason" );
75          server.setPassword( "abc123" );
76  
77          ArtifactRepository repository =
78              repositorySystem.createArtifactRepository( "repository", "http://foo", null, null, null );
79          repositorySystem.injectAuthentication( Arrays.asList( repository ), Arrays.asList( server ) );
80          Authentication authentication = repository.getAuthentication();
81          assertNotNull( authentication );
82          assertEquals( "jason", authentication.getUsername() );
83          assertEquals( "abc123", authentication.getPassword() );
84      }
85  
86  }