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" ) );
635 public void testAutoDetectV1( )
638 // Setup the autodetect-v1.xml file in the target directory (so we can save/load it)
639 File userFile = getTestFile( "target/test-autodetect-v1/archiva-user.xml" );
641 assertFalse( userFile.exists( ) );
643 userFile.getParentFile( ).mkdirs( );
644 FileUtils.copyFile( getTestFile( "src/test/conf/autodetect-v1.xml" ), userFile );
646 // Load the original (unconverted) archiva.xml
647 ArchivaConfiguration archivaConfiguration = lookup( ArchivaConfiguration.class, "test-autodetect-v1" );
649 archivaConfiguration.reload( );
651 Configuration configuration = archivaConfiguration.getConfiguration( );
652 assertConfiguration( configuration, 2, 2, 2 );
653 assertEquals( "check network proxies", 1, configuration.getNetworkProxies( ).size( ) );
655 ManagedRepositoryConfiguration repository = configuration.getManagedRepositories( ).get( 0 );
657 assertEquals( "check managed repositories", "${appserver.base}/repositories/internal",
658 repository.getLocation( ) );
659 assertEquals( "check managed repositories", "Archiva Managed Internal Repository", repository.getName( ) );
660 assertEquals( "check managed repositories", "internal", repository.getId( ) );
661 assertEquals( "check managed repositories", "default", repository.getLayout( ) );
662 assertTrue( "check managed repositories", repository.isScanned( ) );
664 // Test that only 1 set of repositories exist.
665 assertEquals( "check managed repositories size.", 2, configuration.getManagedRepositories( ).size( ) );
666 assertEquals( "check remote repositories size.", 2, configuration.getRemoteRepositories( ).size( ) );
667 assertEquals( "check v1 repositories size.", 0, configuration.getRepositories( ).size( ) );
670 archivaConfiguration.save( configuration );
673 //release( archivaConfiguration );
676 archivaConfiguration = (ArchivaConfiguration) lookup( ArchivaConfiguration.class, "test-autodetect-v1" );
677 configuration = archivaConfiguration.getConfiguration( );
679 // Test that only 1 set of repositories exist.
680 assertEquals( "check managed repositories size.", 2, configuration.getManagedRepositories( ).size( ) );
681 assertEquals( "check managed repositories size.", 2, configuration.getManagedRepositoriesAsMap( ).size( ) );
682 assertEquals( "check remote repositories size.", 2, configuration.getRemoteRepositories( ).size( ) );
683 assertEquals( "check remote repositories size.", 2, configuration.getRemoteRepositoriesAsMap( ).size( ) );
684 assertEquals( "check v1 repositories size.", 0, configuration.getRepositories( ).size( ) );
686 String actualXML = FileUtils.readFileToString( userFile, null );
687 XMLAssert.assertXpathNotExists( "//configuration/repositories/repository", actualXML );
688 XMLAssert.assertXpathNotExists( "//configuration/repositories", actualXML );
692 public void testArchivaV1( )
695 ArchivaConfiguration archivaConfiguration = lookup( ArchivaConfiguration.class, "test-archiva-v1" );
697 Configuration configuration = archivaConfiguration.getConfiguration( );
698 assertConfiguration( configuration, 2, 2, 2 );
699 assertEquals( "check network proxies", 1, configuration.getNetworkProxies( ).size( ) );
701 assertEquals( "check managed repositories", 2, configuration.getManagedRepositories( ).size( ) );
702 assertEquals( "check v1 repositories size.", 0, configuration.getRepositories( ).size( ) );
704 Map<String, ManagedRepositoryConfiguration> map = configuration.getManagedRepositoriesAsMap( );
706 ManagedRepositoryConfiguration repository = map.get( "internal" );
707 assertEquals( "check managed repositories", "${appserver.base}/repositories/internal",
708 repository.getLocation( ) );
709 assertEquals( "check managed repositories", "Archiva Managed Internal Repository", repository.getName( ) );
710 assertEquals( "check managed repositories", "internal", repository.getId( ) );
711 assertEquals( "check managed repositories", "default", repository.getLayout( ) );
712 assertTrue( "check managed repositories", repository.isScanned( ) );
713 assertFalse( "check managed repositories", repository.isSnapshots( ) );
715 repository = map.get( "snapshots" );
716 assertEquals( "check managed repositories", "${appserver.base}/repositories/snapshots",
717 repository.getLocation( ) );
718 assertEquals( "check managed repositories", "Archiva Managed Snapshot Repository", repository.getName( ) );
719 assertEquals( "check managed repositories", "snapshots", repository.getId( ) );
720 assertEquals( "check managed repositories", "default", repository.getLayout( ) );
721 assertFalse( "check managed repositories", repository.isScanned( ) );
722 assertTrue( "check managed repositories", repository.isSnapshots( ) );
726 public void testCronExpressionsWithComma( )
729 File baseFile = getTestFile( "target/test/test-file.xml" );
731 assertFalse( baseFile.exists( ) );
733 File userFile = getTestFile( "target/test/test-file-user.xml" );
735 assertFalse( userFile.exists( ) );
737 baseFile.getParentFile( ).mkdirs( );
738 FileUtils.copyFile( getTestFile( "src/test/conf/escape-cron-expressions.xml" ), baseFile );
740 userFile.getParentFile( ).mkdirs( );
741 FileUtils.writeStringToFile( userFile, "<configuration/>", null );
743 final ArchivaConfiguration archivaConfiguration = lookup( ArchivaConfiguration.class, "test-cron-expressions" );
745 archivaConfiguration.reload( );
747 Configuration configuration = archivaConfiguration.getConfiguration( );
749 ManagedRepositoryConfiguration repository =
750 (ManagedRepositoryConfiguration) configuration.getManagedRepositories( ).get( 0 );
752 assertEquals( "check cron expression", "0 0,30 * * * ?", repository.getRefreshCronExpression( ).trim( ) );
754 // add a test listener to confirm it doesn't see the escaped format. We don't need to test the number of calls,
755 // etc. as it's done in other tests
756 archivaConfiguration.addListener( new ConfigurationListener( )
758 public void configurationEvent( ConfigurationEvent event )
760 assertEquals( ConfigurationEvent.SAVED, event.getType( ) );
765 archivaConfiguration.save( configuration );
767 configuration = archivaConfiguration.getConfiguration( );
769 // test for the escape character '\' showing up on repositories.jsp
770 repository.setRefreshCronExpression( "0 0,20 0 * * ?" );
772 archivaConfiguration.save( configuration );
774 repository = archivaConfiguration.getConfiguration( ).findManagedRepositoryById( "snapshots" );
776 assertEquals( "check cron expression", "0 0,20 0 * * ?", repository.getRefreshCronExpression( ) );
780 public void testRemoveLastElements( )
783 File baseFile = getTestFile( "target/test/test-file.xml" );
785 assertFalse( baseFile.exists( ) );
787 File userFile = getTestFile( "target/test/test-file-user.xml" );
789 assertFalse( userFile.exists( ) );
791 baseFile.getParentFile( ).mkdirs( );
792 FileUtils.copyFile( getTestFile( "src/test/conf/conf-single-list-elements.xml" ), baseFile );
794 userFile.getParentFile( ).mkdirs( );
795 FileUtils.writeStringToFile( userFile, "<configuration/>", null );
797 ArchivaConfiguration archivaConfiguration =
798 (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 =
822 (ProxyConnectorConfiguration) configuration.getProxyConnectors( ).get( 0 );
823 assertNotNull( proxyConnector );
824 configuration.removeProxyConnector( proxyConnector );
825 assertTrue( configuration.getProxyConnectors( ).isEmpty( ) );
827 NetworkProxyConfiguration networkProxy = configuration.getNetworkProxiesAsMap( ).get( "proxy" );
828 assertNotNull( networkProxy );
829 configuration.removeNetworkProxy( networkProxy );
830 assertTrue( configuration.getNetworkProxies( ).isEmpty( ) );
832 LegacyArtifactPath path = (LegacyArtifactPath) configuration.getLegacyArtifactPaths( ).get( 0 );
833 assertNotNull( path );
834 configuration.removeLegacyArtifactPath( path );
835 assertTrue( configuration.getLegacyArtifactPaths( ).isEmpty( ) );
837 RepositoryScanningConfiguration scanning = configuration.getRepositoryScanning( );
838 String consumer = (String) scanning.getKnownContentConsumers( ).get( 0 );
839 assertNotNull( consumer );
840 scanning.removeKnownContentConsumer( consumer );
841 assertTrue( scanning.getKnownContentConsumers( ).isEmpty( ) );
842 consumer = (String) scanning.getInvalidContentConsumers( ).get( 0 );
843 assertNotNull( consumer );
844 scanning.removeInvalidContentConsumer( consumer );
845 assertTrue( scanning.getInvalidContentConsumers( ).isEmpty( ) );
847 archivaConfiguration.save( configuration );
849 archivaConfiguration = (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 assertTrue( 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( ) );