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.apache.archiva.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 = lookup( ArchivaConfiguration.class, "test-save-user" );
311 Configuration configuration = new Configuration( );
312 configuration.setWebapp( new WebappConfiguration( ) );
313 configuration.getWebapp( ).setUi( new UserInterfaceOptions( ) );
314 configuration.getWebapp( ).getUi( ).setAppletFindEnabled( false );
316 archivaConfiguration.save( configuration );
318 assertTrue( "Check file exists", userFile.exists( ) );
319 assertFalse( "Check file not created", baseFile.exists( ) );
322 configuration = archivaConfiguration.getConfiguration( );
323 assertFalse( "check value", configuration.getWebapp( ).getUi( ).isAppletFindEnabled( ) );
327 public void testStoreConfigurationLoadedFromDefaults( )
330 File baseFile = getTestFile( "target/test/test-file.xml" );
332 assertFalse( baseFile.exists( ) );
334 File userFile = getTestFile( "target/test/test-file-user.xml" );
336 assertFalse( userFile.exists( ) );
338 ArchivaConfiguration archivaConfiguration = lookup( ArchivaConfiguration.class, "test-save-user-defaults" );
340 archivaConfiguration.reload( );
342 Configuration configuration = new Configuration( );
343 configuration.setWebapp( new WebappConfiguration( ) );
344 configuration.getWebapp( ).setUi( new UserInterfaceOptions( ) );
345 configuration.getWebapp( ).getUi( ).setAppletFindEnabled( false );
347 // add a change listener
348 MockControl control = createConfigurationListenerMockControl( );
349 ConfigurationListener listener = (ConfigurationListener) control.getMock( );
350 archivaConfiguration.addListener( listener );
352 listener.configurationEvent( new ConfigurationEvent( ConfigurationEvent.SAVED ) );
354 control.setVoidCallable( 1 );
358 archivaConfiguration.save( configuration );
362 assertTrue( "Check file exists", userFile.exists( ) );
363 assertFalse( "Check file not created", baseFile.exists( ) );
366 configuration = archivaConfiguration.getConfiguration( );
367 assertFalse( "check value", configuration.getWebapp( ).getUi( ).isAppletFindEnabled( ) );
371 public void testDefaultUserConfigFilename( )
374 DefaultArchivaConfiguration archivaConfiguration =
375 (DefaultArchivaConfiguration) lookup( ArchivaConfiguration.class, "default" );
377 archivaConfiguration.reload( );
379 assertEquals( System.getProperty( "user.home" ) + "/.m2/archiva.xml",
380 archivaConfiguration.getUserConfigFilename( ) );
381 assertEquals( System.getProperty( "appserver.base", "${appserver.base}" ) + "/conf/archiva.xml",
382 archivaConfiguration.getAltConfigFilename( ) );
386 public void testStoreConfigurationFallback( )
389 File baseFile = getTestFile( "target/test/test-file.xml" );
391 assertFalse( baseFile.exists( ) );
393 File userFile = getTestFile( "target/test/test-file-user.xml" );
395 assertFalse( userFile.exists( ) );
397 baseFile.getParentFile( ).mkdirs( );
398 FileUtils.writeStringToFile( baseFile, "<configuration/>", null );
400 ArchivaConfiguration archivaConfiguration =
401 (ArchivaConfiguration) lookup( ArchivaConfiguration.class, "test-save-user-fallback" );
403 archivaConfiguration.reload( );
405 Configuration configuration = new Configuration( );
406 configuration.setWebapp( new WebappConfiguration( ) );
407 configuration.getWebapp( ).setUi( new UserInterfaceOptions( ) );
408 configuration.getWebapp( ).getUi( ).setAppletFindEnabled( false );
410 archivaConfiguration.save( configuration );
412 assertTrue( "Check file exists", baseFile.exists( ) );
413 assertFalse( "Check file not created", userFile.exists( ) );
416 configuration = archivaConfiguration.getConfiguration( );
417 assertFalse( "check value", configuration.getWebapp( ).getUi( ).isAppletFindEnabled( ) );
421 public void testStoreConfigurationFailsWhenReadFromBothLocationsNoLists( )
424 File baseFile = getTestFile( "target/test/test-file.xml" );
426 assertFalse( baseFile.exists( ) );
428 File userFile = getTestFile( "target/test/test-file-user.xml" );
430 assertFalse( userFile.exists( ) );
432 baseFile.getParentFile( ).mkdirs( );
433 FileUtils.writeStringToFile( baseFile, "<configuration/>", null );
435 userFile.getParentFile( ).mkdirs( );
436 FileUtils.writeStringToFile( userFile, "<configuration/>", null );
438 ArchivaConfiguration archivaConfiguration =
439 (ArchivaConfiguration) lookup( ArchivaConfiguration.class, "test-save-user" );
441 archivaConfiguration.reload( );
443 Configuration configuration = archivaConfiguration.getConfiguration( );
444 assertTrue( "check value", configuration.getWebapp( ).getUi( ).isAppletFindEnabled( ) );
446 configuration.getWebapp( ).getUi( ).setAppletFindEnabled( false );
448 archivaConfiguration.save( configuration );
450 assertTrue( "Check file exists", baseFile.exists( ) );
451 assertEquals( "Check base file is unchanged", "<configuration/>",
452 FileUtils.readFileToString( baseFile, null ) );
453 assertTrue( "Check file exists", userFile.exists( ) );
454 assertFalse( "Check base file is changed",
455 "<configuration/>".equals( FileUtils.readFileToString( userFile, null ) ) );
458 configuration = archivaConfiguration.getConfiguration( );
459 assertFalse( "check value", configuration.getWebapp( ).getUi( ).isAppletFindEnabled( ) );
463 public void testStoreConfigurationFailsWhenReadFromBothLocationsUserHasLists( )
466 File baseFile = getTestFile( "target/test/test-file.xml" );
468 assertFalse( baseFile.exists( ) );
470 File userFile = getTestFile( "target/test/test-file-user.xml" );
472 assertFalse( userFile.exists( ) );
474 userFile.getParentFile( ).mkdirs( );
475 FileUtils.copyFile( getTestFile( "src/test/conf/conf-user.xml" ), userFile );
477 baseFile.getParentFile( ).mkdirs( );
478 FileUtils.writeStringToFile( baseFile, "<configuration/>", null );
480 ArchivaConfiguration archivaConfiguration =
481 (ArchivaConfiguration) lookup( ArchivaConfiguration.class, "test-save-user" );
483 archivaConfiguration.reload( );
485 Configuration configuration = archivaConfiguration.getConfiguration( );
486 assertTrue( "check value", configuration.getWebapp( ).getUi( ).isShowFindArtifacts( ) );
488 configuration.getWebapp( ).getUi( ).setShowFindArtifacts( false );
490 archivaConfiguration.save( configuration );
492 assertTrue( "Check file exists", baseFile.exists( ) );
493 assertEquals( "Check base file is unchanged", "<configuration/>",
494 FileUtils.readFileToString( baseFile, null ) );
495 assertTrue( "Check file exists", userFile.exists( ) );
496 assertFalse( "Check base file is changed",
497 "<configuration/>".equals( FileUtils.readFileToString( userFile, null ) ) );
500 configuration = archivaConfiguration.getConfiguration( );
501 assertFalse( "check value", configuration.getWebapp( ).getUi( ).isShowFindArtifacts( ) );
505 public void testStoreConfigurationFailsWhenReadFromBothLocationsAppserverHasLists( )
508 File baseFile = getTestFile( "target/test/test-file.xml" );
510 assertFalse( baseFile.exists( ) );
512 File userFile = getTestFile( "target/test/test-file-user.xml" );
514 assertFalse( userFile.exists( ) );
516 baseFile.getParentFile( ).mkdirs( );
517 FileUtils.copyFile( getTestFile( "src/test/conf/conf-base.xml" ), baseFile );
519 userFile.getParentFile( ).mkdirs( );
520 FileUtils.writeStringToFile( userFile, "<configuration/>", null );
522 ArchivaConfiguration archivaConfiguration =
523 (ArchivaConfiguration) lookup( ArchivaConfiguration.class, "test-save-user" );
525 archivaConfiguration.reload( );
527 Configuration configuration = archivaConfiguration.getConfiguration( );
528 assertTrue( "check value", configuration.getWebapp( ).getUi( ).isAppletFindEnabled( ) );
530 configuration.getWebapp( ).getUi( ).setAppletFindEnabled( false );
534 archivaConfiguration.save( configuration );
535 fail( "Configuration saving should not succeed if it was loaded from two locations" );
537 catch ( IndeterminateConfigurationException e )
539 // check it was reverted
540 configuration = archivaConfiguration.getConfiguration( );
541 assertTrue( "check value", configuration.getWebapp( ).getUi( ).isAppletFindEnabled( ) );
546 public void testLoadConfigurationFromInvalidBothLocationsOnDisk( )
549 ArchivaConfiguration archivaConfiguration =
550 (ArchivaConfiguration) lookup( ArchivaConfiguration.class, "test-not-allowed-to-write-to-both" );
551 Configuration config = archivaConfiguration.getConfiguration( );
555 archivaConfiguration.save( config );
556 fail( "Should have thrown a RegistryException because the configuration can't be saved." );
558 catch ( RegistryException e )
560 /* expected exception */
565 public void testLoadConfigurationFromInvalidUserLocationOnDisk( )
568 File testConfDir = getTestFile( "target/test-appserver-base/conf/" );
569 testConfDir.mkdirs( );
571 ArchivaConfiguration archivaConfiguration =
572 (ArchivaConfiguration) lookup( ArchivaConfiguration.class, "test-not-allowed-to-write-to-user" );
573 Configuration config = archivaConfiguration.getConfiguration( );
574 archivaConfiguration.save( config );
575 // No Exception == test passes.
576 // Expected Path is: Should not have thrown an exception.
580 public void testConfigurationUpgradeFrom09( )
583 ArchivaConfiguration archivaConfiguration = lookup( ArchivaConfiguration.class, "test-upgrade-09" );
585 // we just use the defaults when upgrading from 0.9 at this point.
586 Configuration configuration = archivaConfiguration.getConfiguration( );
587 // test-upgrade-09 contains a managed with id: local so it's 3 managed
588 assertConfiguration( configuration, 3, 1, 1 );
589 assertEquals( "check network proxies", 0, configuration.getNetworkProxies( ).size( ) );
591 ManagedRepositoryConfiguration repository = configuration.getManagedRepositories( ).get( 0 );
593 assertEquals( "check managed repositories", "${appserver.base}/data/repositories/internal",
594 repository.getLocation( ) );
595 assertEquals( "check managed repositories", "Archiva Managed Internal Repository", repository.getName( ) );
596 assertEquals( "check managed repositories", "internal", repository.getId( ) );
597 assertEquals( "check managed repositories", "default", repository.getLayout( ) );
598 assertTrue( "check managed repositories", repository.isScanned( ) );
602 public void testConfigurationUpgradeFrom13( )
605 ArchivaConfiguration archivaConfiguration = lookup( ArchivaConfiguration.class, "test-upgrade-1.3" );
607 // we just use the defaults when upgrading from 1.3 at this point.
608 Configuration configuration = archivaConfiguration.getConfiguration( );
609 assertConfiguration( configuration, 2, 2, 2 );
610 assertEquals( "check network proxies", 0, configuration.getNetworkProxies( ).size( ) );
612 ManagedRepositoryConfiguration repository = configuration.getManagedRepositories( ).get( 0 );
614 assertEquals( "check managed repositories", "${appserver.base}/data/repositories/internal",
615 repository.getLocation( ) );
616 assertEquals( "check managed repositories", "Archiva Managed Internal Repository", repository.getName( ) );
617 assertEquals( "check managed repositories", "internal", repository.getId( ) );
618 assertEquals( "check managed repositories", "default", repository.getLayout( ) );
619 assertTrue( "check managed repositories", repository.isScanned( ) );
621 log.info( "knowContentConsumers " + configuration.getRepositoryScanning( ).getKnownContentConsumers( ) );
624 configuration.getRepositoryScanning( ).getKnownContentConsumers( ).contains( "update-db-artifact" ) );
625 assertFalse( configuration.getRepositoryScanning( ).getKnownContentConsumers( ).contains(
626 "update-db-repository-metadata" ) );
629 configuration.getRepositoryScanning( ).getKnownContentConsumers( ).contains( "create-archiva-metadata" ) );
632 configuration.getRepositoryScanning( ).getKnownContentConsumers( ).contains( "duplicate-artifacts" ) );
636 public void testAutoDetectV1( )
639 // Setup the autodetect-v1.xml file in the target directory (so we can save/load it)
640 File userFile = getTestFile( "target/test-autodetect-v1/archiva-user.xml" );
642 assertFalse( userFile.exists( ) );
644 userFile.getParentFile( ).mkdirs( );
645 FileUtils.copyFile( getTestFile( "src/test/conf/autodetect-v1.xml" ), userFile );
647 // Load the original (unconverted) archiva.xml
648 ArchivaConfiguration archivaConfiguration = lookup( ArchivaConfiguration.class, "test-autodetect-v1" );
650 archivaConfiguration.reload( );
652 Configuration configuration = archivaConfiguration.getConfiguration( );
653 assertConfiguration( configuration, 2, 2, 2 );
654 assertEquals( "check network proxies", 1, configuration.getNetworkProxies( ).size( ) );
656 ManagedRepositoryConfiguration repository = configuration.getManagedRepositories( ).get( 0 );
658 assertEquals( "check managed repositories", "${appserver.base}/repositories/internal",
659 repository.getLocation( ) );
660 assertEquals( "check managed repositories", "Archiva Managed Internal Repository", repository.getName( ) );
661 assertEquals( "check managed repositories", "internal", repository.getId( ) );
662 assertEquals( "check managed repositories", "default", repository.getLayout( ) );
663 assertTrue( "check managed repositories", repository.isScanned( ) );
665 // Test that only 1 set of repositories exist.
666 assertEquals( "check managed repositories size.", 2, configuration.getManagedRepositories( ).size( ) );
667 assertEquals( "check remote repositories size.", 2, configuration.getRemoteRepositories( ).size( ) );
668 assertEquals( "check v1 repositories size.", 0, configuration.getRepositories( ).size( ) );
671 archivaConfiguration.save( configuration );
674 //release( archivaConfiguration );
677 archivaConfiguration = (ArchivaConfiguration) lookup( ArchivaConfiguration.class, "test-autodetect-v1" );
678 configuration = archivaConfiguration.getConfiguration( );
680 // Test that only 1 set of repositories exist.
681 assertEquals( "check managed repositories size.", 2, configuration.getManagedRepositories( ).size( ) );
682 assertEquals( "check managed repositories size.", 2, configuration.getManagedRepositoriesAsMap( ).size( ) );
683 assertEquals( "check remote repositories size.", 2, configuration.getRemoteRepositories( ).size( ) );
684 assertEquals( "check remote repositories size.", 2, configuration.getRemoteRepositoriesAsMap( ).size( ) );
685 assertEquals( "check v1 repositories size.", 0, configuration.getRepositories( ).size( ) );
687 String actualXML = FileUtils.readFileToString( userFile, null );
688 XMLAssert.assertXpathNotExists( "//configuration/repositories/repository", actualXML );
689 XMLAssert.assertXpathNotExists( "//configuration/repositories", actualXML );
693 public void testArchivaV1( )
696 ArchivaConfiguration archivaConfiguration = lookup( ArchivaConfiguration.class, "test-archiva-v1" );
698 Configuration configuration = archivaConfiguration.getConfiguration( );
699 assertConfiguration( configuration, 2, 2, 2 );
700 assertEquals( "check network proxies", 1, configuration.getNetworkProxies( ).size( ) );
702 assertEquals( "check managed repositories", 2, configuration.getManagedRepositories( ).size( ) );
703 assertEquals( "check v1 repositories size.", 0, configuration.getRepositories( ).size( ) );
705 Map<String, ManagedRepositoryConfiguration> map = configuration.getManagedRepositoriesAsMap( );
707 ManagedRepositoryConfiguration repository = map.get( "internal" );
708 assertEquals( "check managed repositories", "${appserver.base}/repositories/internal",
709 repository.getLocation( ) );
710 assertEquals( "check managed repositories", "Archiva Managed Internal Repository", repository.getName( ) );
711 assertEquals( "check managed repositories", "internal", repository.getId( ) );
712 assertEquals( "check managed repositories", "default", repository.getLayout( ) );
713 assertTrue( "check managed repositories", repository.isScanned( ) );
714 assertFalse( "check managed repositories", repository.isSnapshots( ) );
716 repository = map.get( "snapshots" );
717 assertEquals( "check managed repositories", "${appserver.base}/repositories/snapshots",
718 repository.getLocation( ) );
719 assertEquals( "check managed repositories", "Archiva Managed Snapshot Repository", repository.getName( ) );
720 assertEquals( "check managed repositories", "snapshots", repository.getId( ) );
721 assertEquals( "check managed repositories", "default", repository.getLayout( ) );
722 assertFalse( "check managed repositories", repository.isScanned( ) );
723 assertTrue( "check managed repositories", repository.isSnapshots( ) );
727 public void testCronExpressionsWithComma( )
730 File baseFile = getTestFile( "target/test/test-file.xml" );
732 assertFalse( baseFile.exists( ) );
734 File userFile = getTestFile( "target/test/test-file-user.xml" );
736 assertFalse( userFile.exists( ) );
738 baseFile.getParentFile( ).mkdirs( );
739 FileUtils.copyFile( getTestFile( "src/test/conf/escape-cron-expressions.xml" ), baseFile );
741 userFile.getParentFile( ).mkdirs( );
742 FileUtils.writeStringToFile( userFile, "<configuration/>", null );
744 final ArchivaConfiguration archivaConfiguration = lookup( ArchivaConfiguration.class, "test-cron-expressions" );
746 archivaConfiguration.reload( );
748 Configuration configuration = archivaConfiguration.getConfiguration( );
750 ManagedRepositoryConfiguration repository =
751 (ManagedRepositoryConfiguration) configuration.getManagedRepositories( ).get( 0 );
753 assertEquals( "check cron expression", "0 0,30 * * * ?", repository.getRefreshCronExpression( ).trim( ) );
755 // add a test listener to confirm it doesn't see the escaped format. We don't need to test the number of calls,
756 // etc. as it's done in other tests
757 archivaConfiguration.addListener( new ConfigurationListener( )
759 public void configurationEvent( ConfigurationEvent event )
761 assertEquals( ConfigurationEvent.SAVED, event.getType( ) );
766 archivaConfiguration.save( configuration );
768 configuration = archivaConfiguration.getConfiguration( );
770 // test for the escape character '\' showing up on repositories.jsp
771 repository.setRefreshCronExpression( "0 0,20 0 * * ?" );
773 archivaConfiguration.save( configuration );
775 repository = archivaConfiguration.getConfiguration( ).findManagedRepositoryById( "snapshots" );
777 assertEquals( "check cron expression", "0 0,20 0 * * ?", repository.getRefreshCronExpression( ) );
781 public void testRemoveLastElements( )
784 File baseFile = getTestFile( "target/test/test-file.xml" );
786 assertFalse( baseFile.exists( ) );
788 File userFile = getTestFile( "target/test/test-file-user.xml" );
790 assertFalse( userFile.exists( ) );
792 baseFile.getParentFile( ).mkdirs( );
793 FileUtils.copyFile( getTestFile( "src/test/conf/conf-single-list-elements.xml" ), baseFile );
795 userFile.getParentFile( ).mkdirs( );
796 FileUtils.writeStringToFile( userFile, "<configuration/>", null );
798 ArchivaConfiguration archivaConfiguration = lookup( ArchivaConfiguration.class, "test-remove-central" );
800 archivaConfiguration.reload( );
802 Configuration configuration = archivaConfiguration.getConfiguration( );
804 RepositoryGroupConfiguration repositoryGroup =
805 (RepositoryGroupConfiguration) configuration.getRepositoryGroups( ).get( 0 );
806 assertNotNull( repositoryGroup );
807 configuration.removeRepositoryGroup( repositoryGroup );
808 assertTrue( configuration.getRepositoryGroups( ).isEmpty( ) );
810 RemoteRepositoryConfiguration repository = configuration.getRemoteRepositoriesAsMap( ).get( "central" );
811 assertNotNull( repository );
812 configuration.removeRemoteRepository( repository );
813 assertTrue( configuration.getRemoteRepositories( ).isEmpty( ) );
815 ManagedRepositoryConfiguration managedRepository =
816 configuration.getManagedRepositoriesAsMap( ).get( "snapshots" );
817 assertNotNull( managedRepository );
818 configuration.removeManagedRepository( managedRepository );
819 assertTrue( configuration.getManagedRepositories( ).isEmpty( ) );
821 ProxyConnectorConfiguration proxyConnector = configuration.getProxyConnectors( ).get( 0 );
822 assertNotNull( proxyConnector );
823 configuration.removeProxyConnector( proxyConnector );
824 assertTrue( configuration.getProxyConnectors( ).isEmpty( ) );
826 NetworkProxyConfiguration networkProxy = configuration.getNetworkProxiesAsMap( ).get( "proxy" );
827 assertNotNull( networkProxy );
828 configuration.removeNetworkProxy( networkProxy );
829 assertTrue( configuration.getNetworkProxies( ).isEmpty( ) );
831 LegacyArtifactPath path = configuration.getLegacyArtifactPaths( ).get( 0 );
832 assertNotNull( path );
833 configuration.removeLegacyArtifactPath( path );
834 assertTrue( configuration.getLegacyArtifactPaths( ).isEmpty( ) );
836 RepositoryScanningConfiguration scanning = configuration.getRepositoryScanning( );
837 String consumer = scanning.getKnownContentConsumers( ).get( 0 );
838 assertNotNull( consumer );
839 scanning.removeKnownContentConsumer( consumer );
841 assertFalse( scanning.getKnownContentConsumers( ).isEmpty( ) );
842 consumer = scanning.getInvalidContentConsumers( ).get( 0 );
843 assertNotNull( consumer );
844 scanning.removeInvalidContentConsumer( consumer );
845 assertTrue( scanning.getInvalidContentConsumers( ).isEmpty( ) );
847 archivaConfiguration.save( configuration );
849 archivaConfiguration = lookup( ArchivaConfiguration.class, "test-read-saved" );
850 configuration = archivaConfiguration.getConfiguration( );
851 assertNull( configuration.getRemoteRepositoriesAsMap( ).get( "central" ) );
852 assertTrue( configuration.getRepositoryGroups( ).isEmpty( ) );
853 assertNull( configuration.getManagedRepositoriesAsMap( ).get( "snapshots" ) );
854 assertTrue( configuration.getProxyConnectors( ).isEmpty( ) );
855 assertNull( configuration.getNetworkProxiesAsMap( ).get( "proxy" ) );
856 assertTrue( configuration.getLegacyArtifactPaths( ).isEmpty( ) );
857 scanning = configuration.getRepositoryScanning( );
858 assertFalse( scanning.getKnownContentConsumers( ).isEmpty( ) );
859 assertTrue( scanning.getInvalidContentConsumers( ).isEmpty( ) );
863 * [MRM-582] Remote Repositories with empty <username> and <password> fields shouldn't be created in configuration.
866 public void testGetConfigurationFixEmptyRemoteRepoUsernamePassword( )
869 ArchivaConfiguration archivaConfiguration = lookup( ArchivaConfiguration.class, "test-configuration" );
871 archivaConfiguration.reload( );
872 Configuration configuration = archivaConfiguration.getConfiguration( );
873 assertConfiguration( configuration, 2, 2, 2 );
874 assertEquals( "check remote repositories", 2, configuration.getRemoteRepositories( ).size( ) );
876 RemoteRepositoryConfiguration repository =
877 configuration.getRemoteRepositoriesAsMap( ).get( "maven2-repository.dev.java.net" );
879 assertEquals( "remote repository.url", "https://maven2-repository.dev.java.net/nonav/repository",
880 repository.getUrl( ) );
881 assertEquals( "remote repository.name", "Java.net Repository for Maven 2", repository.getName( ) );
882 assertEquals( "remote repository.id", "maven2-repository.dev.java.net", repository.getId( ) );
883 assertEquals( "remote repository.layout", "default", repository.getLayout( ) );
884 assertNull( "remote repository.username == null", repository.getUsername( ) );
885 assertNull( "remote repository.password == null", repository.getPassword( ) );