1 package org.apache.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 junit.framework.TestCase;
23 import org.junit.Before;
24 import org.junit.Test;
25 import org.junit.runner.RunWith;
26 import org.junit.runners.JUnit4;
29 import java.io.FileInputStream;
30 import java.io.IOException;
32 import java.util.Properties;
33 import org.apache.archiva.test.ArchivaBlockJUnit4ClassRunner;
37 @RunWith( ArchivaBlockJUnit4ClassRunner.class )
38 public class MavenProxyPropertyLoaderTest
41 private MavenProxyPropertyLoader loader;
44 public void testLoadValidMavenProxyConfiguration()
45 throws IOException, InvalidConfigurationException
47 File confFile = ArchivaConfigurationTest.getTestFile( "src/test/conf/maven-proxy-complete.conf" );
49 Configuration configuration = new Configuration();
50 NetworkProxyConfiguration proxy = new NetworkProxyConfiguration();
51 proxy.setHost( "original-host" );
52 configuration.addNetworkProxy( proxy ); // overwritten
54 loader.load( new FileInputStream( confFile ), configuration );
56 Map<String, ManagedRepositoryConfiguration> repositoryIdMap = configuration.getManagedRepositoriesAsMap();
57 assertEquals( "Count repositories", 1, repositoryIdMap.size() );
58 assertRepositoryExists( "maven-proxy", "target", repositoryIdMap.get( "maven-proxy" ) );
60 Map<String, RemoteRepositoryConfiguration> remoteRepositoryMap = configuration.getRemoteRepositoriesAsMap();
61 assertEquals( "Count repositories", 4, remoteRepositoryMap.size() );
62 assertRepositoryExists( "local-repo", "file://target", remoteRepositoryMap.get( "local-repo" ) );
63 assertRepositoryExists( "www-ibiblio-org", "http://www.ibiblio.org/maven2",
64 remoteRepositoryMap.get( "www-ibiblio-org" ) );
65 assertRepositoryExists( "dist-codehaus-org", "http://dist.codehaus.org",
66 remoteRepositoryMap.get( "dist-codehaus-org" ) );
67 assertRepositoryExists( "private-example-com", "http://private.example.com/internal",
68 remoteRepositoryMap.get( "private-example-com" ) );
71 private void assertRepositoryExists( String id, String expectedLocation, ManagedRepositoryConfiguration repo )
73 assertNotNull( "Repository id [" + id + "] should not be null", repo );
74 assertEquals( "Repository id", id, repo.getId() );
75 assertEquals( "Repository url", expectedLocation, repo.getLocation() );
78 private void assertRepositoryExists( String id, String expectedUrl, RemoteRepositoryConfiguration repo )
80 assertNotNull( "Repository id [" + id + "] should not be null", repo );
81 assertEquals( "Repository id", id, repo.getId() );
82 assertEquals( "Repository url", expectedUrl, repo.getUrl() );
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 )
105 loader = new MavenProxyPropertyLoader();