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.mockito.Mockito;
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;
37 import java.nio.charset.Charset;
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.junit.Assert.*;
44 import static org.mockito.Mockito.mock;
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 = mock( ConfigurationListener.class );
223 archivaConfiguration.addListener( listener );
225 listener.configurationEvent( new ConfigurationEvent( ConfigurationEvent.SAVED ) );
227 archivaConfiguration.save( configuration );
229 assertTrue( "Check file exists", Files.exists(file) );
232 configuration = archivaConfiguration.getConfiguration();
233 assertFalse( "check value", configuration.getWebapp().getUi().isAppletFindEnabled() );
236 archivaConfiguration = (DefaultArchivaConfiguration) lookup( ArchivaConfiguration.class, "test-read-saved" );
238 archivaConfiguration.reload();
239 configuration = archivaConfiguration.getConfiguration();
240 assertFalse( "check value", configuration.getWebapp().getUi().isAppletFindEnabled() );
243 private static ConfigurationListener createConfigurationListenerMockControl()
245 return mock( ConfigurationListener.class );// MockControl.createControl( ConfigurationListener.class );
249 public void testStoreConfigurationUser()
252 Path baseFile = getTestFile( "target/test/test-file.xml" );
253 Files.deleteIfExists( baseFile );
254 assertFalse( Files.exists(baseFile) );
256 Path userFile = getTestFile( "target/test/test-file-user.xml" );
257 Files.deleteIfExists( userFile );
258 assertFalse( Files.exists(userFile) );
260 Files.createDirectories(userFile.getParent());
261 FileUtils.writeStringToFile( userFile.toFile(), "<configuration/>", Charset.forName( "UTF-8" ) );
263 ArchivaConfiguration archivaConfiguration = lookup( ArchivaConfiguration.class, "test-save-user" );
265 Configuration configuration = new Configuration();
266 configuration.setWebapp( new WebappConfiguration() );
267 configuration.getWebapp().setUi( new UserInterfaceOptions() );
268 configuration.getWebapp().getUi().setAppletFindEnabled( false );
270 archivaConfiguration.save( configuration );
272 assertTrue( "Check file exists", Files.exists(userFile) );
273 assertFalse( "Check file not created", Files.exists(baseFile) );
276 configuration = archivaConfiguration.getConfiguration();
277 assertFalse( "check value", configuration.getWebapp().getUi().isAppletFindEnabled() );
281 public void testStoreConfigurationLoadedFromDefaults()
284 Path baseFile = getTestFile( "target/test/test-file.xml" );
285 Files.delete(baseFile);
286 assertFalse( Files.exists(baseFile) );
288 Path userFile = getTestFile( "target/test/test-file-user.xml" );
289 Files.deleteIfExists(userFile);
290 assertFalse( Files.exists(userFile) );
292 ArchivaConfiguration archivaConfiguration = lookup( ArchivaConfiguration.class, "test-save-user-defaults" );
294 archivaConfiguration.reload();
296 Configuration configuration = new Configuration();
297 configuration.setWebapp( new WebappConfiguration() );
298 configuration.getWebapp().setUi( new UserInterfaceOptions() );
299 configuration.getWebapp().getUi().setAppletFindEnabled( false );
301 // add a change listener
302 ConfigurationListener listener = createConfigurationListenerMockControl();
303 archivaConfiguration.addListener( listener );
305 listener.configurationEvent( new ConfigurationEvent( ConfigurationEvent.SAVED ) );
307 archivaConfiguration.save( configuration );
309 assertTrue( "Check file exists", Files.exists(userFile) );
310 assertFalse( "Check file not created", Files.exists(baseFile) );
313 configuration = archivaConfiguration.getConfiguration();
314 assertFalse( "check value", configuration.getWebapp().getUi().isAppletFindEnabled() );
318 public void testDefaultUserConfigFilename()
321 DefaultArchivaConfiguration archivaConfiguration =
322 (DefaultArchivaConfiguration) lookup( ArchivaConfiguration.class, "default" );
323 String expectedFile = System.getProperty( "user.home" ) + "/.m2/archiva.xml";
324 String systemFile = System.getProperty(ArchivaConfiguration.USER_CONFIG_PROPERTY);
325 if (StringUtils.isNotEmpty( systemFile )) {
326 expectedFile = systemFile;
329 String envFile = System.getenv( ArchivaConfiguration.USER_CONFIG_ENVVAR );
330 if ( StringUtils.isNotEmpty( envFile ) )
331 expectedFile = envFile;
334 archivaConfiguration.reload();
336 assertEquals( expectedFile,
337 archivaConfiguration.getUserConfigFilename() );
338 assertEquals( System.getProperty( "appserver.base", "${appserver.base}" ) + "/conf/archiva.xml",
339 archivaConfiguration.getAltConfigFilename() );
343 public void testStoreConfigurationFallback()
346 Path baseFile = getTestFile( "target/test/test-file.xml" );
347 Files.deleteIfExists(baseFile);
348 assertFalse( Files.exists(baseFile) );
350 Path userFile = getTestFile( "target/test/test-file-user.xml" );
351 Files.deleteIfExists(userFile);
352 assertFalse( Files.exists(userFile) );
354 Files.createDirectories( baseFile.getParent());
355 FileUtils.writeStringToFile( baseFile.toFile(), "<configuration/>", Charset.forName( "UTF-8" ) );
357 ArchivaConfiguration archivaConfiguration =
358 (ArchivaConfiguration) lookup( ArchivaConfiguration.class, "test-save-user-fallback" );
360 archivaConfiguration.reload();
362 Configuration configuration = new Configuration();
363 configuration.setWebapp( new WebappConfiguration() );
364 configuration.getWebapp().setUi( new UserInterfaceOptions() );
365 configuration.getWebapp().getUi().setAppletFindEnabled( false );
367 archivaConfiguration.save( configuration );
369 assertTrue( "Check file exists", Files.exists(baseFile) );
370 assertFalse( "Check file not created", Files.exists(userFile) );
373 configuration = archivaConfiguration.getConfiguration();
374 assertFalse( "check value", configuration.getWebapp().getUi().isAppletFindEnabled() );
378 public void testStoreConfigurationFailsWhenReadFromBothLocationsNoLists()
381 Path baseFile = getTestFile( "target/test/test-file.xml" );
382 Files.deleteIfExists(baseFile);
383 assertFalse( Files.exists(baseFile) );
385 Path userFile = getTestFile( "target/test/test-file-user.xml" );
386 Files.deleteIfExists(userFile);
387 assertFalse( Files.exists(userFile) );
389 Files.createDirectories( baseFile.getParent() );
390 FileUtils.writeStringToFile( baseFile.toFile(), "<configuration/>", Charset.forName( "UTF-8" ) );
392 Files.createDirectories( userFile.getParent());
393 FileUtils.writeStringToFile( userFile.toFile(), "<configuration/>", Charset.forName( "UTF-8" ) );
395 ArchivaConfiguration archivaConfiguration = lookup( ArchivaConfiguration.class, "test-save-user" );
397 archivaConfiguration.reload();
399 Configuration configuration = archivaConfiguration.getConfiguration();
400 assertTrue( "check value", configuration.getWebapp().getUi().isAppletFindEnabled() );
402 configuration.getWebapp().getUi().setAppletFindEnabled( false );
404 archivaConfiguration.save( configuration );
406 assertTrue( "Check file exists", Files.exists(baseFile) );
407 assertEquals( "Check base file is unchanged", "<configuration/>",
408 FileUtils.readFileToString( baseFile.toFile(), Charset.forName( "UTF-8" ) ) );
409 assertTrue( "Check file exists", Files.exists(userFile) );
410 assertFalse( "Check base file is changed",
411 "<configuration/>".equals( FileUtils.readFileToString( userFile.toFile(), Charset.forName( "UTF-8" ) ) ) );
414 configuration = archivaConfiguration.getConfiguration();
415 assertFalse( "check value", configuration.getWebapp().getUi().isAppletFindEnabled() );
419 public void testStoreConfigurationFailsWhenReadFromBothLocationsUserHasLists()
422 Path baseFile = getTestFile( "target/test/test-file.xml" );
423 Files.deleteIfExists(baseFile);
424 assertFalse( Files.exists(baseFile) );
426 Path userFile = getTestFile( "target/test/test-file-user.xml" );
427 Files.deleteIfExists(userFile);
428 assertFalse( Files.exists(userFile) );
430 Files.createDirectories( userFile.getParent() );
431 FileUtils.copyFile( getTestFile( "src/test/conf/conf-user.xml" ).toFile(), userFile.toFile() );
433 Files.createDirectories(baseFile.getParent());
434 FileUtils.writeStringToFile( baseFile.toFile(), "<configuration/>", Charset.forName( "UTF-8" ) );
436 ArchivaConfiguration archivaConfiguration = lookup( ArchivaConfiguration.class, "test-save-user" );
438 archivaConfiguration.reload();
440 Configuration configuration = archivaConfiguration.getConfiguration();
441 assertTrue( "check value", configuration.getWebapp().getUi().isShowFindArtifacts() );
443 configuration.getWebapp().getUi().setShowFindArtifacts( false );
445 archivaConfiguration.save( configuration );
447 assertTrue( "Check file exists", Files.exists(baseFile) );
448 assertEquals( "Check base file is unchanged", "<configuration/>",
449 FileUtils.readFileToString( baseFile.toFile(), Charset.forName( "UTF-8" ) ) );
450 assertTrue( "Check file exists", Files.exists(userFile) );
451 assertFalse( "Check base file is changed",
452 "<configuration/>".equals( FileUtils.readFileToString( userFile.toFile(), Charset.forName( "UTF-8" ) ) ) );
455 configuration = archivaConfiguration.getConfiguration();
456 assertFalse( "check value", configuration.getWebapp().getUi().isShowFindArtifacts() );
460 public void testStoreConfigurationFailsWhenReadFromBothLocationsAppserverHasLists()
463 Path baseFile = getTestFile( "target/test/test-file.xml" );
464 Files.deleteIfExists(baseFile);
465 assertFalse( Files.exists(baseFile) );
467 Path userFile = getTestFile( "target/test/test-file-user.xml" );
468 Files.deleteIfExists(userFile);
469 assertFalse( Files.exists(userFile) );
471 Files.createDirectories(baseFile.getParent());
472 FileUtils.copyFile( getTestFile( "src/test/conf/conf-base.xml" ).toFile(), baseFile.toFile() );
474 Files.createDirectories(userFile.getParent());
475 FileUtils.writeStringToFile( userFile.toFile(), "<configuration/>", Charset.forName( "UTF-8" ) );
477 ArchivaConfiguration archivaConfiguration = lookup( ArchivaConfiguration.class, "test-save-user" );
479 archivaConfiguration.reload();
481 Configuration configuration = archivaConfiguration.getConfiguration();
482 assertTrue( "check value", configuration.getWebapp().getUi().isAppletFindEnabled() );
484 configuration.getWebapp().getUi().setAppletFindEnabled( false );
488 archivaConfiguration.save( configuration );
489 fail( "Configuration saving should not succeed if it was loaded from two locations" );
491 catch ( IndeterminateConfigurationException e )
493 // check it was reverted
494 configuration = archivaConfiguration.getConfiguration();
495 assertTrue( "check value", configuration.getWebapp().getUi().isAppletFindEnabled() );
500 public void testLoadConfigurationFromInvalidBothLocationsOnDisk()
503 String propFile = System.getProperty( ArchivaConfiguration.USER_CONFIG_PROPERTY );
504 System.setProperty( ArchivaConfiguration.USER_CONFIG_PROPERTY, "/../../..//*intentionally:invalid*/.m2/archiva-user.xml" );
505 ArchivaConfiguration archivaConfiguration =
506 lookup( ArchivaConfiguration.class, "test-not-allowed-to-write-to-both" );
507 Configuration config = archivaConfiguration.getConfiguration();
511 archivaConfiguration.save( config );
512 fail( "Should have thrown a RegistryException because the configuration can't be saved." );
514 catch ( RegistryException e )
516 /* expected exception */
520 System.setProperty( ArchivaConfiguration.USER_CONFIG_PROPERTY, propFile );
525 public void testLoadConfigurationFromInvalidUserLocationOnDisk()
528 Path testConfDir = getTestFile( "target/test-appserver-base/conf/" );
529 Files.createDirectories( testConfDir );
531 ArchivaConfiguration archivaConfiguration =
532 lookup( ArchivaConfiguration.class, "test-not-allowed-to-write-to-user" );
533 Configuration config = archivaConfiguration.getConfiguration();
534 archivaConfiguration.save( config );
535 // No Exception == test passes.
536 // Expected Path is: Should not have thrown an exception.
541 public void testConfigurationUpgradeFrom13()
544 ArchivaConfiguration archivaConfiguration = lookup( ArchivaConfiguration.class, "test-upgrade-1.3" );
546 // we just use the defaults when upgrading from 1.3 at this point.
547 Configuration configuration = archivaConfiguration.getConfiguration();
548 assertConfiguration( configuration, 2, 2, 2 );
549 assertEquals( "check network proxies", 0, configuration.getNetworkProxies().size() );
551 ManagedRepositoryConfiguration repository = configuration.getManagedRepositories().get( 0 );
553 assertEquals( "check managed repositories", "${appserver.base}/data/repositories/internal",
554 repository.getLocation() );
555 assertEquals( "check managed repositories", "Archiva Managed Internal Repository", repository.getName() );
556 assertEquals( "check managed repositories", "internal", repository.getId() );
557 assertEquals( "check managed repositories", "default", repository.getLayout() );
558 assertTrue( "check managed repositories", repository.isScanned() );
560 log.info( "knowContentConsumers {}", configuration.getRepositoryScanning().getKnownContentConsumers() );
563 configuration.getRepositoryScanning().getKnownContentConsumers().contains( "update-db-artifact" ) );
564 assertFalse( configuration.getRepositoryScanning().getKnownContentConsumers().contains(
565 "update-db-repository-metadata" ) );
568 configuration.getRepositoryScanning().getKnownContentConsumers().contains( "create-archiva-metadata" ) );
571 configuration.getRepositoryScanning().getKnownContentConsumers().contains( "duplicate-artifacts" ) );
576 public void testCronExpressionsWithComma()
579 Path baseFile = getTestFile( "target/test/test-file.xml" );
580 Files.deleteIfExists(baseFile);
581 assertFalse( Files.exists(baseFile) );
583 Path userFile = getTestFile( "target/test/test-file-user.xml" );
584 Files.deleteIfExists(userFile);
585 assertFalse( Files.exists(userFile) );
587 Files.createDirectories(baseFile.getParent());
588 FileUtils.copyFile( getTestFile( "src/test/conf/escape-cron-expressions.xml" ).toFile(), baseFile.toFile() );
590 Files.createDirectories(userFile.getParent());
591 FileUtils.writeStringToFile( userFile.toFile(), "<configuration/>", Charset.defaultCharset() );
593 final ArchivaConfiguration archivaConfiguration = lookup( ArchivaConfiguration.class, "test-cron-expressions" );
595 archivaConfiguration.reload();
597 Configuration configuration = archivaConfiguration.getConfiguration();
599 ManagedRepositoryConfiguration repository = configuration.getManagedRepositories().get( 0 );
601 assertEquals( "check cron expression", "0 0,30 * * * ?", repository.getRefreshCronExpression().trim() );
603 // add a test listener to confirm it doesn't see the escaped format. We don't need to test the number of calls,
604 // etc. as it's done in other tests
605 archivaConfiguration.addListener( new ConfigurationListener()
608 public void configurationEvent( ConfigurationEvent event )
610 assertEquals( ConfigurationEvent.SAVED, event.getType() );
615 archivaConfiguration.save( configuration );
617 configuration = archivaConfiguration.getConfiguration();
619 // test for the escape character '\' showing up on repositories.jsp
620 repository.setRefreshCronExpression( "0 0,20 0 * * ?" );
622 archivaConfiguration.save( configuration );
624 repository = archivaConfiguration.getConfiguration().findManagedRepositoryById( "snapshots" );
626 assertEquals( "check cron expression", "0 0,20 0 * * ?", repository.getRefreshCronExpression() );
630 public void testRemoveLastElements()
633 Path baseFile = getTestFile( "target/test/test-file.xml" );
634 Files.deleteIfExists(baseFile);
635 assertFalse( Files.exists(baseFile) );
637 Path userFile = getTestFile( "target/test/test-file-user.xml" );
638 Files.deleteIfExists(userFile);
639 assertFalse( Files.exists(userFile) );
641 Files.createDirectories( baseFile.getParent() );
642 FileUtils.copyFile( getTestFile( "src/test/conf/conf-single-list-elements.xml" ).toFile(), baseFile.toFile() );
644 Files.createDirectories( userFile.getParent());
645 FileUtils.writeStringToFile( userFile.toFile(), "<configuration/>", Charset.forName( "UTF-8" ) );
647 ArchivaConfiguration archivaConfiguration = lookup( ArchivaConfiguration.class, "test-remove-central" );
649 archivaConfiguration.reload();
651 Configuration configuration = archivaConfiguration.getConfiguration();
653 RepositoryGroupConfiguration repositoryGroup = configuration.getRepositoryGroups().get( 0 );
654 assertNotNull( repositoryGroup );
655 configuration.removeRepositoryGroup( repositoryGroup );
656 assertTrue( configuration.getRepositoryGroups().isEmpty() );
658 RemoteRepositoryConfiguration repository = configuration.getRemoteRepositoriesAsMap().get( "central" );
659 assertNotNull( repository );
660 configuration.removeRemoteRepository( repository );
661 assertTrue( configuration.getRemoteRepositories().isEmpty() );
663 ManagedRepositoryConfiguration managedRepository =
664 configuration.getManagedRepositoriesAsMap().get( "snapshots" );
665 assertNotNull( managedRepository );
666 configuration.removeManagedRepository( managedRepository );
667 assertTrue( configuration.getManagedRepositories().isEmpty() );
669 ProxyConnectorConfiguration proxyConnector = configuration.getProxyConnectors().get( 0 );
670 assertNotNull( proxyConnector );
671 configuration.removeProxyConnector( proxyConnector );
672 assertTrue( configuration.getProxyConnectors().isEmpty() );
674 NetworkProxyConfiguration networkProxy = configuration.getNetworkProxiesAsMap().get( "proxy" );
675 assertNotNull( networkProxy );
676 configuration.removeNetworkProxy( networkProxy );
677 assertTrue( configuration.getNetworkProxies().isEmpty() );
679 LegacyArtifactPath path = configuration.getLegacyArtifactPaths().get( 0 );
680 assertNotNull( path );
681 configuration.removeLegacyArtifactPath( path );
682 assertTrue( configuration.getLegacyArtifactPaths().isEmpty() );
684 RepositoryScanningConfiguration scanning = configuration.getRepositoryScanning();
685 String consumer = scanning.getKnownContentConsumers().get( 0 );
686 assertNotNull( consumer );
687 scanning.removeKnownContentConsumer( consumer );
689 assertFalse( scanning.getKnownContentConsumers().isEmpty() );
690 consumer = scanning.getInvalidContentConsumers().get( 0 );
691 assertNotNull( consumer );
692 scanning.removeInvalidContentConsumer( consumer );
693 assertTrue( scanning.getInvalidContentConsumers().isEmpty() );
695 archivaConfiguration.save( configuration );
697 archivaConfiguration = lookup( ArchivaConfiguration.class, "test-read-saved" );
698 configuration = archivaConfiguration.getConfiguration();
699 assertNull( configuration.getRemoteRepositoriesAsMap().get( "central" ) );
700 assertTrue( configuration.getRepositoryGroups().isEmpty() );
701 assertNull( configuration.getManagedRepositoriesAsMap().get( "snapshots" ) );
702 assertTrue( configuration.getProxyConnectors().isEmpty() );
703 assertNull( configuration.getNetworkProxiesAsMap().get( "proxy" ) );
704 assertTrue( configuration.getLegacyArtifactPaths().isEmpty() );
705 scanning = configuration.getRepositoryScanning();
706 assertFalse( scanning.getKnownContentConsumers().isEmpty() );
707 assertTrue( scanning.getInvalidContentConsumers().isEmpty() );
711 * [MRM-582] Remote Repositories with empty <username> and <password> fields shouldn't be created in configuration.
714 public void testGetConfigurationFixEmptyRemoteRepoUsernamePassword()
717 ArchivaConfiguration archivaConfiguration = lookup( ArchivaConfiguration.class, "test-configuration" );
719 Configuration configuration = archivaConfiguration.getConfiguration();
720 assertConfiguration( configuration, 2, 2, 2 );
721 assertEquals( "check remote repositories", 2, configuration.getRemoteRepositories().size() );
723 RemoteRepositoryConfiguration repository =
724 configuration.getRemoteRepositoriesAsMap().get( "maven2-repository.dev.java.net" );
726 assertEquals( "remote repository.url", "https://maven2-repository.dev.java.net/nonav/repository",
727 repository.getUrl() );
728 assertEquals( "remote repository.name", "Java.net Repository for Maven 2", repository.getName() );
729 assertEquals( "remote repository.id", "maven2-repository.dev.java.net", repository.getId() );
730 assertEquals( "remote repository.layout", "default", repository.getLayout() );
731 assertNull( "remote repository.username == null", repository.getUsername() );
732 assertNull( "remote repository.password == null", repository.getPassword() );