1 package org.apache.maven.archiva.configuration;
4 * Licensed to the Apache Software Foundation (ASF) under one
5 * or more contributor license agreements. See the NOTICE file
6 * distributed with this work for additional information
7 * regarding copyright ownership. The ASF licenses this file
8 * to you under the Apache License, Version 2.0 (the
9 * "License"); you may not use this file except in compliance
10 * with the License. You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 * KIND, either express or implied. See the License for the
18 * specific language governing permissions and limitations
22 import org.codehaus.plexus.PlexusTestCase;
25 import java.io.FileInputStream;
26 import java.io.IOException;
27 import java.util.List;
28 import java.util.Properties;
31 * @author Edwin Punzalan
33 public class MavenProxyPropertyLoaderTest
34 extends PlexusTestCase
36 private static final int DEFAULT_CACHE_PERIOD = 3600;
38 private MavenProxyPropertyLoader loader;
40 public void testLoadValidMavenProxyConfiguration()
41 throws IOException, InvalidConfigurationException
43 File confFile = getTestFile( "src/test/conf/maven-proxy-complete.conf" );
45 Configuration configuration = new Configuration();
46 Proxy proxy = new Proxy();
47 proxy.setHost( "original-host" );
48 configuration.setProxy( proxy ); // overwritten
49 configuration.setIndexPath( "index-path" ); // existing value
51 loader.load( new FileInputStream( confFile ), configuration );
53 List list = configuration.getRepositories();
54 assertEquals( "check single managed repository", 1, list.size() );
55 RepositoryConfiguration managedRepository = (RepositoryConfiguration) list.iterator().next();
56 assertEquals( "cache path changed", "target", managedRepository.getDirectory() );
58 assertEquals( "Count repositories", 4, configuration.getProxiedRepositories().size() );
60 list = configuration.getProxiedRepositories();
61 ProxiedRepositoryConfiguration repo = (ProxiedRepositoryConfiguration) list.get( 0 );
62 assertEquals( "Repository name not as expected", "local-repo", repo.getId() );
63 assertEquals( "Repository url does not match its name", "file://target", repo.getUrl() );
64 assertEquals( "Repository cache period check failed", 0, repo.getSnapshotsInterval() );
65 assertFalse( "Repository failure caching check failed", repo.isCacheFailures() );
67 repo = (ProxiedRepositoryConfiguration) list.get( 1 );
68 assertEquals( "Repository name not as expected", "www-ibiblio-org", repo.getId() );
69 assertEquals( "Repository url does not match its name", "http://www.ibiblio.org/maven2", repo.getUrl() );
70 assertEquals( "Repository cache period check failed", DEFAULT_CACHE_PERIOD, repo.getSnapshotsInterval() );
71 assertTrue( "Repository failure caching check failed", repo.isCacheFailures() );
73 repo = (ProxiedRepositoryConfiguration) list.get( 2 );
74 assertEquals( "Repository name not as expected", "dist-codehaus-org", repo.getId() );
75 assertEquals( "Repository url does not match its name", "http://dist.codehaus.org", repo.getUrl() );
76 assertEquals( "Repository cache period check failed", DEFAULT_CACHE_PERIOD, repo.getSnapshotsInterval() );
77 assertTrue( "Repository failure caching check failed", repo.isCacheFailures() );
79 repo = (ProxiedRepositoryConfiguration) list.get( 3 );
80 assertEquals( "Repository name not as expected", "private-example-com", repo.getId() );
81 assertEquals( "Repository url does not match its name", "http://private.example.com/internal", repo.getUrl() );
82 assertEquals( "Repository cache period check failed", DEFAULT_CACHE_PERIOD, repo.getSnapshotsInterval() );
83 assertFalse( "Repository failure caching check failed", repo.isCacheFailures() );
86 public void testInvalidConfiguration()
88 Configuration configuration = new Configuration();
91 loader.load( new Properties(), configuration );
92 fail( "Incomplete config should have failed" );
94 catch ( InvalidConfigurationException e )
100 protected void setUp()
104 loader = new MavenProxyPropertyLoader();