1 package org.apache.maven.archiva.configuration;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.io.File;
23 import java.io.FileInputStream;
24 import java.io.IOException;
25 import java.util.Map;
26 import java.util.Properties;
27
28 import org.codehaus.plexus.spring.PlexusInSpringTestCase;
29
30
31
32 public class MavenProxyPropertyLoaderTest
33 extends PlexusInSpringTestCase
34 {
35 private MavenProxyPropertyLoader loader;
36
37
38
39
40
41 protected String getSpringConfigLocation()
42 {
43 return "org/apache/maven/archiva/configuration/spring-context.xml";
44 }
45
46 public void testLoadValidMavenProxyConfiguration()
47 throws IOException, InvalidConfigurationException
48 {
49 File confFile = getTestFile( "src/test/conf/maven-proxy-complete.conf" );
50
51 Configuration configuration = new Configuration();
52 NetworkProxyConfiguration proxy = new NetworkProxyConfiguration();
53 proxy.setHost( "original-host" );
54 configuration.addNetworkProxy( proxy );
55
56 loader.load( new FileInputStream( confFile ), configuration );
57
58 Map<String, ManagedRepositoryConfiguration> repositoryIdMap = configuration.getManagedRepositoriesAsMap();
59 assertEquals( "Count repositories", 1, repositoryIdMap.size() );
60 assertRepositoryExists( "maven-proxy", "target", repositoryIdMap.get( "maven-proxy" ) );
61
62 Map<String, RemoteRepositoryConfiguration> remoteRepositoryMap = configuration.getRemoteRepositoriesAsMap();
63 assertEquals( "Count repositories", 4, remoteRepositoryMap.size() );
64 assertRepositoryExists( "local-repo", "file://target", remoteRepositoryMap.get( "local-repo" ) );
65 assertRepositoryExists( "www-ibiblio-org", "http://www.ibiblio.org/maven2",
66 remoteRepositoryMap.get( "www-ibiblio-org" ) );
67 assertRepositoryExists( "dist-codehaus-org", "http://dist.codehaus.org",
68 remoteRepositoryMap.get( "dist-codehaus-org" ) );
69 assertRepositoryExists( "private-example-com", "http://private.example.com/internal",
70 remoteRepositoryMap.get( "private-example-com" ) );
71 }
72
73 private void assertRepositoryExists( String id, String expectedLocation, ManagedRepositoryConfiguration repo )
74 {
75 assertNotNull( "Repository id [" + id + "] should not be null", repo );
76 assertEquals( "Repository id", id, repo.getId() );
77 assertEquals( "Repository url", expectedLocation, repo.getLocation() );
78 }
79
80 private void assertRepositoryExists( String id, String expectedUrl, RemoteRepositoryConfiguration repo )
81 {
82 assertNotNull( "Repository id [" + id + "] should not be null", repo );
83 assertEquals( "Repository id", id, repo.getId() );
84 assertEquals( "Repository url", expectedUrl, repo.getUrl() );
85 }
86
87 public void testInvalidConfiguration()
88 {
89 Configuration configuration = new Configuration();
90 try
91 {
92 loader.load( new Properties(), configuration );
93 fail( "Incomplete config should have failed" );
94 }
95 catch ( InvalidConfigurationException e )
96 {
97 assertTrue( true );
98 }
99 }
100
101 protected void setUp()
102 throws Exception
103 {
104 super.setUp();
105 loader = new MavenProxyPropertyLoader();
106 }
107 }