001 package org.apache.maven.repository.legacy;
002
003 /*
004 * Licensed to the Apache Software Foundation (ASF) under one or more contributor license
005 * agreements. See the NOTICE file distributed with this work for additional information regarding
006 * copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance with the License. You may obtain a
008 * copy of the License at
009 *
010 * http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing, software distributed under the License
013 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
014 * or implied. See the License for the specific language governing permissions and limitations under
015 * the License.
016 */
017
018 import java.io.File;
019 import java.util.Arrays;
020
021 import org.apache.maven.artifact.repository.ArtifactRepository;
022 import org.apache.maven.artifact.repository.Authentication;
023 import org.apache.maven.repository.RepositorySystem;
024 import org.apache.maven.settings.Server;
025 import org.codehaus.plexus.ContainerConfiguration;
026 import org.codehaus.plexus.PlexusTestCase;
027
028 /**
029 * Tests {@link LegacyRepositorySystem}.
030 *
031 * @author Benjamin Bentmann
032 */
033 public class LegacyRepositorySystemTest
034 extends PlexusTestCase
035 {
036 private RepositorySystem repositorySystem;
037
038 @Override
039 protected void customizeContainerConfiguration( ContainerConfiguration containerConfiguration )
040 {
041 super.customizeContainerConfiguration( containerConfiguration );
042 containerConfiguration.setAutoWiring( true );
043 }
044
045 @Override
046 protected void setUp()
047 throws Exception
048 {
049 super.setUp();
050 repositorySystem = lookup( RepositorySystem.class, "default" );
051 }
052
053 @Override
054 protected void tearDown()
055 throws Exception
056 {
057 repositorySystem = null;
058 super.tearDown();
059 }
060
061 public void testThatLocalRepositoryWithSpacesIsProperlyHandled()
062 throws Exception
063 {
064 File basedir = new File( "target/spacy path" ).getAbsoluteFile();
065 ArtifactRepository repo = repositorySystem.createLocalRepository( basedir );
066 assertEquals( basedir, new File( repo.getBasedir() ) );
067 }
068
069 public void testAuthenticationHandling()
070 throws Exception
071 {
072 Server server = new Server();
073 server.setId( "repository" );
074 server.setUsername( "jason" );
075 server.setPassword( "abc123" );
076
077 ArtifactRepository repository =
078 repositorySystem.createArtifactRepository( "repository", "http://foo", null, null, null );
079 repositorySystem.injectAuthentication( Arrays.asList( repository ), Arrays.asList( server ) );
080 Authentication authentication = repository.getAuthentication();
081 assertNotNull( authentication );
082 assertEquals( "jason", authentication.getUsername() );
083 assertEquals( "abc123", authentication.getPassword() );
084 }
085
086 }