1 package org.apache.maven.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.commons.io.FileUtils;
23 import org.codehaus.plexus.PlexusTestCase;
26 import java.util.Properties;
29 * Test the configuration store.
31 * @author <a href="mailto:brett@apache.org">Brett Porter</a>
33 public class ArchivaConfigurationTest
34 extends PlexusTestCase
36 public void testDefaults()
39 ArchivaConfiguration archivaConfiguration =
40 (ArchivaConfiguration) lookup( ArchivaConfiguration.class.getName(), "test-defaults" );
42 Configuration configuration = archivaConfiguration.getConfiguration();
44 // check default configuration
45 assertNotNull( "check configuration returned", configuration );
46 assertEquals( "check configuration has default elements", "0 0,30 * * * ?",
47 configuration.getDataRefreshCronExpression() );
48 assertNull( "check configuration has default elements", configuration.getIndexPath() );
49 assertTrue( "check configuration has default elements", configuration.getRepositories().isEmpty() );
52 public void testGetConfiguration()
55 ArchivaConfiguration archivaConfiguration =
56 (ArchivaConfiguration) lookup( ArchivaConfiguration.class.getName(), "test-configuration" );
58 Configuration configuration = archivaConfiguration.getConfiguration();
60 assertEquals( "check indexPath", ".index", configuration.getIndexPath() );
61 assertEquals( "check localRepository", "local-repository", configuration.getLocalRepository() );
63 assertEquals( "check managed repositories", 1, configuration.getRepositories().size() );
64 RepositoryConfiguration repository =
65 (RepositoryConfiguration) configuration.getRepositories().iterator().next();
67 assertEquals( "check managed repositories", "managed-repository", repository.getDirectory() );
68 assertEquals( "check managed repositories", "local", repository.getName() );
69 assertEquals( "check managed repositories", "local", repository.getId() );
70 assertEquals( "check managed repositories", "default", repository.getLayout() );
71 assertTrue( "check managed repositories", repository.isIndexed() );
73 assertEquals( "check proxied repositories", 1, configuration.getProxiedRepositories().size() );
74 ProxiedRepositoryConfiguration proxiedRepository =
75 (ProxiedRepositoryConfiguration) configuration.getProxiedRepositories().iterator().next();
77 assertEquals( "check proxied repositories", "local", proxiedRepository.getManagedRepository() );
78 assertEquals( "check proxied repositories", "http://www.ibiblio.org/maven2/", proxiedRepository.getUrl() );
79 assertEquals( "check proxied repositories", "ibiblio", proxiedRepository.getId() );
80 assertEquals( "check proxied repositories", "Ibiblio", proxiedRepository.getName() );
81 assertEquals( "check proxied repositories", 0, proxiedRepository.getSnapshotsInterval() );
82 assertEquals( "check proxied repositories", 0, proxiedRepository.getReleasesInterval() );
83 assertTrue( "check proxied repositories", proxiedRepository.isUseNetworkProxy() );
85 assertEquals( "check synced repositories", 1, configuration.getSyncedRepositories().size() );
86 SyncedRepositoryConfiguration syncedRepository =
87 (SyncedRepositoryConfiguration) configuration.getSyncedRepositories().iterator().next();
89 assertEquals( "check synced repositories", "local", syncedRepository.getManagedRepository() );
90 assertEquals( "check synced repositories", "apache", syncedRepository.getId() );
91 assertEquals( "check synced repositories", "ASF", syncedRepository.getName() );
92 assertEquals( "check synced repositories", "0 0 * * * ?", syncedRepository.getCronExpression() );
93 assertEquals( "check synced repositories", "rsync", syncedRepository.getMethod() );
94 Properties properties = new Properties();
95 properties.setProperty( "rsyncHost", "host" );
96 properties.setProperty( "rsyncMethod", "ssh" );
97 assertEquals( "check synced repositories", properties, syncedRepository.getProperties() );
100 public void testGetConfigurationSystemOverride()
103 ArchivaConfiguration archivaConfiguration =
104 (ArchivaConfiguration) lookup( ArchivaConfiguration.class.getName(), "test-configuration" );
106 System.setProperty( "org.apache.maven.archiva.localRepository", "system-repository" );
108 Configuration configuration = archivaConfiguration.getConfiguration();
110 assertEquals( "check localRepository", "system-repository", configuration.getLocalRepository() );
111 assertEquals( "check indexPath", ".index", configuration.getIndexPath() );
114 public void testStoreConfiguration()
117 File file = getTestFile( "target/test/test-file.xml" );
119 assertFalse( file.exists() );
121 // TODO: remove with commons-configuration 1.4
122 file.getParentFile().mkdirs();
123 org.codehaus.plexus.util.FileUtils.fileWrite( file.getAbsolutePath(), "<configuration/>" );
125 ArchivaConfiguration archivaConfiguration =
126 (ArchivaConfiguration) lookup( ArchivaConfiguration.class.getName(), "test-save" );
128 Configuration configuration = new Configuration();
129 configuration.setIndexPath( "index-path" );
131 archivaConfiguration.save( configuration );
133 assertTrue( "Check file exists", file.exists() );
136 configuration = archivaConfiguration.getConfiguration();
137 assertEquals( "check value", "index-path", configuration.getIndexPath() );
140 archivaConfiguration = (ArchivaConfiguration) lookup( ArchivaConfiguration.class.getName(), "test-read-saved" );
141 configuration = archivaConfiguration.getConfiguration();
142 assertEquals( "check value", "index-path", configuration.getIndexPath() );
145 public void testStoreConfigurationUser()
148 File baseFile = getTestFile( "target/test/test-file.xml" );
150 assertFalse( baseFile.exists() );
152 File userFile = getTestFile( "target/test/test-file-user.xml" );
154 assertFalse( userFile.exists() );
156 // TODO: remove with commons-configuration 1.4
157 userFile.getParentFile().mkdirs();
158 org.codehaus.plexus.util.FileUtils.fileWrite( userFile.getAbsolutePath(), "<configuration/>" );
160 ArchivaConfiguration archivaConfiguration =
161 (ArchivaConfiguration) lookup( ArchivaConfiguration.class.getName(), "test-save-user" );
163 Configuration configuration = new Configuration();
164 configuration.setIndexPath( "index-path" );
166 archivaConfiguration.save( configuration );
168 assertTrue( "Check file exists", userFile.exists() );
169 assertFalse( "Check file not created", baseFile.exists() );
172 configuration = archivaConfiguration.getConfiguration();
173 assertEquals( "check value", "index-path", configuration.getIndexPath() );
176 public void testStoreConfigurationFallback()
179 File baseFile = getTestFile( "target/test/test-file.xml" );
181 assertFalse( baseFile.exists() );
183 File userFile = getTestFile( "target/test/test-file-user.xml" );
185 assertFalse( userFile.exists() );
187 // TODO: remove with commons-configuration 1.4
188 baseFile.getParentFile().mkdirs();
189 org.codehaus.plexus.util.FileUtils.fileWrite( baseFile.getAbsolutePath(), "<configuration/>" );
191 ArchivaConfiguration archivaConfiguration =
192 (ArchivaConfiguration) lookup( ArchivaConfiguration.class.getName(), "test-save-user" );
194 Configuration configuration = new Configuration();
195 configuration.setIndexPath( "index-path" );
197 archivaConfiguration.save( configuration );
199 assertTrue( "Check file exists", baseFile.exists() );
200 assertFalse( "Check file not created", userFile.exists() );
203 configuration = archivaConfiguration.getConfiguration();
204 assertEquals( "check value", "index-path", configuration.getIndexPath() );
207 public void testRemoveProxiedRepositoryAndStoreConfiguration()
212 File src = getTestFile( "src/test/conf/with-proxied-repos.xml" );
213 File dest = getTestFile( "target/test/with-proxied-repos.xml" );
214 FileUtils.copyFile( src, dest );
216 ArchivaConfiguration archivaConfiguration =
217 (ArchivaConfiguration) lookup( ArchivaConfiguration.class.getName(), "test-remove-proxied-repo" );
219 Configuration configuration = archivaConfiguration.getConfiguration();
220 configuration.getProxiedRepositories().remove( 0 );
222 archivaConfiguration.save( configuration );
225 configuration = archivaConfiguration.getConfiguration();
226 assertEquals( 1, configuration.getProxiedRepositories().size() );
228 release( archivaConfiguration );
231 archivaConfiguration =
232 (ArchivaConfiguration) lookup( ArchivaConfiguration.class.getName(), "test-read-back-remove-proxied-repo" );
233 configuration = archivaConfiguration.getConfiguration();
234 assertEquals( 1, configuration.getProxiedRepositories().size() );