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.commons.io.FileUtils;
25 import org.apache.commons.lang.StringUtils;
26 import org.codehaus.plexus.registry.RegistryException;
27 import org.codehaus.redback.components.springutils.ComponentContainer;
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 =
96 (ArchivaConfiguration) lookup( ArchivaConfiguration.class, "test-defaults" );
98 Configuration configuration = archivaConfiguration.getConfiguration( );
99 assertConfiguration( configuration, 2, 1, 1 );
100 assertEquals( "check network proxies", 0, configuration.getNetworkProxies( ).size( ) );
102 ManagedRepositoryConfiguration repository =
103 (ManagedRepositoryConfiguration) configuration.getManagedRepositories( ).get( 0 );
105 assertEquals( "check managed repositories", "${appserver.base}/data/repositories/internal",
106 repository.getLocation( ) );
107 assertEquals( "check managed repositories", "Archiva Managed Internal Repository", repository.getName( ) );
108 assertEquals( "check managed repositories", "internal", repository.getId( ) );
109 assertEquals( "check managed repositories", "default", repository.getLayout( ) );
110 assertTrue( "check managed repositories", repository.isScanned( ) );
113 // test for [MRM-789]
115 public void testGetConfigurationFromDefaultsWithDefaultRepoLocationAlreadyExisting( )
118 File repo = new File( FileUtil.getBasedir( ), "/target/test-classes/existing_snapshots" );
121 repo = new File( FileUtil.getBasedir( ), "/target/test-classes/existing_internal" );
124 String existingTestDefaultArchivaConfigFile = FileUtils.readFileToString(
125 getTestFile( "target/test-classes/org/apache/archiva/configuration/test-default-archiva.xml" ) );
126 existingTestDefaultArchivaConfigFile =
127 StringUtils.replace( existingTestDefaultArchivaConfigFile, "${appserver.base}", FileUtil.getBasedir( ) );
129 File generatedTestDefaultArchivaConfigFile = new File( FileUtil.getBasedir( ),
130 "target/test-classes/org/apache/archiva/configuration/default-archiva.xml" );
132 FileUtils.writeStringToFile( generatedTestDefaultArchivaConfigFile, existingTestDefaultArchivaConfigFile,
135 ArchivaConfiguration archivaConfiguration =
136 lookup( ArchivaConfiguration.class, "test-defaults-default-repo-location-exists" );
138 Configuration configuration = archivaConfiguration.getConfiguration( );
139 assertConfiguration( configuration, 2, 1, 1 );
141 ManagedRepositoryConfiguration repository =
142 (ManagedRepositoryConfiguration) configuration.getManagedRepositories( ).get( 0 );
143 assertTrue( "check managed repositories", repository.getLocation( ).endsWith( "data/repositories/internal" ) );
145 generatedTestDefaultArchivaConfigFile.delete( );
146 assertFalse( generatedTestDefaultArchivaConfigFile.exists( ) );
149 private void assertConfiguration( Configuration configuration )
152 assertConfiguration( configuration, 2, 2, 1 );
156 * Ensures that the provided configuration matches the details present in the archiva-default.xml file.
158 private void assertConfiguration( Configuration configuration, int managedExpected, int remoteExpected,
159 int proxyConnectorExpected )
162 FileTypes filetypes = lookup( FileTypes.class );
164 assertEquals( "check managed repositories: " + configuration.getManagedRepositories( ), managedExpected,
165 configuration.getManagedRepositories( ).size( ) );
166 assertEquals( "check remote repositories: " + configuration.getRemoteRepositories( ), remoteExpected,
167 configuration.getRemoteRepositories( ).size( ) );
168 assertEquals( "check proxy connectors:" + configuration.getProxyConnectors( ), proxyConnectorExpected,
169 configuration.getProxyConnectors( ).size( ) );
171 RepositoryScanningConfiguration repoScanning = configuration.getRepositoryScanning( );
172 assertNotNull( "check repository scanning", repoScanning );
173 assertEquals( "check file types", 4, repoScanning.getFileTypes( ).size( ) );
174 assertEquals( "check known consumers", 9, repoScanning.getKnownContentConsumers( ).size( ) );
175 assertEquals( "check invalid consumers", 1, repoScanning.getInvalidContentConsumers( ).size( ) );
177 List<String> patterns = filetypes.getFileTypePatterns( "artifacts" );
178 assertNotNull( "check 'artifacts' file type", patterns );
179 assertEquals( "check 'artifacts' patterns", 13, patterns.size( ) );
181 WebappConfiguration webapp = configuration.getWebapp( );
182 assertNotNull( "check webapp", webapp );
184 UserInterfaceOptions ui = webapp.getUi( );
185 assertNotNull( "check webapp ui", ui );
186 assertTrue( "check showFindArtifacts", ui.isShowFindArtifacts( ) );
187 assertTrue( "check appletFindEnabled", ui.isAppletFindEnabled( ) );
191 public void testGetConfigurationFromRegistryWithTwoConfigurationResources( )
194 ArchivaConfiguration archivaConfiguration = lookup( ArchivaConfiguration.class, "test-configuration-both" );
196 Configuration configuration = archivaConfiguration.getConfiguration( );
199 assertEquals( "check repositories", 2, configuration.getManagedRepositories( ).size( ) );
200 assertEquals( "check repositories", 2, configuration.getRemoteRepositories( ).size( ) );
202 assertEquals( "check proxy connectors", 2, configuration.getProxyConnectors( ).size( ) );
204 WebappConfiguration webapp = configuration.getWebapp( );
205 assertNotNull( "check webapp", webapp );
207 UserInterfaceOptions ui = webapp.getUi( );
208 assertNotNull( "check webapp ui", ui );
210 assertFalse( "check showFindArtifacts", ui.isShowFindArtifacts( ) );
212 assertFalse( "check appletFindEnabled", ui.isAppletFindEnabled( ) );
216 public void testGetConfigurationSystemOverride( )
220 System.setProperty( "org.apache.archiva.webapp.ui.appletFindEnabled", "false" );
222 ArchivaConfiguration archivaConfiguration = lookup( ArchivaConfiguration.class, "test-configuration" );
224 archivaConfiguration.reload( );
228 Configuration configuration = archivaConfiguration.getConfiguration( );
230 assertFalse( "check boolean", configuration.getWebapp( ).getUi( ).isAppletFindEnabled( ) );
234 System.getProperties( ).remove( "org.apache.archiva.webapp.ui.appletFindEnabled" );
239 public void testStoreConfiguration( )
242 File file = getTestFile( "target/test/test-file.xml" );
244 assertFalse( file.exists( ) );
246 // TODO: remove with commons-configuration 1.4
247 //file.getParentFile().mkdirs();
248 //FileUtils.writeStringToFile( file, "<configuration/>", null );
250 DefaultArchivaConfiguration archivaConfiguration =
251 (DefaultArchivaConfiguration) lookup( ArchivaConfiguration.class, "test-save" );
253 archivaConfiguration.reload( );
255 Configuration configuration = new Configuration( );
256 configuration.setVersion( "1" );
257 configuration.setWebapp( new WebappConfiguration( ) );
258 configuration.getWebapp( ).setUi( new UserInterfaceOptions( ) );
259 configuration.getWebapp( ).getUi( ).setAppletFindEnabled( false );
261 // add a change listener
262 MockControl control = createConfigurationListenerMockControl( );
263 ConfigurationListener listener = (ConfigurationListener) control.getMock( );
264 archivaConfiguration.addListener( listener );
266 listener.configurationEvent( new ConfigurationEvent( ConfigurationEvent.SAVED ) );
267 control.setVoidCallable( );
271 archivaConfiguration.save( configuration );
275 assertTrue( "Check file exists", file.exists( ) );
278 configuration = archivaConfiguration.getConfiguration( );
279 assertFalse( "check value", configuration.getWebapp( ).getUi( ).isAppletFindEnabled( ) );
282 archivaConfiguration = (DefaultArchivaConfiguration) lookup( ArchivaConfiguration.class, "test-read-saved" );
284 archivaConfiguration.reload( );
285 configuration = archivaConfiguration.getConfiguration( );
286 assertFalse( "check value", configuration.getWebapp( ).getUi( ).isAppletFindEnabled( ) );
289 private static MockControl createConfigurationListenerMockControl( )
291 return MockControl.createControl( ConfigurationListener.class );
295 public void testStoreConfigurationUser( )
298 File baseFile = getTestFile( "target/test/test-file.xml" );
300 assertFalse( baseFile.exists( ) );
302 File userFile = getTestFile( "target/test/test-file-user.xml" );
304 assertFalse( userFile.exists( ) );
306 userFile.getParentFile( ).mkdirs( );
307 FileUtils.writeStringToFile( userFile, "<configuration/>", null );
309 ArchivaConfiguration archivaConfiguration =
310 (ArchivaConfiguration) lookup( ArchivaConfiguration.class, "test-save-user" );
312 Configuration configuration = new Configuration( );
313 configuration.setWebapp( new WebappConfiguration( ) );
314 configuration.getWebapp( ).setUi( new UserInterfaceOptions( ) );
315 configuration.getWebapp( ).getUi( ).setAppletFindEnabled( false );
317 archivaConfiguration.save( configuration );
319 assertTrue( "Check file exists", userFile.exists( ) );
320 assertFalse( "Check file not created", baseFile.exists( ) );
323 configuration = archivaConfiguration.getConfiguration( );
324 assertFalse( "check value", configuration.getWebapp( ).getUi( ).isAppletFindEnabled( ) );
328 public void testStoreConfigurationLoadedFromDefaults( )
331 File baseFile = getTestFile( "target/test/test-file.xml" );
333 assertFalse( baseFile.exists( ) );
335 File userFile = getTestFile( "target/test/test-file-user.xml" );
337 assertFalse( userFile.exists( ) );
339 ArchivaConfiguration archivaConfiguration =
340 (ArchivaConfiguration) lookup( ArchivaConfiguration.class, "test-save-user-defaults" );
342 archivaConfiguration.reload( );
344 Configuration configuration = new Configuration( );
345 configuration.setWebapp( new WebappConfiguration( ) );
346 configuration.getWebapp( ).setUi( new UserInterfaceOptions( ) );
347 configuration.getWebapp( ).getUi( ).setAppletFindEnabled( false );
349 // add a change listener
350 MockControl control = createConfigurationListenerMockControl( );
351 ConfigurationListener listener = (ConfigurationListener) control.getMock( );
352 archivaConfiguration.addListener( listener );
354 listener.configurationEvent( new ConfigurationEvent( ConfigurationEvent.SAVED ) );
356 control.setVoidCallable( 1 );
360 archivaConfiguration.save( configuration );
364 assertTrue( "Check file exists", userFile.exists( ) );
365 assertFalse( "Check file not created", baseFile.exists( ) );
368 configuration = archivaConfiguration.getConfiguration( );
369 assertFalse( "check value", configuration.getWebapp( ).getUi( ).isAppletFindEnabled( ) );
373 public void testDefaultUserConfigFilename( )
376 DefaultArchivaConfiguration archivaConfiguration =
377 (DefaultArchivaConfiguration) lookup( ArchivaConfiguration.class, "default" );
379 archivaConfiguration.reload( );
381 assertEquals( System.getProperty( "user.home" ) + "/.m2/archiva.xml",
382 archivaConfiguration.getUserConfigFilename( ) );
383 assertEquals( System.getProperty( "appserver.base", "${appserver.base}" ) + "/conf/archiva.xml",
384 archivaConfiguration.getAltConfigFilename( ) );
388 public void testStoreConfigurationFallback( )
391 File baseFile = getTestFile( "target/test/test-file.xml" );
393 assertFalse( baseFile.exists( ) );
395 File userFile = getTestFile( "target/test/test-file-user.xml" );
397 assertFalse( userFile.exists( ) );
399 baseFile.getParentFile( ).mkdirs( );
400 FileUtils.writeStringToFile( baseFile, "<configuration/>", null );
402 ArchivaConfiguration archivaConfiguration =
403 (ArchivaConfiguration) lookup( ArchivaConfiguration.class, "test-save-user-fallback" );
405 archivaConfiguration.reload( );
407 Configuration configuration = new Configuration( );
408 configuration.setWebapp( new WebappConfiguration( ) );
409 configuration.getWebapp( ).setUi( new UserInterfaceOptions( ) );
410 configuration.getWebapp( ).getUi( ).setAppletFindEnabled( false );
412 archivaConfiguration.save( configuration );
414 assertTrue( "Check file exists", baseFile.exists( ) );
415 assertFalse( "Check file not created", userFile.exists( ) );
418 configuration = archivaConfiguration.getConfiguration( );
419 assertFalse( "check value", configuration.getWebapp( ).getUi( ).isAppletFindEnabled( ) );
423 public void testStoreConfigurationFailsWhenReadFromBothLocationsNoLists( )
426 File baseFile = getTestFile( "target/test/test-file.xml" );
428 assertFalse( baseFile.exists( ) );
430 File userFile = getTestFile( "target/test/test-file-user.xml" );
432 assertFalse( userFile.exists( ) );
434 baseFile.getParentFile( ).mkdirs( );
435 FileUtils.writeStringToFile( baseFile, "<configuration/>", null );
437 userFile.getParentFile( ).mkdirs( );
438 FileUtils.writeStringToFile( userFile, "<configuration/>", null );
440 ArchivaConfiguration archivaConfiguration =
441 (ArchivaConfiguration) lookup( ArchivaConfiguration.class, "test-save-user" );
443 archivaConfiguration.reload( );
445 Configuration configuration = archivaConfiguration.getConfiguration( );
446 assertTrue( "check value", configuration.getWebapp( ).getUi( ).isAppletFindEnabled( ) );
448 configuration.getWebapp( ).getUi( ).setAppletFindEnabled( false );
450 archivaConfiguration.save( configuration );
452 assertTrue( "Check file exists", baseFile.exists( ) );
453 assertEquals( "Check base file is unchanged", "<configuration/>",
454 FileUtils.readFileToString( baseFile, null ) );
455 assertTrue( "Check file exists", userFile.exists( ) );
456 assertFalse( "Check base file is changed",
457 "<configuration/>".equals( FileUtils.readFileToString( userFile, null ) ) );
460 configuration = archivaConfiguration.getConfiguration( );
461 assertFalse( "check value", configuration.getWebapp( ).getUi( ).isAppletFindEnabled( ) );
465 public void testStoreConfigurationFailsWhenReadFromBothLocationsUserHasLists( )
468 File baseFile = getTestFile( "target/test/test-file.xml" );
470 assertFalse( baseFile.exists( ) );
472 File userFile = getTestFile( "target/test/test-file-user.xml" );
474 assertFalse( userFile.exists( ) );
476 userFile.getParentFile( ).mkdirs( );
477 FileUtils.copyFile( getTestFile( "src/test/conf/conf-user.xml" ), userFile );
479 baseFile.getParentFile( ).mkdirs( );
480 FileUtils.writeStringToFile( baseFile, "<configuration/>", null );
482 ArchivaConfiguration archivaConfiguration =
483 (ArchivaConfiguration) lookup( ArchivaConfiguration.class, "test-save-user" );
485 archivaConfiguration.reload( );
487 Configuration configuration = archivaConfiguration.getConfiguration( );
488 assertTrue( "check value", configuration.getWebapp( ).getUi( ).isShowFindArtifacts( ) );
490 configuration.getWebapp( ).getUi( ).setShowFindArtifacts( false );
492 archivaConfiguration.save( configuration );
494 assertTrue( "Check file exists", baseFile.exists( ) );
495 assertEquals( "Check base file is unchanged", "<configuration/>",
496 FileUtils.readFileToString( baseFile, null ) );
497 assertTrue( "Check file exists", userFile.exists( ) );
498 assertFalse( "Check base file is changed",
499 "<configuration/>".equals( FileUtils.readFileToString( userFile, null ) ) );
502 configuration = archivaConfiguration.getConfiguration( );
503 assertFalse( "check value", configuration.getWebapp( ).getUi( ).isShowFindArtifacts( ) );
507 public void testStoreConfigurationFailsWhenReadFromBothLocationsAppserverHasLists( )
510 File baseFile = getTestFile( "target/test/test-file.xml" );
512 assertFalse( baseFile.exists( ) );
514 File userFile = getTestFile( "target/test/test-file-user.xml" );
516 assertFalse( userFile.exists( ) );
518 baseFile.getParentFile( ).mkdirs( );
519 FileUtils.copyFile( getTestFile( "src/test/conf/conf-base.xml" ), baseFile );
521 userFile.getParentFile( ).mkdirs( );
522 FileUtils.writeStringToFile( userFile, "<configuration/>", null );
524 ArchivaConfiguration archivaConfiguration =
525 (ArchivaConfiguration) lookup( ArchivaConfiguration.class, "test-save-user" );
527 archivaConfiguration.reload( );
529 Configuration configuration = archivaConfiguration.getConfiguration( );
530 assertTrue( "check value", configuration.getWebapp( ).getUi( ).isAppletFindEnabled( ) );
532 configuration.getWebapp( ).getUi( ).setAppletFindEnabled( false );
536 archivaConfiguration.save( configuration );
537 fail( "Configuration saving should not succeed if it was loaded from two locations" );
539 catch ( IndeterminateConfigurationException e )
541 // check it was reverted
542 configuration = archivaConfiguration.getConfiguration( );
543 assertTrue( "check value", configuration.getWebapp( ).getUi( ).isAppletFindEnabled( ) );
548 public void testLoadConfigurationFromInvalidBothLocationsOnDisk( )
551 ArchivaConfiguration archivaConfiguration =
552 (ArchivaConfiguration) lookup( ArchivaConfiguration.class, "test-not-allowed-to-write-to-both" );
553 Configuration config = archivaConfiguration.getConfiguration( );
557 archivaConfiguration.save( config );
558 fail( "Should have thrown a RegistryException because the configuration can't be saved." );
560 catch ( RegistryException e )
562 /* expected exception */
567 public void testLoadConfigurationFromInvalidUserLocationOnDisk( )
570 File testConfDir = getTestFile( "target/test-appserver-base/conf/" );
571 testConfDir.mkdirs( );
573 ArchivaConfiguration archivaConfiguration =
574 (ArchivaConfiguration) lookup( ArchivaConfiguration.class, "test-not-allowed-to-write-to-user" );
575 Configuration config = archivaConfiguration.getConfiguration( );
576 archivaConfiguration.save( config );
577 // No Exception == test passes.
578 // Expected Path is: Should not have thrown an exception.
582 public void testConfigurationUpgradeFrom09( )
585 ArchivaConfiguration archivaConfiguration = lookup( ArchivaConfiguration.class, "test-upgrade-09" );
587 // we just use the defaults when upgrading from 0.9 at this point.
588 Configuration configuration = archivaConfiguration.getConfiguration( );
589 // test-upgrade-09 contains a managed with id: local so it's 3 managed
590 assertConfiguration( configuration, 3, 1, 1 );
591 assertEquals( "check network proxies", 0, configuration.getNetworkProxies( ).size( ) );
593 ManagedRepositoryConfiguration repository = configuration.getManagedRepositories( ).get( 0 );
595 assertEquals( "check managed repositories", "${appserver.base}/data/repositories/internal",
596 repository.getLocation( ) );
597 assertEquals( "check managed repositories", "Archiva Managed Internal Repository", repository.getName( ) );
598 assertEquals( "check managed repositories", "internal", repository.getId( ) );
599 assertEquals( "check managed repositories", "default", repository.getLayout( ) );
600 assertTrue( "check managed repositories", repository.isScanned( ) );
604 public void testConfigurationUpgradeFrom13( )
607 ArchivaConfiguration archivaConfiguration = lookup( ArchivaConfiguration.class, "test-upgrade-1.3" );
609 // we just use the defaults when upgrading from 1.3 at this point.
610 Configuration configuration = archivaConfiguration.getConfiguration( );
611 assertConfiguration( configuration, 2, 2, 2 );
612 assertEquals( "check network proxies", 0, configuration.getNetworkProxies( ).size( ) );
614 ManagedRepositoryConfiguration repository = configuration.getManagedRepositories( ).get( 0 );
616 assertEquals( "check managed repositories", "${appserver.base}/data/repositories/internal",
617 repository.getLocation( ) );
618 assertEquals( "check managed repositories", "Archiva Managed Internal Repository", repository.getName( ) );
619 assertEquals( "check managed repositories", "internal", repository.getId( ) );
620 assertEquals( "check managed repositories", "default", repository.getLayout( ) );
621 assertTrue( "check managed repositories", repository.isScanned( ) );
623 log.info( "knowContentConsumers " + configuration.getRepositoryScanning( ).getKnownContentConsumers( ) );
626 configuration.getRepositoryScanning( ).getKnownContentConsumers( ).contains( "update-db-artifact" ) );
627 assertFalse( configuration.getRepositoryScanning( ).getKnownContentConsumers( ).contains(
628 "update-db-repository-metadata" ) );
631 configuration.getRepositoryScanning( ).getKnownContentConsumers( ).contains( "create-archiva-metadata" ) );
634 configuration.getRepositoryScanning( ).getKnownContentConsumers( ).contains( "duplicate-artifacts" ) );
638 public void testAutoDetectV1( )
641 // Setup the autodetect-v1.xml file in the target directory (so we can save/load it)
642 File userFile = getTestFile( "target/test-autodetect-v1/archiva-user.xml" );
644 assertFalse( userFile.exists( ) );
646 userFile.getParentFile( ).mkdirs( );
647 FileUtils.copyFile( getTestFile( "src/test/conf/autodetect-v1.xml" ), userFile );
649 // Load the original (unconverted) archiva.xml
650 ArchivaConfiguration archivaConfiguration = lookup( ArchivaConfiguration.class, "test-autodetect-v1" );
652 archivaConfiguration.reload( );
654 Configuration configuration = archivaConfiguration.getConfiguration( );
655 assertConfiguration( configuration, 2, 2, 2 );
656 assertEquals( "check network proxies", 1, configuration.getNetworkProxies( ).size( ) );
658 ManagedRepositoryConfiguration repository = configuration.getManagedRepositories( ).get( 0 );
660 assertEquals( "check managed repositories", "${appserver.base}/repositories/internal",
661 repository.getLocation( ) );
662 assertEquals( "check managed repositories", "Archiva Managed Internal Repository", repository.getName( ) );
663 assertEquals( "check managed repositories", "internal", repository.getId( ) );
664 assertEquals( "check managed repositories", "default", repository.getLayout( ) );
665 assertTrue( "check managed repositories", repository.isScanned( ) );
667 // Test that only 1 set of repositories exist.
668 assertEquals( "check managed repositories size.", 2, configuration.getManagedRepositories( ).size( ) );
669 assertEquals( "check remote repositories size.", 2, configuration.getRemoteRepositories( ).size( ) );
670 assertEquals( "check v1 repositories size.", 0, configuration.getRepositories( ).size( ) );
673 archivaConfiguration.save( configuration );
676 //release( archivaConfiguration );
679 archivaConfiguration = (ArchivaConfiguration) lookup( ArchivaConfiguration.class, "test-autodetect-v1" );
680 configuration = archivaConfiguration.getConfiguration( );
682 // Test that only 1 set of repositories exist.
683 assertEquals( "check managed repositories size.", 2, configuration.getManagedRepositories( ).size( ) );
684 assertEquals( "check managed repositories size.", 2, configuration.getManagedRepositoriesAsMap( ).size( ) );
685 assertEquals( "check remote repositories size.", 2, configuration.getRemoteRepositories( ).size( ) );
686 assertEquals( "check remote repositories size.", 2, configuration.getRemoteRepositoriesAsMap( ).size( ) );
687 assertEquals( "check v1 repositories size.", 0, configuration.getRepositories( ).size( ) );
689 String actualXML = FileUtils.readFileToString( userFile, null );
690 XMLAssert.assertXpathNotExists( "//configuration/repositories/repository", actualXML );
691 XMLAssert.assertXpathNotExists( "//configuration/repositories", actualXML );
695 public void testArchivaV1( )
698 ArchivaConfiguration archivaConfiguration = lookup( ArchivaConfiguration.class, "test-archiva-v1" );
700 Configuration configuration = archivaConfiguration.getConfiguration( );
701 assertConfiguration( configuration, 2, 2, 2 );
702 assertEquals( "check network proxies", 1, configuration.getNetworkProxies( ).size( ) );
704 assertEquals( "check managed repositories", 2, configuration.getManagedRepositories( ).size( ) );
705 assertEquals( "check v1 repositories size.", 0, configuration.getRepositories( ).size( ) );
707 Map<String, ManagedRepositoryConfiguration> map = configuration.getManagedRepositoriesAsMap( );
709 ManagedRepositoryConfiguration repository = map.get( "internal" );
710 assertEquals( "check managed repositories", "${appserver.base}/repositories/internal",
711 repository.getLocation( ) );
712 assertEquals( "check managed repositories", "Archiva Managed Internal Repository", repository.getName( ) );
713 assertEquals( "check managed repositories", "internal", repository.getId( ) );
714 assertEquals( "check managed repositories", "default", repository.getLayout( ) );
715 assertTrue( "check managed repositories", repository.isScanned( ) );
716 assertFalse( "check managed repositories", repository.isSnapshots( ) );
718 repository = map.get( "snapshots" );
719 assertEquals( "check managed repositories", "${appserver.base}/repositories/snapshots",
720 repository.getLocation( ) );
721 assertEquals( "check managed repositories", "Archiva Managed Snapshot Repository", repository.getName( ) );
722 assertEquals( "check managed repositories", "snapshots", repository.getId( ) );
723 assertEquals( "check managed repositories", "default", repository.getLayout( ) );
724 assertFalse( "check managed repositories", repository.isScanned( ) );
725 assertTrue( "check managed repositories", repository.isSnapshots( ) );
729 public void testCronExpressionsWithComma( )
732 File baseFile = getTestFile( "target/test/test-file.xml" );
734 assertFalse( baseFile.exists( ) );
736 File userFile = getTestFile( "target/test/test-file-user.xml" );
738 assertFalse( userFile.exists( ) );
740 baseFile.getParentFile( ).mkdirs( );
741 FileUtils.copyFile( getTestFile( "src/test/conf/escape-cron-expressions.xml" ), baseFile );
743 userFile.getParentFile( ).mkdirs( );
744 FileUtils.writeStringToFile( userFile, "<configuration/>", null );
746 final ArchivaConfiguration archivaConfiguration = lookup( ArchivaConfiguration.class, "test-cron-expressions" );
748 archivaConfiguration.reload( );
750 Configuration configuration = archivaConfiguration.getConfiguration( );
752 ManagedRepositoryConfiguration repository =
753 (ManagedRepositoryConfiguration) configuration.getManagedRepositories( ).get( 0 );
755 assertEquals( "check cron expression", "0 0,30 * * * ?", repository.getRefreshCronExpression( ).trim( ) );
757 // add a test listener to confirm it doesn't see the escaped format. We don't need to test the number of calls,
758 // etc. as it's done in other tests
759 archivaConfiguration.addListener( new ConfigurationListener( )
761 public void configurationEvent( ConfigurationEvent event )
763 assertEquals( ConfigurationEvent.SAVED, event.getType( ) );
768 archivaConfiguration.save( configuration );
770 configuration = archivaConfiguration.getConfiguration( );
772 // test for the escape character '\' showing up on repositories.jsp
773 repository.setRefreshCronExpression( "0 0,20 0 * * ?" );
775 archivaConfiguration.save( configuration );
777 repository = archivaConfiguration.getConfiguration( ).findManagedRepositoryById( "snapshots" );
779 assertEquals( "check cron expression", "0 0,20 0 * * ?", repository.getRefreshCronExpression( ) );
783 public void testRemoveLastElements( )
786 File baseFile = getTestFile( "target/test/test-file.xml" );
788 assertFalse( baseFile.exists( ) );
790 File userFile = getTestFile( "target/test/test-file-user.xml" );
792 assertFalse( userFile.exists( ) );
794 baseFile.getParentFile( ).mkdirs( );
795 FileUtils.copyFile( getTestFile( "src/test/conf/conf-single-list-elements.xml" ), baseFile );
797 userFile.getParentFile( ).mkdirs( );
798 FileUtils.writeStringToFile( userFile, "<configuration/>", null );
800 ArchivaConfiguration archivaConfiguration = lookup( ArchivaConfiguration.class, "test-remove-central" );
802 archivaConfiguration.reload( );
804 Configuration configuration = archivaConfiguration.getConfiguration( );
806 RepositoryGroupConfiguration repositoryGroup =
807 (RepositoryGroupConfiguration) configuration.getRepositoryGroups( ).get( 0 );
808 assertNotNull( repositoryGroup );
809 configuration.removeRepositoryGroup( repositoryGroup );
810 assertTrue( configuration.getRepositoryGroups( ).isEmpty( ) );
812 RemoteRepositoryConfiguration repository = configuration.getRemoteRepositoriesAsMap( ).get( "central" );
813 assertNotNull( repository );
814 configuration.removeRemoteRepository( repository );
815 assertTrue( configuration.getRemoteRepositories( ).isEmpty( ) );
817 ManagedRepositoryConfiguration managedRepository =
818 configuration.getManagedRepositoriesAsMap( ).get( "snapshots" );
819 assertNotNull( managedRepository );
820 configuration.removeManagedRepository( managedRepository );
821 assertTrue( configuration.getManagedRepositories( ).isEmpty( ) );
823 ProxyConnectorConfiguration proxyConnector = configuration.getProxyConnectors( ).get( 0 );
824 assertNotNull( proxyConnector );
825 configuration.removeProxyConnector( proxyConnector );
826 assertTrue( configuration.getProxyConnectors( ).isEmpty( ) );
828 NetworkProxyConfiguration networkProxy = configuration.getNetworkProxiesAsMap( ).get( "proxy" );
829 assertNotNull( networkProxy );
830 configuration.removeNetworkProxy( networkProxy );
831 assertTrue( configuration.getNetworkProxies( ).isEmpty( ) );
833 LegacyArtifactPath path = configuration.getLegacyArtifactPaths( ).get( 0 );
834 assertNotNull( path );
835 configuration.removeLegacyArtifactPath( path );
836 assertTrue( configuration.getLegacyArtifactPaths( ).isEmpty( ) );
838 RepositoryScanningConfiguration scanning = configuration.getRepositoryScanning( );
839 String consumer = scanning.getKnownContentConsumers( ).get( 0 );
840 assertNotNull( consumer );
841 scanning.removeKnownContentConsumer( consumer );
843 assertFalse( scanning.getKnownContentConsumers( ).isEmpty( ) );
844 consumer = scanning.getInvalidContentConsumers( ).get( 0 );
845 assertNotNull( consumer );
846 scanning.removeInvalidContentConsumer( consumer );
847 assertTrue( scanning.getInvalidContentConsumers( ).isEmpty( ) );
849 archivaConfiguration.save( configuration );
851 archivaConfiguration = lookup( ArchivaConfiguration.class, "test-read-saved" );
852 configuration = archivaConfiguration.getConfiguration( );
853 assertNull( configuration.getRemoteRepositoriesAsMap( ).get( "central" ) );
854 assertTrue( configuration.getRepositoryGroups( ).isEmpty( ) );
855 assertNull( configuration.getManagedRepositoriesAsMap( ).get( "snapshots" ) );
856 assertTrue( configuration.getProxyConnectors( ).isEmpty( ) );
857 assertNull( configuration.getNetworkProxiesAsMap( ).get( "proxy" ) );
858 assertTrue( configuration.getLegacyArtifactPaths( ).isEmpty( ) );
859 scanning = configuration.getRepositoryScanning( );
860 assertFalse( scanning.getKnownContentConsumers( ).isEmpty( ) );
861 assertTrue( scanning.getInvalidContentConsumers( ).isEmpty( ) );
865 * [MRM-582] Remote Repositories with empty <username> and <password> fields shouldn't be created in configuration.
868 public void testGetConfigurationFixEmptyRemoteRepoUsernamePassword( )
871 ArchivaConfiguration archivaConfiguration = lookup( ArchivaConfiguration.class, "test-configuration" );
873 archivaConfiguration.reload( );
874 Configuration configuration = archivaConfiguration.getConfiguration( );
875 assertConfiguration( configuration, 2, 2, 2 );
876 assertEquals( "check remote repositories", 2, configuration.getRemoteRepositories( ).size( ) );
878 RemoteRepositoryConfiguration repository =
879 configuration.getRemoteRepositoriesAsMap( ).get( "maven2-repository.dev.java.net" );
881 assertEquals( "remote repository.url", "https://maven2-repository.dev.java.net/nonav/repository",
882 repository.getUrl( ) );
883 assertEquals( "remote repository.name", "Java.net Repository for Maven 2", repository.getName( ) );
884 assertEquals( "remote repository.id", "maven2-repository.dev.java.net", repository.getId( ) );
885 assertEquals( "remote repository.layout", "default", repository.getLayout( ) );
886 assertNull( "remote repository.username == null", repository.getUsername( ) );
887 assertNull( "remote repository.password == null", repository.getPassword( ) );