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()
189 ArchivaConfiguration archivaConfiguration =
190 (ArchivaConfiguration) lookup( ArchivaConfiguration.class.getName(), "test-configuration" );
192 System.setProperty( "org.apache.maven.archiva.webapp.ui.appletFindEnabled", "false" );
196 Configuration configuration = archivaConfiguration.getConfiguration();
198 assertFalse( "check boolean", configuration.getWebapp().getUi().isAppletFindEnabled() );
202 System.getProperties().remove( "org.apache.maven.archiva.webapp.ui.appletFindEnabled" );
206 public void testStoreConfiguration()
209 File file = getTestFile( "target/test/test-file.xml" );
211 assertFalse( file.exists() );
213 // TODO: remove with commons-configuration 1.4
214 file.getParentFile().mkdirs();
215 FileUtils.writeStringToFile( file, "<configuration/>", null );
217 DefaultArchivaConfiguration archivaConfiguration =
218 (DefaultArchivaConfiguration) lookup( ArchivaConfiguration.class.getName(), "test-save" );
220 Configuration configuration = new Configuration();
221 configuration.setVersion( "1" );
222 configuration.setWebapp( new WebappConfiguration() );
223 configuration.getWebapp().setUi( new UserInterfaceOptions() );
224 configuration.getWebapp().getUi().setAppletFindEnabled( false );
226 // add a change listener
227 MockControl control = createConfigurationListenerMockControl();
228 ConfigurationListener listener = (ConfigurationListener) control.getMock();
229 archivaConfiguration.addListener( listener );
231 listener.configurationEvent( new ConfigurationEvent( ConfigurationEvent.SAVED ) );
232 control.setVoidCallable();
236 archivaConfiguration.save( configuration );
240 assertTrue( "Check file exists", file.exists() );
243 configuration = archivaConfiguration.getConfiguration();
244 assertFalse( "check value", configuration.getWebapp().getUi().isAppletFindEnabled() );
247 archivaConfiguration =
248 (DefaultArchivaConfiguration) lookup( ArchivaConfiguration.class.getName(), "test-read-saved" );
249 configuration = archivaConfiguration.getConfiguration();
250 assertFalse( "check value", configuration.getWebapp().getUi().isAppletFindEnabled() );
253 private static MockControl createConfigurationListenerMockControl()
255 return MockControl.createControl( ConfigurationListener.class );
258 public void testStoreConfigurationUser()
261 File baseFile = getTestFile( "target/test/test-file.xml" );
263 assertFalse( baseFile.exists() );
265 File userFile = getTestFile( "target/test/test-file-user.xml" );
267 assertFalse( userFile.exists() );
269 userFile.getParentFile().mkdirs();
270 FileUtils.writeStringToFile( userFile, "<configuration/>", null );
272 ArchivaConfiguration archivaConfiguration =
273 (ArchivaConfiguration) lookup( ArchivaConfiguration.class.getName(), "test-save-user" );
275 Configuration configuration = new Configuration();
276 configuration.setWebapp( new WebappConfiguration() );
277 configuration.getWebapp().setUi( new UserInterfaceOptions() );
278 configuration.getWebapp().getUi().setAppletFindEnabled( false );
280 archivaConfiguration.save( configuration );
282 assertTrue( "Check file exists", userFile.exists() );
283 assertFalse( "Check file not created", baseFile.exists() );
286 configuration = archivaConfiguration.getConfiguration();
287 assertFalse( "check value", configuration.getWebapp().getUi().isAppletFindEnabled() );
290 public void testStoreConfigurationLoadedFromDefaults()
293 File baseFile = getTestFile( "target/test/test-file.xml" );
295 assertFalse( baseFile.exists() );
297 File userFile = getTestFile( "target/test/test-file-user.xml" );
299 assertFalse( userFile.exists() );
301 ArchivaConfiguration archivaConfiguration =
302 (ArchivaConfiguration) lookup( ArchivaConfiguration.class.getName(), "test-save-user" );
304 Configuration configuration = new Configuration();
305 configuration.setWebapp( new WebappConfiguration() );
306 configuration.getWebapp().setUi( new UserInterfaceOptions() );
307 configuration.getWebapp().getUi().setAppletFindEnabled( false );
309 // add a change listener
310 MockControl control = createConfigurationListenerMockControl();
311 ConfigurationListener listener = (ConfigurationListener) control.getMock();
312 archivaConfiguration.addListener( listener );
314 listener.configurationEvent( new ConfigurationEvent( ConfigurationEvent.SAVED ) );
315 // once from default creation, and again from manual call to save
316 control.setVoidCallable( 2 );
320 archivaConfiguration.save( configuration );
324 assertTrue( "Check file exists", userFile.exists() );
325 assertFalse( "Check file not created", baseFile.exists() );
328 configuration = archivaConfiguration.getConfiguration();
329 assertFalse( "check value", configuration.getWebapp().getUi().isAppletFindEnabled() );
332 public void testDefaultUserConfigFilename()
335 DefaultArchivaConfiguration archivaConfiguration =
336 (DefaultArchivaConfiguration) lookup( ArchivaConfiguration.class.getName() );
338 assertEquals( System.getProperty( "user.home" ) + "/.m2/archiva.xml",
339 archivaConfiguration.getUserConfigFilename() );
340 assertEquals( System.getProperty( "appserver.base", "${appserver.base}" ) + "/conf/archiva.xml",
341 archivaConfiguration.getAltConfigFilename() );
344 public void testStoreConfigurationFallback()
347 File baseFile = getTestFile( "target/test/test-file.xml" );
349 assertFalse( baseFile.exists() );
351 File userFile = getTestFile( "target/test/test-file-user.xml" );
353 assertFalse( userFile.exists() );
355 baseFile.getParentFile().mkdirs();
356 FileUtils.writeStringToFile( baseFile, "<configuration/>", null );
358 ArchivaConfiguration archivaConfiguration =
359 (ArchivaConfiguration) lookup( ArchivaConfiguration.class.getName(), "test-save-user" );
361 Configuration configuration = new Configuration();
362 configuration.setWebapp( new WebappConfiguration() );
363 configuration.getWebapp().setUi( new UserInterfaceOptions() );
364 configuration.getWebapp().getUi().setAppletFindEnabled( false );
366 archivaConfiguration.save( configuration );
368 assertTrue( "Check file exists", baseFile.exists() );
369 assertFalse( "Check file not created", userFile.exists() );
372 configuration = archivaConfiguration.getConfiguration();
373 assertFalse( "check value", configuration.getWebapp().getUi().isAppletFindEnabled() );
376 public void testStoreConfigurationFailsWhenReadFromBothLocationsNoLists()
379 File baseFile = getTestFile( "target/test/test-file.xml" );
381 assertFalse( baseFile.exists() );
383 File userFile = getTestFile( "target/test/test-file-user.xml" );
385 assertFalse( userFile.exists() );
387 baseFile.getParentFile().mkdirs();
388 FileUtils.writeStringToFile( baseFile, "<configuration/>", null );
390 userFile.getParentFile().mkdirs();
391 FileUtils.writeStringToFile( userFile, "<configuration/>", null );
393 ArchivaConfiguration archivaConfiguration =
394 (ArchivaConfiguration) lookup( ArchivaConfiguration.class.getName(), "test-save-user" );
396 Configuration configuration = archivaConfiguration.getConfiguration();
397 assertTrue( "check value", configuration.getWebapp().getUi().isAppletFindEnabled() );
399 configuration.getWebapp().getUi().setAppletFindEnabled( false );
401 archivaConfiguration.save( configuration );
403 assertTrue( "Check file exists", baseFile.exists() );
404 assertEquals( "Check base file is unchanged", "<configuration/>",
405 FileUtils.readFileToString( baseFile, null ) );
406 assertTrue( "Check file exists", userFile.exists() );
407 assertFalse( "Check base file is changed",
408 "<configuration/>".equals( FileUtils.readFileToString( userFile, null ) ) );
411 configuration = archivaConfiguration.getConfiguration();
412 assertFalse( "check value", configuration.getWebapp().getUi().isAppletFindEnabled() );
415 public void testStoreConfigurationFailsWhenReadFromBothLocationsUserHasLists()
418 File baseFile = getTestFile( "target/test/test-file.xml" );
420 assertFalse( baseFile.exists() );
422 File userFile = getTestFile( "target/test/test-file-user.xml" );
424 assertFalse( userFile.exists() );
426 userFile.getParentFile().mkdirs();
427 FileUtils.copyFile( getTestFile( "src/test/conf/conf-user.xml" ), userFile );
429 baseFile.getParentFile().mkdirs();
430 FileUtils.writeStringToFile( baseFile, "<configuration/>", null );
432 ArchivaConfiguration archivaConfiguration =
433 (ArchivaConfiguration) lookup( ArchivaConfiguration.class.getName(), "test-save-user" );
435 Configuration configuration = archivaConfiguration.getConfiguration();
436 assertTrue( "check value", configuration.getWebapp().getUi().isShowFindArtifacts() );
438 configuration.getWebapp().getUi().setShowFindArtifacts( false );
440 archivaConfiguration.save( configuration );
442 assertTrue( "Check file exists", baseFile.exists() );
443 assertEquals( "Check base file is unchanged", "<configuration/>",
444 FileUtils.readFileToString( baseFile, null ) );
445 assertTrue( "Check file exists", userFile.exists() );
446 assertFalse( "Check base file is changed",
447 "<configuration/>".equals( FileUtils.readFileToString( userFile, null ) ) );
450 configuration = archivaConfiguration.getConfiguration();
451 assertFalse( "check value", configuration.getWebapp().getUi().isShowFindArtifacts() );
454 public void testStoreConfigurationFailsWhenReadFromBothLocationsAppserverHasLists()
457 File baseFile = getTestFile( "target/test/test-file.xml" );
459 assertFalse( baseFile.exists() );
461 File userFile = getTestFile( "target/test/test-file-user.xml" );
463 assertFalse( userFile.exists() );
465 baseFile.getParentFile().mkdirs();
466 FileUtils.copyFile( getTestFile( "src/test/conf/conf-base.xml" ), baseFile );
468 userFile.getParentFile().mkdirs();
469 FileUtils.writeStringToFile( userFile, "<configuration/>", null );
471 ArchivaConfiguration archivaConfiguration =
472 (ArchivaConfiguration) lookup( ArchivaConfiguration.class.getName(), "test-save-user" );
474 Configuration configuration = archivaConfiguration.getConfiguration();
475 assertTrue( "check value", configuration.getWebapp().getUi().isAppletFindEnabled() );
477 configuration.getWebapp().getUi().setAppletFindEnabled( false );
481 archivaConfiguration.save( configuration );
482 fail( "Configuration saving should not succeed if it was loaded from two locations" );
484 catch ( IndeterminateConfigurationException e )
486 // check it was reverted
487 configuration = archivaConfiguration.getConfiguration();
488 assertTrue( "check value", configuration.getWebapp().getUi().isAppletFindEnabled() );
492 public void testLoadConfigurationFromInvalidBothLocationsOnDisk()
495 ArchivaConfiguration archivaConfiguration =
496 (ArchivaConfiguration) lookup( ArchivaConfiguration.class.getName(), "test-not-allowed-to-write-to-both" );
497 Configuration config = archivaConfiguration.getConfiguration();
501 archivaConfiguration.save( config );
502 fail( "Should have thrown a RegistryException because the configuration can't be saved." );
504 catch ( RegistryException e )
506 /* expected exception */
510 public void testLoadConfigurationFromInvalidUserLocationOnDisk()
513 File testConfDir = getTestFile( "target/test-appserver-base/conf/" );
514 testConfDir.mkdirs();
516 ArchivaConfiguration archivaConfiguration =
517 (ArchivaConfiguration) lookup( ArchivaConfiguration.class.getName(), "test-not-allowed-to-write-to-user" );
518 Configuration config = archivaConfiguration.getConfiguration();
519 archivaConfiguration.save( config );
520 // No Exception == test passes.
521 // Expected Path is: Should not have thrown an exception.
524 public void testConfigurationUpgradeFrom09()
527 ArchivaConfiguration archivaConfiguration =
528 (ArchivaConfiguration) lookup( ArchivaConfiguration.class.getName(), "test-upgrade-09" );
530 // we just use the defaults when upgrading from 0.9 at this point.
531 Configuration configuration = archivaConfiguration.getConfiguration();
532 assertConfiguration( configuration );
533 assertEquals( "check network proxies", 0, configuration.getNetworkProxies().size() );
535 ManagedRepositoryConfiguration repository =
536 (ManagedRepositoryConfiguration) configuration.getManagedRepositories().get( 0 );
538 assertEquals( "check managed repositories", "${appserver.base}/data/repositories/internal",
539 repository.getLocation() );
540 assertEquals( "check managed repositories", "Archiva Managed Internal Repository", repository.getName() );
541 assertEquals( "check managed repositories", "internal", repository.getId() );
542 assertEquals( "check managed repositories", "default", repository.getLayout() );
543 assertTrue( "check managed repositories", repository.isScanned() );
546 public void testAutoDetectV1()
549 // Setup the autodetect-v1.xml file in the target directory (so we can save/load it)
550 File userFile = getTestFile( "target/test-autodetect-v1/archiva-user.xml" );
552 assertFalse( userFile.exists() );
554 userFile.getParentFile().mkdirs();
555 FileUtils.copyFile( getTestFile( "src/test/conf/autodetect-v1.xml" ), userFile );
557 // Load the original (unconverted) archiva.xml
558 ArchivaConfiguration archivaConfiguration =
559 (ArchivaConfiguration) lookup( ArchivaConfiguration.class.getName(), "test-autodetect-v1" );
561 Configuration configuration = archivaConfiguration.getConfiguration();
562 assertConfiguration( configuration );
563 assertEquals( "check network proxies", 1, configuration.getNetworkProxies().size() );
565 ManagedRepositoryConfiguration repository =
566 (ManagedRepositoryConfiguration) configuration.getManagedRepositories().get( 0 );
568 assertEquals( "check managed repositories", "${appserver.base}/repositories/internal",
569 repository.getLocation() );
570 assertEquals( "check managed repositories", "Archiva Managed Internal Repository", repository.getName() );
571 assertEquals( "check managed repositories", "internal", repository.getId() );
572 assertEquals( "check managed repositories", "default", repository.getLayout() );
573 assertTrue( "check managed repositories", repository.isScanned() );
575 // Test that only 1 set of repositories exist.
576 assertEquals( "check managed repositories size.", 2, configuration.getManagedRepositories().size() );
577 assertEquals( "check remote repositories size.", 2, configuration.getRemoteRepositories().size() );
578 assertEquals( "check v1 repositories size.", 0, configuration.getRepositories().size() );
581 archivaConfiguration.save( configuration );
584 // FIXME spring equivalent ? release( archivaConfiguration );
587 archivaConfiguration =
588 (ArchivaConfiguration) lookup( ArchivaConfiguration.class.getName(), "test-autodetect-v1" );
589 configuration = archivaConfiguration.getConfiguration();
591 // Test that only 1 set of repositories exist.
592 assertEquals( "check managed repositories size.", 2, configuration.getManagedRepositories().size() );
593 assertEquals( "check managed repositories size.", 2, configuration.getManagedRepositoriesAsMap().size() );
594 assertEquals( "check remote repositories size.", 2, configuration.getRemoteRepositories().size() );
595 assertEquals( "check remote repositories size.", 2, configuration.getRemoteRepositoriesAsMap().size() );
596 assertEquals( "check v1 repositories size.", 0, configuration.getRepositories().size() );
598 String actualXML = FileUtils.readFileToString( userFile, null );
599 XMLAssert.assertXpathNotExists( "//configuration/repositories/repository", actualXML );
600 XMLAssert.assertXpathNotExists( "//configuration/repositories", actualXML );
603 public void testArchivaV1()
606 ArchivaConfiguration archivaConfiguration =
607 (ArchivaConfiguration) lookup( ArchivaConfiguration.class.getName(), "test-archiva-v1" );
609 Configuration configuration = archivaConfiguration.getConfiguration();
610 assertConfiguration( configuration );
611 assertEquals( "check network proxies", 1, configuration.getNetworkProxies().size() );
613 assertEquals( "check managed repositories", 2, configuration.getManagedRepositories().size() );
614 assertEquals( "check v1 repositories size.", 0, configuration.getRepositories().size() );
616 Map<String, ManagedRepositoryConfiguration> map = configuration.getManagedRepositoriesAsMap();
618 ManagedRepositoryConfiguration repository = map.get( "internal" );
619 assertEquals( "check managed repositories", "${appserver.base}/repositories/internal",
620 repository.getLocation() );
621 assertEquals( "check managed repositories", "Archiva Managed Internal Repository", repository.getName() );
622 assertEquals( "check managed repositories", "internal", repository.getId() );
623 assertEquals( "check managed repositories", "default", repository.getLayout() );
624 assertTrue( "check managed repositories", repository.isScanned() );
625 assertFalse( "check managed repositories", repository.isSnapshots() );
627 repository = map.get( "snapshots" );
628 assertEquals( "check managed repositories", "${appserver.base}/repositories/snapshots",
629 repository.getLocation() );
630 assertEquals( "check managed repositories", "Archiva Managed Snapshot Repository", repository.getName() );
631 assertEquals( "check managed repositories", "snapshots", repository.getId() );
632 assertEquals( "check managed repositories", "default", repository.getLayout() );
633 assertFalse( "check managed repositories", repository.isScanned() );
634 assertTrue( "check managed repositories", repository.isSnapshots() );
637 public void testCronExpressionsWithComma()
640 File baseFile = getTestFile( "target/test/test-file.xml" );
642 assertFalse( baseFile.exists() );
644 File userFile = getTestFile( "target/test/test-file-user.xml" );
646 assertFalse( userFile.exists() );
648 baseFile.getParentFile().mkdirs();
649 FileUtils.copyFile( getTestFile( "src/test/conf/escape-cron-expressions.xml" ), baseFile );
651 userFile.getParentFile().mkdirs();
652 FileUtils.writeStringToFile( userFile, "<configuration/>", null );
654 final ArchivaConfiguration archivaConfiguration =
655 (ArchivaConfiguration) lookup( ArchivaConfiguration.class.getName(), "test-cron-expressions" );
657 Configuration configuration = archivaConfiguration.getConfiguration();
659 ManagedRepositoryConfiguration repository =
660 (ManagedRepositoryConfiguration) configuration.getManagedRepositories().get( 0 );
662 assertEquals( "check cron expression", "0 0,30 * * * ?", repository.getRefreshCronExpression().trim() );
664 configuration.getDatabaseScanning().setCronExpression( "0 0,15 0 * * ?" );
666 // add a test listener to confirm it doesn't see the escaped format. We don't need to test the number of calls,
667 // etc. as it's done in other tests
668 archivaConfiguration.addListener( new ConfigurationListener()
670 public void configurationEvent( ConfigurationEvent event )
672 assertEquals( ConfigurationEvent.SAVED, event.getType() );
674 Configuration configuration = archivaConfiguration.getConfiguration();
676 ManagedRepositoryConfiguration repository =
677 (ManagedRepositoryConfiguration) configuration.getManagedRepositories().get( 0 );
679 assertEquals( "check cron expression", "0 0,15 0 * * ?",
680 configuration.getDatabaseScanning().getCronExpression() );
684 archivaConfiguration.save( configuration );
686 configuration = archivaConfiguration.getConfiguration();
688 assertEquals( "check cron expression", "0 0,15 0 * * ?",
689 configuration.getDatabaseScanning().getCronExpression() );
691 // test for the escape character '\' showing up on repositories.jsp
692 repository.setRefreshCronExpression( "0 0,20 0 * * ?" );
694 archivaConfiguration.save( configuration );
696 repository = archivaConfiguration.getConfiguration().findManagedRepositoryById( "snapshots" );
698 assertEquals( "check cron expression", "0 0,20 0 * * ?", repository.getRefreshCronExpression() );
701 public void testRemoveLastElements()
704 File baseFile = getTestFile( "target/test/test-file.xml" );
706 assertFalse( baseFile.exists() );
708 File userFile = getTestFile( "target/test/test-file-user.xml" );
710 assertFalse( userFile.exists() );
712 baseFile.getParentFile().mkdirs();
713 FileUtils.copyFile( getTestFile( "src/test/conf/conf-single-list-elements.xml" ), baseFile );
715 userFile.getParentFile().mkdirs();
716 FileUtils.writeStringToFile( userFile, "<configuration/>", null );
718 ArchivaConfiguration archivaConfiguration =
719 (ArchivaConfiguration) lookup( ArchivaConfiguration.class.getName(), "test-remove-central" );
721 Configuration configuration = archivaConfiguration.getConfiguration();
723 RepositoryGroupConfiguration repositoryGroup = ( RepositoryGroupConfiguration ) configuration.getRepositoryGroups().get( 0 );
724 assertNotNull( repositoryGroup );
725 configuration.removeRepositoryGroup( repositoryGroup );
726 assertTrue( configuration.getRepositoryGroups().isEmpty() );
728 RemoteRepositoryConfiguration repository = configuration.getRemoteRepositoriesAsMap().get( "central" );
729 assertNotNull( repository );
730 configuration.removeRemoteRepository( repository );
731 assertTrue( configuration.getRemoteRepositories().isEmpty() );
733 ManagedRepositoryConfiguration managedRepository =
734 configuration.getManagedRepositoriesAsMap().get( "snapshots" );
735 assertNotNull( managedRepository );
736 configuration.removeManagedRepository( managedRepository );
737 assertTrue( configuration.getManagedRepositories().isEmpty() );
739 ProxyConnectorConfiguration proxyConnector =
740 (ProxyConnectorConfiguration) configuration.getProxyConnectors().get( 0 );
741 assertNotNull( proxyConnector );
742 configuration.removeProxyConnector( proxyConnector );
743 assertTrue( configuration.getProxyConnectors().isEmpty() );
745 NetworkProxyConfiguration networkProxy = configuration.getNetworkProxiesAsMap().get( "proxy" );
746 assertNotNull( networkProxy );
747 configuration.removeNetworkProxy( networkProxy );
748 assertTrue( configuration.getNetworkProxies().isEmpty() );
750 LegacyArtifactPath path = (LegacyArtifactPath) configuration.getLegacyArtifactPaths().get( 0 );
751 assertNotNull( path );
752 configuration.removeLegacyArtifactPath( path );
753 assertTrue( configuration.getLegacyArtifactPaths().isEmpty() );
755 RepositoryScanningConfiguration scanning = configuration.getRepositoryScanning();
756 String consumer = (String) scanning.getKnownContentConsumers().get( 0 );
757 assertNotNull( consumer );
758 scanning.removeKnownContentConsumer( consumer );
759 assertTrue( scanning.getKnownContentConsumers().isEmpty() );
760 consumer = (String) scanning.getInvalidContentConsumers().get( 0 );
761 assertNotNull( consumer );
762 scanning.removeInvalidContentConsumer( consumer );
763 assertTrue( scanning.getInvalidContentConsumers().isEmpty() );
765 DatabaseScanningConfiguration databaseScanning = configuration.getDatabaseScanning();
766 consumer = (String) databaseScanning.getCleanupConsumers().get( 0 );
767 assertNotNull( consumer );
768 databaseScanning.removeCleanupConsumer( consumer );
769 assertTrue( databaseScanning.getCleanupConsumers().isEmpty() );
770 consumer = (String) databaseScanning.getUnprocessedConsumers().get( 0 );
771 assertNotNull( consumer );
772 databaseScanning.removeUnprocessedConsumer( consumer );
773 assertTrue( databaseScanning.getUnprocessedConsumers().isEmpty() );
775 archivaConfiguration.save( configuration );
777 archivaConfiguration =
778 (ArchivaConfiguration) lookup( ArchivaConfiguration.class.getName(), "test-read-saved" );
779 configuration = archivaConfiguration.getConfiguration();
780 assertNull( configuration.getRemoteRepositoriesAsMap().get( "central" ) );
781 assertTrue( configuration.getRepositoryGroups().isEmpty() );
782 assertNull( configuration.getManagedRepositoriesAsMap().get( "snapshots" ) );
783 assertTrue( configuration.getProxyConnectors().isEmpty() );
784 assertNull( configuration.getNetworkProxiesAsMap().get( "proxy" ) );
785 assertTrue( configuration.getLegacyArtifactPaths().isEmpty() );
786 scanning = configuration.getRepositoryScanning();
787 assertTrue( scanning.getKnownContentConsumers().isEmpty() );
788 assertTrue( scanning.getInvalidContentConsumers().isEmpty() );
789 databaseScanning = configuration.getDatabaseScanning();
790 assertTrue( databaseScanning.getCleanupConsumers().isEmpty() );
791 assertTrue( databaseScanning.getUnprocessedConsumers().isEmpty() );
795 * [MRM-582] Remote Repositories with empty <username> and <password> fields shouldn't be created in configuration.
797 public void testGetConfigurationFixEmptyRemoteRepoUsernamePassword()
800 ArchivaConfiguration archivaConfiguration = (ArchivaConfiguration) lookup(
801 ArchivaConfiguration.class.getName(),
802 "test-configuration" );
804 Configuration configuration = archivaConfiguration.getConfiguration();
805 assertConfiguration( configuration );
806 assertEquals( "check remote repositories", 2, configuration.getRemoteRepositories().size() );
808 RemoteRepositoryConfiguration repository = (RemoteRepositoryConfiguration) configuration
809 .getRemoteRepositoriesAsMap().get( "maven2-repository.dev.java.net" );
811 assertEquals( "remote repository.url", "https://maven2-repository.dev.java.net/nonav/repository", repository.getUrl() );
812 assertEquals( "remote repository.name", "Java.net Repository for Maven 2", repository.getName() );
813 assertEquals( "remote repository.id", "maven2-repository.dev.java.net", repository.getId() );
814 assertEquals( "remote repository.layout", "default", repository.getLayout() );
815 assertNull( "remote repository.username == null", repository.getUsername() );
816 assertNull( "remote repository.password == null", repository.getPassword() );