1 package org.apache.archiva.configuration;
4 * Licensed to the Apache Software Foundation (ASF) under one
5 * or more contributor license agreements. See the NOTICE file
6 * distributed with this work for additional information
7 * regarding copyright ownership. The ASF licenses this file
8 * to you under the Apache License, Version 2.0 (the
9 * "License"); you may not use this file except in compliance
10 * with the License. You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 * KIND, either express or implied. See the License for the
18 * specific language governing permissions and limitations
22 import junit.framework.TestCase;
23 import org.apache.archiva.common.utils.FileUtil;
24 import org.apache.archiva.redback.components.registry.RegistryException;
25 import org.apache.commons.io.FileUtils;
26 import org.apache.commons.lang.StringUtils;
27 import org.custommonkey.xmlunit.XMLAssert;
28 import org.easymock.MockControl;
29 import org.junit.Test;
30 import org.junit.runner.RunWith;
31 import org.slf4j.Logger;
32 import org.slf4j.LoggerFactory;
33 import org.springframework.context.ApplicationContext;
34 import org.springframework.test.context.ContextConfiguration;
37 import javax.inject.Inject;
39 import java.util.List;
41 import org.apache.archiva.test.utils.ArchivaSpringJUnit4ClassRunner;
44 * Test the configuration store.
46 @RunWith( ArchivaSpringJUnit4ClassRunner.class )
47 @ContextConfiguration( locations = { "classpath*:/META-INF/spring-context.xml", "classpath:/spring-context.xml" } )
48 public class ArchivaConfigurationTest
52 private Logger log = LoggerFactory.getLogger( getClass() );
55 protected ApplicationContext applicationContext;
60 public static File getTestFile( String path )
62 return new File( FileUtil.getBasedir(), path );
65 protected <T> T lookup( Class<T> clazz, String hint )
67 return (T) applicationContext.getBean( "archivaConfiguration#" + hint, ArchivaConfiguration.class );
71 public void testGetConfigurationFromDefaults()
74 ArchivaConfiguration archivaConfiguration = lookup( ArchivaConfiguration.class, "test-defaults" );
75 Configuration configuration = archivaConfiguration.getConfiguration();
77 assertConfiguration( configuration, 2, 1, 1 );
78 assertEquals( "check network proxies", 0, configuration.getNetworkProxies().size() );
80 ManagedRepositoryConfiguration repository = configuration.getManagedRepositories().get( 0 );
82 assertEquals( "check managed repositories", "${appserver.base}/data/repositories/internal",
83 repository.getLocation() );
84 assertEquals( "check managed repositories", "Archiva Managed Internal Repository", repository.getName() );
85 assertEquals( "check managed repositories", "internal", repository.getId() );
86 assertEquals( "check managed repositories", "default", repository.getLayout() );
87 assertTrue( "check managed repositories", repository.isScanned() );
91 public void testGetConfigurationFromRegistryWithASingleNamedConfigurationResource()
94 ArchivaConfiguration archivaConfiguration = lookup( ArchivaConfiguration.class, "test-configuration" );
95 Configuration configuration = archivaConfiguration.getConfiguration();
96 assertConfiguration( configuration, 2, 2, 2 );
97 assertEquals( "check network proxies", 1, configuration.getNetworkProxies().size() );
99 ManagedRepositoryConfiguration repository = configuration.getManagedRepositories().get( 0 );
101 assertEquals( "check managed repositories", "${appserver.base}/repositories/internal",
102 repository.getLocation() );
103 assertEquals( "check managed repositories", "Archiva Managed Internal Repository", repository.getName() );
104 assertEquals( "check managed repositories", "internal", repository.getId() );
105 assertEquals( "check managed repositories", "default", repository.getLayout() );
106 assertTrue( "check managed repositories", repository.isScanned() );
110 * Ensures that the provided configuration matches the details present in the archiva-default.xml file.
112 private void assertConfiguration( Configuration configuration, int managedExpected, int remoteExpected,
113 int proxyConnectorExpected )
117 assertEquals( "check managed repositories: " + configuration.getManagedRepositories(), managedExpected,
118 configuration.getManagedRepositories().size() );
119 assertEquals( "check remote repositories: " + configuration.getRemoteRepositories(), remoteExpected,
120 configuration.getRemoteRepositories().size() );
121 assertEquals( "check proxy connectors:" + configuration.getProxyConnectors(), proxyConnectorExpected,
122 configuration.getProxyConnectors().size() );
124 RepositoryScanningConfiguration repoScanning = configuration.getRepositoryScanning();
125 assertNotNull( "check repository scanning", repoScanning );
126 assertEquals( "check file types", 4, repoScanning.getFileTypes().size() );
127 assertEquals( "check known consumers", 9, repoScanning.getKnownContentConsumers().size() );
128 assertEquals( "check invalid consumers", 1, repoScanning.getInvalidContentConsumers().size() );
130 List<String> patterns = filetypes.getFileTypePatterns( "artifacts" );
131 assertNotNull( "check 'artifacts' file type", patterns );
132 assertEquals( "check 'artifacts' patterns", 13, patterns.size() );
134 WebappConfiguration webapp = configuration.getWebapp();
135 assertNotNull( "check webapp", webapp );
137 UserInterfaceOptions ui = webapp.getUi();
138 assertNotNull( "check webapp ui", ui );
139 assertTrue( "check showFindArtifacts", ui.isShowFindArtifacts() );
140 assertTrue( "check appletFindEnabled", ui.isAppletFindEnabled() );
144 public void testGetConfigurationFromRegistryWithTwoConfigurationResources()
147 ArchivaConfiguration archivaConfiguration = lookup( ArchivaConfiguration.class, "test-configuration-both" );
149 Configuration configuration = archivaConfiguration.getConfiguration();
152 assertEquals( "check repositories", 2, configuration.getManagedRepositories().size() );
153 assertEquals( "check repositories", 2, configuration.getRemoteRepositories().size() );
155 assertEquals( "check proxy connectors", 2, configuration.getProxyConnectors().size() );
157 WebappConfiguration webapp = configuration.getWebapp();
158 assertNotNull( "check webapp", webapp );
160 UserInterfaceOptions ui = webapp.getUi();
161 assertNotNull( "check webapp ui", ui );
163 assertFalse( "check showFindArtifacts", ui.isShowFindArtifacts() );
165 assertFalse( "check appletFindEnabled", ui.isAppletFindEnabled() );
169 public void testGetConfigurationSystemOverride()
173 System.setProperty( "org.apache.archiva.webapp.ui.appletFindEnabled", "false" );
175 ArchivaConfiguration archivaConfiguration = lookup( ArchivaConfiguration.class, "test-configuration" );
177 archivaConfiguration.reload();
181 Configuration configuration = archivaConfiguration.getConfiguration();
183 assertFalse( "check boolean", configuration.getWebapp().getUi().isAppletFindEnabled() );
187 System.getProperties().remove( "org.apache.archiva.webapp.ui.appletFindEnabled" );
188 archivaConfiguration.reload();
189 Configuration configuration = archivaConfiguration.getConfiguration();
190 assertTrue( "check boolean", configuration.getWebapp().getUi().isAppletFindEnabled() );
195 public void testStoreConfiguration()
198 File file = getTestFile( "target/test/test-file.xml" );
200 assertFalse( file.exists() );
202 // TODO: remove with commons-configuration 1.4
203 //file.getParentFile().mkdirs();
204 //FileUtils.writeStringToFile( file, "<configuration/>", null );
206 DefaultArchivaConfiguration archivaConfiguration =
207 (DefaultArchivaConfiguration) lookup( ArchivaConfiguration.class, "test-save" );
209 archivaConfiguration.reload();
211 Configuration configuration = new Configuration();
212 configuration.setVersion( "1" );
213 configuration.setWebapp( new WebappConfiguration() );
214 configuration.getWebapp().setUi( new UserInterfaceOptions() );
215 configuration.getWebapp().getUi().setAppletFindEnabled( false );
217 // add a change listener
218 MockControl control = createConfigurationListenerMockControl();
219 ConfigurationListener listener = (ConfigurationListener) control.getMock();
220 archivaConfiguration.addListener( listener );
222 listener.configurationEvent( new ConfigurationEvent( ConfigurationEvent.SAVED ) );
223 control.setVoidCallable();
227 archivaConfiguration.save( configuration );
231 assertTrue( "Check file exists", file.exists() );
234 configuration = archivaConfiguration.getConfiguration();
235 assertFalse( "check value", configuration.getWebapp().getUi().isAppletFindEnabled() );
238 archivaConfiguration = (DefaultArchivaConfiguration) lookup( ArchivaConfiguration.class, "test-read-saved" );
240 archivaConfiguration.reload();
241 configuration = archivaConfiguration.getConfiguration();
242 assertFalse( "check value", configuration.getWebapp().getUi().isAppletFindEnabled() );
245 private static MockControl createConfigurationListenerMockControl()
247 return MockControl.createControl( ConfigurationListener.class );
251 public void testStoreConfigurationUser()
254 File baseFile = getTestFile( "target/test/test-file.xml" );
256 assertFalse( baseFile.exists() );
258 File userFile = getTestFile( "target/test/test-file-user.xml" );
260 assertFalse( userFile.exists() );
262 userFile.getParentFile().mkdirs();
263 FileUtils.writeStringToFile( userFile, "<configuration/>", null );
265 ArchivaConfiguration archivaConfiguration = lookup( ArchivaConfiguration.class, "test-save-user" );
267 Configuration configuration = new Configuration();
268 configuration.setWebapp( new WebappConfiguration() );
269 configuration.getWebapp().setUi( new UserInterfaceOptions() );
270 configuration.getWebapp().getUi().setAppletFindEnabled( false );
272 archivaConfiguration.save( configuration );
274 assertTrue( "Check file exists", userFile.exists() );
275 assertFalse( "Check file not created", baseFile.exists() );
278 configuration = archivaConfiguration.getConfiguration();
279 assertFalse( "check value", configuration.getWebapp().getUi().isAppletFindEnabled() );
283 public void testStoreConfigurationLoadedFromDefaults()
286 File baseFile = getTestFile( "target/test/test-file.xml" );
288 assertFalse( baseFile.exists() );
290 File userFile = getTestFile( "target/test/test-file-user.xml" );
292 assertFalse( userFile.exists() );
294 ArchivaConfiguration archivaConfiguration = lookup( ArchivaConfiguration.class, "test-save-user-defaults" );
296 archivaConfiguration.reload();
298 Configuration configuration = new Configuration();
299 configuration.setWebapp( new WebappConfiguration() );
300 configuration.getWebapp().setUi( new UserInterfaceOptions() );
301 configuration.getWebapp().getUi().setAppletFindEnabled( false );
303 // add a change listener
304 MockControl control = createConfigurationListenerMockControl();
305 ConfigurationListener listener = (ConfigurationListener) control.getMock();
306 archivaConfiguration.addListener( listener );
308 listener.configurationEvent( new ConfigurationEvent( ConfigurationEvent.SAVED ) );
310 control.setVoidCallable( 1 );
314 archivaConfiguration.save( configuration );
318 assertTrue( "Check file exists", userFile.exists() );
319 assertFalse( "Check file not created", baseFile.exists() );
322 configuration = archivaConfiguration.getConfiguration();
323 assertFalse( "check value", configuration.getWebapp().getUi().isAppletFindEnabled() );
327 public void testDefaultUserConfigFilename()
330 DefaultArchivaConfiguration archivaConfiguration =
331 (DefaultArchivaConfiguration) lookup( ArchivaConfiguration.class, "default" );
333 archivaConfiguration.reload();
335 assertEquals( System.getProperty( "user.home" ) + "/.m2/archiva.xml",
336 archivaConfiguration.getUserConfigFilename() );
337 assertEquals( System.getProperty( "appserver.base", "${appserver.base}" ) + "/conf/archiva.xml",
338 archivaConfiguration.getAltConfigFilename() );
342 public void testStoreConfigurationFallback()
345 File baseFile = getTestFile( "target/test/test-file.xml" );
347 assertFalse( baseFile.exists() );
349 File userFile = getTestFile( "target/test/test-file-user.xml" );
351 assertFalse( userFile.exists() );
353 baseFile.getParentFile().mkdirs();
354 FileUtils.writeStringToFile( baseFile, "<configuration/>", null );
356 ArchivaConfiguration archivaConfiguration =
357 (ArchivaConfiguration) lookup( ArchivaConfiguration.class, "test-save-user-fallback" );
359 archivaConfiguration.reload();
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() );
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, "test-save-user" );
397 archivaConfiguration.reload();
399 Configuration configuration = archivaConfiguration.getConfiguration();
400 assertTrue( "check value", configuration.getWebapp().getUi().isAppletFindEnabled() );
402 configuration.getWebapp().getUi().setAppletFindEnabled( false );
404 archivaConfiguration.save( configuration );
406 assertTrue( "Check file exists", baseFile.exists() );
407 assertEquals( "Check base file is unchanged", "<configuration/>",
408 FileUtils.readFileToString( baseFile, null ) );
409 assertTrue( "Check file exists", userFile.exists() );
410 assertFalse( "Check base file is changed",
411 "<configuration/>".equals( FileUtils.readFileToString( userFile, null ) ) );
414 configuration = archivaConfiguration.getConfiguration();
415 assertFalse( "check value", configuration.getWebapp().getUi().isAppletFindEnabled() );
419 public void testStoreConfigurationFailsWhenReadFromBothLocationsUserHasLists()
422 File baseFile = getTestFile( "target/test/test-file.xml" );
424 assertFalse( baseFile.exists() );
426 File userFile = getTestFile( "target/test/test-file-user.xml" );
428 assertFalse( userFile.exists() );
430 userFile.getParentFile().mkdirs();
431 FileUtils.copyFile( getTestFile( "src/test/conf/conf-user.xml" ), userFile );
433 baseFile.getParentFile().mkdirs();
434 FileUtils.writeStringToFile( baseFile, "<configuration/>", null );
436 ArchivaConfiguration archivaConfiguration =
437 (ArchivaConfiguration) lookup( ArchivaConfiguration.class, "test-save-user" );
439 archivaConfiguration.reload();
441 Configuration configuration = archivaConfiguration.getConfiguration();
442 assertTrue( "check value", configuration.getWebapp().getUi().isShowFindArtifacts() );
444 configuration.getWebapp().getUi().setShowFindArtifacts( false );
446 archivaConfiguration.save( configuration );
448 assertTrue( "Check file exists", baseFile.exists() );
449 assertEquals( "Check base file is unchanged", "<configuration/>",
450 FileUtils.readFileToString( baseFile, null ) );
451 assertTrue( "Check file exists", userFile.exists() );
452 assertFalse( "Check base file is changed",
453 "<configuration/>".equals( FileUtils.readFileToString( userFile, null ) ) );
456 configuration = archivaConfiguration.getConfiguration();
457 assertFalse( "check value", configuration.getWebapp().getUi().isShowFindArtifacts() );
461 public void testStoreConfigurationFailsWhenReadFromBothLocationsAppserverHasLists()
464 File baseFile = getTestFile( "target/test/test-file.xml" );
466 assertFalse( baseFile.exists() );
468 File userFile = getTestFile( "target/test/test-file-user.xml" );
470 assertFalse( userFile.exists() );
472 baseFile.getParentFile().mkdirs();
473 FileUtils.copyFile( getTestFile( "src/test/conf/conf-base.xml" ), baseFile );
475 userFile.getParentFile().mkdirs();
476 FileUtils.writeStringToFile( userFile, "<configuration/>", null );
478 ArchivaConfiguration archivaConfiguration =
479 (ArchivaConfiguration) lookup( ArchivaConfiguration.class, "test-save-user" );
481 archivaConfiguration.reload();
483 Configuration configuration = archivaConfiguration.getConfiguration();
484 assertTrue( "check value", configuration.getWebapp().getUi().isAppletFindEnabled() );
486 configuration.getWebapp().getUi().setAppletFindEnabled( false );
490 archivaConfiguration.save( configuration );
491 fail( "Configuration saving should not succeed if it was loaded from two locations" );
493 catch ( IndeterminateConfigurationException e )
495 // check it was reverted
496 configuration = archivaConfiguration.getConfiguration();
497 assertTrue( "check value", configuration.getWebapp().getUi().isAppletFindEnabled() );
502 public void testLoadConfigurationFromInvalidBothLocationsOnDisk()
505 ArchivaConfiguration archivaConfiguration =
506 lookup( ArchivaConfiguration.class, "test-not-allowed-to-write-to-both" );
507 Configuration config = archivaConfiguration.getConfiguration();
511 archivaConfiguration.save( config );
512 fail( "Should have thrown a RegistryException because the configuration can't be saved." );
514 catch ( RegistryException e )
516 /* expected exception */
521 public void testLoadConfigurationFromInvalidUserLocationOnDisk()
524 File testConfDir = getTestFile( "target/test-appserver-base/conf/" );
525 testConfDir.mkdirs();
527 ArchivaConfiguration archivaConfiguration =
528 lookup( ArchivaConfiguration.class, "test-not-allowed-to-write-to-user" );
529 Configuration config = archivaConfiguration.getConfiguration();
530 archivaConfiguration.save( config );
531 // No Exception == test passes.
532 // Expected Path is: Should not have thrown an exception.
536 public void testConfigurationUpgradeFrom09()
539 ArchivaConfiguration archivaConfiguration = lookup( ArchivaConfiguration.class, "test-upgrade-09" );
541 // we just use the defaults when upgrading from 0.9 at this point.
542 Configuration configuration = archivaConfiguration.getConfiguration();
543 // test-upgrade-09 contains a managed with id: local so it's 3 managed
544 assertConfiguration( configuration, 3, 1, 1 );
545 assertEquals( "check network proxies", 0, configuration.getNetworkProxies().size() );
547 ManagedRepositoryConfiguration repository = configuration.getManagedRepositories().get( 0 );
549 assertEquals( "check managed repositories", "${appserver.base}/data/repositories/internal",
550 repository.getLocation() );
551 assertEquals( "check managed repositories", "Archiva Managed Internal Repository", repository.getName() );
552 assertEquals( "check managed repositories", "internal", repository.getId() );
553 assertEquals( "check managed repositories", "default", repository.getLayout() );
554 assertTrue( "check managed repositories", repository.isScanned() );
558 public void testConfigurationUpgradeFrom13()
561 ArchivaConfiguration archivaConfiguration = lookup( ArchivaConfiguration.class, "test-upgrade-1.3" );
563 // we just use the defaults when upgrading from 1.3 at this point.
564 Configuration configuration = archivaConfiguration.getConfiguration();
565 assertConfiguration( configuration, 2, 2, 2 );
566 assertEquals( "check network proxies", 0, configuration.getNetworkProxies().size() );
568 ManagedRepositoryConfiguration repository = configuration.getManagedRepositories().get( 0 );
570 assertEquals( "check managed repositories", "${appserver.base}/data/repositories/internal",
571 repository.getLocation() );
572 assertEquals( "check managed repositories", "Archiva Managed Internal Repository", repository.getName() );
573 assertEquals( "check managed repositories", "internal", repository.getId() );
574 assertEquals( "check managed repositories", "default", repository.getLayout() );
575 assertTrue( "check managed repositories", repository.isScanned() );
577 log.info( "knowContentConsumers " + configuration.getRepositoryScanning().getKnownContentConsumers() );
580 configuration.getRepositoryScanning().getKnownContentConsumers().contains( "update-db-artifact" ) );
581 assertFalse( configuration.getRepositoryScanning().getKnownContentConsumers().contains(
582 "update-db-repository-metadata" ) );
585 configuration.getRepositoryScanning().getKnownContentConsumers().contains( "create-archiva-metadata" ) );
588 configuration.getRepositoryScanning().getKnownContentConsumers().contains( "duplicate-artifacts" ) );
592 public void testAutoDetectV1()
595 // Setup the autodetect-v1.xml file in the target directory (so we can save/load it)
596 File userFile = getTestFile( "target/test-autodetect-v1/archiva-user.xml" );
598 assertFalse( userFile.exists() );
600 userFile.getParentFile().mkdirs();
601 FileUtils.copyFile( getTestFile( "src/test/conf/autodetect-v1.xml" ), userFile );
603 // Load the original (unconverted) archiva.xml
604 ArchivaConfiguration archivaConfiguration = lookup( ArchivaConfiguration.class, "test-autodetect-v1" );
606 archivaConfiguration.reload();
608 Configuration configuration = archivaConfiguration.getConfiguration();
609 assertConfiguration( configuration, 2, 2, 2 );
610 assertEquals( "check network proxies", 1, configuration.getNetworkProxies().size() );
612 ManagedRepositoryConfiguration repository = configuration.getManagedRepositories().get( 0 );
614 assertEquals( "check managed repositories", "${appserver.base}/repositories/internal",
615 repository.getLocation() );
616 assertEquals( "check managed repositories", "Archiva Managed Internal Repository", repository.getName() );
617 assertEquals( "check managed repositories", "internal", repository.getId() );
618 assertEquals( "check managed repositories", "default", repository.getLayout() );
619 assertTrue( "check managed repositories", repository.isScanned() );
621 // Test that only 1 set of repositories exist.
622 assertEquals( "check managed repositories size.", 2, configuration.getManagedRepositories().size() );
623 assertEquals( "check remote repositories size.", 2, configuration.getRemoteRepositories().size() );
624 assertEquals( "check v1 repositories size.", 0, configuration.getRepositories().size() );
627 archivaConfiguration.save( configuration );
630 //release( archivaConfiguration );
633 archivaConfiguration = lookup( ArchivaConfiguration.class, "test-autodetect-v1" );
634 configuration = archivaConfiguration.getConfiguration();
636 // Test that only 1 set of repositories exist.
637 assertEquals( "check managed repositories size.", 2, configuration.getManagedRepositories().size() );
638 assertEquals( "check managed repositories size.", 2, configuration.getManagedRepositoriesAsMap().size() );
639 assertEquals( "check remote repositories size.", 2, configuration.getRemoteRepositories().size() );
640 assertEquals( "check remote repositories size.", 2, configuration.getRemoteRepositoriesAsMap().size() );
641 assertEquals( "check v1 repositories size.", 0, configuration.getRepositories().size() );
643 String actualXML = FileUtils.readFileToString( userFile, null );
644 XMLAssert.assertXpathNotExists( "//configuration/repositories/repository", actualXML );
645 XMLAssert.assertXpathNotExists( "//configuration/repositories", actualXML );
649 public void testArchivaV1()
652 ArchivaConfiguration archivaConfiguration = lookup( ArchivaConfiguration.class, "test-archiva-v1" );
654 Configuration configuration = archivaConfiguration.getConfiguration();
655 assertConfiguration( configuration, 2, 2, 2 );
656 assertEquals( "check network proxies", 1, configuration.getNetworkProxies().size() );
658 assertEquals( "check managed repositories", 2, configuration.getManagedRepositories().size() );
659 assertEquals( "check v1 repositories size.", 0, configuration.getRepositories().size() );
661 Map<String, ManagedRepositoryConfiguration> map = configuration.getManagedRepositoriesAsMap();
663 ManagedRepositoryConfiguration repository = map.get( "internal" );
664 assertEquals( "check managed repositories", "${appserver.base}/repositories/internal",
665 repository.getLocation() );
666 assertEquals( "check managed repositories", "Archiva Managed Internal Repository", repository.getName() );
667 assertEquals( "check managed repositories", "internal", repository.getId() );
668 assertEquals( "check managed repositories", "default", repository.getLayout() );
669 assertTrue( "check managed repositories", repository.isScanned() );
670 assertFalse( "check managed repositories", repository.isSnapshots() );
672 repository = map.get( "snapshots" );
673 assertEquals( "check managed repositories", "${appserver.base}/repositories/snapshots",
674 repository.getLocation() );
675 assertEquals( "check managed repositories", "Archiva Managed Snapshot Repository", repository.getName() );
676 assertEquals( "check managed repositories", "snapshots", repository.getId() );
677 assertEquals( "check managed repositories", "default", repository.getLayout() );
678 assertFalse( "check managed repositories", repository.isScanned() );
679 assertTrue( "check managed repositories", repository.isSnapshots() );
683 public void testCronExpressionsWithComma()
686 File baseFile = getTestFile( "target/test/test-file.xml" );
688 assertFalse( baseFile.exists() );
690 File userFile = getTestFile( "target/test/test-file-user.xml" );
692 assertFalse( userFile.exists() );
694 baseFile.getParentFile().mkdirs();
695 FileUtils.copyFile( getTestFile( "src/test/conf/escape-cron-expressions.xml" ), baseFile );
697 userFile.getParentFile().mkdirs();
698 FileUtils.writeStringToFile( userFile, "<configuration/>", null );
700 final ArchivaConfiguration archivaConfiguration = lookup( ArchivaConfiguration.class, "test-cron-expressions" );
702 archivaConfiguration.reload();
704 Configuration configuration = archivaConfiguration.getConfiguration();
706 ManagedRepositoryConfiguration repository = configuration.getManagedRepositories().get( 0 );
708 assertEquals( "check cron expression", "0 0,30 * * * ?", repository.getRefreshCronExpression().trim() );
710 // add a test listener to confirm it doesn't see the escaped format. We don't need to test the number of calls,
711 // etc. as it's done in other tests
712 archivaConfiguration.addListener( new ConfigurationListener()
714 public void configurationEvent( ConfigurationEvent event )
716 assertEquals( ConfigurationEvent.SAVED, event.getType() );
721 archivaConfiguration.save( configuration );
723 configuration = archivaConfiguration.getConfiguration();
725 // test for the escape character '\' showing up on repositories.jsp
726 repository.setRefreshCronExpression( "0 0,20 0 * * ?" );
728 archivaConfiguration.save( configuration );
730 repository = archivaConfiguration.getConfiguration().findManagedRepositoryById( "snapshots" );
732 assertEquals( "check cron expression", "0 0,20 0 * * ?", repository.getRefreshCronExpression() );
736 public void testRemoveLastElements()
739 File baseFile = getTestFile( "target/test/test-file.xml" );
741 assertFalse( baseFile.exists() );
743 File userFile = getTestFile( "target/test/test-file-user.xml" );
745 assertFalse( userFile.exists() );
747 baseFile.getParentFile().mkdirs();
748 FileUtils.copyFile( getTestFile( "src/test/conf/conf-single-list-elements.xml" ), baseFile );
750 userFile.getParentFile().mkdirs();
751 FileUtils.writeStringToFile( userFile, "<configuration/>", null );
753 ArchivaConfiguration archivaConfiguration = lookup( ArchivaConfiguration.class, "test-remove-central" );
755 archivaConfiguration.reload();
757 Configuration configuration = archivaConfiguration.getConfiguration();
759 RepositoryGroupConfiguration repositoryGroup = configuration.getRepositoryGroups().get( 0 );
760 assertNotNull( repositoryGroup );
761 configuration.removeRepositoryGroup( repositoryGroup );
762 assertTrue( configuration.getRepositoryGroups().isEmpty() );
764 RemoteRepositoryConfiguration repository = configuration.getRemoteRepositoriesAsMap().get( "central" );
765 assertNotNull( repository );
766 configuration.removeRemoteRepository( repository );
767 assertTrue( configuration.getRemoteRepositories().isEmpty() );
769 ManagedRepositoryConfiguration managedRepository =
770 configuration.getManagedRepositoriesAsMap().get( "snapshots" );
771 assertNotNull( managedRepository );
772 configuration.removeManagedRepository( managedRepository );
773 assertTrue( configuration.getManagedRepositories().isEmpty() );
775 ProxyConnectorConfiguration proxyConnector = configuration.getProxyConnectors().get( 0 );
776 assertNotNull( proxyConnector );
777 configuration.removeProxyConnector( proxyConnector );
778 assertTrue( configuration.getProxyConnectors().isEmpty() );
780 NetworkProxyConfiguration networkProxy = configuration.getNetworkProxiesAsMap().get( "proxy" );
781 assertNotNull( networkProxy );
782 configuration.removeNetworkProxy( networkProxy );
783 assertTrue( configuration.getNetworkProxies().isEmpty() );
785 LegacyArtifactPath path = configuration.getLegacyArtifactPaths().get( 0 );
786 assertNotNull( path );
787 configuration.removeLegacyArtifactPath( path );
788 assertTrue( configuration.getLegacyArtifactPaths().isEmpty() );
790 RepositoryScanningConfiguration scanning = configuration.getRepositoryScanning();
791 String consumer = scanning.getKnownContentConsumers().get( 0 );
792 assertNotNull( consumer );
793 scanning.removeKnownContentConsumer( consumer );
795 assertFalse( scanning.getKnownContentConsumers().isEmpty() );
796 consumer = scanning.getInvalidContentConsumers().get( 0 );
797 assertNotNull( consumer );
798 scanning.removeInvalidContentConsumer( consumer );
799 assertTrue( scanning.getInvalidContentConsumers().isEmpty() );
801 archivaConfiguration.save( configuration );
803 archivaConfiguration = lookup( ArchivaConfiguration.class, "test-read-saved" );
804 configuration = archivaConfiguration.getConfiguration();
805 assertNull( configuration.getRemoteRepositoriesAsMap().get( "central" ) );
806 assertTrue( configuration.getRepositoryGroups().isEmpty() );
807 assertNull( configuration.getManagedRepositoriesAsMap().get( "snapshots" ) );
808 assertTrue( configuration.getProxyConnectors().isEmpty() );
809 assertNull( configuration.getNetworkProxiesAsMap().get( "proxy" ) );
810 assertTrue( configuration.getLegacyArtifactPaths().isEmpty() );
811 scanning = configuration.getRepositoryScanning();
812 assertFalse( scanning.getKnownContentConsumers().isEmpty() );
813 assertTrue( scanning.getInvalidContentConsumers().isEmpty() );
817 * [MRM-582] Remote Repositories with empty <username> and <password> fields shouldn't be created in configuration.
820 public void testGetConfigurationFixEmptyRemoteRepoUsernamePassword()
823 ArchivaConfiguration archivaConfiguration = lookup( ArchivaConfiguration.class, "test-configuration" );
825 archivaConfiguration.reload();
826 Configuration configuration = archivaConfiguration.getConfiguration();
827 assertConfiguration( configuration, 2, 2, 2 );
828 assertEquals( "check remote repositories", 2, configuration.getRemoteRepositories().size() );
830 RemoteRepositoryConfiguration repository =
831 configuration.getRemoteRepositoriesAsMap().get( "maven2-repository.dev.java.net" );
833 assertEquals( "remote repository.url", "https://maven2-repository.dev.java.net/nonav/repository",
834 repository.getUrl() );
835 assertEquals( "remote repository.name", "Java.net Repository for Maven 2", repository.getName() );
836 assertEquals( "remote repository.id", "maven2-repository.dev.java.net", repository.getId() );
837 assertEquals( "remote repository.layout", "default", repository.getLayout() );
838 assertNull( "remote repository.username == null", repository.getUsername() );
839 assertNull( "remote repository.password == null", repository.getPassword() );