1 package org.apache.maven.archiva.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.codehaus.plexus.PlexusTestCase;
\r
21 import java.io.File;
\r
22 import java.io.FileInputStream;
\r
23 import java.io.IOException;
\r
24 import java.util.List;
\r
25 import java.util.Properties;
\r
28 * @author Edwin Punzalan
\r
30 public class MavenProxyPropertyLoaderTest
\r
31 extends PlexusTestCase
\r
33 private static final int DEFAULT_CACHE_PERIOD = 3600;
\r
35 private MavenProxyPropertyLoader loader;
\r
37 public void testLoadValidMavenProxyConfiguration()
\r
38 throws IOException, InvalidConfigurationException
\r
40 File confFile = getTestFile( "src/test/conf/maven-proxy-complete.conf" );
\r
42 Configuration configuration = new Configuration();
\r
43 Proxy proxy = new Proxy();
\r
44 proxy.setHost( "original-host" );
\r
45 configuration.setProxy( proxy ); // overwritten
\r
46 configuration.setIndexPath( "index-path" ); // existing value
\r
48 loader.load( new FileInputStream( confFile ), configuration );
\r
50 List list = configuration.getRepositories();
\r
51 assertEquals( "check single managed repository", 1, list.size() );
\r
52 RepositoryConfiguration managedRepository = (RepositoryConfiguration) list.iterator().next();
\r
53 assertEquals( "cache path changed", "target", managedRepository.getDirectory() );
\r
55 assertEquals( "Count repositories", 4, configuration.getProxiedRepositories().size() );
\r
57 list = configuration.getProxiedRepositories();
\r
58 ProxiedRepositoryConfiguration repo = (ProxiedRepositoryConfiguration) list.get( 0 );
\r
59 assertEquals( "Repository name not as expected", "local-repo", repo.getId() );
\r
60 assertEquals( "Repository url does not match its name", "file://target", repo.getUrl() );
\r
61 assertEquals( "Repository cache period check failed", 0, repo.getSnapshotsInterval() );
\r
62 assertFalse( "Repository failure caching check failed", repo.isCacheFailures() );
\r
64 repo = (ProxiedRepositoryConfiguration) list.get( 1 );
\r
65 assertEquals( "Repository name not as expected", "www-ibiblio-org", repo.getId() );
\r
66 assertEquals( "Repository url does not match its name", "http://www.ibiblio.org/maven2", repo.getUrl() );
\r
67 assertEquals( "Repository cache period check failed", DEFAULT_CACHE_PERIOD, repo.getSnapshotsInterval() );
\r
68 assertTrue( "Repository failure caching check failed", repo.isCacheFailures() );
\r
70 repo = (ProxiedRepositoryConfiguration) list.get( 2 );
\r
71 assertEquals( "Repository name not as expected", "dist-codehaus-org", repo.getId() );
\r
72 assertEquals( "Repository url does not match its name", "http://dist.codehaus.org", repo.getUrl() );
\r
73 assertEquals( "Repository cache period check failed", DEFAULT_CACHE_PERIOD, repo.getSnapshotsInterval() );
\r
74 assertTrue( "Repository failure caching check failed", repo.isCacheFailures() );
\r
76 repo = (ProxiedRepositoryConfiguration) list.get( 3 );
\r
77 assertEquals( "Repository name not as expected", "private-example-com", repo.getId() );
\r
78 assertEquals( "Repository url does not match its name", "http://private.example.com/internal", repo.getUrl() );
\r
79 assertEquals( "Repository cache period check failed", DEFAULT_CACHE_PERIOD, repo.getSnapshotsInterval() );
\r
80 assertFalse( "Repository failure caching check failed", repo.isCacheFailures() );
\r
83 public void testInvalidConfiguration()
\r
85 Configuration configuration = new Configuration();
\r
88 loader.load( new Properties(), configuration );
\r
89 fail( "Incomplete config should have failed" );
\r
91 catch ( InvalidConfigurationException e )
\r
97 protected void setUp()
\r
101 loader = new MavenProxyPropertyLoader();
\r