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
23 import java.io.FileInputStream;
24 import java.io.IOException;
26 import java.util.Properties;
27 import org.apache.archiva.test.utils.ArchivaBlockJUnit4ClassRunner;
28 import static org.junit.Assert.*;
29 import org.junit.Before;
30 import org.junit.Test;
31 import org.junit.runner.RunWith;
35 @RunWith( ArchivaBlockJUnit4ClassRunner.class )
36 public class MavenProxyPropertyLoaderTest
38 private MavenProxyPropertyLoader loader;
41 public void testLoadValidMavenProxyConfiguration()
42 throws IOException, InvalidConfigurationException
44 File confFile = ArchivaConfigurationTest.getTestFile( "src/test/conf/maven-proxy-complete.conf" );
46 Configuration configuration = new Configuration();
47 NetworkProxyConfiguration proxy = new NetworkProxyConfiguration();
48 proxy.setHost( "original-host" );
49 configuration.addNetworkProxy( proxy ); // overwritten
51 loader.load( new FileInputStream( confFile ), configuration );
53 Map<String, ManagedRepositoryConfiguration> repositoryIdMap = configuration.getManagedRepositoriesAsMap();
54 assertEquals( "Count repositories", 1, repositoryIdMap.size() );
55 assertRepositoryExists( "maven-proxy", "target", repositoryIdMap.get( "maven-proxy" ) );
57 Map<String, RemoteRepositoryConfiguration> remoteRepositoryMap = configuration.getRemoteRepositoriesAsMap();
58 assertEquals( "Count repositories", 4, remoteRepositoryMap.size() );
59 assertRepositoryExists( "local-repo", "file://target", remoteRepositoryMap.get( "local-repo" ) );
60 assertRepositoryExists( "www-ibiblio-org", "http://www.ibiblio.org/maven2",
61 remoteRepositoryMap.get( "www-ibiblio-org" ) );
62 assertRepositoryExists( "dist-codehaus-org", "http://dist.codehaus.org",
63 remoteRepositoryMap.get( "dist-codehaus-org" ) );
64 assertRepositoryExists( "private-example-com", "http://private.example.com/internal",
65 remoteRepositoryMap.get( "private-example-com" ) );
68 private void assertRepositoryExists( String id, String expectedLocation, ManagedRepositoryConfiguration repo )
70 assertNotNull( "Repository id [" + id + "] should not be null", repo );
71 assertEquals( "Repository id", id, repo.getId() );
72 assertEquals( "Repository url", expectedLocation, repo.getLocation() );
75 private void assertRepositoryExists( String id, String expectedUrl, RemoteRepositoryConfiguration repo )
77 assertNotNull( "Repository id [" + id + "] should not be null", repo );
78 assertEquals( "Repository id", id, repo.getId() );
79 assertEquals( "Repository url", expectedUrl, repo.getUrl() );
82 @Test( expected=InvalidConfigurationException.class )
83 public void testInvalidConfiguration()
84 throws InvalidConfigurationException
86 Configuration configuration = new Configuration();
87 loader.load( new Properties(), configuration );
88 //fail( "Incomplete config should have failed" );
95 loader = new MavenProxyPropertyLoader();