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 org.apache.archiva.test.utils.ArchivaBlockJUnit4ClassRunner;
23 import org.junit.Test;
24 import org.junit.runner.RunWith;
26 import java.util.Arrays;
27 import java.util.HashSet;
30 import static org.junit.Assert.*;
33 * Test the generated Configuration class from Modello. This is primarily to test the hand coded methods.
35 @RunWith( ArchivaBlockJUnit4ClassRunner.class )
36 public class ConfigurationTest
38 private Configuration configuration = new Configuration();
41 public void testNetworkProxyRetrieval()
43 NetworkProxyConfiguration proxy1 = createNetworkProxy( "id1", "host1", 8080 );
44 configuration.addNetworkProxy( proxy1 );
45 NetworkProxyConfiguration proxy2 = createNetworkProxy( "id2", "host2", 9090 );
46 configuration.addNetworkProxy( proxy2 );
48 Map<String, NetworkProxyConfiguration> map = configuration.getNetworkProxiesAsMap();
50 assertEquals( 2, map.size() );
51 assertEquals( new HashSet<String>( Arrays.asList( "id1", "id2" ) ), map.keySet() );
52 assertEquals( new HashSet<NetworkProxyConfiguration>( Arrays.asList( proxy1, proxy2 ) ),
53 new HashSet<NetworkProxyConfiguration>( map.values() ) );
56 private NetworkProxyConfiguration createNetworkProxy( String id, String host, int port )
58 NetworkProxyConfiguration proxy = new NetworkProxyConfiguration();
60 proxy.setHost( host );
61 proxy.setPort( port );
62 proxy.setProtocol( "http" );
67 public void testRemoteRepositoryRetrieval()
69 RemoteRepositoryConfiguration repo1 = createRemoteRepository( "id1", "name 1", "url 1" );
70 configuration.addRemoteRepository( repo1 );
71 RemoteRepositoryConfiguration repo2 = createRemoteRepository( "id2", "name 2", "url 2" );
72 configuration.addRemoteRepository( repo2 );
74 Map<String, RemoteRepositoryConfiguration> map = configuration.getRemoteRepositoriesAsMap();
76 assertEquals( 2, map.size() );
77 assertEquals( new HashSet<String>( Arrays.asList( "id1", "id2" ) ), map.keySet() );
78 assertEquals( new HashSet<RemoteRepositoryConfiguration>( Arrays.asList( repo1, repo2 ) ),
79 new HashSet<RemoteRepositoryConfiguration>( map.values() ) );
81 assertEquals( repo1, configuration.findRemoteRepositoryById( "id1" ) );
82 assertEquals( repo2, configuration.findRemoteRepositoryById( "id2" ) );
83 assertNull( configuration.findRemoteRepositoryById( "id3" ) );
86 private RemoteRepositoryConfiguration createRemoteRepository( String id, String name, String url )
88 RemoteRepositoryConfiguration repo = new RemoteRepositoryConfiguration();
91 repo.setLayout( "default" );
97 public void testManagedRepositoryRetrieval()
99 ManagedRepositoryConfiguration repo1 = createManagedRepository( "id1", "name 1", "path 1", false );
100 configuration.addManagedRepository( repo1 );
101 ManagedRepositoryConfiguration repo2 = createManagedRepository( "id2", "name 2", "path 2", true );
102 configuration.addManagedRepository( repo2 );
104 Map<String, ManagedRepositoryConfiguration> map = configuration.getManagedRepositoriesAsMap();
105 assertNotNull( map );
106 assertEquals( 2, map.size() );
107 assertEquals( new HashSet<String>( Arrays.asList( "id1", "id2" ) ), map.keySet() );
108 assertEquals( new HashSet<ManagedRepositoryConfiguration>( Arrays.asList( repo1, repo2 ) ),
109 new HashSet<ManagedRepositoryConfiguration>( map.values() ) );
111 assertEquals( repo1, configuration.findManagedRepositoryById( "id1" ) );
112 assertEquals( repo2, configuration.findManagedRepositoryById( "id2" ) );
113 assertNull( configuration.findManagedRepositoryById( "id3" ) );
116 private ManagedRepositoryConfiguration createManagedRepository( String id, String name, String location,
119 ManagedRepositoryConfiguration repo = new ManagedRepositoryConfiguration();
121 repo.setName( name );
122 repo.setLocation( location );
123 repo.setScanned( scanned );
128 public void testNetworkProxyRetrievalWhenEmpty()
130 Map<String, NetworkProxyConfiguration> map = configuration.getNetworkProxiesAsMap();
131 assertNotNull( map );
132 assertTrue( map.isEmpty() );
136 public void testRemoteRepositoryRetrievalWhenEmpty()
138 Map<String, RemoteRepositoryConfiguration> map = configuration.getRemoteRepositoriesAsMap();
139 assertNotNull( map );
140 assertTrue( map.isEmpty() );
142 assertNull( configuration.findRemoteRepositoryById( "id" ) );
146 public void testManagedRepositoryRetrievalWhenEmpty()
148 Map<String, ManagedRepositoryConfiguration> map = configuration.getManagedRepositoriesAsMap();
149 assertNotNull( map );
150 assertTrue( map.isEmpty() );
152 assertNull( configuration.findManagedRepositoryById( "id" ) );