1 package org.apache.maven.repository.configuration;
3 import org.codehaus.plexus.PlexusTestCase;
4 import org.easymock.MockControl;
7 import java.util.Properties;
10 * Copyright 2005-2006 The Apache Software Foundation.
12 * Licensed under the Apache License, Version 2.0 (the "License");
13 * you may not use this file except in compliance with the License.
14 * You may obtain a copy of the License at
16 * http://www.apache.org/licenses/LICENSE-2.0
18 * Unless required by applicable law or agreed to in writing, software
19 * distributed under the License is distributed on an "AS IS" BASIS,
20 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21 * See the License for the specific language governing permissions and
22 * limitations under the License.
26 * Test the configuration store.
28 * @author <a href="mailto:brett@apache.org">Brett Porter</a>
29 * @noinspection JavaDoc
31 public class ConfigurationStoreTest
32 extends PlexusTestCase
34 public void testInvalidFile()
37 ConfigurationStore configurationStore = (ConfigurationStore) lookup( ConfigurationStore.ROLE, "invalid-file" );
39 Configuration configuration = configurationStore.getConfigurationFromStore();
41 // check default configuration
42 assertNotNull( "check configuration returned", configuration );
43 assertEquals( "check configuration has default elements", "0 0 * * * ?",
44 configuration.getIndexerCronExpression() );
45 assertNull( "check configuration has default elements", configuration.getIndexPath() );
46 assertTrue( "check configuration has default elements", configuration.getRepositories().isEmpty() );
49 public void testCorruptFile()
52 ConfigurationStore configurationStore = (ConfigurationStore) lookup( ConfigurationStore.ROLE, "corrupt-file" );
56 configurationStore.getConfigurationFromStore();
57 fail( "Configuration should not have succeeded" );
59 catch ( ConfigurationStoreException e )
66 public void testGetConfiguration()
69 ConfigurationStore configurationStore = (ConfigurationStore) lookup( ConfigurationStore.ROLE, "default" );
71 Configuration configuration = configurationStore.getConfigurationFromStore();
73 assertEquals( "check indexPath", ".index", configuration.getIndexPath() );
74 assertEquals( "check localRepository", "local-repository", configuration.getLocalRepository() );
76 assertEquals( "check managed repositories", 1, configuration.getRepositories().size() );
77 RepositoryConfiguration repository =
78 (RepositoryConfiguration) configuration.getRepositories().iterator().next();
80 assertEquals( "check managed repositories", "managed-repository", repository.getDirectory() );
81 assertEquals( "check managed repositories", "local", repository.getName() );
82 assertEquals( "check managed repositories", "local", repository.getId() );
83 assertEquals( "check managed repositories", "default", repository.getLayout() );
84 assertTrue( "check managed repositories", repository.isIndexed() );
86 assertEquals( "check proxied repositories", 1, configuration.getProxiedRepositories().size() );
87 ProxiedRepositoryConfiguration proxiedRepository =
88 (ProxiedRepositoryConfiguration) configuration.getProxiedRepositories().iterator().next();
90 assertEquals( "check proxied repositories", "local", proxiedRepository.getManagedRepository() );
91 assertEquals( "check proxied repositories", "http://www.ibiblio.org/maven2/", proxiedRepository.getUrl() );
92 assertEquals( "check proxied repositories", "ibiblio", proxiedRepository.getId() );
93 assertEquals( "check proxied repositories", "Ibiblio", proxiedRepository.getName() );
94 assertEquals( "check proxied repositories", 0, proxiedRepository.getSnapshotsInterval() );
95 assertEquals( "check proxied repositories", 0, proxiedRepository.getReleasesInterval() );
96 assertTrue( "check proxied repositories", proxiedRepository.isUseNetworkProxy() );
98 assertEquals( "check synced repositories", 1, configuration.getSyncedRepositories().size() );
99 SyncedRepositoryConfiguration syncedRepository =
100 (SyncedRepositoryConfiguration) configuration.getSyncedRepositories().iterator().next();
102 assertEquals( "check synced repositories", "local", syncedRepository.getManagedRepository() );
103 assertEquals( "check synced repositories", "apache", syncedRepository.getId() );
104 assertEquals( "check synced repositories", "ASF", syncedRepository.getName() );
105 assertEquals( "check synced repositories", "0 0 * * * ?", syncedRepository.getCronExpression() );
106 assertEquals( "check synced repositories", "rsync", syncedRepository.getMethod() );
107 Properties properties = new Properties();
108 properties.setProperty( "rsyncHost", "host" );
109 properties.setProperty( "rsyncMethod", "ssh" );
110 assertEquals( "check synced repositories", properties, syncedRepository.getProperties() );
113 public void testStoreConfiguration()
116 ConfigurationStore configurationStore = (ConfigurationStore) lookup( ConfigurationStore.ROLE, "save-file" );
118 Configuration configuration = new Configuration();
119 configuration.setIndexPath( "index-path" );
121 File file = getTestFile( "target/test/test-file.xml" );
123 assertFalse( file.exists() );
125 configurationStore.storeConfiguration( configuration );
127 assertTrue( "Check file exists", file.exists() );
130 configuration = configurationStore.getConfigurationFromStore();
131 assertEquals( "check value", "index-path", configuration.getIndexPath() );
135 * @noinspection JUnitTestMethodWithNoAssertions
137 public void testChangeListeners()
140 ConfigurationStore configurationStore = (ConfigurationStore) lookup( ConfigurationStore.ROLE, "save-file" );
142 MockControl control = MockControl.createControl( ConfigurationChangeListener.class );
143 ConfigurationChangeListener mock = (ConfigurationChangeListener) control.getMock();
144 configurationStore.addChangeListener( mock );
146 Configuration configuration = new Configuration();
147 mock.notifyOfConfigurationChange( configuration );
150 configurationStore.storeConfiguration( configuration );