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
25 import org.codehaus.plexus.util.FileUtils;
\r
27 import java.io.File;
\r
28 import java.io.IOException;
\r
29 import java.util.ArrayList;
\r
30 import java.util.Iterator;
\r
31 import java.util.List;
\r
33 public class ProxyConfigurationTest
\r
34 extends PlexusTestCase
\r
36 private ProxyConfiguration config;
\r
38 protected void setUp()
\r
43 config = (ProxyConfiguration) container.lookup( ProxyConfiguration.ROLE );
\r
46 public void testBrowsable()
\r
48 assertFalse( config.isBrowsable() );
\r
49 config.setBrowsable( true );
\r
50 assertTrue( config.isBrowsable() );
\r
53 public void testRepositoryCache()
\r
55 File cacheFile = new File( "target/proxy-cache" );
\r
56 config.setRepositoryCachePath( cacheFile.getAbsolutePath() );
\r
57 ArtifactRepository cache = config.getRepositoryCache();
\r
58 assertEquals( cacheFile.getAbsolutePath(), cache.getBasedir() );
\r
59 assertEquals( config.getRepositoryCachePath(), cache.getBasedir() );
\r
62 public void testRepositories()
\r
64 ArtifactRepositoryLayout defLayout = new DefaultRepositoryLayout();
\r
65 ProxyRepository repo1 = new ProxyRepository( "repo1", "http://www.ibiblio.org/maven2", defLayout );
\r
66 config.addRepository( repo1 );
\r
67 assertEquals( 1, config.getRepositories().size() );
\r
69 ArtifactRepositoryLayout legacyLayout = new LegacyRepositoryLayout();
\r
70 ProxyRepository repo2 = new ProxyRepository( "repo2", "http://www.ibiblio.org/maven", legacyLayout );
\r
71 config.addRepository( repo2 );
\r
72 assertEquals( 2, config.getRepositories().size() );
\r
74 List repositories = config.getRepositories();
\r
75 ProxyRepository repo = (ProxyRepository) repositories.get( 0 );
\r
76 assertEquals( repo1, repo );
\r
78 repo = (ProxyRepository) repositories.get( 1 );
\r
79 assertEquals( repo2, repo );
\r
83 repositories.add( new ProxyRepository( "repo", "url", defLayout ) );
\r
84 fail( "Expected UnsupportedOperationException not thrown." );
\r
86 catch ( java.lang.UnsupportedOperationException e )
\r
91 repositories = new ArrayList();
\r
92 repositories.add( repo1 );
\r
93 repositories.add( repo2 );
\r
94 config.setRepositories( repositories );
\r
95 assertEquals( repositories, config.getRepositories() );
\r
98 public void testLoadValidMavenProxyConfiguration()
\r
99 throws ValidationException, IOException
\r
101 //must create the test directory bec configuration is using relative path which varies
\r
102 FileUtils.mkdir( "target/remote-repo1" );
\r
106 File confFile = getTestFile( "src/test/conf/maven-proxy-complete.conf" );
\r
108 config.loadMavenProxyConfiguration( confFile );
\r
110 assertTrue( config.getRepositoryCachePath().endsWith( "target" ) );
\r
112 assertEquals( "Count repositories", 4, config.getRepositories().size() );
\r
114 for ( Iterator repos = config.getRepositories().iterator(); repos.hasNext(); )
\r
116 ProxyRepository repo = (ProxyRepository) repos.next();
\r
118 if ( "local-repo".equals( repo.getKey() ) )
\r
120 assertEquals( "file:///./target/remote-repo1", repo.getUrl() );
\r
122 else if ( "www-ibiblio-org".equals( repo.getKey() ) )
\r
124 assertEquals( "http://www.ibiblio.org/maven2", repo.getUrl() );
\r
126 else if ( "dist-codehaus-org".equals( repo.getKey() ) )
\r
128 assertEquals( "http://dist.codehaus.org", repo.getUrl() );
\r
130 else if ( "private-example-com".equals( repo.getKey() ) )
\r
132 assertEquals( "http://private.example.com/internal", repo.getUrl() );
\r
136 //make sure to delete the test directory after tests
\r
139 FileUtils.deleteDirectory( "target/remote-repo1" );
\r
143 protected void tearDown()
\r