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.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 );
72 public void testGetConfigurationFromRegistryWithASingleNamedConfigurationResource()
75 ArchivaConfiguration archivaConfiguration = lookup( ArchivaConfiguration.class, "test-configuration" );
77 Configuration configuration = archivaConfiguration.getConfiguration();
78 assertConfiguration( configuration, 2, 2, 2 );
79 assertEquals( "check network proxies", 1, configuration.getNetworkProxies().size() );
81 ManagedRepositoryConfiguration repository = configuration.getManagedRepositories().get( 0 );
83 assertEquals( "check managed repositories", "${appserver.base}/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 testGetConfigurationFromDefaults()
95 ArchivaConfiguration archivaConfiguration = lookup( ArchivaConfiguration.class, "test-defaults" );
97 Configuration configuration = archivaConfiguration.getConfiguration();
98 assertConfiguration( configuration, 2, 1, 1 );
99 assertEquals( "check network proxies", 0, configuration.getNetworkProxies().size() );
101 ManagedRepositoryConfiguration repository = configuration.getManagedRepositories().get( 0 );
103 assertEquals( "check managed repositories", "${appserver.base}/data/repositories/internal",
104 repository.getLocation() );
105 assertEquals( "check managed repositories", "Archiva Managed Internal Repository", repository.getName() );
106 assertEquals( "check managed repositories", "internal", repository.getId() );
107 assertEquals( "check managed repositories", "default", repository.getLayout() );
108 assertTrue( "check managed repositories", repository.isScanned() );
111 // test for [MRM-789]
113 public void testGetConfigurationFromDefaultsWithDefaultRepoLocationAlreadyExisting()
116 File repo = new File( FileUtil.getBasedir(), "/target/test-classes/existing_snapshots" );
119 repo = new File( FileUtil.getBasedir(), "/target/test-classes/existing_internal" );
122 String existingTestDefaultArchivaConfigFile = FileUtils.readFileToString(
123 getTestFile( "target/test-classes/org/apache/archiva/configuration/test-default-archiva.xml" ) );
124 existingTestDefaultArchivaConfigFile =
125 StringUtils.replace( existingTestDefaultArchivaConfigFile, "${appserver.base}", FileUtil.getBasedir() );
127 File generatedTestDefaultArchivaConfigFile = new File( FileUtil.getBasedir(),
128 "target/test-classes/org/apache/archiva/configuration/default-archiva.xml" );
130 FileUtils.writeStringToFile( generatedTestDefaultArchivaConfigFile, existingTestDefaultArchivaConfigFile,
133 ArchivaConfiguration archivaConfiguration =
134 lookup( ArchivaConfiguration.class, "test-defaults-default-repo-location-exists" );
136 Configuration configuration = archivaConfiguration.getConfiguration();
137 assertConfiguration( configuration, 2, 1, 1 );
139 ManagedRepositoryConfiguration repository = configuration.getManagedRepositories().get( 0 );
140 assertTrue( "check managed repositories", repository.getLocation().endsWith( "data/repositories/internal" ) );
142 generatedTestDefaultArchivaConfigFile.delete();
143 assertFalse( generatedTestDefaultArchivaConfigFile.exists() );
148 * Ensures that the provided configuration matches the details present in the archiva-default.xml file.
150 private void assertConfiguration( Configuration configuration, int managedExpected, int remoteExpected,
151 int proxyConnectorExpected )
155 assertEquals( "check managed repositories: " + configuration.getManagedRepositories(), managedExpected,
156 configuration.getManagedRepositories().size() );
157 assertEquals( "check remote repositories: " + configuration.getRemoteRepositories(), remoteExpected,
158 configuration.getRemoteRepositories().size() );
159 assertEquals( "check proxy connectors:" + configuration.getProxyConnectors(), proxyConnectorExpected,
160 configuration.getProxyConnectors().size() );
162 RepositoryScanningConfiguration repoScanning = configuration.getRepositoryScanning();
163 assertNotNull( "check repository scanning", repoScanning );
164 assertEquals( "check file types", 4, repoScanning.getFileTypes().size() );
165 assertEquals( "check known consumers", 9, repoScanning.getKnownContentConsumers().size() );
166 assertEquals( "check invalid consumers", 1, repoScanning.getInvalidContentConsumers().size() );
168 List<String> patterns = filetypes.getFileTypePatterns( "artifacts" );
169 assertNotNull( "check 'artifacts' file type", patterns );
170 assertEquals( "check 'artifacts' patterns", 13, patterns.size() );
172 WebappConfiguration webapp = configuration.getWebapp();
173 assertNotNull( "check webapp", webapp );
175 UserInterfaceOptions ui = webapp.getUi();
176 assertNotNull( "check webapp ui", ui );
177 assertTrue( "check showFindArtifacts", ui.isShowFindArtifacts() );
178 assertTrue( "check appletFindEnabled", ui.isAppletFindEnabled() );
182 public void testGetConfigurationFromRegistryWithTwoConfigurationResources()
185 ArchivaConfiguration archivaConfiguration = lookup( ArchivaConfiguration.class, "test-configuration-both" );
187 Configuration configuration = archivaConfiguration.getConfiguration();
190 assertEquals( "check repositories", 2, configuration.getManagedRepositories().size() );
191 assertEquals( "check repositories", 2, configuration.getRemoteRepositories().size() );
193 assertEquals( "check proxy connectors", 2, configuration.getProxyConnectors().size() );
195 WebappConfiguration webapp = configuration.getWebapp();
196 assertNotNull( "check webapp", webapp );
198 UserInterfaceOptions ui = webapp.getUi();
199 assertNotNull( "check webapp ui", ui );
201 assertFalse( "check showFindArtifacts", ui.isShowFindArtifacts() );
203 assertFalse( "check appletFindEnabled", ui.isAppletFindEnabled() );
207 public void testGetConfigurationSystemOverride()
211 System.setProperty( "org.apache.archiva.webapp.ui.appletFindEnabled", "false" );
213 ArchivaConfiguration archivaConfiguration = lookup( ArchivaConfiguration.class, "test-configuration" );
215 archivaConfiguration.reload();
219 Configuration configuration = archivaConfiguration.getConfiguration();
221 assertFalse( "check boolean", configuration.getWebapp().getUi().isAppletFindEnabled() );
225 System.getProperties().remove( "org.apache.archiva.webapp.ui.appletFindEnabled" );
230 public void testStoreConfiguration()
233 File file = getTestFile( "target/test/test-file.xml" );
235 assertFalse( file.exists() );
237 // TODO: remove with commons-configuration 1.4
238 //file.getParentFile().mkdirs();
239 //FileUtils.writeStringToFile( file, "<configuration/>", null );
241 DefaultArchivaConfiguration archivaConfiguration =
242 (DefaultArchivaConfiguration) lookup( ArchivaConfiguration.class, "test-save" );
244 archivaConfiguration.reload();
246 Configuration configuration = new Configuration();
247 configuration.setVersion( "1" );
248 configuration.setWebapp( new WebappConfiguration() );
249 configuration.getWebapp().setUi( new UserInterfaceOptions() );
250 configuration.getWebapp().getUi().setAppletFindEnabled( false );
252 // add a change listener
253 MockControl control = createConfigurationListenerMockControl();
254 ConfigurationListener listener = (ConfigurationListener) control.getMock();
255 archivaConfiguration.addListener( listener );
257 listener.configurationEvent( new ConfigurationEvent( ConfigurationEvent.SAVED ) );
258 control.setVoidCallable();
262 archivaConfiguration.save( configuration );
266 assertTrue( "Check file exists", file.exists() );
269 configuration = archivaConfiguration.getConfiguration();
270 assertFalse( "check value", configuration.getWebapp().getUi().isAppletFindEnabled() );
273 archivaConfiguration = (DefaultArchivaConfiguration) lookup( ArchivaConfiguration.class, "test-read-saved" );
275 archivaConfiguration.reload();
276 configuration = archivaConfiguration.getConfiguration();
277 assertFalse( "check value", configuration.getWebapp().getUi().isAppletFindEnabled() );
280 private static MockControl createConfigurationListenerMockControl()
282 return MockControl.createControl( ConfigurationListener.class );
286 public void testStoreConfigurationUser()
289 File baseFile = getTestFile( "target/test/test-file.xml" );
291 assertFalse( baseFile.exists() );
293 File userFile = getTestFile( "target/test/test-file-user.xml" );
295 assertFalse( userFile.exists() );
297 userFile.getParentFile().mkdirs();
298 FileUtils.writeStringToFile( userFile, "<configuration/>", null );
300 ArchivaConfiguration archivaConfiguration = lookup( ArchivaConfiguration.class, "test-save-user" );
302 Configuration configuration = new Configuration();
303 configuration.setWebapp( new WebappConfiguration() );
304 configuration.getWebapp().setUi( new UserInterfaceOptions() );
305 configuration.getWebapp().getUi().setAppletFindEnabled( false );
307 archivaConfiguration.save( configuration );
309 assertTrue( "Check file exists", userFile.exists() );
310 assertFalse( "Check file not created", baseFile.exists() );
313 configuration = archivaConfiguration.getConfiguration();
314 assertFalse( "check value", configuration.getWebapp().getUi().isAppletFindEnabled() );
318 public void testStoreConfigurationLoadedFromDefaults()
321 File baseFile = getTestFile( "target/test/test-file.xml" );
323 assertFalse( baseFile.exists() );
325 File userFile = getTestFile( "target/test/test-file-user.xml" );
327 assertFalse( userFile.exists() );
329 ArchivaConfiguration archivaConfiguration = lookup( ArchivaConfiguration.class, "test-save-user-defaults" );
331 archivaConfiguration.reload();
333 Configuration configuration = new Configuration();
334 configuration.setWebapp( new WebappConfiguration() );
335 configuration.getWebapp().setUi( new UserInterfaceOptions() );
336 configuration.getWebapp().getUi().setAppletFindEnabled( false );
338 // add a change listener
339 MockControl control = createConfigurationListenerMockControl();
340 ConfigurationListener listener = (ConfigurationListener) control.getMock();
341 archivaConfiguration.addListener( listener );
343 listener.configurationEvent( new ConfigurationEvent( ConfigurationEvent.SAVED ) );
345 control.setVoidCallable( 1 );
349 archivaConfiguration.save( configuration );
353 assertTrue( "Check file exists", userFile.exists() );
354 assertFalse( "Check file not created", baseFile.exists() );
357 configuration = archivaConfiguration.getConfiguration();
358 assertFalse( "check value", configuration.getWebapp().getUi().isAppletFindEnabled() );
362 public void testDefaultUserConfigFilename()
365 DefaultArchivaConfiguration archivaConfiguration =
366 (DefaultArchivaConfiguration) lookup( ArchivaConfiguration.class, "default" );
368 archivaConfiguration.reload();
370 assertEquals( System.getProperty( "user.home" ) + "/.m2/archiva.xml",
371 archivaConfiguration.getUserConfigFilename() );
372 assertEquals( System.getProperty( "appserver.base", "${appserver.base}" ) + "/conf/archiva.xml",
373 archivaConfiguration.getAltConfigFilename() );
377 public void testStoreConfigurationFallback()
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 ArchivaConfiguration archivaConfiguration =
392 (ArchivaConfiguration) lookup( ArchivaConfiguration.class, "test-save-user-fallback" );
394 archivaConfiguration.reload();
396 Configuration configuration = new Configuration();
397 configuration.setWebapp( new WebappConfiguration() );
398 configuration.getWebapp().setUi( new UserInterfaceOptions() );
399 configuration.getWebapp().getUi().setAppletFindEnabled( false );
401 archivaConfiguration.save( configuration );
403 assertTrue( "Check file exists", baseFile.exists() );
404 assertFalse( "Check file not created", userFile.exists() );
407 configuration = archivaConfiguration.getConfiguration();
408 assertFalse( "check value", configuration.getWebapp().getUi().isAppletFindEnabled() );
412 public void testStoreConfigurationFailsWhenReadFromBothLocationsNoLists()
415 File baseFile = getTestFile( "target/test/test-file.xml" );
417 assertFalse( baseFile.exists() );
419 File userFile = getTestFile( "target/test/test-file-user.xml" );
421 assertFalse( userFile.exists() );
423 baseFile.getParentFile().mkdirs();
424 FileUtils.writeStringToFile( baseFile, "<configuration/>", null );
426 userFile.getParentFile().mkdirs();
427 FileUtils.writeStringToFile( userFile, "<configuration/>", null );
429 ArchivaConfiguration archivaConfiguration =
430 (ArchivaConfiguration) lookup( ArchivaConfiguration.class, "test-save-user" );
432 archivaConfiguration.reload();
434 Configuration configuration = archivaConfiguration.getConfiguration();
435 assertTrue( "check value", configuration.getWebapp().getUi().isAppletFindEnabled() );
437 configuration.getWebapp().getUi().setAppletFindEnabled( false );
439 archivaConfiguration.save( configuration );
441 assertTrue( "Check file exists", baseFile.exists() );
442 assertEquals( "Check base file is unchanged", "<configuration/>",
443 FileUtils.readFileToString( baseFile, null ) );
444 assertTrue( "Check file exists", userFile.exists() );
445 assertFalse( "Check base file is changed",
446 "<configuration/>".equals( FileUtils.readFileToString( userFile, null ) ) );
449 configuration = archivaConfiguration.getConfiguration();
450 assertFalse( "check value", configuration.getWebapp().getUi().isAppletFindEnabled() );
454 public void testStoreConfigurationFailsWhenReadFromBothLocationsUserHasLists()
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 userFile.getParentFile().mkdirs();
466 FileUtils.copyFile( getTestFile( "src/test/conf/conf-user.xml" ), userFile );
468 baseFile.getParentFile().mkdirs();
469 FileUtils.writeStringToFile( baseFile, "<configuration/>", null );
471 ArchivaConfiguration archivaConfiguration =
472 (ArchivaConfiguration) lookup( ArchivaConfiguration.class, "test-save-user" );
474 archivaConfiguration.reload();
476 Configuration configuration = archivaConfiguration.getConfiguration();
477 assertTrue( "check value", configuration.getWebapp().getUi().isShowFindArtifacts() );
479 configuration.getWebapp().getUi().setShowFindArtifacts( false );
481 archivaConfiguration.save( configuration );
483 assertTrue( "Check file exists", baseFile.exists() );
484 assertEquals( "Check base file is unchanged", "<configuration/>",
485 FileUtils.readFileToString( baseFile, null ) );
486 assertTrue( "Check file exists", userFile.exists() );
487 assertFalse( "Check base file is changed",
488 "<configuration/>".equals( FileUtils.readFileToString( userFile, null ) ) );
491 configuration = archivaConfiguration.getConfiguration();
492 assertFalse( "check value", configuration.getWebapp().getUi().isShowFindArtifacts() );
496 public void testStoreConfigurationFailsWhenReadFromBothLocationsAppserverHasLists()
499 File baseFile = getTestFile( "target/test/test-file.xml" );
501 assertFalse( baseFile.exists() );
503 File userFile = getTestFile( "target/test/test-file-user.xml" );
505 assertFalse( userFile.exists() );
507 baseFile.getParentFile().mkdirs();
508 FileUtils.copyFile( getTestFile( "src/test/conf/conf-base.xml" ), baseFile );
510 userFile.getParentFile().mkdirs();
511 FileUtils.writeStringToFile( userFile, "<configuration/>", null );
513 ArchivaConfiguration archivaConfiguration =
514 (ArchivaConfiguration) lookup( ArchivaConfiguration.class, "test-save-user" );
516 archivaConfiguration.reload();
518 Configuration configuration = archivaConfiguration.getConfiguration();
519 assertTrue( "check value", configuration.getWebapp().getUi().isAppletFindEnabled() );
521 configuration.getWebapp().getUi().setAppletFindEnabled( false );
525 archivaConfiguration.save( configuration );
526 fail( "Configuration saving should not succeed if it was loaded from two locations" );
528 catch ( IndeterminateConfigurationException e )
530 // check it was reverted
531 configuration = archivaConfiguration.getConfiguration();
532 assertTrue( "check value", configuration.getWebapp().getUi().isAppletFindEnabled() );
537 public void testLoadConfigurationFromInvalidBothLocationsOnDisk()
540 ArchivaConfiguration archivaConfiguration =
541 lookup( ArchivaConfiguration.class, "test-not-allowed-to-write-to-both" );
542 Configuration config = archivaConfiguration.getConfiguration();
546 archivaConfiguration.save( config );
547 fail( "Should have thrown a RegistryException because the configuration can't be saved." );
549 catch ( RegistryException e )
551 /* expected exception */
556 public void testLoadConfigurationFromInvalidUserLocationOnDisk()
559 File testConfDir = getTestFile( "target/test-appserver-base/conf/" );
560 testConfDir.mkdirs();
562 ArchivaConfiguration archivaConfiguration =
563 lookup( ArchivaConfiguration.class, "test-not-allowed-to-write-to-user" );
564 Configuration config = archivaConfiguration.getConfiguration();
565 archivaConfiguration.save( config );
566 // No Exception == test passes.
567 // Expected Path is: Should not have thrown an exception.
571 public void testConfigurationUpgradeFrom09()
574 ArchivaConfiguration archivaConfiguration = lookup( ArchivaConfiguration.class, "test-upgrade-09" );
576 // we just use the defaults when upgrading from 0.9 at this point.
577 Configuration configuration = archivaConfiguration.getConfiguration();
578 // test-upgrade-09 contains a managed with id: local so it's 3 managed
579 assertConfiguration( configuration, 3, 1, 1 );
580 assertEquals( "check network proxies", 0, configuration.getNetworkProxies().size() );
582 ManagedRepositoryConfiguration repository = configuration.getManagedRepositories().get( 0 );
584 assertEquals( "check managed repositories", "${appserver.base}/data/repositories/internal",
585 repository.getLocation() );
586 assertEquals( "check managed repositories", "Archiva Managed Internal Repository", repository.getName() );
587 assertEquals( "check managed repositories", "internal", repository.getId() );
588 assertEquals( "check managed repositories", "default", repository.getLayout() );
589 assertTrue( "check managed repositories", repository.isScanned() );
593 public void testConfigurationUpgradeFrom13()
596 ArchivaConfiguration archivaConfiguration = lookup( ArchivaConfiguration.class, "test-upgrade-1.3" );
598 // we just use the defaults when upgrading from 1.3 at this point.
599 Configuration configuration = archivaConfiguration.getConfiguration();
600 assertConfiguration( configuration, 2, 2, 2 );
601 assertEquals( "check network proxies", 0, configuration.getNetworkProxies().size() );
603 ManagedRepositoryConfiguration repository = configuration.getManagedRepositories().get( 0 );
605 assertEquals( "check managed repositories", "${appserver.base}/data/repositories/internal",
606 repository.getLocation() );
607 assertEquals( "check managed repositories", "Archiva Managed Internal Repository", repository.getName() );
608 assertEquals( "check managed repositories", "internal", repository.getId() );
609 assertEquals( "check managed repositories", "default", repository.getLayout() );
610 assertTrue( "check managed repositories", repository.isScanned() );
612 log.info( "knowContentConsumers " + configuration.getRepositoryScanning().getKnownContentConsumers() );
615 configuration.getRepositoryScanning().getKnownContentConsumers().contains( "update-db-artifact" ) );
616 assertFalse( configuration.getRepositoryScanning().getKnownContentConsumers().contains(
617 "update-db-repository-metadata" ) );
620 configuration.getRepositoryScanning().getKnownContentConsumers().contains( "create-archiva-metadata" ) );
623 configuration.getRepositoryScanning().getKnownContentConsumers().contains( "duplicate-artifacts" ) );
627 public void testAutoDetectV1()
630 // Setup the autodetect-v1.xml file in the target directory (so we can save/load it)
631 File userFile = getTestFile( "target/test-autodetect-v1/archiva-user.xml" );
633 assertFalse( userFile.exists() );
635 userFile.getParentFile().mkdirs();
636 FileUtils.copyFile( getTestFile( "src/test/conf/autodetect-v1.xml" ), userFile );
638 // Load the original (unconverted) archiva.xml
639 ArchivaConfiguration archivaConfiguration = lookup( ArchivaConfiguration.class, "test-autodetect-v1" );
641 archivaConfiguration.reload();
643 Configuration configuration = archivaConfiguration.getConfiguration();
644 assertConfiguration( configuration, 2, 2, 2 );
645 assertEquals( "check network proxies", 1, configuration.getNetworkProxies().size() );
647 ManagedRepositoryConfiguration repository = configuration.getManagedRepositories().get( 0 );
649 assertEquals( "check managed repositories", "${appserver.base}/repositories/internal",
650 repository.getLocation() );
651 assertEquals( "check managed repositories", "Archiva Managed Internal Repository", repository.getName() );
652 assertEquals( "check managed repositories", "internal", repository.getId() );
653 assertEquals( "check managed repositories", "default", repository.getLayout() );
654 assertTrue( "check managed repositories", repository.isScanned() );
656 // Test that only 1 set of repositories exist.
657 assertEquals( "check managed repositories size.", 2, configuration.getManagedRepositories().size() );
658 assertEquals( "check remote repositories size.", 2, configuration.getRemoteRepositories().size() );
659 assertEquals( "check v1 repositories size.", 0, configuration.getRepositories().size() );
662 archivaConfiguration.save( configuration );
665 //release( archivaConfiguration );
668 archivaConfiguration = lookup( ArchivaConfiguration.class, "test-autodetect-v1" );
669 configuration = archivaConfiguration.getConfiguration();
671 // Test that only 1 set of repositories exist.
672 assertEquals( "check managed repositories size.", 2, configuration.getManagedRepositories().size() );
673 assertEquals( "check managed repositories size.", 2, configuration.getManagedRepositoriesAsMap().size() );
674 assertEquals( "check remote repositories size.", 2, configuration.getRemoteRepositories().size() );
675 assertEquals( "check remote repositories size.", 2, configuration.getRemoteRepositoriesAsMap().size() );
676 assertEquals( "check v1 repositories size.", 0, configuration.getRepositories().size() );
678 String actualXML = FileUtils.readFileToString( userFile, null );
679 XMLAssert.assertXpathNotExists( "//configuration/repositories/repository", actualXML );
680 XMLAssert.assertXpathNotExists( "//configuration/repositories", actualXML );
684 public void testArchivaV1()
687 ArchivaConfiguration archivaConfiguration = lookup( ArchivaConfiguration.class, "test-archiva-v1" );
689 Configuration configuration = archivaConfiguration.getConfiguration();
690 assertConfiguration( configuration, 2, 2, 2 );
691 assertEquals( "check network proxies", 1, configuration.getNetworkProxies().size() );
693 assertEquals( "check managed repositories", 2, configuration.getManagedRepositories().size() );
694 assertEquals( "check v1 repositories size.", 0, configuration.getRepositories().size() );
696 Map<String, ManagedRepositoryConfiguration> map = configuration.getManagedRepositoriesAsMap();
698 ManagedRepositoryConfiguration repository = map.get( "internal" );
699 assertEquals( "check managed repositories", "${appserver.base}/repositories/internal",
700 repository.getLocation() );
701 assertEquals( "check managed repositories", "Archiva Managed Internal Repository", repository.getName() );
702 assertEquals( "check managed repositories", "internal", repository.getId() );
703 assertEquals( "check managed repositories", "default", repository.getLayout() );
704 assertTrue( "check managed repositories", repository.isScanned() );
705 assertFalse( "check managed repositories", repository.isSnapshots() );
707 repository = map.get( "snapshots" );
708 assertEquals( "check managed repositories", "${appserver.base}/repositories/snapshots",
709 repository.getLocation() );
710 assertEquals( "check managed repositories", "Archiva Managed Snapshot Repository", repository.getName() );
711 assertEquals( "check managed repositories", "snapshots", repository.getId() );
712 assertEquals( "check managed repositories", "default", repository.getLayout() );
713 assertFalse( "check managed repositories", repository.isScanned() );
714 assertTrue( "check managed repositories", repository.isSnapshots() );
718 public void testCronExpressionsWithComma()
721 File baseFile = getTestFile( "target/test/test-file.xml" );
723 assertFalse( baseFile.exists() );
725 File userFile = getTestFile( "target/test/test-file-user.xml" );
727 assertFalse( userFile.exists() );
729 baseFile.getParentFile().mkdirs();
730 FileUtils.copyFile( getTestFile( "src/test/conf/escape-cron-expressions.xml" ), baseFile );
732 userFile.getParentFile().mkdirs();
733 FileUtils.writeStringToFile( userFile, "<configuration/>", null );
735 final ArchivaConfiguration archivaConfiguration = lookup( ArchivaConfiguration.class, "test-cron-expressions" );
737 archivaConfiguration.reload();
739 Configuration configuration = archivaConfiguration.getConfiguration();
741 ManagedRepositoryConfiguration repository = configuration.getManagedRepositories().get( 0 );
743 assertEquals( "check cron expression", "0 0,30 * * * ?", repository.getRefreshCronExpression().trim() );
745 // add a test listener to confirm it doesn't see the escaped format. We don't need to test the number of calls,
746 // etc. as it's done in other tests
747 archivaConfiguration.addListener( new ConfigurationListener()
749 public void configurationEvent( ConfigurationEvent event )
751 assertEquals( ConfigurationEvent.SAVED, event.getType() );
756 archivaConfiguration.save( configuration );
758 configuration = archivaConfiguration.getConfiguration();
760 // test for the escape character '\' showing up on repositories.jsp
761 repository.setRefreshCronExpression( "0 0,20 0 * * ?" );
763 archivaConfiguration.save( configuration );
765 repository = archivaConfiguration.getConfiguration().findManagedRepositoryById( "snapshots" );
767 assertEquals( "check cron expression", "0 0,20 0 * * ?", repository.getRefreshCronExpression() );
771 public void testRemoveLastElements()
774 File baseFile = getTestFile( "target/test/test-file.xml" );
776 assertFalse( baseFile.exists() );
778 File userFile = getTestFile( "target/test/test-file-user.xml" );
780 assertFalse( userFile.exists() );
782 baseFile.getParentFile().mkdirs();
783 FileUtils.copyFile( getTestFile( "src/test/conf/conf-single-list-elements.xml" ), baseFile );
785 userFile.getParentFile().mkdirs();
786 FileUtils.writeStringToFile( userFile, "<configuration/>", null );
788 ArchivaConfiguration archivaConfiguration = lookup( ArchivaConfiguration.class, "test-remove-central" );
790 archivaConfiguration.reload();
792 Configuration configuration = archivaConfiguration.getConfiguration();
794 RepositoryGroupConfiguration repositoryGroup = configuration.getRepositoryGroups().get( 0 );
795 assertNotNull( repositoryGroup );
796 configuration.removeRepositoryGroup( repositoryGroup );
797 assertTrue( configuration.getRepositoryGroups().isEmpty() );
799 RemoteRepositoryConfiguration repository = configuration.getRemoteRepositoriesAsMap().get( "central" );
800 assertNotNull( repository );
801 configuration.removeRemoteRepository( repository );
802 assertTrue( configuration.getRemoteRepositories().isEmpty() );
804 ManagedRepositoryConfiguration managedRepository =
805 configuration.getManagedRepositoriesAsMap().get( "snapshots" );
806 assertNotNull( managedRepository );
807 configuration.removeManagedRepository( managedRepository );
808 assertTrue( configuration.getManagedRepositories().isEmpty() );
810 ProxyConnectorConfiguration proxyConnector = configuration.getProxyConnectors().get( 0 );
811 assertNotNull( proxyConnector );
812 configuration.removeProxyConnector( proxyConnector );
813 assertTrue( configuration.getProxyConnectors().isEmpty() );
815 NetworkProxyConfiguration networkProxy = configuration.getNetworkProxiesAsMap().get( "proxy" );
816 assertNotNull( networkProxy );
817 configuration.removeNetworkProxy( networkProxy );
818 assertTrue( configuration.getNetworkProxies().isEmpty() );
820 LegacyArtifactPath path = configuration.getLegacyArtifactPaths().get( 0 );
821 assertNotNull( path );
822 configuration.removeLegacyArtifactPath( path );
823 assertTrue( configuration.getLegacyArtifactPaths().isEmpty() );
825 RepositoryScanningConfiguration scanning = configuration.getRepositoryScanning();
826 String consumer = scanning.getKnownContentConsumers().get( 0 );
827 assertNotNull( consumer );
828 scanning.removeKnownContentConsumer( consumer );
830 assertFalse( scanning.getKnownContentConsumers().isEmpty() );
831 consumer = scanning.getInvalidContentConsumers().get( 0 );
832 assertNotNull( consumer );
833 scanning.removeInvalidContentConsumer( consumer );
834 assertTrue( scanning.getInvalidContentConsumers().isEmpty() );
836 archivaConfiguration.save( configuration );
838 archivaConfiguration = lookup( ArchivaConfiguration.class, "test-read-saved" );
839 configuration = archivaConfiguration.getConfiguration();
840 assertNull( configuration.getRemoteRepositoriesAsMap().get( "central" ) );
841 assertTrue( configuration.getRepositoryGroups().isEmpty() );
842 assertNull( configuration.getManagedRepositoriesAsMap().get( "snapshots" ) );
843 assertTrue( configuration.getProxyConnectors().isEmpty() );
844 assertNull( configuration.getNetworkProxiesAsMap().get( "proxy" ) );
845 assertTrue( configuration.getLegacyArtifactPaths().isEmpty() );
846 scanning = configuration.getRepositoryScanning();
847 assertFalse( scanning.getKnownContentConsumers().isEmpty() );
848 assertTrue( scanning.getInvalidContentConsumers().isEmpty() );
852 * [MRM-582] Remote Repositories with empty <username> and <password> fields shouldn't be created in configuration.
855 public void testGetConfigurationFixEmptyRemoteRepoUsernamePassword()
858 ArchivaConfiguration archivaConfiguration = lookup( ArchivaConfiguration.class, "test-configuration" );
860 archivaConfiguration.reload();
861 Configuration configuration = archivaConfiguration.getConfiguration();
862 assertConfiguration( configuration, 2, 2, 2 );
863 assertEquals( "check remote repositories", 2, configuration.getRemoteRepositories().size() );
865 RemoteRepositoryConfiguration repository =
866 configuration.getRemoteRepositoriesAsMap().get( "maven2-repository.dev.java.net" );
868 assertEquals( "remote repository.url", "https://maven2-repository.dev.java.net/nonav/repository",
869 repository.getUrl() );
870 assertEquals( "remote repository.name", "Java.net Repository for Maven 2", repository.getName() );
871 assertEquals( "remote repository.id", "maven2-repository.dev.java.net", repository.getId() );
872 assertEquals( "remote repository.layout", "default", repository.getLayout() );
873 assertNull( "remote repository.username == null", repository.getUsername() );
874 assertNull( "remote repository.password == null", repository.getPassword() );