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 org.apache.archiva.common.utils.FileUtil;
23 import org.apache.archiva.redback.components.registry.RegistryException;
24 import org.apache.archiva.test.utils.ArchivaSpringJUnit4ClassRunner;
25 import org.apache.commons.io.FileUtils;
26 import org.custommonkey.xmlunit.XMLAssert;
27 import org.junit.Test;
28 import org.junit.runner.RunWith;
29 import org.slf4j.Logger;
30 import org.slf4j.LoggerFactory;
31 import org.springframework.context.ApplicationContext;
32 import org.springframework.test.annotation.DirtiesContext;
33 import org.springframework.test.annotation.DirtiesContext.ClassMode;
34 import org.springframework.test.context.ContextConfiguration;
36 import javax.inject.Inject;
38 import java.nio.charset.Charset;
39 import java.util.List;
42 import static org.easymock.EasyMock.*;
43 import static org.junit.Assert.*;
46 * Test the configuration store.
48 @RunWith( ArchivaSpringJUnit4ClassRunner.class )
49 @ContextConfiguration( locations = { "classpath*:/META-INF/spring-context.xml", "classpath:/spring-context.xml" } )
50 @DirtiesContext(classMode = ClassMode.AFTER_EACH_TEST_METHOD)
51 public class ArchivaConfigurationTest
54 private Logger log = LoggerFactory.getLogger( getClass() );
57 protected ApplicationContext applicationContext;
62 public static File getTestFile( String path )
64 return new File( FileUtil.getBasedir(), path );
67 protected <T> T lookup( Class<T> clazz, String hint )
69 return (T) applicationContext.getBean( "archivaConfiguration#" + hint, ArchivaConfiguration.class );
73 public void testGetConfigurationFromDefaults()
76 ArchivaConfiguration archivaConfiguration = lookup( ArchivaConfiguration.class, "test-defaults" );
77 Configuration configuration = archivaConfiguration.getConfiguration();
79 assertConfiguration( configuration, 2, 1, 1 );
80 assertEquals( "check network proxies", 0, configuration.getNetworkProxies().size() );
82 ManagedRepositoryConfiguration repository = configuration.getManagedRepositories().get( 0 );
84 assertEquals( "check managed repositories", "${appserver.base}/repositories/internal",
85 repository.getLocation() );
86 assertEquals( "check managed repositories", "Archiva Managed Internal Repository", repository.getName() );
87 assertEquals( "check managed repositories", "internal", repository.getId() );
88 assertEquals( "check managed repositories", "default", repository.getLayout() );
89 assertTrue( "check managed repositories", repository.isScanned() );
93 public void testGetConfigurationFromRegistryWithASingleNamedConfigurationResource()
96 ArchivaConfiguration archivaConfiguration = lookup( ArchivaConfiguration.class, "test-configuration" );
97 Configuration configuration = archivaConfiguration.getConfiguration();
98 assertConfiguration( configuration, 2, 2, 2 );
99 assertEquals( "check network proxies", 1, configuration.getNetworkProxies().size() );
101 ManagedRepositoryConfiguration repository = configuration.getManagedRepositories().get( 0 );
103 assertEquals( "check managed repositories", "${appserver.base}/repositories/internal",
104 repository.getLocation() );
105 assertEquals( "check managed repositories", "Archiva Managed Internal Repository", repository.getName() );
106 assertEquals( "check managed repositories", "internal", repository.getId() );
107 assertEquals( "check managed repositories", "default", repository.getLayout() );
108 assertTrue( "check managed repositories", repository.isScanned() );
112 * Ensures that the provided configuration matches the details present in the archiva-default.xml file.
114 private void assertConfiguration( Configuration configuration, int managedExpected, int remoteExpected,
115 int proxyConnectorExpected )
119 assertEquals( "check managed repositories: " + configuration.getManagedRepositories(), managedExpected,
120 configuration.getManagedRepositories().size() );
121 assertEquals( "check remote repositories: " + configuration.getRemoteRepositories(), remoteExpected,
122 configuration.getRemoteRepositories().size() );
123 assertEquals( "check proxy connectors:" + configuration.getProxyConnectors(), proxyConnectorExpected,
124 configuration.getProxyConnectors().size() );
126 RepositoryScanningConfiguration repoScanning = configuration.getRepositoryScanning();
127 assertNotNull( "check repository scanning", repoScanning );
128 assertEquals( "check file types", 4, repoScanning.getFileTypes().size() );
129 assertEquals( "check known consumers", 9, repoScanning.getKnownContentConsumers().size() );
130 assertEquals( "check invalid consumers", 1, repoScanning.getInvalidContentConsumers().size() );
132 List<String> patterns = filetypes.getFileTypePatterns( "artifacts" );
133 assertNotNull( "check 'artifacts' file type", patterns );
134 assertEquals( "check 'artifacts' patterns", 13, patterns.size() );
136 WebappConfiguration webapp = configuration.getWebapp();
137 assertNotNull( "check webapp", webapp );
139 UserInterfaceOptions ui = webapp.getUi();
140 assertNotNull( "check webapp ui", ui );
141 assertTrue( "check showFindArtifacts", ui.isShowFindArtifacts() );
142 assertTrue( "check appletFindEnabled", ui.isAppletFindEnabled() );
146 public void testGetConfigurationFromRegistryWithTwoConfigurationResources()
149 ArchivaConfiguration archivaConfiguration = lookup( ArchivaConfiguration.class, "test-configuration-both" );
151 Configuration configuration = archivaConfiguration.getConfiguration();
154 assertEquals( "check repositories", 2, configuration.getManagedRepositories().size() );
155 assertEquals( "check repositories", 2, configuration.getRemoteRepositories().size() );
157 assertEquals( "check proxy connectors", 2, configuration.getProxyConnectors().size() );
159 WebappConfiguration webapp = configuration.getWebapp();
160 assertNotNull( "check webapp", webapp );
162 UserInterfaceOptions ui = webapp.getUi();
163 assertNotNull( "check webapp ui", ui );
165 assertFalse( "check showFindArtifacts", ui.isShowFindArtifacts() );
167 assertFalse( "check appletFindEnabled", ui.isAppletFindEnabled() );
171 public void testGetConfigurationSystemOverride()
175 System.setProperty( "org.apache.archiva.webapp.ui.appletFindEnabled", "false" );
177 ArchivaConfiguration archivaConfiguration = lookup( ArchivaConfiguration.class, "test-configuration" );
179 archivaConfiguration.reload();
183 Configuration configuration = archivaConfiguration.getConfiguration();
185 assertFalse( "check boolean", configuration.getWebapp().getUi().isAppletFindEnabled() );
189 System.getProperties().remove( "org.apache.archiva.webapp.ui.appletFindEnabled" );
190 archivaConfiguration.reload();
191 Configuration configuration = archivaConfiguration.getConfiguration();
192 assertTrue( "check boolean", configuration.getWebapp().getUi().isAppletFindEnabled() );
197 public void testStoreConfiguration()
200 File file = getTestFile( "target/test/test-file.xml" );
202 assertFalse( file.exists() );
204 // TODO: remove with commons-configuration 1.4
205 //file.getParentFile().mkdirs();
206 //FileUtils.writeStringToFile( file, "<configuration/>", null );
208 DefaultArchivaConfiguration archivaConfiguration =
209 (DefaultArchivaConfiguration) lookup( ArchivaConfiguration.class, "test-save" );
211 archivaConfiguration.reload();
213 Configuration configuration = new Configuration();
214 configuration.setVersion( "1" );
215 configuration.setWebapp( new WebappConfiguration() );
216 configuration.getWebapp().setUi( new UserInterfaceOptions() );
217 configuration.getWebapp().getUi().setAppletFindEnabled( false );
219 // add a change listener
220 //MockControl control = createConfigurationListenerMockControl();
221 ConfigurationListener listener = createMock( ConfigurationListener.class );// (ConfigurationListener) control.getMock();
222 archivaConfiguration.addListener( listener );
224 listener.configurationEvent( new ConfigurationEvent( ConfigurationEvent.SAVED ) );
225 //control.setVoidCallable();
231 archivaConfiguration.save( configuration );
236 assertTrue( "Check file exists", file.exists() );
239 configuration = archivaConfiguration.getConfiguration();
240 assertFalse( "check value", configuration.getWebapp().getUi().isAppletFindEnabled() );
243 archivaConfiguration = (DefaultArchivaConfiguration) lookup( ArchivaConfiguration.class, "test-read-saved" );
245 archivaConfiguration.reload();
246 configuration = archivaConfiguration.getConfiguration();
247 assertFalse( "check value", configuration.getWebapp().getUi().isAppletFindEnabled() );
250 private static ConfigurationListener createConfigurationListenerMockControl()
252 return createMock( ConfigurationListener.class );// MockControl.createControl( ConfigurationListener.class );
256 public void testStoreConfigurationUser()
259 File baseFile = getTestFile( "target/test/test-file.xml" );
261 assertFalse( baseFile.exists() );
263 File userFile = getTestFile( "target/test/test-file-user.xml" );
265 assertFalse( userFile.exists() );
267 userFile.getParentFile().mkdirs();
268 FileUtils.writeStringToFile( userFile, "<configuration/>", Charset.forName("UTF-8") );
270 ArchivaConfiguration archivaConfiguration = lookup( ArchivaConfiguration.class, "test-save-user" );
272 Configuration configuration = new Configuration();
273 configuration.setWebapp( new WebappConfiguration() );
274 configuration.getWebapp().setUi( new UserInterfaceOptions() );
275 configuration.getWebapp().getUi().setAppletFindEnabled( false );
277 archivaConfiguration.save( configuration );
279 assertTrue( "Check file exists", userFile.exists() );
280 assertFalse( "Check file not created", baseFile.exists() );
283 configuration = archivaConfiguration.getConfiguration();
284 assertFalse( "check value", configuration.getWebapp().getUi().isAppletFindEnabled() );
288 public void testStoreConfigurationLoadedFromDefaults()
291 File baseFile = getTestFile( "target/test/test-file.xml" );
293 assertFalse( baseFile.exists() );
295 File userFile = getTestFile( "target/test/test-file-user.xml" );
297 assertFalse( userFile.exists() );
299 ArchivaConfiguration archivaConfiguration = lookup( ArchivaConfiguration.class, "test-save-user-defaults" );
301 archivaConfiguration.reload();
303 Configuration configuration = new Configuration();
304 configuration.setWebapp( new WebappConfiguration() );
305 configuration.getWebapp().setUi( new UserInterfaceOptions() );
306 configuration.getWebapp().getUi().setAppletFindEnabled( false );
308 // add a change listener
309 //MockControl control = createConfigurationListenerMockControl();
310 //ConfigurationListener listener = (ConfigurationListener) control.getMock();
311 ConfigurationListener listener = createConfigurationListenerMockControl();
312 archivaConfiguration.addListener( listener );
314 listener.configurationEvent( new ConfigurationEvent( ConfigurationEvent.SAVED ) );
316 //control.setVoidCallable( 1 );
322 archivaConfiguration.save( configuration );
328 assertTrue( "Check file exists", userFile.exists() );
329 assertFalse( "Check file not created", baseFile.exists() );
332 configuration = archivaConfiguration.getConfiguration();
333 assertFalse( "check value", configuration.getWebapp().getUi().isAppletFindEnabled() );
337 public void testDefaultUserConfigFilename()
340 DefaultArchivaConfiguration archivaConfiguration =
341 (DefaultArchivaConfiguration) lookup( ArchivaConfiguration.class, "default" );
343 archivaConfiguration.reload();
345 assertEquals( System.getProperty( "user.home" ) + "/.m2/archiva.xml",
346 archivaConfiguration.getUserConfigFilename() );
347 assertEquals( System.getProperty( "appserver.base", "${appserver.base}" ) + "/conf/archiva.xml",
348 archivaConfiguration.getAltConfigFilename() );
352 public void testStoreConfigurationFallback()
355 File baseFile = getTestFile( "target/test/test-file.xml" );
357 assertFalse( baseFile.exists() );
359 File userFile = getTestFile( "target/test/test-file-user.xml" );
361 assertFalse( userFile.exists() );
363 baseFile.getParentFile().mkdirs();
364 FileUtils.writeStringToFile( baseFile, "<configuration/>", Charset.forName("UTF-8") );
366 ArchivaConfiguration archivaConfiguration =
367 (ArchivaConfiguration) lookup( ArchivaConfiguration.class, "test-save-user-fallback" );
369 archivaConfiguration.reload();
371 Configuration configuration = new Configuration();
372 configuration.setWebapp( new WebappConfiguration() );
373 configuration.getWebapp().setUi( new UserInterfaceOptions() );
374 configuration.getWebapp().getUi().setAppletFindEnabled( false );
376 archivaConfiguration.save( configuration );
378 assertTrue( "Check file exists", baseFile.exists() );
379 assertFalse( "Check file not created", userFile.exists() );
382 configuration = archivaConfiguration.getConfiguration();
383 assertFalse( "check value", configuration.getWebapp().getUi().isAppletFindEnabled() );
387 public void testStoreConfigurationFailsWhenReadFromBothLocationsNoLists()
390 File baseFile = getTestFile( "target/test/test-file.xml" );
392 assertFalse( baseFile.exists() );
394 File userFile = getTestFile( "target/test/test-file-user.xml" );
396 assertFalse( userFile.exists() );
398 baseFile.getParentFile().mkdirs();
399 FileUtils.writeStringToFile( baseFile, "<configuration/>", Charset.forName("UTF-8") );
401 userFile.getParentFile().mkdirs();
402 FileUtils.writeStringToFile( userFile, "<configuration/>", Charset.forName("UTF-8") );
404 ArchivaConfiguration archivaConfiguration =
405 (ArchivaConfiguration) lookup( ArchivaConfiguration.class, "test-save-user" );
407 archivaConfiguration.reload();
409 Configuration configuration = archivaConfiguration.getConfiguration();
410 assertTrue( "check value", configuration.getWebapp().getUi().isAppletFindEnabled() );
412 configuration.getWebapp().getUi().setAppletFindEnabled( false );
414 archivaConfiguration.save( configuration );
416 assertTrue( "Check file exists", baseFile.exists() );
417 assertEquals( "Check base file is unchanged", "<configuration/>",
418 FileUtils.readFileToString( baseFile, Charset.forName("UTF-8") ) );
419 assertTrue( "Check file exists", userFile.exists() );
420 assertFalse( "Check base file is changed",
421 "<configuration/>".equals( FileUtils.readFileToString( userFile, Charset.forName("UTF-8") ) ) );
424 configuration = archivaConfiguration.getConfiguration();
425 assertFalse( "check value", configuration.getWebapp().getUi().isAppletFindEnabled() );
429 public void testStoreConfigurationFailsWhenReadFromBothLocationsUserHasLists()
432 File baseFile = getTestFile( "target/test/test-file.xml" );
434 assertFalse( baseFile.exists() );
436 File userFile = getTestFile( "target/test/test-file-user.xml" );
438 assertFalse( userFile.exists() );
440 userFile.getParentFile().mkdirs();
441 FileUtils.copyFile( getTestFile( "src/test/conf/conf-user.xml" ), userFile );
443 baseFile.getParentFile().mkdirs();
444 FileUtils.writeStringToFile( baseFile, "<configuration/>", Charset.forName("UTF-8") );
446 ArchivaConfiguration archivaConfiguration =
447 (ArchivaConfiguration) lookup( ArchivaConfiguration.class, "test-save-user" );
449 archivaConfiguration.reload();
451 Configuration configuration = archivaConfiguration.getConfiguration();
452 assertTrue( "check value", configuration.getWebapp().getUi().isShowFindArtifacts() );
454 configuration.getWebapp().getUi().setShowFindArtifacts( false );
456 archivaConfiguration.save( configuration );
458 assertTrue( "Check file exists", baseFile.exists() );
459 assertEquals( "Check base file is unchanged", "<configuration/>",
460 FileUtils.readFileToString( baseFile, Charset.forName("UTF-8") ) );
461 assertTrue( "Check file exists", userFile.exists() );
462 assertFalse( "Check base file is changed",
463 "<configuration/>".equals( FileUtils.readFileToString( userFile, Charset.forName("UTF-8") ) ) );
466 configuration = archivaConfiguration.getConfiguration();
467 assertFalse( "check value", configuration.getWebapp().getUi().isShowFindArtifacts() );
471 public void testStoreConfigurationFailsWhenReadFromBothLocationsAppserverHasLists()
474 File baseFile = getTestFile( "target/test/test-file.xml" );
476 assertFalse( baseFile.exists() );
478 File userFile = getTestFile( "target/test/test-file-user.xml" );
480 assertFalse( userFile.exists() );
482 baseFile.getParentFile().mkdirs();
483 FileUtils.copyFile( getTestFile( "src/test/conf/conf-base.xml" ), baseFile );
485 userFile.getParentFile().mkdirs();
486 FileUtils.writeStringToFile( userFile, "<configuration/>", Charset.forName("UTF-8") );
488 ArchivaConfiguration archivaConfiguration =
489 (ArchivaConfiguration) lookup( ArchivaConfiguration.class, "test-save-user" );
491 archivaConfiguration.reload();
493 Configuration configuration = archivaConfiguration.getConfiguration();
494 assertTrue( "check value", configuration.getWebapp().getUi().isAppletFindEnabled() );
496 configuration.getWebapp().getUi().setAppletFindEnabled( false );
500 archivaConfiguration.save( configuration );
501 fail( "Configuration saving should not succeed if it was loaded from two locations" );
503 catch ( IndeterminateConfigurationException e )
505 // check it was reverted
506 configuration = archivaConfiguration.getConfiguration();
507 assertTrue( "check value", configuration.getWebapp().getUi().isAppletFindEnabled() );
512 public void testLoadConfigurationFromInvalidBothLocationsOnDisk()
515 ArchivaConfiguration archivaConfiguration =
516 lookup( ArchivaConfiguration.class, "test-not-allowed-to-write-to-both" );
517 Configuration config = archivaConfiguration.getConfiguration();
521 archivaConfiguration.save( config );
522 fail( "Should have thrown a RegistryException because the configuration can't be saved." );
524 catch ( RegistryException e )
526 /* expected exception */
531 public void testLoadConfigurationFromInvalidUserLocationOnDisk()
534 File testConfDir = getTestFile( "target/test-appserver-base/conf/" );
535 testConfDir.mkdirs();
537 ArchivaConfiguration archivaConfiguration =
538 lookup( ArchivaConfiguration.class, "test-not-allowed-to-write-to-user" );
539 Configuration config = archivaConfiguration.getConfiguration();
540 archivaConfiguration.save( config );
541 // No Exception == test passes.
542 // Expected Path is: Should not have thrown an exception.
546 public void testConfigurationUpgradeFrom09()
549 ArchivaConfiguration archivaConfiguration = lookup( ArchivaConfiguration.class, "test-upgrade-09" );
551 // we just use the defaults when upgrading from 0.9 at this point.
552 Configuration configuration = archivaConfiguration.getConfiguration();
553 // test-upgrade-09 contains a managed with id: local so it's 3 managed
554 assertConfiguration( configuration, 3, 1, 1 );
555 assertEquals( "check network proxies", 0, configuration.getNetworkProxies().size() );
557 ManagedRepositoryConfiguration repository = configuration.getManagedRepositories().get( 0 );
559 assertEquals( "check managed repositories", "${appserver.base}/repositories/internal",
560 repository.getLocation() );
561 assertEquals( "check managed repositories", "Archiva Managed Internal Repository", repository.getName() );
562 assertEquals( "check managed repositories", "internal", repository.getId() );
563 assertEquals( "check managed repositories", "default", repository.getLayout() );
564 assertTrue( "check managed repositories", repository.isScanned() );
568 public void testConfigurationUpgradeFrom13()
571 ArchivaConfiguration archivaConfiguration = lookup( ArchivaConfiguration.class, "test-upgrade-1.3" );
573 // we just use the defaults when upgrading from 1.3 at this point.
574 Configuration configuration = archivaConfiguration.getConfiguration();
575 assertConfiguration( configuration, 2, 2, 2 );
576 assertEquals( "check network proxies", 0, configuration.getNetworkProxies().size() );
578 ManagedRepositoryConfiguration repository = configuration.getManagedRepositories().get( 0 );
580 assertEquals( "check managed repositories", "${appserver.base}/data/repositories/internal",
581 repository.getLocation() );
582 assertEquals( "check managed repositories", "Archiva Managed Internal Repository", repository.getName() );
583 assertEquals( "check managed repositories", "internal", repository.getId() );
584 assertEquals( "check managed repositories", "default", repository.getLayout() );
585 assertTrue( "check managed repositories", repository.isScanned() );
587 log.info( "knowContentConsumers " + configuration.getRepositoryScanning().getKnownContentConsumers() );
590 configuration.getRepositoryScanning().getKnownContentConsumers().contains( "update-db-artifact" ) );
591 assertFalse( configuration.getRepositoryScanning().getKnownContentConsumers().contains(
592 "update-db-repository-metadata" ) );
595 configuration.getRepositoryScanning().getKnownContentConsumers().contains( "create-archiva-metadata" ) );
598 configuration.getRepositoryScanning().getKnownContentConsumers().contains( "duplicate-artifacts" ) );
602 public void testAutoDetectV1()
605 // Setup the autodetect-v1.xml file in the target directory (so we can save/load it)
606 File userFile = getTestFile( "target/test-autodetect-v1/archiva-user.xml" );
608 assertFalse( userFile.exists() );
610 userFile.getParentFile().mkdirs();
611 FileUtils.copyFile( getTestFile( "src/test/conf/autodetect-v1.xml" ), userFile );
613 // Load the original (unconverted) archiva.xml
614 ArchivaConfiguration archivaConfiguration = lookup( ArchivaConfiguration.class, "test-autodetect-v1" );
616 archivaConfiguration.reload();
618 Configuration configuration = archivaConfiguration.getConfiguration();
619 assertConfiguration( configuration, 2, 2, 2 );
620 assertEquals( "check network proxies", 1, configuration.getNetworkProxies().size() );
622 ManagedRepositoryConfiguration repository = configuration.getManagedRepositories().get( 0 );
624 assertEquals( "check managed repositories", "${appserver.base}/repositories/internal",
625 repository.getLocation() );
626 assertEquals( "check managed repositories", "Archiva Managed Internal Repository", repository.getName() );
627 assertEquals( "check managed repositories", "internal", repository.getId() );
628 assertEquals( "check managed repositories", "default", repository.getLayout() );
629 assertTrue( "check managed repositories", repository.isScanned() );
631 // Test that only 1 set of repositories exist.
632 assertEquals( "check managed repositories size.", 2, configuration.getManagedRepositories().size() );
633 assertEquals( "check remote repositories size.", 2, configuration.getRemoteRepositories().size() );
634 assertEquals( "check v1 repositories size.", 0, configuration.getRepositories().size() );
637 archivaConfiguration.save( configuration );
640 //release( archivaConfiguration );
643 archivaConfiguration = lookup( ArchivaConfiguration.class, "test-autodetect-v1" );
644 configuration = archivaConfiguration.getConfiguration();
646 // Test that only 1 set of repositories exist.
647 assertEquals( "check managed repositories size.", 2, configuration.getManagedRepositories().size() );
648 assertEquals( "check managed repositories size.", 2, configuration.getManagedRepositoriesAsMap().size() );
649 assertEquals( "check remote repositories size.", 2, configuration.getRemoteRepositories().size() );
650 assertEquals( "check remote repositories size.", 2, configuration.getRemoteRepositoriesAsMap().size() );
651 assertEquals( "check v1 repositories size.", 0, configuration.getRepositories().size() );
653 String actualXML = FileUtils.readFileToString( userFile, Charset.forName("UTF-8") );
654 XMLAssert.assertXpathNotExists( "//configuration/repositories/repository", actualXML );
655 XMLAssert.assertXpathNotExists( "//configuration/repositories", actualXML );
659 public void testArchivaV1()
662 ArchivaConfiguration archivaConfiguration = lookup( ArchivaConfiguration.class, "test-archiva-v1" );
664 Configuration configuration = archivaConfiguration.getConfiguration();
665 assertConfiguration( configuration, 2, 2, 2 );
666 assertEquals( "check network proxies", 1, configuration.getNetworkProxies().size() );
668 assertEquals( "check managed repositories", 2, configuration.getManagedRepositories().size() );
669 assertEquals( "check v1 repositories size.", 0, configuration.getRepositories().size() );
671 Map<String, ManagedRepositoryConfiguration> map = configuration.getManagedRepositoriesAsMap();
673 ManagedRepositoryConfiguration repository = map.get( "internal" );
674 assertEquals( "check managed repositories", "${appserver.base}/repositories/internal",
675 repository.getLocation() );
676 assertEquals( "check managed repositories", "Archiva Managed Internal Repository", repository.getName() );
677 assertEquals( "check managed repositories", "internal", repository.getId() );
678 assertEquals( "check managed repositories", "default", repository.getLayout() );
679 assertTrue( "check managed repositories", repository.isScanned() );
680 assertFalse( "check managed repositories", repository.isSnapshots() );
682 repository = map.get( "snapshots" );
683 assertEquals( "check managed repositories", "${appserver.base}/repositories/snapshots",
684 repository.getLocation() );
685 assertEquals( "check managed repositories", "Archiva Managed Snapshot Repository", repository.getName() );
686 assertEquals( "check managed repositories", "snapshots", repository.getId() );
687 assertEquals( "check managed repositories", "default", repository.getLayout() );
688 assertFalse( "check managed repositories", repository.isScanned() );
689 assertTrue( "check managed repositories", repository.isSnapshots() );
693 public void testCronExpressionsWithComma()
696 File baseFile = getTestFile( "target/test/test-file.xml" );
698 assertFalse( baseFile.exists() );
700 File userFile = getTestFile( "target/test/test-file-user.xml" );
702 assertFalse( userFile.exists() );
704 baseFile.getParentFile().mkdirs();
705 FileUtils.copyFile( getTestFile( "src/test/conf/escape-cron-expressions.xml" ), baseFile );
707 userFile.getParentFile().mkdirs();
708 FileUtils.writeStringToFile( userFile, "<configuration/>", Charset.defaultCharset() );
710 final ArchivaConfiguration archivaConfiguration = lookup( ArchivaConfiguration.class, "test-cron-expressions" );
712 archivaConfiguration.reload();
714 Configuration configuration = archivaConfiguration.getConfiguration();
716 ManagedRepositoryConfiguration repository = configuration.getManagedRepositories().get( 0 );
718 assertEquals( "check cron expression", "0 0,30 * * * ?", repository.getRefreshCronExpression().trim() );
720 // add a test listener to confirm it doesn't see the escaped format. We don't need to test the number of calls,
721 // etc. as it's done in other tests
722 archivaConfiguration.addListener( new ConfigurationListener()
724 public void configurationEvent( ConfigurationEvent event )
726 assertEquals( ConfigurationEvent.SAVED, event.getType() );
731 archivaConfiguration.save( configuration );
733 configuration = archivaConfiguration.getConfiguration();
735 // test for the escape character '\' showing up on repositories.jsp
736 repository.setRefreshCronExpression( "0 0,20 0 * * ?" );
738 archivaConfiguration.save( configuration );
740 repository = archivaConfiguration.getConfiguration().findManagedRepositoryById( "snapshots" );
742 assertEquals( "check cron expression", "0 0,20 0 * * ?", repository.getRefreshCronExpression() );
746 public void testRemoveLastElements()
749 File baseFile = getTestFile( "target/test/test-file.xml" );
751 assertFalse( baseFile.exists() );
753 File userFile = getTestFile( "target/test/test-file-user.xml" );
755 assertFalse( userFile.exists() );
757 baseFile.getParentFile().mkdirs();
758 FileUtils.copyFile( getTestFile( "src/test/conf/conf-single-list-elements.xml" ), baseFile );
760 userFile.getParentFile().mkdirs();
761 FileUtils.writeStringToFile( userFile, "<configuration/>", Charset.forName("UTF-8") );
763 ArchivaConfiguration archivaConfiguration = lookup( ArchivaConfiguration.class, "test-remove-central" );
765 archivaConfiguration.reload();
767 Configuration configuration = archivaConfiguration.getConfiguration();
769 RepositoryGroupConfiguration repositoryGroup = configuration.getRepositoryGroups().get( 0 );
770 assertNotNull( repositoryGroup );
771 configuration.removeRepositoryGroup( repositoryGroup );
772 assertTrue( configuration.getRepositoryGroups().isEmpty() );
774 RemoteRepositoryConfiguration repository = configuration.getRemoteRepositoriesAsMap().get( "central" );
775 assertNotNull( repository );
776 configuration.removeRemoteRepository( repository );
777 assertTrue( configuration.getRemoteRepositories().isEmpty() );
779 ManagedRepositoryConfiguration managedRepository =
780 configuration.getManagedRepositoriesAsMap().get( "snapshots" );
781 assertNotNull( managedRepository );
782 configuration.removeManagedRepository( managedRepository );
783 assertTrue( configuration.getManagedRepositories().isEmpty() );
785 ProxyConnectorConfiguration proxyConnector = configuration.getProxyConnectors().get( 0 );
786 assertNotNull( proxyConnector );
787 configuration.removeProxyConnector( proxyConnector );
788 assertTrue( configuration.getProxyConnectors().isEmpty() );
790 NetworkProxyConfiguration networkProxy = configuration.getNetworkProxiesAsMap().get( "proxy" );
791 assertNotNull( networkProxy );
792 configuration.removeNetworkProxy( networkProxy );
793 assertTrue( configuration.getNetworkProxies().isEmpty() );
795 LegacyArtifactPath path = configuration.getLegacyArtifactPaths().get( 0 );
796 assertNotNull( path );
797 configuration.removeLegacyArtifactPath( path );
798 assertTrue( configuration.getLegacyArtifactPaths().isEmpty() );
800 RepositoryScanningConfiguration scanning = configuration.getRepositoryScanning();
801 String consumer = scanning.getKnownContentConsumers().get( 0 );
802 assertNotNull( consumer );
803 scanning.removeKnownContentConsumer( consumer );
805 assertFalse( scanning.getKnownContentConsumers().isEmpty() );
806 consumer = scanning.getInvalidContentConsumers().get( 0 );
807 assertNotNull( consumer );
808 scanning.removeInvalidContentConsumer( consumer );
809 assertTrue( scanning.getInvalidContentConsumers().isEmpty() );
811 archivaConfiguration.save( configuration );
813 archivaConfiguration = lookup( ArchivaConfiguration.class, "test-read-saved" );
814 configuration = archivaConfiguration.getConfiguration();
815 assertNull( configuration.getRemoteRepositoriesAsMap().get( "central" ) );
816 assertTrue( configuration.getRepositoryGroups().isEmpty() );
817 assertNull( configuration.getManagedRepositoriesAsMap().get( "snapshots" ) );
818 assertTrue( configuration.getProxyConnectors().isEmpty() );
819 assertNull( configuration.getNetworkProxiesAsMap().get( "proxy" ) );
820 assertTrue( configuration.getLegacyArtifactPaths().isEmpty() );
821 scanning = configuration.getRepositoryScanning();
822 assertFalse( scanning.getKnownContentConsumers().isEmpty() );
823 assertTrue( scanning.getInvalidContentConsumers().isEmpty() );
827 * [MRM-582] Remote Repositories with empty <username> and <password> fields shouldn't be created in configuration.
830 public void testGetConfigurationFixEmptyRemoteRepoUsernamePassword()
833 ArchivaConfiguration archivaConfiguration = lookup( ArchivaConfiguration.class, "test-configuration" );
835 archivaConfiguration.reload();
836 Configuration configuration = archivaConfiguration.getConfiguration();
837 assertConfiguration( configuration, 2, 2, 2 );
838 assertEquals( "check remote repositories", 2, configuration.getRemoteRepositories().size() );
840 RemoteRepositoryConfiguration repository =
841 configuration.getRemoteRepositoriesAsMap().get( "maven2-repository.dev.java.net" );
843 assertEquals( "remote repository.url", "https://maven2-repository.dev.java.net/nonav/repository",
844 repository.getUrl() );
845 assertEquals( "remote repository.name", "Java.net Repository for Maven 2", repository.getName() );
846 assertEquals( "remote repository.id", "maven2-repository.dev.java.net", repository.getId() );
847 assertEquals( "remote repository.layout", "default", repository.getLayout() );
848 assertNull( "remote repository.username == null", repository.getUsername() );
849 assertNull( "remote repository.password == null", repository.getPassword() );