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.archiva.redback.components.springutils.ComponentContainer;
26 import org.apache.commons.io.FileUtils;
27 import org.apache.commons.lang.StringUtils;
28 import org.custommonkey.xmlunit.XMLAssert;
29 import org.easymock.MockControl;
30 import org.junit.Test;
31 import org.junit.runner.RunWith;
32 import org.slf4j.Logger;
33 import org.slf4j.LoggerFactory;
34 import org.springframework.test.context.ContextConfiguration;
35 import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
37 import javax.inject.Inject;
39 import java.util.List;
43 * Test the configuration store.
45 @RunWith( SpringJUnit4ClassRunner.class )
46 @ContextConfiguration( locations = { "classpath*:/META-INF/spring-context.xml", "classpath:/spring-context.xml" } )
47 public class ArchivaConfigurationTest
51 private Logger log = LoggerFactory.getLogger( getClass() );
54 private ComponentContainer componentContainer;
56 public static File getTestFile( String path )
58 return new File( FileUtil.getBasedir(), path );
61 protected <T> T lookup( Class<T> clazz, String hint )
63 return componentContainer.getComponent( clazz, hint );
66 protected <T> T lookup( Class<T> clazz )
68 return componentContainer.getComponent( clazz );
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 )
154 FileTypes filetypes = lookup( FileTypes.class );
156 assertEquals( "check managed repositories: " + configuration.getManagedRepositories(), managedExpected,
157 configuration.getManagedRepositories().size() );
158 assertEquals( "check remote repositories: " + configuration.getRemoteRepositories(), remoteExpected,
159 configuration.getRemoteRepositories().size() );
160 assertEquals( "check proxy connectors:" + configuration.getProxyConnectors(), proxyConnectorExpected,
161 configuration.getProxyConnectors().size() );
163 RepositoryScanningConfiguration repoScanning = configuration.getRepositoryScanning();
164 assertNotNull( "check repository scanning", repoScanning );
165 assertEquals( "check file types", 4, repoScanning.getFileTypes().size() );
166 assertEquals( "check known consumers", 9, repoScanning.getKnownContentConsumers().size() );
167 assertEquals( "check invalid consumers", 1, repoScanning.getInvalidContentConsumers().size() );
169 List<String> patterns = filetypes.getFileTypePatterns( "artifacts" );
170 assertNotNull( "check 'artifacts' file type", patterns );
171 assertEquals( "check 'artifacts' patterns", 13, patterns.size() );
173 WebappConfiguration webapp = configuration.getWebapp();
174 assertNotNull( "check webapp", webapp );
176 UserInterfaceOptions ui = webapp.getUi();
177 assertNotNull( "check webapp ui", ui );
178 assertTrue( "check showFindArtifacts", ui.isShowFindArtifacts() );
179 assertTrue( "check appletFindEnabled", ui.isAppletFindEnabled() );
183 public void testGetConfigurationFromRegistryWithTwoConfigurationResources()
186 ArchivaConfiguration archivaConfiguration = lookup( ArchivaConfiguration.class, "test-configuration-both" );
188 Configuration configuration = archivaConfiguration.getConfiguration();
191 assertEquals( "check repositories", 2, configuration.getManagedRepositories().size() );
192 assertEquals( "check repositories", 2, configuration.getRemoteRepositories().size() );
194 assertEquals( "check proxy connectors", 2, configuration.getProxyConnectors().size() );
196 WebappConfiguration webapp = configuration.getWebapp();
197 assertNotNull( "check webapp", webapp );
199 UserInterfaceOptions ui = webapp.getUi();
200 assertNotNull( "check webapp ui", ui );
202 assertFalse( "check showFindArtifacts", ui.isShowFindArtifacts() );
204 assertFalse( "check appletFindEnabled", ui.isAppletFindEnabled() );
208 public void testGetConfigurationSystemOverride()
212 System.setProperty( "org.apache.archiva.webapp.ui.appletFindEnabled", "false" );
214 ArchivaConfiguration archivaConfiguration = lookup( ArchivaConfiguration.class, "test-configuration" );
216 archivaConfiguration.reload();
220 Configuration configuration = archivaConfiguration.getConfiguration();
222 assertFalse( "check boolean", configuration.getWebapp().getUi().isAppletFindEnabled() );
226 System.getProperties().remove( "org.apache.archiva.webapp.ui.appletFindEnabled" );
231 public void testStoreConfiguration()
234 File file = getTestFile( "target/test/test-file.xml" );
236 assertFalse( file.exists() );
238 // TODO: remove with commons-configuration 1.4
239 //file.getParentFile().mkdirs();
240 //FileUtils.writeStringToFile( file, "<configuration/>", null );
242 DefaultArchivaConfiguration archivaConfiguration =
243 (DefaultArchivaConfiguration) lookup( ArchivaConfiguration.class, "test-save" );
245 archivaConfiguration.reload();
247 Configuration configuration = new Configuration();
248 configuration.setVersion( "1" );
249 configuration.setWebapp( new WebappConfiguration() );
250 configuration.getWebapp().setUi( new UserInterfaceOptions() );
251 configuration.getWebapp().getUi().setAppletFindEnabled( false );
253 // add a change listener
254 MockControl control = createConfigurationListenerMockControl();
255 ConfigurationListener listener = (ConfigurationListener) control.getMock();
256 archivaConfiguration.addListener( listener );
258 listener.configurationEvent( new ConfigurationEvent( ConfigurationEvent.SAVED ) );
259 control.setVoidCallable();
263 archivaConfiguration.save( configuration );
267 assertTrue( "Check file exists", file.exists() );
270 configuration = archivaConfiguration.getConfiguration();
271 assertFalse( "check value", configuration.getWebapp().getUi().isAppletFindEnabled() );
274 archivaConfiguration = (DefaultArchivaConfiguration) lookup( ArchivaConfiguration.class, "test-read-saved" );
276 archivaConfiguration.reload();
277 configuration = archivaConfiguration.getConfiguration();
278 assertFalse( "check value", configuration.getWebapp().getUi().isAppletFindEnabled() );
281 private static MockControl createConfigurationListenerMockControl()
283 return MockControl.createControl( ConfigurationListener.class );
287 public void testStoreConfigurationUser()
290 File baseFile = getTestFile( "target/test/test-file.xml" );
292 assertFalse( baseFile.exists() );
294 File userFile = getTestFile( "target/test/test-file-user.xml" );
296 assertFalse( userFile.exists() );
298 userFile.getParentFile().mkdirs();
299 FileUtils.writeStringToFile( userFile, "<configuration/>", null );
301 ArchivaConfiguration archivaConfiguration = lookup( ArchivaConfiguration.class, "test-save-user" );
303 Configuration configuration = new Configuration();
304 configuration.setWebapp( new WebappConfiguration() );
305 configuration.getWebapp().setUi( new UserInterfaceOptions() );
306 configuration.getWebapp().getUi().setAppletFindEnabled( false );
308 archivaConfiguration.save( configuration );
310 assertTrue( "Check file exists", userFile.exists() );
311 assertFalse( "Check file not created", baseFile.exists() );
314 configuration = archivaConfiguration.getConfiguration();
315 assertFalse( "check value", configuration.getWebapp().getUi().isAppletFindEnabled() );
319 public void testStoreConfigurationLoadedFromDefaults()
322 File baseFile = getTestFile( "target/test/test-file.xml" );
324 assertFalse( baseFile.exists() );
326 File userFile = getTestFile( "target/test/test-file-user.xml" );
328 assertFalse( userFile.exists() );
330 ArchivaConfiguration archivaConfiguration = lookup( ArchivaConfiguration.class, "test-save-user-defaults" );
332 archivaConfiguration.reload();
334 Configuration configuration = new Configuration();
335 configuration.setWebapp( new WebappConfiguration() );
336 configuration.getWebapp().setUi( new UserInterfaceOptions() );
337 configuration.getWebapp().getUi().setAppletFindEnabled( false );
339 // add a change listener
340 MockControl control = createConfigurationListenerMockControl();
341 ConfigurationListener listener = (ConfigurationListener) control.getMock();
342 archivaConfiguration.addListener( listener );
344 listener.configurationEvent( new ConfigurationEvent( ConfigurationEvent.SAVED ) );
346 control.setVoidCallable( 1 );
350 archivaConfiguration.save( configuration );
354 assertTrue( "Check file exists", userFile.exists() );
355 assertFalse( "Check file not created", baseFile.exists() );
358 configuration = archivaConfiguration.getConfiguration();
359 assertFalse( "check value", configuration.getWebapp().getUi().isAppletFindEnabled() );
363 public void testDefaultUserConfigFilename()
366 DefaultArchivaConfiguration archivaConfiguration =
367 (DefaultArchivaConfiguration) lookup( ArchivaConfiguration.class, "default" );
369 archivaConfiguration.reload();
371 assertEquals( System.getProperty( "user.home" ) + "/.m2/archiva.xml",
372 archivaConfiguration.getUserConfigFilename() );
373 assertEquals( System.getProperty( "appserver.base", "${appserver.base}" ) + "/conf/archiva.xml",
374 archivaConfiguration.getAltConfigFilename() );
378 public void testStoreConfigurationFallback()
381 File baseFile = getTestFile( "target/test/test-file.xml" );
383 assertFalse( baseFile.exists() );
385 File userFile = getTestFile( "target/test/test-file-user.xml" );
387 assertFalse( userFile.exists() );
389 baseFile.getParentFile().mkdirs();
390 FileUtils.writeStringToFile( baseFile, "<configuration/>", null );
392 ArchivaConfiguration archivaConfiguration =
393 (ArchivaConfiguration) lookup( ArchivaConfiguration.class, "test-save-user-fallback" );
395 archivaConfiguration.reload();
397 Configuration configuration = new Configuration();
398 configuration.setWebapp( new WebappConfiguration() );
399 configuration.getWebapp().setUi( new UserInterfaceOptions() );
400 configuration.getWebapp().getUi().setAppletFindEnabled( false );
402 archivaConfiguration.save( configuration );
404 assertTrue( "Check file exists", baseFile.exists() );
405 assertFalse( "Check file not created", userFile.exists() );
408 configuration = archivaConfiguration.getConfiguration();
409 assertFalse( "check value", configuration.getWebapp().getUi().isAppletFindEnabled() );
413 public void testStoreConfigurationFailsWhenReadFromBothLocationsNoLists()
416 File baseFile = getTestFile( "target/test/test-file.xml" );
418 assertFalse( baseFile.exists() );
420 File userFile = getTestFile( "target/test/test-file-user.xml" );
422 assertFalse( userFile.exists() );
424 baseFile.getParentFile().mkdirs();
425 FileUtils.writeStringToFile( baseFile, "<configuration/>", null );
427 userFile.getParentFile().mkdirs();
428 FileUtils.writeStringToFile( userFile, "<configuration/>", null );
430 ArchivaConfiguration archivaConfiguration =
431 (ArchivaConfiguration) lookup( ArchivaConfiguration.class, "test-save-user" );
433 archivaConfiguration.reload();
435 Configuration configuration = archivaConfiguration.getConfiguration();
436 assertTrue( "check value", configuration.getWebapp().getUi().isAppletFindEnabled() );
438 configuration.getWebapp().getUi().setAppletFindEnabled( 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().isAppletFindEnabled() );
455 public void testStoreConfigurationFailsWhenReadFromBothLocationsUserHasLists()
458 File baseFile = getTestFile( "target/test/test-file.xml" );
460 assertFalse( baseFile.exists() );
462 File userFile = getTestFile( "target/test/test-file-user.xml" );
464 assertFalse( userFile.exists() );
466 userFile.getParentFile().mkdirs();
467 FileUtils.copyFile( getTestFile( "src/test/conf/conf-user.xml" ), userFile );
469 baseFile.getParentFile().mkdirs();
470 FileUtils.writeStringToFile( baseFile, "<configuration/>", null );
472 ArchivaConfiguration archivaConfiguration =
473 (ArchivaConfiguration) lookup( ArchivaConfiguration.class, "test-save-user" );
475 archivaConfiguration.reload();
477 Configuration configuration = archivaConfiguration.getConfiguration();
478 assertTrue( "check value", configuration.getWebapp().getUi().isShowFindArtifacts() );
480 configuration.getWebapp().getUi().setShowFindArtifacts( false );
482 archivaConfiguration.save( configuration );
484 assertTrue( "Check file exists", baseFile.exists() );
485 assertEquals( "Check base file is unchanged", "<configuration/>",
486 FileUtils.readFileToString( baseFile, null ) );
487 assertTrue( "Check file exists", userFile.exists() );
488 assertFalse( "Check base file is changed",
489 "<configuration/>".equals( FileUtils.readFileToString( userFile, null ) ) );
492 configuration = archivaConfiguration.getConfiguration();
493 assertFalse( "check value", configuration.getWebapp().getUi().isShowFindArtifacts() );
497 public void testStoreConfigurationFailsWhenReadFromBothLocationsAppserverHasLists()
500 File baseFile = getTestFile( "target/test/test-file.xml" );
502 assertFalse( baseFile.exists() );
504 File userFile = getTestFile( "target/test/test-file-user.xml" );
506 assertFalse( userFile.exists() );
508 baseFile.getParentFile().mkdirs();
509 FileUtils.copyFile( getTestFile( "src/test/conf/conf-base.xml" ), baseFile );
511 userFile.getParentFile().mkdirs();
512 FileUtils.writeStringToFile( userFile, "<configuration/>", null );
514 ArchivaConfiguration archivaConfiguration =
515 (ArchivaConfiguration) lookup( ArchivaConfiguration.class, "test-save-user" );
517 archivaConfiguration.reload();
519 Configuration configuration = archivaConfiguration.getConfiguration();
520 assertTrue( "check value", configuration.getWebapp().getUi().isAppletFindEnabled() );
522 configuration.getWebapp().getUi().setAppletFindEnabled( false );
526 archivaConfiguration.save( configuration );
527 fail( "Configuration saving should not succeed if it was loaded from two locations" );
529 catch ( IndeterminateConfigurationException e )
531 // check it was reverted
532 configuration = archivaConfiguration.getConfiguration();
533 assertTrue( "check value", configuration.getWebapp().getUi().isAppletFindEnabled() );
538 public void testLoadConfigurationFromInvalidBothLocationsOnDisk()
541 ArchivaConfiguration archivaConfiguration =
542 lookup( ArchivaConfiguration.class, "test-not-allowed-to-write-to-both" );
543 Configuration config = archivaConfiguration.getConfiguration();
547 archivaConfiguration.save( config );
548 fail( "Should have thrown a RegistryException because the configuration can't be saved." );
550 catch ( RegistryException e )
552 /* expected exception */
557 public void testLoadConfigurationFromInvalidUserLocationOnDisk()
560 File testConfDir = getTestFile( "target/test-appserver-base/conf/" );
561 testConfDir.mkdirs();
563 ArchivaConfiguration archivaConfiguration =
564 lookup( ArchivaConfiguration.class, "test-not-allowed-to-write-to-user" );
565 Configuration config = archivaConfiguration.getConfiguration();
566 archivaConfiguration.save( config );
567 // No Exception == test passes.
568 // Expected Path is: Should not have thrown an exception.
572 public void testConfigurationUpgradeFrom09()
575 ArchivaConfiguration archivaConfiguration = lookup( ArchivaConfiguration.class, "test-upgrade-09" );
577 // we just use the defaults when upgrading from 0.9 at this point.
578 Configuration configuration = archivaConfiguration.getConfiguration();
579 // test-upgrade-09 contains a managed with id: local so it's 3 managed
580 assertConfiguration( configuration, 3, 1, 1 );
581 assertEquals( "check network proxies", 0, configuration.getNetworkProxies().size() );
583 ManagedRepositoryConfiguration repository = configuration.getManagedRepositories().get( 0 );
585 assertEquals( "check managed repositories", "${appserver.base}/data/repositories/internal",
586 repository.getLocation() );
587 assertEquals( "check managed repositories", "Archiva Managed Internal Repository", repository.getName() );
588 assertEquals( "check managed repositories", "internal", repository.getId() );
589 assertEquals( "check managed repositories", "default", repository.getLayout() );
590 assertTrue( "check managed repositories", repository.isScanned() );
594 public void testConfigurationUpgradeFrom13()
597 ArchivaConfiguration archivaConfiguration = lookup( ArchivaConfiguration.class, "test-upgrade-1.3" );
599 // we just use the defaults when upgrading from 1.3 at this point.
600 Configuration configuration = archivaConfiguration.getConfiguration();
601 assertConfiguration( configuration, 2, 2, 2 );
602 assertEquals( "check network proxies", 0, configuration.getNetworkProxies().size() );
604 ManagedRepositoryConfiguration repository = configuration.getManagedRepositories().get( 0 );
606 assertEquals( "check managed repositories", "${appserver.base}/data/repositories/internal",
607 repository.getLocation() );
608 assertEquals( "check managed repositories", "Archiva Managed Internal Repository", repository.getName() );
609 assertEquals( "check managed repositories", "internal", repository.getId() );
610 assertEquals( "check managed repositories", "default", repository.getLayout() );
611 assertTrue( "check managed repositories", repository.isScanned() );
613 log.info( "knowContentConsumers " + configuration.getRepositoryScanning().getKnownContentConsumers() );
616 configuration.getRepositoryScanning().getKnownContentConsumers().contains( "update-db-artifact" ) );
617 assertFalse( configuration.getRepositoryScanning().getKnownContentConsumers().contains(
618 "update-db-repository-metadata" ) );
621 configuration.getRepositoryScanning().getKnownContentConsumers().contains( "create-archiva-metadata" ) );
624 configuration.getRepositoryScanning().getKnownContentConsumers().contains( "duplicate-artifacts" ) );
628 public void testAutoDetectV1()
631 // Setup the autodetect-v1.xml file in the target directory (so we can save/load it)
632 File userFile = getTestFile( "target/test-autodetect-v1/archiva-user.xml" );
634 assertFalse( userFile.exists() );
636 userFile.getParentFile().mkdirs();
637 FileUtils.copyFile( getTestFile( "src/test/conf/autodetect-v1.xml" ), userFile );
639 // Load the original (unconverted) archiva.xml
640 ArchivaConfiguration archivaConfiguration = lookup( ArchivaConfiguration.class, "test-autodetect-v1" );
642 archivaConfiguration.reload();
644 Configuration configuration = archivaConfiguration.getConfiguration();
645 assertConfiguration( configuration, 2, 2, 2 );
646 assertEquals( "check network proxies", 1, configuration.getNetworkProxies().size() );
648 ManagedRepositoryConfiguration repository = configuration.getManagedRepositories().get( 0 );
650 assertEquals( "check managed repositories", "${appserver.base}/repositories/internal",
651 repository.getLocation() );
652 assertEquals( "check managed repositories", "Archiva Managed Internal Repository", repository.getName() );
653 assertEquals( "check managed repositories", "internal", repository.getId() );
654 assertEquals( "check managed repositories", "default", repository.getLayout() );
655 assertTrue( "check managed repositories", repository.isScanned() );
657 // Test that only 1 set of repositories exist.
658 assertEquals( "check managed repositories size.", 2, configuration.getManagedRepositories().size() );
659 assertEquals( "check remote repositories size.", 2, configuration.getRemoteRepositories().size() );
660 assertEquals( "check v1 repositories size.", 0, configuration.getRepositories().size() );
663 archivaConfiguration.save( configuration );
666 //release( archivaConfiguration );
669 archivaConfiguration = lookup( ArchivaConfiguration.class, "test-autodetect-v1" );
670 configuration = archivaConfiguration.getConfiguration();
672 // Test that only 1 set of repositories exist.
673 assertEquals( "check managed repositories size.", 2, configuration.getManagedRepositories().size() );
674 assertEquals( "check managed repositories size.", 2, configuration.getManagedRepositoriesAsMap().size() );
675 assertEquals( "check remote repositories size.", 2, configuration.getRemoteRepositories().size() );
676 assertEquals( "check remote repositories size.", 2, configuration.getRemoteRepositoriesAsMap().size() );
677 assertEquals( "check v1 repositories size.", 0, configuration.getRepositories().size() );
679 String actualXML = FileUtils.readFileToString( userFile, null );
680 XMLAssert.assertXpathNotExists( "//configuration/repositories/repository", actualXML );
681 XMLAssert.assertXpathNotExists( "//configuration/repositories", actualXML );
685 public void testArchivaV1()
688 ArchivaConfiguration archivaConfiguration = lookup( ArchivaConfiguration.class, "test-archiva-v1" );
690 Configuration configuration = archivaConfiguration.getConfiguration();
691 assertConfiguration( configuration, 2, 2, 2 );
692 assertEquals( "check network proxies", 1, configuration.getNetworkProxies().size() );
694 assertEquals( "check managed repositories", 2, configuration.getManagedRepositories().size() );
695 assertEquals( "check v1 repositories size.", 0, configuration.getRepositories().size() );
697 Map<String, ManagedRepositoryConfiguration> map = configuration.getManagedRepositoriesAsMap();
699 ManagedRepositoryConfiguration repository = map.get( "internal" );
700 assertEquals( "check managed repositories", "${appserver.base}/repositories/internal",
701 repository.getLocation() );
702 assertEquals( "check managed repositories", "Archiva Managed Internal Repository", repository.getName() );
703 assertEquals( "check managed repositories", "internal", repository.getId() );
704 assertEquals( "check managed repositories", "default", repository.getLayout() );
705 assertTrue( "check managed repositories", repository.isScanned() );
706 assertFalse( "check managed repositories", repository.isSnapshots() );
708 repository = map.get( "snapshots" );
709 assertEquals( "check managed repositories", "${appserver.base}/repositories/snapshots",
710 repository.getLocation() );
711 assertEquals( "check managed repositories", "Archiva Managed Snapshot Repository", repository.getName() );
712 assertEquals( "check managed repositories", "snapshots", repository.getId() );
713 assertEquals( "check managed repositories", "default", repository.getLayout() );
714 assertFalse( "check managed repositories", repository.isScanned() );
715 assertTrue( "check managed repositories", repository.isSnapshots() );
719 public void testCronExpressionsWithComma()
722 File baseFile = getTestFile( "target/test/test-file.xml" );
724 assertFalse( baseFile.exists() );
726 File userFile = getTestFile( "target/test/test-file-user.xml" );
728 assertFalse( userFile.exists() );
730 baseFile.getParentFile().mkdirs();
731 FileUtils.copyFile( getTestFile( "src/test/conf/escape-cron-expressions.xml" ), baseFile );
733 userFile.getParentFile().mkdirs();
734 FileUtils.writeStringToFile( userFile, "<configuration/>", null );
736 final ArchivaConfiguration archivaConfiguration = lookup( ArchivaConfiguration.class, "test-cron-expressions" );
738 archivaConfiguration.reload();
740 Configuration configuration = archivaConfiguration.getConfiguration();
742 ManagedRepositoryConfiguration repository = configuration.getManagedRepositories().get( 0 );
744 assertEquals( "check cron expression", "0 0,30 * * * ?", repository.getRefreshCronExpression().trim() );
746 // add a test listener to confirm it doesn't see the escaped format. We don't need to test the number of calls,
747 // etc. as it's done in other tests
748 archivaConfiguration.addListener( new ConfigurationListener()
750 public void configurationEvent( ConfigurationEvent event )
752 assertEquals( ConfigurationEvent.SAVED, event.getType() );
757 archivaConfiguration.save( configuration );
759 configuration = archivaConfiguration.getConfiguration();
761 // test for the escape character '\' showing up on repositories.jsp
762 repository.setRefreshCronExpression( "0 0,20 0 * * ?" );
764 archivaConfiguration.save( configuration );
766 repository = archivaConfiguration.getConfiguration().findManagedRepositoryById( "snapshots" );
768 assertEquals( "check cron expression", "0 0,20 0 * * ?", repository.getRefreshCronExpression() );
772 public void testRemoveLastElements()
775 File baseFile = getTestFile( "target/test/test-file.xml" );
777 assertFalse( baseFile.exists() );
779 File userFile = getTestFile( "target/test/test-file-user.xml" );
781 assertFalse( userFile.exists() );
783 baseFile.getParentFile().mkdirs();
784 FileUtils.copyFile( getTestFile( "src/test/conf/conf-single-list-elements.xml" ), baseFile );
786 userFile.getParentFile().mkdirs();
787 FileUtils.writeStringToFile( userFile, "<configuration/>", null );
789 ArchivaConfiguration archivaConfiguration = lookup( ArchivaConfiguration.class, "test-remove-central" );
791 archivaConfiguration.reload();
793 Configuration configuration = archivaConfiguration.getConfiguration();
795 RepositoryGroupConfiguration repositoryGroup = configuration.getRepositoryGroups().get( 0 );
796 assertNotNull( repositoryGroup );
797 configuration.removeRepositoryGroup( repositoryGroup );
798 assertTrue( configuration.getRepositoryGroups().isEmpty() );
800 RemoteRepositoryConfiguration repository = configuration.getRemoteRepositoriesAsMap().get( "central" );
801 assertNotNull( repository );
802 configuration.removeRemoteRepository( repository );
803 assertTrue( configuration.getRemoteRepositories().isEmpty() );
805 ManagedRepositoryConfiguration managedRepository =
806 configuration.getManagedRepositoriesAsMap().get( "snapshots" );
807 assertNotNull( managedRepository );
808 configuration.removeManagedRepository( managedRepository );
809 assertTrue( configuration.getManagedRepositories().isEmpty() );
811 ProxyConnectorConfiguration proxyConnector = configuration.getProxyConnectors().get( 0 );
812 assertNotNull( proxyConnector );
813 configuration.removeProxyConnector( proxyConnector );
814 assertTrue( configuration.getProxyConnectors().isEmpty() );
816 NetworkProxyConfiguration networkProxy = configuration.getNetworkProxiesAsMap().get( "proxy" );
817 assertNotNull( networkProxy );
818 configuration.removeNetworkProxy( networkProxy );
819 assertTrue( configuration.getNetworkProxies().isEmpty() );
821 LegacyArtifactPath path = configuration.getLegacyArtifactPaths().get( 0 );
822 assertNotNull( path );
823 configuration.removeLegacyArtifactPath( path );
824 assertTrue( configuration.getLegacyArtifactPaths().isEmpty() );
826 RepositoryScanningConfiguration scanning = configuration.getRepositoryScanning();
827 String consumer = scanning.getKnownContentConsumers().get( 0 );
828 assertNotNull( consumer );
829 scanning.removeKnownContentConsumer( consumer );
831 assertFalse( scanning.getKnownContentConsumers().isEmpty() );
832 consumer = scanning.getInvalidContentConsumers().get( 0 );
833 assertNotNull( consumer );
834 scanning.removeInvalidContentConsumer( consumer );
835 assertTrue( scanning.getInvalidContentConsumers().isEmpty() );
837 archivaConfiguration.save( configuration );
839 archivaConfiguration = lookup( ArchivaConfiguration.class, "test-read-saved" );
840 configuration = archivaConfiguration.getConfiguration();
841 assertNull( configuration.getRemoteRepositoriesAsMap().get( "central" ) );
842 assertTrue( configuration.getRepositoryGroups().isEmpty() );
843 assertNull( configuration.getManagedRepositoriesAsMap().get( "snapshots" ) );
844 assertTrue( configuration.getProxyConnectors().isEmpty() );
845 assertNull( configuration.getNetworkProxiesAsMap().get( "proxy" ) );
846 assertTrue( configuration.getLegacyArtifactPaths().isEmpty() );
847 scanning = configuration.getRepositoryScanning();
848 assertFalse( scanning.getKnownContentConsumers().isEmpty() );
849 assertTrue( scanning.getInvalidContentConsumers().isEmpty() );
853 * [MRM-582] Remote Repositories with empty <username> and <password> fields shouldn't be created in configuration.
856 public void testGetConfigurationFixEmptyRemoteRepoUsernamePassword()
859 ArchivaConfiguration archivaConfiguration = lookup( ArchivaConfiguration.class, "test-configuration" );
861 archivaConfiguration.reload();
862 Configuration configuration = archivaConfiguration.getConfiguration();
863 assertConfiguration( configuration, 2, 2, 2 );
864 assertEquals( "check remote repositories", 2, configuration.getRemoteRepositories().size() );
866 RemoteRepositoryConfiguration repository =
867 configuration.getRemoteRepositoriesAsMap().get( "maven2-repository.dev.java.net" );
869 assertEquals( "remote repository.url", "https://maven2-repository.dev.java.net/nonav/repository",
870 repository.getUrl() );
871 assertEquals( "remote repository.name", "Java.net Repository for Maven 2", repository.getName() );
872 assertEquals( "remote repository.id", "maven2-repository.dev.java.net", repository.getId() );
873 assertEquals( "remote repository.layout", "default", repository.getLayout() );
874 assertNull( "remote repository.username == null", repository.getUsername() );
875 assertNull( "remote repository.password == null", repository.getPassword() );