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.apache.commons.lang.StringUtils;
28 import org.codehaus.plexus.registry.RegistryException;
29 import org.codehaus.plexus.spring.PlexusInSpringTestCase;
30 import org.custommonkey.xmlunit.XMLAssert;
31 import org.easymock.MockControl;
34 * Test the configuration store.
37 public class ArchivaConfigurationTest
38 extends PlexusInSpringTestCase
42 * @see org.codehaus.plexus.spring.PlexusInSpringTestCase#getSpringConfigLocation()
44 protected String getSpringConfigLocation()
46 return "org/apache/maven/archiva/configuration/spring-context.xml";
49 public void testGetConfigurationFromRegistryWithASingleNamedConfigurationResource()
52 ArchivaConfiguration archivaConfiguration =
53 (ArchivaConfiguration) lookup( ArchivaConfiguration.class.getName(), "test-configuration" );
55 Configuration configuration = archivaConfiguration.getConfiguration();
56 assertConfiguration( configuration );
57 assertEquals( "check network proxies", 1, configuration.getNetworkProxies().size() );
59 ManagedRepositoryConfiguration repository =
60 (ManagedRepositoryConfiguration) configuration.getManagedRepositories().get( 0 );
62 assertEquals( "check managed repositories", "${appserver.base}/repositories/internal",
63 repository.getLocation() );
64 assertEquals( "check managed repositories", "Archiva Managed Internal Repository", repository.getName() );
65 assertEquals( "check managed repositories", "internal", repository.getId() );
66 assertEquals( "check managed repositories", "default", repository.getLayout() );
67 assertTrue( "check managed repositories", repository.isScanned() );
70 public void testGetConfigurationFromDefaults()
73 ArchivaConfiguration archivaConfiguration =
74 (ArchivaConfiguration) lookup( ArchivaConfiguration.class.getName(), "test-defaults" );
76 Configuration configuration = archivaConfiguration.getConfiguration();
77 assertConfiguration( configuration );
78 assertEquals( "check network proxies", 0, configuration.getNetworkProxies().size() );
80 ManagedRepositoryConfiguration repository =
81 (ManagedRepositoryConfiguration) configuration.getManagedRepositories().get( 0 );
83 assertEquals( "check managed repositories", "${appserver.base}/data/repositories/internal",
84 repository.getLocation() );
85 assertEquals( "check managed repositories", "Archiva Managed Internal Repository", repository.getName() );
86 assertEquals( "check managed repositories", "internal", repository.getId() );
87 assertEquals( "check managed repositories", "default", repository.getLayout() );
88 assertTrue( "check managed repositories", repository.isScanned() );
92 public void testGetConfigurationFromDefaultsWithDefaultRepoLocationAlreadyExisting()
95 File repo = new File( getBasedir(), "/target/test-classes/existing_snapshots" );
98 repo = new File( getBasedir(), "/target/test-classes/existing_internal" );
101 String existingTestDefaultArchivaConfigFile =
102 FileUtils.readFileToString( getTestFile( "target/test-classes/org/apache/maven/archiva/configuration/test-default-archiva.xml" ) ) ;
103 existingTestDefaultArchivaConfigFile = StringUtils.replace( existingTestDefaultArchivaConfigFile, "${appserver.base}", getBasedir() );
105 File generatedTestDefaultArchivaConfigFile =
106 new File( getBasedir(), "target/test-classes/org/apache/maven/archiva/configuration/default-archiva.xml" );
108 FileUtils.writeStringToFile( generatedTestDefaultArchivaConfigFile, existingTestDefaultArchivaConfigFile, null );
110 ArchivaConfiguration archivaConfiguration =
111 (ArchivaConfiguration) lookup( ArchivaConfiguration.class.getName(),
112 "test-defaults-default-repo-location-exists" );
114 Configuration configuration = archivaConfiguration.getConfiguration();
115 assertConfiguration( configuration );
117 ManagedRepositoryConfiguration repository =
118 (ManagedRepositoryConfiguration) configuration.getManagedRepositories().get( 0 );
119 assertTrue( "check managed repositories", repository.getLocation().endsWith( "data/repositories/internal" ) );
121 generatedTestDefaultArchivaConfigFile.delete();
122 assertFalse( generatedTestDefaultArchivaConfigFile.exists() );
126 * Ensures that the provided configuration matches the details present in the archiva-default.xml file.
128 private void assertConfiguration( Configuration configuration )
131 FileTypes filetypes = (FileTypes) lookup( FileTypes.class.getName() );
133 assertEquals( "check repositories", 2, configuration.getManagedRepositories().size() );
134 assertEquals( "check repositories", 2, configuration.getRemoteRepositories().size() );
135 assertEquals( "check proxy connectors", 2, configuration.getProxyConnectors().size() );
137 RepositoryScanningConfiguration repoScanning = configuration.getRepositoryScanning();
138 assertNotNull( "check repository scanning", repoScanning );
139 assertEquals( "check file types", 4, repoScanning.getFileTypes().size() );
140 assertEquals( "check known consumers", 9, repoScanning.getKnownContentConsumers().size() );
141 assertEquals( "check invalid consumers", 1, repoScanning.getInvalidContentConsumers().size() );
143 List<String> patterns = filetypes.getFileTypePatterns( "artifacts" );
144 assertNotNull( "check 'artifacts' file type", patterns );
145 assertEquals( "check 'artifacts' patterns", 13, patterns.size() );
147 DatabaseScanningConfiguration dbScanning = configuration.getDatabaseScanning();
148 assertNotNull( "check database scanning", dbScanning );
149 assertEquals( "check unprocessed consumers", 6, dbScanning.getUnprocessedConsumers().size() );
150 assertEquals( "check cleanup consumers", 3, dbScanning.getCleanupConsumers().size() );
152 WebappConfiguration webapp = configuration.getWebapp();
153 assertNotNull( "check webapp", webapp );
155 UserInterfaceOptions ui = webapp.getUi();
156 assertNotNull( "check webapp ui", ui );
157 assertTrue( "check showFindArtifacts", ui.isShowFindArtifacts() );
158 assertTrue( "check appletFindEnabled", ui.isAppletFindEnabled() );
161 public void testGetConfigurationFromRegistryWithTwoConfigurationResources()
164 ArchivaConfiguration archivaConfiguration =
165 (ArchivaConfiguration) lookup( ArchivaConfiguration.class.getName(), "test-configuration-both" );
167 Configuration configuration = archivaConfiguration.getConfiguration();
170 assertEquals( "check repositories", 2, configuration.getManagedRepositories().size() );
171 assertEquals( "check repositories", 2, configuration.getRemoteRepositories().size() );
173 assertEquals( "check proxy connectors", 2, configuration.getProxyConnectors().size() );
175 WebappConfiguration webapp = configuration.getWebapp();
176 assertNotNull( "check webapp", webapp );
178 UserInterfaceOptions ui = webapp.getUi();
179 assertNotNull( "check webapp ui", ui );
181 assertFalse( "check showFindArtifacts", ui.isShowFindArtifacts() );
183 assertFalse( "check appletFindEnabled", ui.isAppletFindEnabled() );
186 public void testGetConfigurationSystemOverride()
190 System.setProperty( "org.apache.maven.archiva.webapp.ui.appletFindEnabled", "false" );
192 ArchivaConfiguration archivaConfiguration =
193 (ArchivaConfiguration) lookup( ArchivaConfiguration.class.getName(), "test-configuration" );
197 Configuration configuration = archivaConfiguration.getConfiguration();
199 assertFalse( "check boolean", configuration.getWebapp().getUi().isAppletFindEnabled() );
203 System.getProperties().remove( "org.apache.maven.archiva.webapp.ui.appletFindEnabled" );
207 public void testStoreConfiguration()
210 File file = getTestFile( "target/test/test-file.xml" );
212 assertFalse( file.exists() );
214 // TODO: remove with commons-configuration 1.4
215 file.getParentFile().mkdirs();
216 FileUtils.writeStringToFile( file, "<configuration/>", null );
218 DefaultArchivaConfiguration archivaConfiguration =
219 (DefaultArchivaConfiguration) lookup( ArchivaConfiguration.class.getName(), "test-save" );
221 Configuration configuration = new Configuration();
222 configuration.setVersion( "1" );
223 configuration.setWebapp( new WebappConfiguration() );
224 configuration.getWebapp().setUi( new UserInterfaceOptions() );
225 configuration.getWebapp().getUi().setAppletFindEnabled( false );
227 // add a change listener
228 MockControl control = createConfigurationListenerMockControl();
229 ConfigurationListener listener = (ConfigurationListener) control.getMock();
230 archivaConfiguration.addListener( listener );
232 listener.configurationEvent( new ConfigurationEvent( ConfigurationEvent.SAVED ) );
233 control.setVoidCallable();
237 archivaConfiguration.save( configuration );
241 assertTrue( "Check file exists", file.exists() );
244 configuration = archivaConfiguration.getConfiguration();
245 assertFalse( "check value", configuration.getWebapp().getUi().isAppletFindEnabled() );
248 archivaConfiguration =
249 (DefaultArchivaConfiguration) lookup( ArchivaConfiguration.class.getName(), "test-read-saved" );
250 configuration = archivaConfiguration.getConfiguration();
251 assertFalse( "check value", configuration.getWebapp().getUi().isAppletFindEnabled() );
254 private static MockControl createConfigurationListenerMockControl()
256 return MockControl.createControl( ConfigurationListener.class );
259 public void testStoreConfigurationUser()
262 File baseFile = getTestFile( "target/test/test-file.xml" );
264 assertFalse( baseFile.exists() );
266 File userFile = getTestFile( "target/test/test-file-user.xml" );
268 assertFalse( userFile.exists() );
270 userFile.getParentFile().mkdirs();
271 FileUtils.writeStringToFile( userFile, "<configuration/>", null );
273 ArchivaConfiguration archivaConfiguration =
274 (ArchivaConfiguration) lookup( ArchivaConfiguration.class.getName(), "test-save-user" );
276 Configuration configuration = new Configuration();
277 configuration.setWebapp( new WebappConfiguration() );
278 configuration.getWebapp().setUi( new UserInterfaceOptions() );
279 configuration.getWebapp().getUi().setAppletFindEnabled( false );
281 archivaConfiguration.save( configuration );
283 assertTrue( "Check file exists", userFile.exists() );
284 assertFalse( "Check file not created", baseFile.exists() );
287 configuration = archivaConfiguration.getConfiguration();
288 assertFalse( "check value", configuration.getWebapp().getUi().isAppletFindEnabled() );
291 public void testStoreConfigurationLoadedFromDefaults()
294 File baseFile = getTestFile( "target/test/test-file.xml" );
296 assertFalse( baseFile.exists() );
298 File userFile = getTestFile( "target/test/test-file-user.xml" );
300 assertFalse( userFile.exists() );
302 ArchivaConfiguration archivaConfiguration =
303 (ArchivaConfiguration) lookup( ArchivaConfiguration.class.getName(), "test-save-user" );
305 Configuration configuration = new Configuration();
306 configuration.setWebapp( new WebappConfiguration() );
307 configuration.getWebapp().setUi( new UserInterfaceOptions() );
308 configuration.getWebapp().getUi().setAppletFindEnabled( false );
310 // add a change listener
311 MockControl control = createConfigurationListenerMockControl();
312 ConfigurationListener listener = (ConfigurationListener) control.getMock();
313 archivaConfiguration.addListener( listener );
315 listener.configurationEvent( new ConfigurationEvent( ConfigurationEvent.SAVED ) );
316 // once from default creation, and again from manual call to save
317 control.setVoidCallable( 2 );
321 archivaConfiguration.save( configuration );
325 assertTrue( "Check file exists", userFile.exists() );
326 assertFalse( "Check file not created", baseFile.exists() );
329 configuration = archivaConfiguration.getConfiguration();
330 assertFalse( "check value", configuration.getWebapp().getUi().isAppletFindEnabled() );
333 public void testDefaultUserConfigFilename()
336 DefaultArchivaConfiguration archivaConfiguration =
337 (DefaultArchivaConfiguration) lookup( ArchivaConfiguration.class.getName() );
339 assertEquals( System.getProperty( "user.home" ) + "/.m2/archiva.xml",
340 archivaConfiguration.getUserConfigFilename() );
341 assertEquals( System.getProperty( "appserver.base", "${appserver.base}" ) + "/conf/archiva.xml",
342 archivaConfiguration.getAltConfigFilename() );
345 public void testStoreConfigurationFallback()
348 File baseFile = getTestFile( "target/test/test-file.xml" );
350 assertFalse( baseFile.exists() );
352 File userFile = getTestFile( "target/test/test-file-user.xml" );
354 assertFalse( userFile.exists() );
356 baseFile.getParentFile().mkdirs();
357 FileUtils.writeStringToFile( baseFile, "<configuration/>", null );
359 ArchivaConfiguration archivaConfiguration =
360 (ArchivaConfiguration) lookup( ArchivaConfiguration.class.getName(), "test-save-user" );
362 Configuration configuration = new Configuration();
363 configuration.setWebapp( new WebappConfiguration() );
364 configuration.getWebapp().setUi( new UserInterfaceOptions() );
365 configuration.getWebapp().getUi().setAppletFindEnabled( false );
367 archivaConfiguration.save( configuration );
369 assertTrue( "Check file exists", baseFile.exists() );
370 assertFalse( "Check file not created", userFile.exists() );
373 configuration = archivaConfiguration.getConfiguration();
374 assertFalse( "check value", configuration.getWebapp().getUi().isAppletFindEnabled() );
377 public void testStoreConfigurationFailsWhenReadFromBothLocationsNoLists()
380 File baseFile = getTestFile( "target/test/test-file.xml" );
382 assertFalse( baseFile.exists() );
384 File userFile = getTestFile( "target/test/test-file-user.xml" );
386 assertFalse( userFile.exists() );
388 baseFile.getParentFile().mkdirs();
389 FileUtils.writeStringToFile( baseFile, "<configuration/>", null );
391 userFile.getParentFile().mkdirs();
392 FileUtils.writeStringToFile( userFile, "<configuration/>", null );
394 ArchivaConfiguration archivaConfiguration =
395 (ArchivaConfiguration) lookup( ArchivaConfiguration.class.getName(), "test-save-user" );
397 Configuration configuration = archivaConfiguration.getConfiguration();
398 assertTrue( "check value", configuration.getWebapp().getUi().isAppletFindEnabled() );
400 configuration.getWebapp().getUi().setAppletFindEnabled( false );
402 archivaConfiguration.save( configuration );
404 assertTrue( "Check file exists", baseFile.exists() );
405 assertEquals( "Check base file is unchanged", "<configuration/>",
406 FileUtils.readFileToString( baseFile, null ) );
407 assertTrue( "Check file exists", userFile.exists() );
408 assertFalse( "Check base file is changed",
409 "<configuration/>".equals( FileUtils.readFileToString( userFile, null ) ) );
412 configuration = archivaConfiguration.getConfiguration();
413 assertFalse( "check value", configuration.getWebapp().getUi().isAppletFindEnabled() );
416 public void testStoreConfigurationFailsWhenReadFromBothLocationsUserHasLists()
419 File baseFile = getTestFile( "target/test/test-file.xml" );
421 assertFalse( baseFile.exists() );
423 File userFile = getTestFile( "target/test/test-file-user.xml" );
425 assertFalse( userFile.exists() );
427 userFile.getParentFile().mkdirs();
428 FileUtils.copyFile( getTestFile( "src/test/conf/conf-user.xml" ), userFile );
430 baseFile.getParentFile().mkdirs();
431 FileUtils.writeStringToFile( baseFile, "<configuration/>", null );
433 ArchivaConfiguration archivaConfiguration =
434 (ArchivaConfiguration) lookup( ArchivaConfiguration.class.getName(), "test-save-user" );
436 Configuration configuration = archivaConfiguration.getConfiguration();
437 assertTrue( "check value", configuration.getWebapp().getUi().isShowFindArtifacts() );
439 configuration.getWebapp().getUi().setShowFindArtifacts( false );
441 archivaConfiguration.save( configuration );
443 assertTrue( "Check file exists", baseFile.exists() );
444 assertEquals( "Check base file is unchanged", "<configuration/>",
445 FileUtils.readFileToString( baseFile, null ) );
446 assertTrue( "Check file exists", userFile.exists() );
447 assertFalse( "Check base file is changed",
448 "<configuration/>".equals( FileUtils.readFileToString( userFile, null ) ) );
451 configuration = archivaConfiguration.getConfiguration();
452 assertFalse( "check value", configuration.getWebapp().getUi().isShowFindArtifacts() );
455 public void testStoreConfigurationFailsWhenReadFromBothLocationsAppserverHasLists()
458 File baseFile = getTestFile( "target/test/test-file.xml" );
460 assertFalse( baseFile.exists() );
462 File userFile = getTestFile( "target/test/test-file-user.xml" );
464 assertFalse( userFile.exists() );
466 baseFile.getParentFile().mkdirs();
467 FileUtils.copyFile( getTestFile( "src/test/conf/conf-base.xml" ), baseFile );
469 userFile.getParentFile().mkdirs();
470 FileUtils.writeStringToFile( userFile, "<configuration/>", null );
472 ArchivaConfiguration archivaConfiguration =
473 (ArchivaConfiguration) lookup( ArchivaConfiguration.class.getName(), "test-save-user" );
475 Configuration configuration = archivaConfiguration.getConfiguration();
476 assertTrue( "check value", configuration.getWebapp().getUi().isAppletFindEnabled() );
478 configuration.getWebapp().getUi().setAppletFindEnabled( false );
482 archivaConfiguration.save( configuration );
483 fail( "Configuration saving should not succeed if it was loaded from two locations" );
485 catch ( IndeterminateConfigurationException e )
487 // check it was reverted
488 configuration = archivaConfiguration.getConfiguration();
489 assertTrue( "check value", configuration.getWebapp().getUi().isAppletFindEnabled() );
493 public void testLoadConfigurationFromInvalidBothLocationsOnDisk()
496 ArchivaConfiguration archivaConfiguration =
497 (ArchivaConfiguration) lookup( ArchivaConfiguration.class.getName(), "test-not-allowed-to-write-to-both" );
498 Configuration config = archivaConfiguration.getConfiguration();
502 archivaConfiguration.save( config );
503 fail( "Should have thrown a RegistryException because the configuration can't be saved." );
505 catch ( RegistryException e )
507 /* expected exception */
511 public void testLoadConfigurationFromInvalidUserLocationOnDisk()
514 File testConfDir = getTestFile( "target/test-appserver-base/conf/" );
515 testConfDir.mkdirs();
517 ArchivaConfiguration archivaConfiguration =
518 (ArchivaConfiguration) lookup( ArchivaConfiguration.class.getName(), "test-not-allowed-to-write-to-user" );
519 Configuration config = archivaConfiguration.getConfiguration();
520 archivaConfiguration.save( config );
521 // No Exception == test passes.
522 // Expected Path is: Should not have thrown an exception.
525 public void testConfigurationUpgradeFrom09()
528 ArchivaConfiguration archivaConfiguration =
529 (ArchivaConfiguration) lookup( ArchivaConfiguration.class.getName(), "test-upgrade-09" );
531 // we just use the defaults when upgrading from 0.9 at this point.
532 Configuration configuration = archivaConfiguration.getConfiguration();
533 assertConfiguration( configuration );
534 assertEquals( "check network proxies", 0, configuration.getNetworkProxies().size() );
536 ManagedRepositoryConfiguration repository =
537 (ManagedRepositoryConfiguration) configuration.getManagedRepositories().get( 0 );
539 assertEquals( "check managed repositories", "${appserver.base}/data/repositories/internal",
540 repository.getLocation() );
541 assertEquals( "check managed repositories", "Archiva Managed Internal Repository", repository.getName() );
542 assertEquals( "check managed repositories", "internal", repository.getId() );
543 assertEquals( "check managed repositories", "default", repository.getLayout() );
544 assertTrue( "check managed repositories", repository.isScanned() );
547 public void testAutoDetectV1()
550 // Setup the autodetect-v1.xml file in the target directory (so we can save/load it)
551 File userFile = getTestFile( "target/test-autodetect-v1/archiva-user.xml" );
553 assertFalse( userFile.exists() );
555 userFile.getParentFile().mkdirs();
556 FileUtils.copyFile( getTestFile( "src/test/conf/autodetect-v1.xml" ), userFile );
558 // Load the original (unconverted) archiva.xml
559 ArchivaConfiguration archivaConfiguration =
560 (ArchivaConfiguration) lookup( ArchivaConfiguration.class.getName(), "test-autodetect-v1" );
562 Configuration configuration = archivaConfiguration.getConfiguration();
563 assertConfiguration( configuration );
564 assertEquals( "check network proxies", 1, configuration.getNetworkProxies().size() );
566 ManagedRepositoryConfiguration repository =
567 (ManagedRepositoryConfiguration) configuration.getManagedRepositories().get( 0 );
569 assertEquals( "check managed repositories", "${appserver.base}/repositories/internal",
570 repository.getLocation() );
571 assertEquals( "check managed repositories", "Archiva Managed Internal Repository", repository.getName() );
572 assertEquals( "check managed repositories", "internal", repository.getId() );
573 assertEquals( "check managed repositories", "default", repository.getLayout() );
574 assertTrue( "check managed repositories", repository.isScanned() );
576 // Test that only 1 set of repositories exist.
577 assertEquals( "check managed repositories size.", 2, configuration.getManagedRepositories().size() );
578 assertEquals( "check remote repositories size.", 2, configuration.getRemoteRepositories().size() );
579 assertEquals( "check v1 repositories size.", 0, configuration.getRepositories().size() );
582 archivaConfiguration.save( configuration );
585 // FIXME spring equivalent ? release( archivaConfiguration );
588 archivaConfiguration =
589 (ArchivaConfiguration) lookup( ArchivaConfiguration.class.getName(), "test-autodetect-v1" );
590 configuration = archivaConfiguration.getConfiguration();
592 // Test that only 1 set of repositories exist.
593 assertEquals( "check managed repositories size.", 2, configuration.getManagedRepositories().size() );
594 assertEquals( "check managed repositories size.", 2, configuration.getManagedRepositoriesAsMap().size() );
595 assertEquals( "check remote repositories size.", 2, configuration.getRemoteRepositories().size() );
596 assertEquals( "check remote repositories size.", 2, configuration.getRemoteRepositoriesAsMap().size() );
597 assertEquals( "check v1 repositories size.", 0, configuration.getRepositories().size() );
599 String actualXML = FileUtils.readFileToString( userFile, null );
600 XMLAssert.assertXpathNotExists( "//configuration/repositories/repository", actualXML );
601 XMLAssert.assertXpathNotExists( "//configuration/repositories", actualXML );
604 public void testArchivaV1()
607 ArchivaConfiguration archivaConfiguration =
608 (ArchivaConfiguration) lookup( ArchivaConfiguration.class.getName(), "test-archiva-v1" );
610 Configuration configuration = archivaConfiguration.getConfiguration();
611 assertConfiguration( configuration );
612 assertEquals( "check network proxies", 1, configuration.getNetworkProxies().size() );
614 assertEquals( "check managed repositories", 2, configuration.getManagedRepositories().size() );
615 assertEquals( "check v1 repositories size.", 0, configuration.getRepositories().size() );
617 Map<String, ManagedRepositoryConfiguration> map = configuration.getManagedRepositoriesAsMap();
619 ManagedRepositoryConfiguration repository = map.get( "internal" );
620 assertEquals( "check managed repositories", "${appserver.base}/repositories/internal",
621 repository.getLocation() );
622 assertEquals( "check managed repositories", "Archiva Managed Internal Repository", repository.getName() );
623 assertEquals( "check managed repositories", "internal", repository.getId() );
624 assertEquals( "check managed repositories", "default", repository.getLayout() );
625 assertTrue( "check managed repositories", repository.isScanned() );
626 assertFalse( "check managed repositories", repository.isSnapshots() );
628 repository = map.get( "snapshots" );
629 assertEquals( "check managed repositories", "${appserver.base}/repositories/snapshots",
630 repository.getLocation() );
631 assertEquals( "check managed repositories", "Archiva Managed Snapshot Repository", repository.getName() );
632 assertEquals( "check managed repositories", "snapshots", repository.getId() );
633 assertEquals( "check managed repositories", "default", repository.getLayout() );
634 assertFalse( "check managed repositories", repository.isScanned() );
635 assertTrue( "check managed repositories", repository.isSnapshots() );
638 public void testCronExpressionsWithComma()
641 File baseFile = getTestFile( "target/test/test-file.xml" );
643 assertFalse( baseFile.exists() );
645 File userFile = getTestFile( "target/test/test-file-user.xml" );
647 assertFalse( userFile.exists() );
649 baseFile.getParentFile().mkdirs();
650 FileUtils.copyFile( getTestFile( "src/test/conf/escape-cron-expressions.xml" ), baseFile );
652 userFile.getParentFile().mkdirs();
653 FileUtils.writeStringToFile( userFile, "<configuration/>", null );
655 final ArchivaConfiguration archivaConfiguration =
656 (ArchivaConfiguration) lookup( ArchivaConfiguration.class.getName(), "test-cron-expressions" );
658 Configuration configuration = archivaConfiguration.getConfiguration();
660 ManagedRepositoryConfiguration repository =
661 (ManagedRepositoryConfiguration) configuration.getManagedRepositories().get( 0 );
663 assertEquals( "check cron expression", "0 0,30 * * * ?", repository.getRefreshCronExpression().trim() );
665 configuration.getDatabaseScanning().setCronExpression( "0 0,15 0 * * ?" );
667 // add a test listener to confirm it doesn't see the escaped format. We don't need to test the number of calls,
668 // etc. as it's done in other tests
669 archivaConfiguration.addListener( new ConfigurationListener()
671 public void configurationEvent( ConfigurationEvent event )
673 assertEquals( ConfigurationEvent.SAVED, event.getType() );
675 Configuration configuration = archivaConfiguration.getConfiguration();
677 ManagedRepositoryConfiguration repository =
678 (ManagedRepositoryConfiguration) configuration.getManagedRepositories().get( 0 );
680 assertEquals( "check cron expression", "0 0,15 0 * * ?",
681 configuration.getDatabaseScanning().getCronExpression() );
685 archivaConfiguration.save( configuration );
687 configuration = archivaConfiguration.getConfiguration();
689 assertEquals( "check cron expression", "0 0,15 0 * * ?",
690 configuration.getDatabaseScanning().getCronExpression() );
692 // test for the escape character '\' showing up on repositories.jsp
693 repository.setRefreshCronExpression( "0 0,20 0 * * ?" );
695 archivaConfiguration.save( configuration );
697 repository = archivaConfiguration.getConfiguration().findManagedRepositoryById( "snapshots" );
699 assertEquals( "check cron expression", "0 0,20 0 * * ?", repository.getRefreshCronExpression() );
702 public void testRemoveLastElements()
705 File baseFile = getTestFile( "target/test/test-file.xml" );
707 assertFalse( baseFile.exists() );
709 File userFile = getTestFile( "target/test/test-file-user.xml" );
711 assertFalse( userFile.exists() );
713 baseFile.getParentFile().mkdirs();
714 FileUtils.copyFile( getTestFile( "src/test/conf/conf-single-list-elements.xml" ), baseFile );
716 userFile.getParentFile().mkdirs();
717 FileUtils.writeStringToFile( userFile, "<configuration/>", null );
719 ArchivaConfiguration archivaConfiguration =
720 (ArchivaConfiguration) lookup( ArchivaConfiguration.class.getName(), "test-remove-central" );
722 Configuration configuration = archivaConfiguration.getConfiguration();
724 RepositoryGroupConfiguration repositoryGroup = ( RepositoryGroupConfiguration ) configuration.getRepositoryGroups().get( 0 );
725 assertNotNull( repositoryGroup );
726 configuration.removeRepositoryGroup( repositoryGroup );
727 assertTrue( configuration.getRepositoryGroups().isEmpty() );
729 RemoteRepositoryConfiguration repository = configuration.getRemoteRepositoriesAsMap().get( "central" );
730 assertNotNull( repository );
731 configuration.removeRemoteRepository( repository );
732 assertTrue( configuration.getRemoteRepositories().isEmpty() );
734 ManagedRepositoryConfiguration managedRepository =
735 configuration.getManagedRepositoriesAsMap().get( "snapshots" );
736 assertNotNull( managedRepository );
737 configuration.removeManagedRepository( managedRepository );
738 assertTrue( configuration.getManagedRepositories().isEmpty() );
740 ProxyConnectorConfiguration proxyConnector =
741 (ProxyConnectorConfiguration) configuration.getProxyConnectors().get( 0 );
742 assertNotNull( proxyConnector );
743 configuration.removeProxyConnector( proxyConnector );
744 assertTrue( configuration.getProxyConnectors().isEmpty() );
746 NetworkProxyConfiguration networkProxy = configuration.getNetworkProxiesAsMap().get( "proxy" );
747 assertNotNull( networkProxy );
748 configuration.removeNetworkProxy( networkProxy );
749 assertTrue( configuration.getNetworkProxies().isEmpty() );
751 LegacyArtifactPath path = (LegacyArtifactPath) configuration.getLegacyArtifactPaths().get( 0 );
752 assertNotNull( path );
753 configuration.removeLegacyArtifactPath( path );
754 assertTrue( configuration.getLegacyArtifactPaths().isEmpty() );
756 RepositoryScanningConfiguration scanning = configuration.getRepositoryScanning();
757 String consumer = (String) scanning.getKnownContentConsumers().get( 0 );
758 assertNotNull( consumer );
759 scanning.removeKnownContentConsumer( consumer );
760 assertTrue( scanning.getKnownContentConsumers().isEmpty() );
761 consumer = (String) scanning.getInvalidContentConsumers().get( 0 );
762 assertNotNull( consumer );
763 scanning.removeInvalidContentConsumer( consumer );
764 assertTrue( scanning.getInvalidContentConsumers().isEmpty() );
766 DatabaseScanningConfiguration databaseScanning = configuration.getDatabaseScanning();
767 consumer = (String) databaseScanning.getCleanupConsumers().get( 0 );
768 assertNotNull( consumer );
769 databaseScanning.removeCleanupConsumer( consumer );
770 assertTrue( databaseScanning.getCleanupConsumers().isEmpty() );
771 consumer = (String) databaseScanning.getUnprocessedConsumers().get( 0 );
772 assertNotNull( consumer );
773 databaseScanning.removeUnprocessedConsumer( consumer );
774 assertTrue( databaseScanning.getUnprocessedConsumers().isEmpty() );
776 archivaConfiguration.save( configuration );
778 archivaConfiguration =
779 (ArchivaConfiguration) lookup( ArchivaConfiguration.class.getName(), "test-read-saved" );
780 configuration = archivaConfiguration.getConfiguration();
781 assertNull( configuration.getRemoteRepositoriesAsMap().get( "central" ) );
782 assertTrue( configuration.getRepositoryGroups().isEmpty() );
783 assertNull( configuration.getManagedRepositoriesAsMap().get( "snapshots" ) );
784 assertTrue( configuration.getProxyConnectors().isEmpty() );
785 assertNull( configuration.getNetworkProxiesAsMap().get( "proxy" ) );
786 assertTrue( configuration.getLegacyArtifactPaths().isEmpty() );
787 scanning = configuration.getRepositoryScanning();
788 assertTrue( scanning.getKnownContentConsumers().isEmpty() );
789 assertTrue( scanning.getInvalidContentConsumers().isEmpty() );
790 databaseScanning = configuration.getDatabaseScanning();
791 assertTrue( databaseScanning.getCleanupConsumers().isEmpty() );
792 assertTrue( databaseScanning.getUnprocessedConsumers().isEmpty() );
796 * [MRM-582] Remote Repositories with empty <username> and <password> fields shouldn't be created in configuration.
798 public void testGetConfigurationFixEmptyRemoteRepoUsernamePassword()
801 ArchivaConfiguration archivaConfiguration = (ArchivaConfiguration) lookup(
802 ArchivaConfiguration.class.getName(),
803 "test-configuration" );
805 Configuration configuration = archivaConfiguration.getConfiguration();
806 assertConfiguration( configuration );
807 assertEquals( "check remote repositories", 2, configuration.getRemoteRepositories().size() );
809 RemoteRepositoryConfiguration repository = (RemoteRepositoryConfiguration) configuration
810 .getRemoteRepositoriesAsMap().get( "maven2-repository.dev.java.net" );
812 assertEquals( "remote repository.url", "https://maven2-repository.dev.java.net/nonav/repository", repository.getUrl() );
813 assertEquals( "remote repository.name", "Java.net Repository for Maven 2", repository.getName() );
814 assertEquals( "remote repository.id", "maven2-repository.dev.java.net", repository.getId() );
815 assertEquals( "remote repository.layout", "default", repository.getLayout() );
816 assertNull( "remote repository.username == null", repository.getUsername() );
817 assertNull( "remote repository.password == null", repository.getPassword() );