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