001package 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
018import java.io.File;
019import java.util.Arrays;
020
021import org.apache.maven.artifact.repository.ArtifactRepository;
022import org.apache.maven.artifact.repository.Authentication;
023import org.apache.maven.repository.RepositorySystem;
024import org.apache.maven.settings.Server;
025import org.codehaus.plexus.ContainerConfiguration;
026import org.codehaus.plexus.PlexusConstants;
027import org.codehaus.plexus.PlexusTestCase;
028
029/**
030 * Tests {@link LegacyRepositorySystem}.
031 *
032 * @author Benjamin Bentmann
033 */
034public class LegacyRepositorySystemTest
035    extends PlexusTestCase
036{
037    private RepositorySystem repositorySystem;
038
039    @Override
040    protected void customizeContainerConfiguration( ContainerConfiguration containerConfiguration )
041    {
042        super.customizeContainerConfiguration( containerConfiguration );
043        containerConfiguration.setAutoWiring( true );
044        containerConfiguration.setClassPathScanning( PlexusConstants.SCANNING_INDEX );
045    }
046
047    @Override
048    protected void setUp()
049        throws Exception
050    {
051        super.setUp();
052        repositorySystem = lookup( RepositorySystem.class, "default" );
053    }
054
055    @Override
056    protected void tearDown()
057        throws Exception
058    {
059        repositorySystem = null;
060        super.tearDown();
061    }
062
063    public void testThatLocalRepositoryWithSpacesIsProperlyHandled()
064        throws Exception
065    {
066        File basedir = new File( "target/spacy path" ).getAbsoluteFile();
067        ArtifactRepository repo = repositorySystem.createLocalRepository( basedir );
068        assertEquals( basedir, new File( repo.getBasedir() ) );
069    }
070
071    public void testAuthenticationHandling()
072        throws Exception
073    {
074        Server server = new Server();
075        server.setId( "repository" );
076        server.setUsername( "jason" );
077        server.setPassword( "abc123" );
078
079        ArtifactRepository repository =
080            repositorySystem.createArtifactRepository( "repository", "http://foo", null, null, null );
081        repositorySystem.injectAuthentication( Arrays.asList( repository ), Arrays.asList( server ) );
082        Authentication authentication = repository.getAuthentication();
083        assertNotNull( authentication );
084        assertEquals( "jason", authentication.getUsername() );
085        assertEquals( "abc123", authentication.getPassword() );
086    }
087
088}