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.components.registry.RegistryException;
23 import org.apache.archiva.test.utils.ArchivaSpringJUnit4ClassRunner;
24 import org.apache.commons.io.FileUtils;
25 import org.apache.commons.lang3.StringUtils;
26 import org.junit.Test;
27 import org.junit.runner.RunWith;
28 import org.slf4j.Logger;
29 import org.slf4j.LoggerFactory;
30 import org.springframework.context.ApplicationContext;
31 import org.springframework.test.annotation.DirtiesContext;
32 import org.springframework.test.annotation.DirtiesContext.ClassMode;
33 import org.springframework.test.context.ContextConfiguration;
35 import javax.inject.Inject;
36 import java.nio.charset.Charset;
37 import java.nio.file.FileSystems;
38 import java.nio.file.Files;
39 import java.nio.file.Path;
40 import java.nio.file.Paths;
41 import java.util.List;
43 import static org.easymock.EasyMock.*;
44 import static org.junit.Assert.*;
47 * Test the configuration store.
49 @RunWith(ArchivaSpringJUnit4ClassRunner.class)
50 @ContextConfiguration(locations = { "classpath*:/META-INF/spring-context.xml", "classpath:/spring-context.xml" })
51 @DirtiesContext(classMode = ClassMode.AFTER_EACH_TEST_METHOD)
52 public class ArchivaConfigurationTest
55 private Logger log = LoggerFactory.getLogger( getClass() );
58 protected ApplicationContext applicationContext;
63 public static Path getTestFile( String path )
65 return Paths.get( org.apache.archiva.common.utils.FileUtils.getBasedir(), path );
68 @SuppressWarnings( "unchecked" )
69 protected <T> T lookup( Class<T> clazz, String hint )
71 return (T) applicationContext.getBean( "archivaConfiguration#" + hint, ArchivaConfiguration.class );
75 public void testGetConfigurationFromDefaults()
78 ArchivaConfiguration archivaConfiguration = lookup( ArchivaConfiguration.class, "test-defaults" );
79 Configuration configuration = archivaConfiguration.getConfiguration();
81 assertConfiguration( configuration, 2, 1, 1 );
82 assertEquals( "check network proxies", 0, configuration.getNetworkProxies().size() );
84 ManagedRepositoryConfiguration repository = configuration.getManagedRepositories().get( 0 );
86 assertEquals( "check managed repositories", "${appserver.base}/repositories/internal",
87 repository.getLocation() );
88 assertEquals( "check managed repositories", "Archiva Managed Internal Repository", repository.getName() );
89 assertEquals( "check managed repositories", "internal", repository.getId() );
90 assertEquals( "check managed repositories", "default", repository.getLayout() );
91 assertTrue( "check managed repositories", repository.isScanned() );
95 public void testGetConfigurationFromRegistryWithASingleNamedConfigurationResource()
98 ArchivaConfiguration archivaConfiguration = lookup( ArchivaConfiguration.class, "test-configuration" );
99 Configuration configuration = archivaConfiguration.getConfiguration();
100 assertConfiguration( configuration, 2, 2, 2 );
101 assertEquals( "check network proxies", 1, configuration.getNetworkProxies().size() );
103 ManagedRepositoryConfiguration repository = configuration.getManagedRepositories().get( 0 );
105 assertEquals( "check managed repositories", "${appserver.base}/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() );
114 * Ensures that the provided configuration matches the details present in the archiva-default.xml file.
116 private void assertConfiguration( Configuration configuration, int managedExpected, int remoteExpected,
117 int proxyConnectorExpected )
121 assertEquals( "check managed repositories: " + configuration.getManagedRepositories(), managedExpected,
122 configuration.getManagedRepositories().size() );
123 assertEquals( "check remote repositories: " + configuration.getRemoteRepositories(), remoteExpected,
124 configuration.getRemoteRepositories().size() );
125 assertEquals( "check proxy connectors:" + configuration.getProxyConnectors(), proxyConnectorExpected,
126 configuration.getProxyConnectors().size() );
128 RepositoryScanningConfiguration repoScanning = configuration.getRepositoryScanning();
129 assertNotNull( "check repository scanning", repoScanning );
130 assertEquals( "check file types", 4, repoScanning.getFileTypes().size() );
131 assertEquals( "check known consumers", 9, repoScanning.getKnownContentConsumers().size() );
132 assertEquals( "check invalid consumers", 1, repoScanning.getInvalidContentConsumers().size() );
134 List<String> patterns = filetypes.getFileTypePatterns( "artifacts" );
135 assertNotNull( "check 'artifacts' file type", patterns );
136 assertEquals( "check 'artifacts' patterns", 13, patterns.size() );
138 WebappConfiguration webapp = configuration.getWebapp();
139 assertNotNull( "check webapp", webapp );
141 UserInterfaceOptions ui = webapp.getUi();
142 assertNotNull( "check webapp ui", ui );
143 assertTrue( "check showFindArtifacts", ui.isShowFindArtifacts() );
144 assertTrue( "check appletFindEnabled", ui.isAppletFindEnabled() );
148 public void testGetConfigurationFromRegistryWithTwoConfigurationResources()
151 ArchivaConfiguration archivaConfiguration = lookup( ArchivaConfiguration.class, "test-configuration-both" );
153 Configuration configuration = archivaConfiguration.getConfiguration();
156 assertEquals( "check repositories", 2, configuration.getManagedRepositories().size() );
157 assertEquals( "check repositories", 2, configuration.getRemoteRepositories().size() );
159 assertEquals( "check proxy connectors", 2, configuration.getProxyConnectors().size() );
161 WebappConfiguration webapp = configuration.getWebapp();
162 assertNotNull( "check webapp", webapp );
164 UserInterfaceOptions ui = webapp.getUi();
165 assertNotNull( "check webapp ui", ui );
167 assertFalse( "check showFindArtifacts", ui.isShowFindArtifacts() );
169 assertFalse( "check appletFindEnabled", ui.isAppletFindEnabled() );
173 public void testGetConfigurationSystemOverride()
177 System.setProperty( "org.apache.archiva.webapp.ui.appletFindEnabled", "false" );
179 ArchivaConfiguration archivaConfiguration = lookup( ArchivaConfiguration.class, "test-configuration" );
181 archivaConfiguration.reload();
185 Configuration configuration = archivaConfiguration.getConfiguration();
187 assertFalse( "check boolean", configuration.getWebapp().getUi().isAppletFindEnabled() );
191 System.getProperties().remove( "org.apache.archiva.webapp.ui.appletFindEnabled" );
192 archivaConfiguration.reload();
193 Configuration configuration = archivaConfiguration.getConfiguration();
194 assertTrue( "check boolean", configuration.getWebapp().getUi().isAppletFindEnabled() );
199 public void testStoreConfiguration()
202 Path file = getTestFile( "target/test/test-file.xml" );
203 Files.deleteIfExists(file);
204 assertFalse( Files.exists(file) );
206 // TODO: remove with commons-configuration 1.4
207 //file.getParentFile().mkdirs();
208 //FileUtils.writeStringToFile( file, "<configuration/>", null );
210 DefaultArchivaConfiguration archivaConfiguration =
211 (DefaultArchivaConfiguration) lookup( ArchivaConfiguration.class, "test-save" );
213 archivaConfiguration.reload();
215 Configuration configuration = new Configuration();
216 configuration.setVersion( "1" );
217 configuration.setWebapp( new WebappConfiguration() );
218 configuration.getWebapp().setUi( new UserInterfaceOptions() );
219 configuration.getWebapp().getUi().setAppletFindEnabled( false );
221 // add a change listener
222 ConfigurationListener listener = createMock( ConfigurationListener.class );
223 archivaConfiguration.addListener( listener );
225 listener.configurationEvent( new ConfigurationEvent( ConfigurationEvent.SAVED ) );
229 archivaConfiguration.save( configuration );
233 assertTrue( "Check file exists", Files.exists(file) );
236 configuration = archivaConfiguration.getConfiguration();
237 assertFalse( "check value", configuration.getWebapp().getUi().isAppletFindEnabled() );
240 archivaConfiguration = (DefaultArchivaConfiguration) lookup( ArchivaConfiguration.class, "test-read-saved" );
242 archivaConfiguration.reload();
243 configuration = archivaConfiguration.getConfiguration();
244 assertFalse( "check value", configuration.getWebapp().getUi().isAppletFindEnabled() );
247 private static ConfigurationListener createConfigurationListenerMockControl()
249 return createMock( ConfigurationListener.class );// MockControl.createControl( ConfigurationListener.class );
253 public void testStoreConfigurationUser()
256 Path baseFile = getTestFile( "target/test/test-file.xml" );
257 Files.deleteIfExists( baseFile );
258 assertFalse( Files.exists(baseFile) );
260 Path userFile = getTestFile( "target/test/test-file-user.xml" );
261 Files.deleteIfExists( userFile );
262 assertFalse( Files.exists(userFile) );
264 Files.createDirectories(userFile.getParent());
265 FileUtils.writeStringToFile( userFile.toFile(), "<configuration/>", Charset.forName( "UTF-8" ) );
267 ArchivaConfiguration archivaConfiguration = lookup( ArchivaConfiguration.class, "test-save-user" );
269 Configuration configuration = new Configuration();
270 configuration.setWebapp( new WebappConfiguration() );
271 configuration.getWebapp().setUi( new UserInterfaceOptions() );
272 configuration.getWebapp().getUi().setAppletFindEnabled( false );
274 archivaConfiguration.save( configuration );
276 assertTrue( "Check file exists", Files.exists(userFile) );
277 assertFalse( "Check file not created", Files.exists(baseFile) );
280 configuration = archivaConfiguration.getConfiguration();
281 assertFalse( "check value", configuration.getWebapp().getUi().isAppletFindEnabled() );
285 public void testStoreConfigurationLoadedFromDefaults()
288 Path baseFile = getTestFile( "target/test/test-file.xml" );
289 Files.delete(baseFile);
290 assertFalse( Files.exists(baseFile) );
292 Path userFile = getTestFile( "target/test/test-file-user.xml" );
293 Files.deleteIfExists(userFile);
294 assertFalse( Files.exists(userFile) );
296 ArchivaConfiguration archivaConfiguration = lookup( ArchivaConfiguration.class, "test-save-user-defaults" );
298 archivaConfiguration.reload();
300 Configuration configuration = new Configuration();
301 configuration.setWebapp( new WebappConfiguration() );
302 configuration.getWebapp().setUi( new UserInterfaceOptions() );
303 configuration.getWebapp().getUi().setAppletFindEnabled( false );
305 // add a change listener
306 ConfigurationListener listener = createConfigurationListenerMockControl();
307 archivaConfiguration.addListener( listener );
309 listener.configurationEvent( new ConfigurationEvent( ConfigurationEvent.SAVED ) );
313 archivaConfiguration.save( configuration );
317 assertTrue( "Check file exists", Files.exists(userFile) );
318 assertFalse( "Check file not created", Files.exists(baseFile) );
321 configuration = archivaConfiguration.getConfiguration();
322 assertFalse( "check value", configuration.getWebapp().getUi().isAppletFindEnabled() );
326 public void testDefaultUserConfigFilename()
329 DefaultArchivaConfiguration archivaConfiguration =
330 (DefaultArchivaConfiguration) lookup( ArchivaConfiguration.class, "default" );
331 String expectedFile = System.getProperty( "user.home" ) + "/.m2/archiva.xml";
332 String systemFile = System.getProperty(ArchivaConfiguration.USER_CONFIG_PROPERTY);
333 if (StringUtils.isNotEmpty( systemFile )) {
334 expectedFile = systemFile;
337 String envFile = System.getenv( ArchivaConfiguration.USER_CONFIG_ENVVAR );
338 if ( StringUtils.isNotEmpty( envFile ) )
339 expectedFile = envFile;
342 archivaConfiguration.reload();
344 assertEquals( expectedFile,
345 archivaConfiguration.getUserConfigFilename() );
346 assertEquals( System.getProperty( "appserver.base", "${appserver.base}" ) + "/conf/archiva.xml",
347 archivaConfiguration.getAltConfigFilename() );
351 public void testStoreConfigurationFallback()
354 Path baseFile = getTestFile( "target/test/test-file.xml" );
355 Files.deleteIfExists(baseFile);
356 assertFalse( Files.exists(baseFile) );
358 Path userFile = getTestFile( "target/test/test-file-user.xml" );
359 Files.deleteIfExists(userFile);
360 assertFalse( Files.exists(userFile) );
362 Files.createDirectories( baseFile.getParent());
363 FileUtils.writeStringToFile( baseFile.toFile(), "<configuration/>", Charset.forName( "UTF-8" ) );
365 ArchivaConfiguration archivaConfiguration =
366 (ArchivaConfiguration) lookup( ArchivaConfiguration.class, "test-save-user-fallback" );
368 archivaConfiguration.reload();
370 Configuration configuration = new Configuration();
371 configuration.setWebapp( new WebappConfiguration() );
372 configuration.getWebapp().setUi( new UserInterfaceOptions() );
373 configuration.getWebapp().getUi().setAppletFindEnabled( false );
375 archivaConfiguration.save( configuration );
377 assertTrue( "Check file exists", Files.exists(baseFile) );
378 assertFalse( "Check file not created", Files.exists(userFile) );
381 configuration = archivaConfiguration.getConfiguration();
382 assertFalse( "check value", configuration.getWebapp().getUi().isAppletFindEnabled() );
386 public void testStoreConfigurationFailsWhenReadFromBothLocationsNoLists()
389 Path baseFile = getTestFile( "target/test/test-file.xml" );
390 Files.deleteIfExists(baseFile);
391 assertFalse( Files.exists(baseFile) );
393 Path userFile = getTestFile( "target/test/test-file-user.xml" );
394 Files.deleteIfExists(userFile);
395 assertFalse( Files.exists(userFile) );
397 Files.createDirectories( baseFile.getParent() );
398 FileUtils.writeStringToFile( baseFile.toFile(), "<configuration/>", Charset.forName( "UTF-8" ) );
400 Files.createDirectories( userFile.getParent());
401 FileUtils.writeStringToFile( userFile.toFile(), "<configuration/>", Charset.forName( "UTF-8" ) );
403 ArchivaConfiguration archivaConfiguration = lookup( ArchivaConfiguration.class, "test-save-user" );
405 archivaConfiguration.reload();
407 Configuration configuration = archivaConfiguration.getConfiguration();
408 assertTrue( "check value", configuration.getWebapp().getUi().isAppletFindEnabled() );
410 configuration.getWebapp().getUi().setAppletFindEnabled( false );
412 archivaConfiguration.save( configuration );
414 assertTrue( "Check file exists", Files.exists(baseFile) );
415 assertEquals( "Check base file is unchanged", "<configuration/>",
416 FileUtils.readFileToString( baseFile.toFile(), Charset.forName( "UTF-8" ) ) );
417 assertTrue( "Check file exists", Files.exists(userFile) );
418 assertFalse( "Check base file is changed",
419 "<configuration/>".equals( FileUtils.readFileToString( userFile.toFile(), Charset.forName( "UTF-8" ) ) ) );
422 configuration = archivaConfiguration.getConfiguration();
423 assertFalse( "check value", configuration.getWebapp().getUi().isAppletFindEnabled() );
427 public void testStoreConfigurationFailsWhenReadFromBothLocationsUserHasLists()
430 Path baseFile = getTestFile( "target/test/test-file.xml" );
431 Files.deleteIfExists(baseFile);
432 assertFalse( Files.exists(baseFile) );
434 Path userFile = getTestFile( "target/test/test-file-user.xml" );
435 Files.deleteIfExists(userFile);
436 assertFalse( Files.exists(userFile) );
438 Files.createDirectories( userFile.getParent() );
439 FileUtils.copyFile( getTestFile( "src/test/conf/conf-user.xml" ).toFile(), userFile.toFile() );
441 Files.createDirectories(baseFile.getParent());
442 FileUtils.writeStringToFile( baseFile.toFile(), "<configuration/>", Charset.forName( "UTF-8" ) );
444 ArchivaConfiguration archivaConfiguration = lookup( ArchivaConfiguration.class, "test-save-user" );
446 archivaConfiguration.reload();
448 Configuration configuration = archivaConfiguration.getConfiguration();
449 assertTrue( "check value", configuration.getWebapp().getUi().isShowFindArtifacts() );
451 configuration.getWebapp().getUi().setShowFindArtifacts( false );
453 archivaConfiguration.save( configuration );
455 assertTrue( "Check file exists", Files.exists(baseFile) );
456 assertEquals( "Check base file is unchanged", "<configuration/>",
457 FileUtils.readFileToString( baseFile.toFile(), Charset.forName( "UTF-8" ) ) );
458 assertTrue( "Check file exists", Files.exists(userFile) );
459 assertFalse( "Check base file is changed",
460 "<configuration/>".equals( FileUtils.readFileToString( userFile.toFile(), Charset.forName( "UTF-8" ) ) ) );
463 configuration = archivaConfiguration.getConfiguration();
464 assertFalse( "check value", configuration.getWebapp().getUi().isShowFindArtifacts() );
468 public void testStoreConfigurationFailsWhenReadFromBothLocationsAppserverHasLists()
471 Path baseFile = getTestFile( "target/test/test-file.xml" );
472 Files.deleteIfExists(baseFile);
473 assertFalse( Files.exists(baseFile) );
475 Path userFile = getTestFile( "target/test/test-file-user.xml" );
476 Files.deleteIfExists(userFile);
477 assertFalse( Files.exists(userFile) );
479 Files.createDirectories(baseFile.getParent());
480 FileUtils.copyFile( getTestFile( "src/test/conf/conf-base.xml" ).toFile(), baseFile.toFile() );
482 Files.createDirectories(userFile.getParent());
483 FileUtils.writeStringToFile( userFile.toFile(), "<configuration/>", Charset.forName( "UTF-8" ) );
485 ArchivaConfiguration archivaConfiguration = lookup( ArchivaConfiguration.class, "test-save-user" );
487 archivaConfiguration.reload();
489 Configuration configuration = archivaConfiguration.getConfiguration();
490 assertTrue( "check value", configuration.getWebapp().getUi().isAppletFindEnabled() );
492 configuration.getWebapp().getUi().setAppletFindEnabled( false );
496 archivaConfiguration.save( configuration );
497 fail( "Configuration saving should not succeed if it was loaded from two locations" );
499 catch ( IndeterminateConfigurationException e )
501 // check it was reverted
502 configuration = archivaConfiguration.getConfiguration();
503 assertTrue( "check value", configuration.getWebapp().getUi().isAppletFindEnabled() );
508 public void testLoadConfigurationFromInvalidBothLocationsOnDisk()
511 String propFile = System.getProperty( ArchivaConfiguration.USER_CONFIG_PROPERTY );
512 System.setProperty( ArchivaConfiguration.USER_CONFIG_PROPERTY, "/../../..//*intentionally:invalid*/.m2/archiva-user.xml" );
513 ArchivaConfiguration archivaConfiguration =
514 lookup( ArchivaConfiguration.class, "test-not-allowed-to-write-to-both" );
515 Configuration config = archivaConfiguration.getConfiguration();
519 archivaConfiguration.save( config );
520 fail( "Should have thrown a RegistryException because the configuration can't be saved." );
522 catch ( RegistryException e )
524 /* expected exception */
528 System.setProperty( ArchivaConfiguration.USER_CONFIG_PROPERTY, propFile );
533 public void testLoadConfigurationFromInvalidUserLocationOnDisk()
536 Path testConfDir = getTestFile( "target/test-appserver-base/conf/" );
537 Files.createDirectories( testConfDir );
539 ArchivaConfiguration archivaConfiguration =
540 lookup( ArchivaConfiguration.class, "test-not-allowed-to-write-to-user" );
541 Configuration config = archivaConfiguration.getConfiguration();
542 archivaConfiguration.save( config );
543 // No Exception == test passes.
544 // Expected Path is: Should not have thrown an exception.
549 public void testConfigurationUpgradeFrom13()
552 ArchivaConfiguration archivaConfiguration = lookup( ArchivaConfiguration.class, "test-upgrade-1.3" );
554 // we just use the defaults when upgrading from 1.3 at this point.
555 Configuration configuration = archivaConfiguration.getConfiguration();
556 assertConfiguration( configuration, 2, 2, 2 );
557 assertEquals( "check network proxies", 0, configuration.getNetworkProxies().size() );
559 ManagedRepositoryConfiguration repository = configuration.getManagedRepositories().get( 0 );
561 assertEquals( "check managed repositories", "${appserver.base}/data/repositories/internal",
562 repository.getLocation() );
563 assertEquals( "check managed repositories", "Archiva Managed Internal Repository", repository.getName() );
564 assertEquals( "check managed repositories", "internal", repository.getId() );
565 assertEquals( "check managed repositories", "default", repository.getLayout() );
566 assertTrue( "check managed repositories", repository.isScanned() );
568 log.info( "knowContentConsumers {}", configuration.getRepositoryScanning().getKnownContentConsumers() );
571 configuration.getRepositoryScanning().getKnownContentConsumers().contains( "update-db-artifact" ) );
572 assertFalse( configuration.getRepositoryScanning().getKnownContentConsumers().contains(
573 "update-db-repository-metadata" ) );
576 configuration.getRepositoryScanning().getKnownContentConsumers().contains( "create-archiva-metadata" ) );
579 configuration.getRepositoryScanning().getKnownContentConsumers().contains( "duplicate-artifacts" ) );
584 public void testCronExpressionsWithComma()
587 Path baseFile = getTestFile( "target/test/test-file.xml" );
588 Files.deleteIfExists(baseFile);
589 assertFalse( Files.exists(baseFile) );
591 Path userFile = getTestFile( "target/test/test-file-user.xml" );
592 Files.deleteIfExists(userFile);
593 assertFalse( Files.exists(userFile) );
595 Files.createDirectories(baseFile.getParent());
596 FileUtils.copyFile( getTestFile( "src/test/conf/escape-cron-expressions.xml" ).toFile(), baseFile.toFile() );
598 Files.createDirectories(userFile.getParent());
599 FileUtils.writeStringToFile( userFile.toFile(), "<configuration/>", Charset.defaultCharset() );
601 final ArchivaConfiguration archivaConfiguration = lookup( ArchivaConfiguration.class, "test-cron-expressions" );
603 archivaConfiguration.reload();
605 Configuration configuration = archivaConfiguration.getConfiguration();
607 ManagedRepositoryConfiguration repository = configuration.getManagedRepositories().get( 0 );
609 assertEquals( "check cron expression", "0 0,30 * * * ?", repository.getRefreshCronExpression().trim() );
611 // add a test listener to confirm it doesn't see the escaped format. We don't need to test the number of calls,
612 // etc. as it's done in other tests
613 archivaConfiguration.addListener( new ConfigurationListener()
616 public void configurationEvent( ConfigurationEvent event )
618 assertEquals( ConfigurationEvent.SAVED, event.getType() );
623 archivaConfiguration.save( configuration );
625 configuration = archivaConfiguration.getConfiguration();
627 // test for the escape character '\' showing up on repositories.jsp
628 repository.setRefreshCronExpression( "0 0,20 0 * * ?" );
630 archivaConfiguration.save( configuration );
632 repository = archivaConfiguration.getConfiguration().findManagedRepositoryById( "snapshots" );
634 assertEquals( "check cron expression", "0 0,20 0 * * ?", repository.getRefreshCronExpression() );
638 public void testRemoveLastElements()
641 Path baseFile = getTestFile( "target/test/test-file.xml" );
642 Files.deleteIfExists(baseFile);
643 assertFalse( Files.exists(baseFile) );
645 Path userFile = getTestFile( "target/test/test-file-user.xml" );
646 Files.deleteIfExists(userFile);
647 assertFalse( Files.exists(userFile) );
649 Files.createDirectories( baseFile.getParent() );
650 FileUtils.copyFile( getTestFile( "src/test/conf/conf-single-list-elements.xml" ).toFile(), baseFile.toFile() );
652 Files.createDirectories( userFile.getParent());
653 FileUtils.writeStringToFile( userFile.toFile(), "<configuration/>", Charset.forName( "UTF-8" ) );
655 ArchivaConfiguration archivaConfiguration = lookup( ArchivaConfiguration.class, "test-remove-central" );
657 archivaConfiguration.reload();
659 Configuration configuration = archivaConfiguration.getConfiguration();
661 RepositoryGroupConfiguration repositoryGroup = configuration.getRepositoryGroups().get( 0 );
662 assertNotNull( repositoryGroup );
663 configuration.removeRepositoryGroup( repositoryGroup );
664 assertTrue( configuration.getRepositoryGroups().isEmpty() );
666 RemoteRepositoryConfiguration repository = configuration.getRemoteRepositoriesAsMap().get( "central" );
667 assertNotNull( repository );
668 configuration.removeRemoteRepository( repository );
669 assertTrue( configuration.getRemoteRepositories().isEmpty() );
671 ManagedRepositoryConfiguration managedRepository =
672 configuration.getManagedRepositoriesAsMap().get( "snapshots" );
673 assertNotNull( managedRepository );
674 configuration.removeManagedRepository( managedRepository );
675 assertTrue( configuration.getManagedRepositories().isEmpty() );
677 ProxyConnectorConfiguration proxyConnector = configuration.getProxyConnectors().get( 0 );
678 assertNotNull( proxyConnector );
679 configuration.removeProxyConnector( proxyConnector );
680 assertTrue( configuration.getProxyConnectors().isEmpty() );
682 NetworkProxyConfiguration networkProxy = configuration.getNetworkProxiesAsMap().get( "proxy" );
683 assertNotNull( networkProxy );
684 configuration.removeNetworkProxy( networkProxy );
685 assertTrue( configuration.getNetworkProxies().isEmpty() );
687 LegacyArtifactPath path = configuration.getLegacyArtifactPaths().get( 0 );
688 assertNotNull( path );
689 configuration.removeLegacyArtifactPath( path );
690 assertTrue( configuration.getLegacyArtifactPaths().isEmpty() );
692 RepositoryScanningConfiguration scanning = configuration.getRepositoryScanning();
693 String consumer = scanning.getKnownContentConsumers().get( 0 );
694 assertNotNull( consumer );
695 scanning.removeKnownContentConsumer( consumer );
697 assertFalse( scanning.getKnownContentConsumers().isEmpty() );
698 consumer = scanning.getInvalidContentConsumers().get( 0 );
699 assertNotNull( consumer );
700 scanning.removeInvalidContentConsumer( consumer );
701 assertTrue( scanning.getInvalidContentConsumers().isEmpty() );
703 archivaConfiguration.save( configuration );
705 archivaConfiguration = lookup( ArchivaConfiguration.class, "test-read-saved" );
706 configuration = archivaConfiguration.getConfiguration();
707 assertNull( configuration.getRemoteRepositoriesAsMap().get( "central" ) );
708 assertTrue( configuration.getRepositoryGroups().isEmpty() );
709 assertNull( configuration.getManagedRepositoriesAsMap().get( "snapshots" ) );
710 assertTrue( configuration.getProxyConnectors().isEmpty() );
711 assertNull( configuration.getNetworkProxiesAsMap().get( "proxy" ) );
712 assertTrue( configuration.getLegacyArtifactPaths().isEmpty() );
713 scanning = configuration.getRepositoryScanning();
714 assertFalse( scanning.getKnownContentConsumers().isEmpty() );
715 assertTrue( scanning.getInvalidContentConsumers().isEmpty() );
719 * [MRM-582] Remote Repositories with empty <username> and <password> fields shouldn't be created in configuration.
722 public void testGetConfigurationFixEmptyRemoteRepoUsernamePassword()
725 ArchivaConfiguration archivaConfiguration = lookup( ArchivaConfiguration.class, "test-configuration" );
727 Configuration configuration = archivaConfiguration.getConfiguration();
728 assertConfiguration( configuration, 2, 2, 2 );
729 assertEquals( "check remote repositories", 2, configuration.getRemoteRepositories().size() );
731 RemoteRepositoryConfiguration repository =
732 configuration.getRemoteRepositoriesAsMap().get( "maven2-repository.dev.java.net" );
734 assertEquals( "remote repository.url", "https://maven2-repository.dev.java.net/nonav/repository",
735 repository.getUrl() );
736 assertEquals( "remote repository.name", "Java.net Repository for Maven 2", repository.getName() );
737 assertEquals( "remote repository.id", "maven2-repository.dev.java.net", repository.getId() );
738 assertEquals( "remote repository.layout", "default", repository.getLayout() );
739 assertNull( "remote repository.username == null", repository.getUsername() );
740 assertNull( "remote repository.password == null", repository.getPassword() );