1 package org.apache.maven.repository.proxy.configuration;
\r
4 * Copyright 2005-2006 The Apache Software Foundation.
\r
6 * Licensed under the Apache License, Version 2.0 (the "License");
\r
7 * you may not use this file except in compliance with the License.
\r
8 * You may obtain a copy of the License at
\r
10 * http://www.apache.org/licenses/LICENSE-2.0
\r
12 * Unless required by applicable law or agreed to in writing, software
\r
13 * distributed under the License is distributed on an "AS IS" BASIS,
\r
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
15 * See the License for the specific language governing permissions and
\r
16 * limitations under the License.
\r
19 import org.apache.maven.artifact.repository.ArtifactRepository;
\r
20 import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
\r
21 import org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout;
\r
22 import org.apache.maven.artifact.repository.layout.LegacyRepositoryLayout;
\r
23 import org.apache.maven.repository.proxy.repository.ProxyRepository;
\r
24 import org.codehaus.plexus.PlexusTestCase;
\r
26 import java.io.File;
\r
27 import java.io.IOException;
\r
28 import java.util.ArrayList;
\r
29 import java.util.Iterator;
\r
30 import java.util.List;
\r
32 public class ProxyConfigurationTest
\r
33 extends PlexusTestCase
\r
35 private ProxyConfiguration config;
\r
37 protected void setUp()
\r
42 config = (ProxyConfiguration) container.lookup( ProxyConfiguration.ROLE );
\r
45 public void testBrowsable()
\r
47 assertFalse( config.isBrowsable() );
\r
48 config.setBrowsable( true );
\r
49 assertTrue( config.isBrowsable() );
\r
52 public void testRepositoryCache()
\r
54 File cacheFile = new File( "target/proxy-cache" );
\r
55 config.setRepositoryCachePath( cacheFile.getAbsolutePath() );
\r
56 ArtifactRepository cache = config.getRepositoryCache();
\r
57 assertEquals( cacheFile.getAbsolutePath(), cache.getBasedir() );
\r
58 assertEquals( config.getRepositoryCachePath(), cache.getBasedir() );
\r
61 public void testRepositories()
\r
63 ArtifactRepositoryLayout defLayout = new DefaultRepositoryLayout();
\r
64 ProxyRepository repo1 = new ProxyRepository( "repo1", "http://www.ibiblio.org/maven2", defLayout );
\r
65 config.addRepository( repo1 );
\r
66 assertEquals( 1, config.getRepositories().size() );
\r
68 ArtifactRepositoryLayout legacyLayout = new LegacyRepositoryLayout();
\r
69 ProxyRepository repo2 = new ProxyRepository( "repo2", "http://www.ibiblio.org/maven", legacyLayout );
\r
70 config.addRepository( repo2 );
\r
71 assertEquals( 2, config.getRepositories().size() );
\r
73 List repositories = config.getRepositories();
\r
74 ProxyRepository repo = (ProxyRepository) repositories.get( 0 );
\r
75 assertEquals( repo1, repo );
\r
77 repo = (ProxyRepository) repositories.get( 1 );
\r
78 assertEquals( repo2, repo );
\r
82 repositories.add( new ProxyRepository( "repo", "url", defLayout ) );
\r
83 fail( "Expected UnsupportedOperationException not thrown." );
\r
85 catch ( java.lang.UnsupportedOperationException e )
\r
90 repositories = new ArrayList();
\r
91 repositories.add( repo1 );
\r
92 repositories.add( repo2 );
\r
93 config.setRepositories( repositories );
\r
94 assertEquals( repositories, config.getRepositories() );
\r
97 public void testLoadValidMavenProxyConfiguration()
\r
98 throws ValidationException, IOException
\r
100 File confFile = new File( "src/test/conf/maven-proxy-complete.conf" );
\r
102 config.loadMavenProxyConfiguration( confFile );
\r
104 assertTrue( config.getRepositoryCachePath().endsWith( "target" ) );
\r
106 assertEquals( "Count repositories", 4, config.getRepositories().size() );
\r
108 for ( Iterator repos = config.getRepositories().iterator(); repos.hasNext(); )
\r
110 ProxyRepository repo = (ProxyRepository) repos.next();
\r
112 if ( "local-repo".equals( repo.getKey() ) )
\r
114 assertEquals( "file:///./src/test/remote-repo1", repo.getUrl() );
\r
116 else if ( "www-ibiblio-org".equals( repo.getKey() ) )
\r
118 assertEquals( "http://www.ibiblio.org/maven2", repo.getUrl() );
\r
120 else if ( "dist-codehaus-org".equals( repo.getKey() ) )
\r
122 assertEquals( "http://dist.codehaus.org", repo.getUrl() );
\r
124 else if ( "private-example-com".equals( repo.getKey() ) )
\r
126 assertEquals( "http://private.example.com/internal", repo.getUrl() );
\r
131 protected void tearDown()
\r