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
23 import java.util.List;
26 import org.apache.commons.io.FileUtils;
27 import org.codehaus.plexus.registry.RegistryException;
28 import org.codehaus.plexus.spring.PlexusInSpringTestCase;
29 import org.custommonkey.xmlunit.XMLAssert;
30 import org.easymock.MockControl;
33 * Test the configuration store.
35 * @author <a href="mailto:brett@apache.org">Brett Porter</a>
37 public class ArchivaConfigurationTest
38 extends PlexusInSpringTestCase
42 * @see org.codehaus.plexus.spring.PlexusInSpringTestCase#getSpringConfigLocation()
44 protected String getSpringConfigLocation()
47 return "org/apache/maven/archiva/configuration/spring-context.xml";
50 public void testGetConfigurationFromRegistryWithASingleNamedConfigurationResource()
53 ArchivaConfiguration archivaConfiguration =
54 (ArchivaConfiguration) lookup( ArchivaConfiguration.class.getName(), "test-configuration" );
56 Configuration configuration = archivaConfiguration.getConfiguration();
57 assertConfiguration( configuration );
58 assertEquals( "check network proxies", 1, configuration.getNetworkProxies().size() );
60 ManagedRepositoryConfiguration repository =
61 (ManagedRepositoryConfiguration) configuration.getManagedRepositories().get( 0 );
63 assertEquals( "check managed repositories", "${appserver.base}/repositories/internal",
64 repository.getLocation() );
65 assertEquals( "check managed repositories", "Archiva Managed Internal Repository", repository.getName() );
66 assertEquals( "check managed repositories", "internal", repository.getId() );
67 assertEquals( "check managed repositories", "default", repository.getLayout() );
68 assertTrue( "check managed repositories", repository.isScanned() );
71 public void testGetConfigurationFromDefaults()
74 ArchivaConfiguration archivaConfiguration =
75 (ArchivaConfiguration) lookup( ArchivaConfiguration.class.getName(), "test-defaults" );
77 Configuration configuration = archivaConfiguration.getConfiguration();
78 assertConfiguration( configuration );
79 assertEquals( "check network proxies", 0, configuration.getNetworkProxies().size() );
81 ManagedRepositoryConfiguration repository =
82 (ManagedRepositoryConfiguration) configuration.getManagedRepositories().get( 0 );
84 assertEquals( "check managed repositories", "${appserver.base}/data/repositories/internal",
85 repository.getLocation() );
86 assertEquals( "check managed repositories", "Archiva Managed Internal Repository", repository.getName() );
87 assertEquals( "check managed repositories", "internal", repository.getId() );
88 assertEquals( "check managed repositories", "default", repository.getLayout() );
89 assertTrue( "check managed repositories", repository.isScanned() );
93 * Ensures that the provided configuration matches the details present in the archiva-default.xml file.
95 private void assertConfiguration( Configuration configuration )
98 FileTypes filetypes = (FileTypes) lookup( FileTypes.class.getName() );
100 assertEquals( "check repositories", 2, configuration.getManagedRepositories().size() );
101 assertEquals( "check repositories", 2, configuration.getRemoteRepositories().size() );
102 assertEquals( "check proxy connectors", 2, configuration.getProxyConnectors().size() );
104 RepositoryScanningConfiguration repoScanning = configuration.getRepositoryScanning();
105 assertNotNull( "check repository scanning", repoScanning );
106 assertEquals( "check file types", 4, repoScanning.getFileTypes().size() );
107 assertEquals( "check known consumers", 9, repoScanning.getKnownContentConsumers().size() );
108 assertEquals( "check invalid consumers", 1, repoScanning.getInvalidContentConsumers().size() );
110 List<String> patterns = filetypes.getFileTypePatterns( "artifacts" );
111 assertNotNull( "check 'artifacts' file type", patterns );
112 assertEquals( "check 'artifacts' patterns", 13, patterns.size() );
114 DatabaseScanningConfiguration dbScanning = configuration.getDatabaseScanning();
115 assertNotNull( "check database scanning", dbScanning );
116 assertEquals( "check unprocessed consumers", 6, dbScanning.getUnprocessedConsumers().size() );
117 assertEquals( "check cleanup consumers", 3, dbScanning.getCleanupConsumers().size() );
119 WebappConfiguration webapp = configuration.getWebapp();
120 assertNotNull( "check webapp", webapp );
122 UserInterfaceOptions ui = webapp.getUi();
123 assertNotNull( "check webapp ui", ui );
124 assertTrue( "check showFindArtifacts", ui.isShowFindArtifacts() );
125 assertTrue( "check appletFindEnabled", ui.isAppletFindEnabled() );
128 public void testGetConfigurationFromRegistryWithTwoConfigurationResources()
131 ArchivaConfiguration archivaConfiguration =
132 (ArchivaConfiguration) lookup( ArchivaConfiguration.class.getName(), "test-configuration-both" );
134 Configuration configuration = archivaConfiguration.getConfiguration();
137 assertEquals( "check repositories", 2, configuration.getManagedRepositories().size() );
138 assertEquals( "check repositories", 2, configuration.getRemoteRepositories().size() );
140 assertEquals( "check proxy connectors", 2, configuration.getProxyConnectors().size() );
142 WebappConfiguration webapp = configuration.getWebapp();
143 assertNotNull( "check webapp", webapp );
145 UserInterfaceOptions ui = webapp.getUi();
146 assertNotNull( "check webapp ui", ui );
148 assertFalse( "check showFindArtifacts", ui.isShowFindArtifacts() );
150 assertFalse( "check appletFindEnabled", ui.isAppletFindEnabled() );
153 public void testGetConfigurationSystemOverride()
156 ArchivaConfiguration archivaConfiguration =
157 (ArchivaConfiguration) lookup( ArchivaConfiguration.class.getName(), "test-configuration" );
159 System.setProperty( "org.apache.maven.archiva.webapp.ui.appletFindEnabled", "false" );
163 Configuration configuration = archivaConfiguration.getConfiguration();
165 assertFalse( "check boolean", configuration.getWebapp().getUi().isAppletFindEnabled() );
169 System.getProperties().remove( "org.apache.maven.archiva.webapp.ui.appletFindEnabled" );
173 public void testStoreConfiguration()
176 File file = getTestFile( "target/test/test-file.xml" );
178 assertFalse( file.exists() );
180 // TODO: remove with commons-configuration 1.4
181 file.getParentFile().mkdirs();
182 FileUtils.writeStringToFile( file, "<configuration/>", null );
184 DefaultArchivaConfiguration archivaConfiguration =
185 (DefaultArchivaConfiguration) lookup( ArchivaConfiguration.class.getName(), "test-save" );
187 Configuration configuration = new Configuration();
188 configuration.setVersion( "1" );
189 configuration.setWebapp( new WebappConfiguration() );
190 configuration.getWebapp().setUi( new UserInterfaceOptions() );
191 configuration.getWebapp().getUi().setAppletFindEnabled( false );
193 // add a change listener
194 MockControl control = createConfigurationListenerMockControl();
195 ConfigurationListener listener = (ConfigurationListener) control.getMock();
196 archivaConfiguration.addListener( listener );
198 listener.configurationEvent( new ConfigurationEvent( ConfigurationEvent.SAVED ) );
199 control.setVoidCallable();
203 archivaConfiguration.save( configuration );
207 assertTrue( "Check file exists", file.exists() );
210 configuration = archivaConfiguration.getConfiguration();
211 assertFalse( "check value", configuration.getWebapp().getUi().isAppletFindEnabled() );
214 archivaConfiguration =
215 (DefaultArchivaConfiguration) lookup( ArchivaConfiguration.class.getName(), "test-read-saved" );
216 configuration = archivaConfiguration.getConfiguration();
217 assertFalse( "check value", configuration.getWebapp().getUi().isAppletFindEnabled() );
220 private static MockControl createConfigurationListenerMockControl()
222 return MockControl.createControl( ConfigurationListener.class );
225 public void testStoreConfigurationUser()
228 File baseFile = getTestFile( "target/test/test-file.xml" );
230 assertFalse( baseFile.exists() );
232 File userFile = getTestFile( "target/test/test-file-user.xml" );
234 assertFalse( userFile.exists() );
236 userFile.getParentFile().mkdirs();
237 FileUtils.writeStringToFile( userFile, "<configuration/>", null );
239 ArchivaConfiguration archivaConfiguration =
240 (ArchivaConfiguration) lookup( ArchivaConfiguration.class.getName(), "test-save-user" );
242 Configuration configuration = new Configuration();
243 configuration.setWebapp( new WebappConfiguration() );
244 configuration.getWebapp().setUi( new UserInterfaceOptions() );
245 configuration.getWebapp().getUi().setAppletFindEnabled( false );
247 archivaConfiguration.save( configuration );
249 assertTrue( "Check file exists", userFile.exists() );
250 assertFalse( "Check file not created", baseFile.exists() );
253 configuration = archivaConfiguration.getConfiguration();
254 assertFalse( "check value", configuration.getWebapp().getUi().isAppletFindEnabled() );
257 public void testStoreConfigurationLoadedFromDefaults()
260 File baseFile = getTestFile( "target/test/test-file.xml" );
262 assertFalse( baseFile.exists() );
264 File userFile = getTestFile( "target/test/test-file-user.xml" );
266 assertFalse( userFile.exists() );
268 ArchivaConfiguration archivaConfiguration =
269 (ArchivaConfiguration) lookup( ArchivaConfiguration.class.getName(), "test-save-user" );
271 Configuration configuration = new Configuration();
272 configuration.setWebapp( new WebappConfiguration() );
273 configuration.getWebapp().setUi( new UserInterfaceOptions() );
274 configuration.getWebapp().getUi().setAppletFindEnabled( false );
276 // add a change listener
277 MockControl control = createConfigurationListenerMockControl();
278 ConfigurationListener listener = (ConfigurationListener) control.getMock();
279 archivaConfiguration.addListener( listener );
281 listener.configurationEvent( new ConfigurationEvent( ConfigurationEvent.SAVED ) );
282 // once from default creation, and again from manual call to save
283 control.setVoidCallable( 2 );
287 archivaConfiguration.save( configuration );
291 assertTrue( "Check file exists", userFile.exists() );
292 assertFalse( "Check file not created", baseFile.exists() );
295 configuration = archivaConfiguration.getConfiguration();
296 assertFalse( "check value", configuration.getWebapp().getUi().isAppletFindEnabled() );
299 public void testDefaultUserConfigFilename()
302 DefaultArchivaConfiguration archivaConfiguration =
303 (DefaultArchivaConfiguration) lookup( ArchivaConfiguration.class.getName() );
305 assertEquals( System.getProperty( "user.home" ) + "/.m2/archiva.xml",
306 archivaConfiguration.getUserConfigFilename() );
307 assertEquals( System.getProperty( "appserver.base", "${appserver.base}" ) + "/conf/archiva.xml",
308 archivaConfiguration.getAltConfigFilename() );
311 public void testStoreConfigurationFallback()
314 File baseFile = getTestFile( "target/test/test-file.xml" );
316 assertFalse( baseFile.exists() );
318 File userFile = getTestFile( "target/test/test-file-user.xml" );
320 assertFalse( userFile.exists() );
322 baseFile.getParentFile().mkdirs();
323 FileUtils.writeStringToFile( baseFile, "<configuration/>", null );
325 ArchivaConfiguration archivaConfiguration =
326 (ArchivaConfiguration) lookup( ArchivaConfiguration.class.getName(), "test-save-user" );
328 Configuration configuration = new Configuration();
329 configuration.setWebapp( new WebappConfiguration() );
330 configuration.getWebapp().setUi( new UserInterfaceOptions() );
331 configuration.getWebapp().getUi().setAppletFindEnabled( false );
333 archivaConfiguration.save( configuration );
335 assertTrue( "Check file exists", baseFile.exists() );
336 assertFalse( "Check file not created", userFile.exists() );
339 configuration = archivaConfiguration.getConfiguration();
340 assertFalse( "check value", configuration.getWebapp().getUi().isAppletFindEnabled() );
343 public void testStoreConfigurationFailsWhenReadFromBothLocationsNoLists()
346 File baseFile = getTestFile( "target/test/test-file.xml" );
348 assertFalse( baseFile.exists() );
350 File userFile = getTestFile( "target/test/test-file-user.xml" );
352 assertFalse( userFile.exists() );
354 baseFile.getParentFile().mkdirs();
355 FileUtils.writeStringToFile( baseFile, "<configuration/>", null );
357 userFile.getParentFile().mkdirs();
358 FileUtils.writeStringToFile( userFile, "<configuration/>", null );
360 ArchivaConfiguration archivaConfiguration =
361 (ArchivaConfiguration) lookup( ArchivaConfiguration.class.getName(), "test-save-user" );
363 Configuration configuration = archivaConfiguration.getConfiguration();
364 assertTrue( "check value", configuration.getWebapp().getUi().isAppletFindEnabled() );
366 configuration.getWebapp().getUi().setAppletFindEnabled( false );
368 archivaConfiguration.save( configuration );
370 assertTrue( "Check file exists", baseFile.exists() );
371 assertEquals( "Check base file is unchanged", "<configuration/>",
372 FileUtils.readFileToString( baseFile, null ) );
373 assertTrue( "Check file exists", userFile.exists() );
374 assertFalse( "Check base file is changed",
375 "<configuration/>".equals( FileUtils.readFileToString( userFile, null ) ) );
378 configuration = archivaConfiguration.getConfiguration();
379 assertFalse( "check value", configuration.getWebapp().getUi().isAppletFindEnabled() );
382 public void testStoreConfigurationFailsWhenReadFromBothLocationsUserHasLists()
385 File baseFile = getTestFile( "target/test/test-file.xml" );
387 assertFalse( baseFile.exists() );
389 File userFile = getTestFile( "target/test/test-file-user.xml" );
391 assertFalse( userFile.exists() );
393 userFile.getParentFile().mkdirs();
394 FileUtils.copyFile( getTestFile( "src/test/conf/conf-user.xml" ), userFile );
396 baseFile.getParentFile().mkdirs();
397 FileUtils.writeStringToFile( baseFile, "<configuration/>", null );
399 ArchivaConfiguration archivaConfiguration =
400 (ArchivaConfiguration) lookup( ArchivaConfiguration.class.getName(), "test-save-user" );
402 Configuration configuration = archivaConfiguration.getConfiguration();
403 assertTrue( "check value", configuration.getWebapp().getUi().isShowFindArtifacts() );
405 configuration.getWebapp().getUi().setShowFindArtifacts( false );
407 archivaConfiguration.save( configuration );
409 assertTrue( "Check file exists", baseFile.exists() );
410 assertEquals( "Check base file is unchanged", "<configuration/>",
411 FileUtils.readFileToString( baseFile, null ) );
412 assertTrue( "Check file exists", userFile.exists() );
413 assertFalse( "Check base file is changed",
414 "<configuration/>".equals( FileUtils.readFileToString( userFile, null ) ) );
417 configuration = archivaConfiguration.getConfiguration();
418 assertFalse( "check value", configuration.getWebapp().getUi().isShowFindArtifacts() );
421 public void testStoreConfigurationFailsWhenReadFromBothLocationsAppserverHasLists()
424 File baseFile = getTestFile( "target/test/test-file.xml" );
426 assertFalse( baseFile.exists() );
428 File userFile = getTestFile( "target/test/test-file-user.xml" );
430 assertFalse( userFile.exists() );
432 baseFile.getParentFile().mkdirs();
433 FileUtils.copyFile( getTestFile( "src/test/conf/conf-base.xml" ), baseFile );
435 userFile.getParentFile().mkdirs();
436 FileUtils.writeStringToFile( userFile, "<configuration/>", null );
438 ArchivaConfiguration archivaConfiguration =
439 (ArchivaConfiguration) lookup( ArchivaConfiguration.class.getName(), "test-save-user" );
441 Configuration configuration = archivaConfiguration.getConfiguration();
442 assertTrue( "check value", configuration.getWebapp().getUi().isAppletFindEnabled() );
444 configuration.getWebapp().getUi().setAppletFindEnabled( false );
448 archivaConfiguration.save( configuration );
449 fail( "Configuration saving should not succeed if it was loaded from two locations" );
451 catch ( IndeterminateConfigurationException e )
453 // check it was reverted
454 configuration = archivaConfiguration.getConfiguration();
455 assertTrue( "check value", configuration.getWebapp().getUi().isAppletFindEnabled() );
459 public void testLoadConfigurationFromInvalidBothLocationsOnDisk()
462 ArchivaConfiguration archivaConfiguration =
463 (ArchivaConfiguration) lookup( ArchivaConfiguration.class.getName(), "test-not-allowed-to-write-to-both" );
464 Configuration config = archivaConfiguration.getConfiguration();
468 archivaConfiguration.save( config );
469 fail( "Should have thrown a RegistryException because the configuration can't be saved." );
471 catch ( RegistryException e )
473 /* expected exception */
477 public void testLoadConfigurationFromInvalidUserLocationOnDisk()
480 File testConfDir = getTestFile( "target/test-appserver-base/conf/" );
481 testConfDir.mkdirs();
483 ArchivaConfiguration archivaConfiguration =
484 (ArchivaConfiguration) lookup( ArchivaConfiguration.class.getName(), "test-not-allowed-to-write-to-user" );
485 Configuration config = archivaConfiguration.getConfiguration();
486 archivaConfiguration.save( config );
487 // No Exception == test passes.
488 // Expected Path is: Should not have thrown an exception.
491 public void testConfigurationUpgradeFrom09()
494 ArchivaConfiguration archivaConfiguration =
495 (ArchivaConfiguration) lookup( ArchivaConfiguration.class.getName(), "test-upgrade-09" );
497 // we just use the defaults when upgrading from 0.9 at this point.
498 Configuration configuration = archivaConfiguration.getConfiguration();
499 assertConfiguration( configuration );
500 assertEquals( "check network proxies", 0, configuration.getNetworkProxies().size() );
502 ManagedRepositoryConfiguration repository =
503 (ManagedRepositoryConfiguration) configuration.getManagedRepositories().get( 0 );
505 assertEquals( "check managed repositories", "${appserver.base}/data/repositories/internal",
506 repository.getLocation() );
507 assertEquals( "check managed repositories", "Archiva Managed Internal Repository", repository.getName() );
508 assertEquals( "check managed repositories", "internal", repository.getId() );
509 assertEquals( "check managed repositories", "default", repository.getLayout() );
510 assertTrue( "check managed repositories", repository.isScanned() );
513 public void testAutoDetectV1()
516 // Setup the autodetect-v1.xml file in the target directory (so we can save/load it)
517 File userFile = getTestFile( "target/test-autodetect-v1/archiva-user.xml" );
519 assertFalse( userFile.exists() );
521 userFile.getParentFile().mkdirs();
522 FileUtils.copyFile( getTestFile( "src/test/conf/autodetect-v1.xml" ), userFile );
524 // Load the original (unconverted) archiva.xml
525 ArchivaConfiguration archivaConfiguration =
526 (ArchivaConfiguration) lookup( ArchivaConfiguration.class.getName(), "test-autodetect-v1" );
528 Configuration configuration = archivaConfiguration.getConfiguration();
529 assertConfiguration( configuration );
530 assertEquals( "check network proxies", 1, configuration.getNetworkProxies().size() );
532 ManagedRepositoryConfiguration repository =
533 (ManagedRepositoryConfiguration) configuration.getManagedRepositories().get( 0 );
535 assertEquals( "check managed repositories", "${appserver.base}/repositories/internal",
536 repository.getLocation() );
537 assertEquals( "check managed repositories", "Archiva Managed Internal Repository", repository.getName() );
538 assertEquals( "check managed repositories", "internal", repository.getId() );
539 assertEquals( "check managed repositories", "default", repository.getLayout() );
540 assertTrue( "check managed repositories", repository.isScanned() );
542 // Test that only 1 set of repositories exist.
543 assertEquals( "check managed repositories size.", 2, configuration.getManagedRepositories().size() );
544 assertEquals( "check remote repositories size.", 2, configuration.getRemoteRepositories().size() );
545 assertEquals( "check v1 repositories size.", 0, configuration.getRepositories().size() );
548 archivaConfiguration.save( configuration );
551 // FIXME spring equivalent ? release( archivaConfiguration );
554 archivaConfiguration =
555 (ArchivaConfiguration) lookup( ArchivaConfiguration.class.getName(), "test-autodetect-v1" );
556 configuration = archivaConfiguration.getConfiguration();
558 // Test that only 1 set of repositories exist.
559 assertEquals( "check managed repositories size.", 2, configuration.getManagedRepositories().size() );
560 assertEquals( "check managed repositories size.", 2, configuration.getManagedRepositoriesAsMap().size() );
561 assertEquals( "check remote repositories size.", 2, configuration.getRemoteRepositories().size() );
562 assertEquals( "check remote repositories size.", 2, configuration.getRemoteRepositoriesAsMap().size() );
563 assertEquals( "check v1 repositories size.", 0, configuration.getRepositories().size() );
565 String actualXML = FileUtils.readFileToString( userFile, null );
566 XMLAssert.assertXpathNotExists( "//configuration/repositories/repository", actualXML );
567 XMLAssert.assertXpathNotExists( "//configuration/repositories", actualXML );
570 public void testArchivaV1()
573 ArchivaConfiguration archivaConfiguration =
574 (ArchivaConfiguration) lookup( ArchivaConfiguration.class.getName(), "test-archiva-v1" );
576 Configuration configuration = archivaConfiguration.getConfiguration();
577 assertConfiguration( configuration );
578 assertEquals( "check network proxies", 1, configuration.getNetworkProxies().size() );
580 assertEquals( "check managed repositories", 2, configuration.getManagedRepositories().size() );
581 assertEquals( "check v1 repositories size.", 0, configuration.getRepositories().size() );
583 Map<String, ManagedRepositoryConfiguration> map = configuration.getManagedRepositoriesAsMap();
585 ManagedRepositoryConfiguration repository = map.get( "internal" );
586 assertEquals( "check managed repositories", "${appserver.base}/repositories/internal",
587 repository.getLocation() );
588 assertEquals( "check managed repositories", "Archiva Managed Internal Repository", repository.getName() );
589 assertEquals( "check managed repositories", "internal", repository.getId() );
590 assertEquals( "check managed repositories", "default", repository.getLayout() );
591 assertTrue( "check managed repositories", repository.isScanned() );
592 assertFalse( "check managed repositories", repository.isSnapshots() );
594 repository = map.get( "snapshots" );
595 assertEquals( "check managed repositories", "${appserver.base}/repositories/snapshots",
596 repository.getLocation() );
597 assertEquals( "check managed repositories", "Archiva Managed Snapshot Repository", repository.getName() );
598 assertEquals( "check managed repositories", "snapshots", repository.getId() );
599 assertEquals( "check managed repositories", "default", repository.getLayout() );
600 assertFalse( "check managed repositories", repository.isScanned() );
601 assertTrue( "check managed repositories", repository.isSnapshots() );
604 public void testCronExpressionsWithComma()
607 File baseFile = getTestFile( "target/test/test-file.xml" );
609 assertFalse( baseFile.exists() );
611 File userFile = getTestFile( "target/test/test-file-user.xml" );
613 assertFalse( userFile.exists() );
615 baseFile.getParentFile().mkdirs();
616 FileUtils.copyFile( getTestFile( "src/test/conf/escape-cron-expressions.xml" ), baseFile );
618 userFile.getParentFile().mkdirs();
619 FileUtils.writeStringToFile( userFile, "<configuration/>", null );
621 final ArchivaConfiguration archivaConfiguration =
622 (ArchivaConfiguration) lookup( ArchivaConfiguration.class.getName(), "test-cron-expressions" );
624 Configuration configuration = archivaConfiguration.getConfiguration();
626 ManagedRepositoryConfiguration repository =
627 (ManagedRepositoryConfiguration) configuration.getManagedRepositories().get( 0 );
629 assertEquals( "check cron expression", "0 0,30 * * * ?", repository.getRefreshCronExpression().trim() );
631 configuration.getDatabaseScanning().setCronExpression( "0 0,15 0 * * ?" );
633 // add a test listener to confirm it doesn't see the escaped format. We don't need to test the number of calls,
634 // etc. as it's done in other tests
635 archivaConfiguration.addListener( new ConfigurationListener()
637 public void configurationEvent( ConfigurationEvent event )
639 assertEquals( ConfigurationEvent.SAVED, event.getType() );
641 Configuration configuration = archivaConfiguration.getConfiguration();
643 ManagedRepositoryConfiguration repository =
644 (ManagedRepositoryConfiguration) configuration.getManagedRepositories().get( 0 );
646 assertEquals( "check cron expression", "0 0,15 0 * * ?",
647 configuration.getDatabaseScanning().getCronExpression() );
651 archivaConfiguration.save( configuration );
653 configuration = archivaConfiguration.getConfiguration();
655 assertEquals( "check cron expression", "0 0,15 0 * * ?",
656 configuration.getDatabaseScanning().getCronExpression() );
658 // test for the escape character '\' showing up on repositories.jsp
659 repository.setRefreshCronExpression( "0 0,20 0 * * ?" );
661 archivaConfiguration.save( configuration );
663 repository = archivaConfiguration.getConfiguration().findManagedRepositoryById( "snapshots" );
665 assertEquals( "check cron expression", "0 0,20 0 * * ?", repository.getRefreshCronExpression() );
668 public void testRemoveLastElements()
671 File baseFile = getTestFile( "target/test/test-file.xml" );
673 assertFalse( baseFile.exists() );
675 File userFile = getTestFile( "target/test/test-file-user.xml" );
677 assertFalse( userFile.exists() );
679 baseFile.getParentFile().mkdirs();
680 FileUtils.copyFile( getTestFile( "src/test/conf/conf-single-list-elements.xml" ), baseFile );
682 userFile.getParentFile().mkdirs();
683 FileUtils.writeStringToFile( userFile, "<configuration/>", null );
685 ArchivaConfiguration archivaConfiguration =
686 (ArchivaConfiguration) lookup( ArchivaConfiguration.class.getName(), "test-remove-central" );
688 Configuration configuration = archivaConfiguration.getConfiguration();
690 RemoteRepositoryConfiguration repository = configuration.getRemoteRepositoriesAsMap().get( "central" );
691 assertNotNull( repository );
692 configuration.removeRemoteRepository( repository );
693 assertTrue( configuration.getRemoteRepositories().isEmpty() );
695 ManagedRepositoryConfiguration managedRepository =
696 configuration.getManagedRepositoriesAsMap().get( "snapshots" );
697 assertNotNull( managedRepository );
698 configuration.removeManagedRepository( managedRepository );
699 assertTrue( configuration.getManagedRepositories().isEmpty() );
701 ProxyConnectorConfiguration proxyConnector =
702 (ProxyConnectorConfiguration) configuration.getProxyConnectors().get( 0 );
703 assertNotNull( proxyConnector );
704 configuration.removeProxyConnector( proxyConnector );
705 assertTrue( configuration.getProxyConnectors().isEmpty() );
707 NetworkProxyConfiguration networkProxy = configuration.getNetworkProxiesAsMap().get( "proxy" );
708 assertNotNull( networkProxy );
709 configuration.removeNetworkProxy( networkProxy );
710 assertTrue( configuration.getNetworkProxies().isEmpty() );
712 LegacyArtifactPath path = (LegacyArtifactPath) configuration.getLegacyArtifactPaths().get( 0 );
713 assertNotNull( path );
714 configuration.removeLegacyArtifactPath( path );
715 assertTrue( configuration.getLegacyArtifactPaths().isEmpty() );
717 RepositoryScanningConfiguration scanning = configuration.getRepositoryScanning();
718 String consumer = (String) scanning.getKnownContentConsumers().get( 0 );
719 assertNotNull( consumer );
720 scanning.removeKnownContentConsumer( consumer );
721 assertTrue( scanning.getKnownContentConsumers().isEmpty() );
722 consumer = (String) scanning.getInvalidContentConsumers().get( 0 );
723 assertNotNull( consumer );
724 scanning.removeInvalidContentConsumer( consumer );
725 assertTrue( scanning.getInvalidContentConsumers().isEmpty() );
727 DatabaseScanningConfiguration databaseScanning = configuration.getDatabaseScanning();
728 consumer = (String) databaseScanning.getCleanupConsumers().get( 0 );
729 assertNotNull( consumer );
730 databaseScanning.removeCleanupConsumer( consumer );
731 assertTrue( databaseScanning.getCleanupConsumers().isEmpty() );
732 consumer = (String) databaseScanning.getUnprocessedConsumers().get( 0 );
733 assertNotNull( consumer );
734 databaseScanning.removeUnprocessedConsumer( consumer );
735 assertTrue( databaseScanning.getUnprocessedConsumers().isEmpty() );
737 archivaConfiguration.save( configuration );
739 archivaConfiguration =
740 (ArchivaConfiguration) lookup( ArchivaConfiguration.class.getName(), "test-read-saved" );
741 configuration = archivaConfiguration.getConfiguration();
742 assertNull( configuration.getRemoteRepositoriesAsMap().get( "central" ) );
743 assertNull( configuration.getManagedRepositoriesAsMap().get( "snapshots" ) );
744 assertTrue( configuration.getProxyConnectors().isEmpty() );
745 assertNull( configuration.getNetworkProxiesAsMap().get( "proxy" ) );
746 assertTrue( configuration.getLegacyArtifactPaths().isEmpty() );
747 scanning = configuration.getRepositoryScanning();
748 assertTrue( scanning.getKnownContentConsumers().isEmpty() );
749 assertTrue( scanning.getInvalidContentConsumers().isEmpty() );
750 databaseScanning = configuration.getDatabaseScanning();
751 assertTrue( databaseScanning.getCleanupConsumers().isEmpty() );
752 assertTrue( databaseScanning.getUnprocessedConsumers().isEmpty() );
756 * [MRM-582] Remote Repositories with empty <username> and <password> fields shouldn't be created in configuration.
758 public void testGetConfigurationFixEmptyRemoteRepoUsernamePassword()
761 ArchivaConfiguration archivaConfiguration = (ArchivaConfiguration) lookup(
762 ArchivaConfiguration.class.getName(),
763 "test-configuration" );
765 Configuration configuration = archivaConfiguration.getConfiguration();
766 assertConfiguration( configuration );
767 assertEquals( "check remote repositories", 2, configuration.getRemoteRepositories().size() );
769 RemoteRepositoryConfiguration repository = (RemoteRepositoryConfiguration) configuration
770 .getRemoteRepositoriesAsMap().get( "maven2-repository.dev.java.net" );
772 assertEquals( "remote repository.url", "https://maven2-repository.dev.java.net/nonav/repository", repository.getUrl() );
773 assertEquals( "remote repository.name", "Java.net Repository for Maven 2", repository.getName() );
774 assertEquals( "remote repository.id", "maven2-repository.dev.java.net", repository.getId() );
775 assertEquals( "remote repository.layout", "default", repository.getLayout() );
776 assertNull( "remote repository.username == null", repository.getUsername() );
777 assertNull( "remote repository.password == null", repository.getPassword() );