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.PlexusTestCase; 026 027 /** 028 * Tests {@link LegacyRepositorySystem}. 029 * 030 * @author Benjamin Bentmann 031 */ 032 public class LegacyRepositorySystemTest 033 extends PlexusTestCase 034 { 035 private RepositorySystem repositorySystem; 036 037 @Override 038 protected void setUp() 039 throws Exception 040 { 041 super.setUp(); 042 repositorySystem = lookup( RepositorySystem.class, "default" ); 043 } 044 045 @Override 046 protected void tearDown() 047 throws Exception 048 { 049 repositorySystem = null; 050 super.tearDown(); 051 } 052 053 public void testThatLocalRepositoryWithSpacesIsProperlyHandled() 054 throws Exception 055 { 056 File basedir = new File( "target/spacy path" ).getAbsoluteFile(); 057 ArtifactRepository repo = repositorySystem.createLocalRepository( basedir ); 058 assertEquals( basedir, new File( repo.getBasedir() ) ); 059 } 060 061 public void testAuthenticationHandling() 062 throws Exception 063 { 064 Server server = new Server(); 065 server.setId( "repository" ); 066 server.setUsername( "jason" ); 067 server.setPassword( "abc123" ); 068 069 ArtifactRepository repository = 070 repositorySystem.createArtifactRepository( "repository", "http://foo", null, null, null ); 071 repositorySystem.injectAuthentication( Arrays.asList( repository ), Arrays.asList( server ) ); 072 Authentication authentication = repository.getAuthentication(); 073 assertNotNull( authentication ); 074 assertEquals( "jason", authentication.getUsername() ); 075 assertEquals( "abc123", authentication.getPassword() ); 076 } 077 078 }