1 package org.apache.maven.repository.configuration;
4 * Copyright 2005-2006 The Apache Software Foundation.
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
19 import org.codehaus.plexus.PlexusTestCase;
22 import java.io.FileInputStream;
23 import java.io.IOException;
24 import java.util.List;
25 import java.util.Properties;
28 * @author Edwin Punzalan
30 public class MavenProxyPropertyLoaderTest
31 extends PlexusTestCase
33 private static final int DEFAULT_CACHE_PERIOD = 3600;
35 private MavenProxyPropertyLoader loader;
37 public void testLoadValidMavenProxyConfiguration()
38 throws IOException, InvalidConfigurationException
40 File confFile = getTestFile( "src/test/conf/maven-proxy-complete.conf" );
42 Configuration configuration = new Configuration();
43 Proxy proxy = new Proxy();
44 proxy.setHost( "original-host" );
45 configuration.setProxy( proxy ); // overwritten
46 configuration.setIndexPath( "index-path" ); // existing value
48 loader.load( new FileInputStream( confFile ), configuration );
50 List list = configuration.getRepositories();
51 assertEquals( "check single managed repository", 1, list.size() );
52 RepositoryConfiguration managedRepository = (RepositoryConfiguration) list.iterator().next();
53 assertEquals( "cache path changed", "target", managedRepository.getDirectory() );
55 assertEquals( "Count repositories", 4, configuration.getProxiedRepositories().size() );
57 list = configuration.getProxiedRepositories();
58 ProxiedRepositoryConfiguration repo = (ProxiedRepositoryConfiguration) list.get( 0 );
59 assertEquals( "Repository name not as expected", "local-repo", repo.getId() );
60 assertEquals( "Repository url does not match its name", "file://target", repo.getUrl() );
61 assertEquals( "Repository cache period check failed", 0, repo.getSnapshotsInterval() );
62 assertFalse( "Repository failure caching check failed", repo.isCacheFailures() );
64 repo = (ProxiedRepositoryConfiguration) list.get( 1 );
65 assertEquals( "Repository name not as expected", "www-ibiblio-org", repo.getId() );
66 assertEquals( "Repository url does not match its name", "http://www.ibiblio.org/maven2", repo.getUrl() );
67 assertEquals( "Repository cache period check failed", DEFAULT_CACHE_PERIOD, repo.getSnapshotsInterval() );
68 assertTrue( "Repository failure caching check failed", repo.isCacheFailures() );
70 repo = (ProxiedRepositoryConfiguration) list.get( 2 );
71 assertEquals( "Repository name not as expected", "dist-codehaus-org", repo.getId() );
72 assertEquals( "Repository url does not match its name", "http://dist.codehaus.org", repo.getUrl() );
73 assertEquals( "Repository cache period check failed", DEFAULT_CACHE_PERIOD, repo.getSnapshotsInterval() );
74 assertTrue( "Repository failure caching check failed", repo.isCacheFailures() );
76 repo = (ProxiedRepositoryConfiguration) list.get( 3 );
77 assertEquals( "Repository name not as expected", "private-example-com", repo.getId() );
78 assertEquals( "Repository url does not match its name", "http://private.example.com/internal", repo.getUrl() );
79 assertEquals( "Repository cache period check failed", DEFAULT_CACHE_PERIOD, repo.getSnapshotsInterval() );
80 assertFalse( "Repository failure caching check failed", repo.isCacheFailures() );
83 public void testInvalidConfiguration()
85 Configuration configuration = new Configuration();
88 loader.load( new Properties(), configuration );
89 fail( "Incomplete config should have failed" );
91 catch ( InvalidConfigurationException e )
97 protected void setUp()
101 loader = new MavenProxyPropertyLoader();