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 repo1.setCacheFailures( true );
\r
67 repo1.setCachePeriod( 0 );
\r
68 config.addRepository( repo1 );
\r
69 assertEquals( 1, config.getRepositories().size() );
\r
71 ArtifactRepositoryLayout legacyLayout = new LegacyRepositoryLayout();
\r
72 ProxyRepository repo2 = new ProxyRepository( "repo2", "http://www.ibiblio.org/maven", legacyLayout );
\r
73 repo2.setCacheFailures( false );
\r
74 repo2.setCachePeriod( 3600 );
\r
75 config.addRepository( repo2 );
\r
76 assertEquals( 2, config.getRepositories().size() );
\r
78 List repositories = config.getRepositories();
\r
79 ProxyRepository repo = (ProxyRepository) repositories.get( 0 );
\r
80 assertEquals( "repo1", repo.getId() );
\r
81 assertEquals( "http://www.ibiblio.org/maven2", repo.getUrl() );
\r
82 assertTrue( repo.isCacheFailures() );
\r
83 assertEquals( 0, repo.getCachePeriod() );
\r
84 assertEquals( repo1, repo );
\r
86 repo = (ProxyRepository) repositories.get( 1 );
\r
87 assertEquals( "repo2", repo.getId() );
\r
88 assertEquals( "http://www.ibiblio.org/maven", repo.getUrl() );
\r
89 assertFalse( repo.isCacheFailures() );
\r
90 assertEquals( 3600, repo.getCachePeriod() );
\r
91 assertEquals( repo2, repo );
\r
95 repositories.add( new ProxyRepository( "repo", "url", defLayout ) );
\r
96 fail( "Expected UnsupportedOperationException not thrown." );
\r
98 catch ( java.lang.UnsupportedOperationException e )
\r
100 assertTrue( true );
\r
103 repositories = new ArrayList();
\r
104 repositories.add( repo1 );
\r
105 repositories.add( repo2 );
\r
106 config.setRepositories( repositories );
\r
107 assertEquals( repositories, config.getRepositories() );
\r
110 public void testLoadValidMavenProxyConfiguration()
\r
111 throws ValidationException, IOException
\r
113 //must create the test directory bec configuration is using relative path which varies
\r
114 FileUtils.mkdir( "target/remote-repo1" );
\r
118 File confFile = getTestFile( "src/test/conf/maven-proxy-complete.conf" );
\r
120 config.loadMavenProxyConfiguration( confFile );
\r
122 assertTrue( "cache path changed", config.getRepositoryCachePath().endsWith( "target" ) );
\r
124 assertEquals( "Count repositories", 4, config.getRepositories().size() );
\r
127 for ( Iterator repos = config.getRepositories().iterator(); repos.hasNext(); )
\r
131 ProxyRepository repo = (ProxyRepository) repos.next();
\r
133 //switch is made to check for ordering
\r
137 assertEquals( "Repository name not as expected", "local-repo", repo.getKey() );
\r
138 assertEquals( "Repository url does not match its name", "file:///./target/remote-repo1",
\r
140 assertEquals( "Repository cache period check failed", 0, repo.getCachePeriod() );
\r
141 assertFalse( "Repository failure caching check failed", repo.isCacheFailures() );
\r
144 assertEquals( "Repository name not as expected", "www-ibiblio-org", repo.getKey() );
\r
145 assertEquals( "Repository url does not match its name", "http://www.ibiblio.org/maven2",
\r
147 assertEquals( "Repository cache period check failed", 3600, repo.getCachePeriod() );
\r
148 assertTrue( "Repository failure caching check failed", repo.isCacheFailures() );
\r
151 assertEquals( "Repository name not as expected", "dist-codehaus-org", repo.getKey() );
\r
152 assertEquals( "Repository url does not match its name", "http://dist.codehaus.org",
\r
154 assertEquals( "Repository cache period check failed", 3600, repo.getCachePeriod() );
\r
155 assertTrue( "Repository failure caching check failed", repo.isCacheFailures() );
\r
158 assertEquals( "Repository name not as expected", "private-example-com", repo.getKey() );
\r
159 assertEquals( "Repository url does not match its name", "http://private.example.com/internal",
\r
161 assertEquals( "Repository cache period check failed", 3600, repo.getCachePeriod() );
\r
162 assertFalse( "Repository failure caching check failed", repo.isCacheFailures() );
\r
165 fail( "Unexpected order count" );
\r
169 //make sure to delete the test directory after tests
\r
172 FileUtils.deleteDirectory( "target/remote-repo1" );
\r
176 protected void tearDown()
\r