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;
36 @RunWith( JUnit4.class )
37 public class MavenProxyPropertyLoaderTest
40 private MavenProxyPropertyLoader loader;
43 public void testLoadValidMavenProxyConfiguration()
44 throws IOException, InvalidConfigurationException
46 File confFile = ArchivaConfigurationTest.getTestFile( "src/test/conf/maven-proxy-complete.conf" );
48 Configuration configuration = new Configuration();
49 NetworkProxyConfiguration proxy = new NetworkProxyConfiguration();
50 proxy.setHost( "original-host" );
51 configuration.addNetworkProxy( proxy ); // overwritten
53 loader.load( new FileInputStream( confFile ), configuration );
55 Map<String, ManagedRepositoryConfiguration> repositoryIdMap = configuration.getManagedRepositoriesAsMap();
56 assertEquals( "Count repositories", 1, repositoryIdMap.size() );
57 assertRepositoryExists( "maven-proxy", "target", repositoryIdMap.get( "maven-proxy" ) );
59 Map<String, RemoteRepositoryConfiguration> remoteRepositoryMap = configuration.getRemoteRepositoriesAsMap();
60 assertEquals( "Count repositories", 4, remoteRepositoryMap.size() );
61 assertRepositoryExists( "local-repo", "file://target", remoteRepositoryMap.get( "local-repo" ) );
62 assertRepositoryExists( "www-ibiblio-org", "http://www.ibiblio.org/maven2",
63 remoteRepositoryMap.get( "www-ibiblio-org" ) );
64 assertRepositoryExists( "dist-codehaus-org", "http://dist.codehaus.org",
65 remoteRepositoryMap.get( "dist-codehaus-org" ) );
66 assertRepositoryExists( "private-example-com", "http://private.example.com/internal",
67 remoteRepositoryMap.get( "private-example-com" ) );
70 private void assertRepositoryExists( String id, String expectedLocation, ManagedRepositoryConfiguration repo )
72 assertNotNull( "Repository id [" + id + "] should not be null", repo );
73 assertEquals( "Repository id", id, repo.getId() );
74 assertEquals( "Repository url", expectedLocation, repo.getLocation() );
77 private void assertRepositoryExists( String id, String expectedUrl, RemoteRepositoryConfiguration repo )
79 assertNotNull( "Repository id [" + id + "] should not be null", repo );
80 assertEquals( "Repository id", id, repo.getId() );
81 assertEquals( "Repository url", expectedUrl, repo.getUrl() );
85 public void testInvalidConfiguration()
87 Configuration configuration = new Configuration();
90 loader.load( new Properties(), configuration );
91 fail( "Incomplete config should have failed" );
93 catch ( InvalidConfigurationException e )
104 loader = new MavenProxyPropertyLoader();