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.redback.components.registry.RegistryException;
23 import org.apache.archiva.test.utils.ArchivaSpringJUnit4ClassRunner;
24 import org.apache.commons.io.FileUtils;
25 import org.junit.Test;
26 import org.junit.runner.RunWith;
27 import org.slf4j.Logger;
28 import org.slf4j.LoggerFactory;
29 import org.springframework.context.ApplicationContext;
30 import org.springframework.test.annotation.DirtiesContext;
31 import org.springframework.test.annotation.DirtiesContext.ClassMode;
32 import org.springframework.test.context.ContextConfiguration;
34 import javax.inject.Inject;
35 import java.nio.charset.Charset;
36 import java.nio.file.Files;
37 import java.nio.file.Path;
38 import java.nio.file.Paths;
39 import java.util.List;
41 import static org.easymock.EasyMock.*;
42 import static org.junit.Assert.*;
45 * Test the configuration store.
47 @RunWith(ArchivaSpringJUnit4ClassRunner.class)
48 @ContextConfiguration(locations = { "classpath*:/META-INF/spring-context.xml", "classpath:/spring-context.xml" })
49 @DirtiesContext(classMode = ClassMode.AFTER_EACH_TEST_METHOD)
50 public class ArchivaConfigurationTest
53 private Logger log = LoggerFactory.getLogger( getClass() );
56 protected ApplicationContext applicationContext;
61 public static Path getTestFile( String path )
63 return Paths.get( org.apache.archiva.common.utils.FileUtils.getBasedir(), path );
66 @SuppressWarnings( "unchecked" )
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 Path file = getTestFile( "target/test/test-file.xml" );
201 Files.deleteIfExists(file);
202 assertFalse( Files.exists(file) );
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 ConfigurationListener listener = createMock( ConfigurationListener.class );
221 archivaConfiguration.addListener( listener );
223 listener.configurationEvent( new ConfigurationEvent( ConfigurationEvent.SAVED ) );
227 archivaConfiguration.save( configuration );
231 assertTrue( "Check file exists", Files.exists(file) );
234 configuration = archivaConfiguration.getConfiguration();
235 assertFalse( "check value", configuration.getWebapp().getUi().isAppletFindEnabled() );
238 archivaConfiguration = (DefaultArchivaConfiguration) lookup( ArchivaConfiguration.class, "test-read-saved" );
240 archivaConfiguration.reload();
241 configuration = archivaConfiguration.getConfiguration();
242 assertFalse( "check value", configuration.getWebapp().getUi().isAppletFindEnabled() );
245 private static ConfigurationListener createConfigurationListenerMockControl()
247 return createMock( ConfigurationListener.class );// MockControl.createControl( ConfigurationListener.class );
251 public void testStoreConfigurationUser()
254 Path baseFile = getTestFile( "target/test/test-file.xml" );
255 Files.deleteIfExists( baseFile );
256 assertFalse( Files.exists(baseFile) );
258 Path userFile = getTestFile( "target/test/test-file-user.xml" );
259 Files.deleteIfExists( userFile );
260 assertFalse( Files.exists(userFile) );
262 Files.createDirectories(userFile.getParent());
263 FileUtils.writeStringToFile( userFile.toFile(), "<configuration/>", Charset.forName( "UTF-8" ) );
265 ArchivaConfiguration archivaConfiguration = lookup( ArchivaConfiguration.class, "test-save-user" );
267 Configuration configuration = new Configuration();
268 configuration.setWebapp( new WebappConfiguration() );
269 configuration.getWebapp().setUi( new UserInterfaceOptions() );
270 configuration.getWebapp().getUi().setAppletFindEnabled( false );
272 archivaConfiguration.save( configuration );
274 assertTrue( "Check file exists", Files.exists(userFile) );
275 assertFalse( "Check file not created", Files.exists(baseFile) );
278 configuration = archivaConfiguration.getConfiguration();
279 assertFalse( "check value", configuration.getWebapp().getUi().isAppletFindEnabled() );
283 public void testStoreConfigurationLoadedFromDefaults()
286 Path baseFile = getTestFile( "target/test/test-file.xml" );
287 Files.delete(baseFile);
288 assertFalse( Files.exists(baseFile) );
290 Path userFile = getTestFile( "target/test/test-file-user.xml" );
291 Files.deleteIfExists(userFile);
292 assertFalse( Files.exists(userFile) );
294 ArchivaConfiguration archivaConfiguration = lookup( ArchivaConfiguration.class, "test-save-user-defaults" );
296 archivaConfiguration.reload();
298 Configuration configuration = new Configuration();
299 configuration.setWebapp( new WebappConfiguration() );
300 configuration.getWebapp().setUi( new UserInterfaceOptions() );
301 configuration.getWebapp().getUi().setAppletFindEnabled( false );
303 // add a change listener
304 ConfigurationListener listener = createConfigurationListenerMockControl();
305 archivaConfiguration.addListener( listener );
307 listener.configurationEvent( new ConfigurationEvent( ConfigurationEvent.SAVED ) );
311 archivaConfiguration.save( configuration );
315 assertTrue( "Check file exists", Files.exists(userFile) );
316 assertFalse( "Check file not created", Files.exists(baseFile) );
319 configuration = archivaConfiguration.getConfiguration();
320 assertFalse( "check value", configuration.getWebapp().getUi().isAppletFindEnabled() );
324 public void testDefaultUserConfigFilename()
327 DefaultArchivaConfiguration archivaConfiguration =
328 (DefaultArchivaConfiguration) lookup( ArchivaConfiguration.class, "default" );
330 archivaConfiguration.reload();
332 assertEquals( System.getProperty( "user.home" ) + "/.m2/archiva.xml",
333 archivaConfiguration.getUserConfigFilename() );
334 assertEquals( System.getProperty( "appserver.base", "${appserver.base}" ) + "/conf/archiva.xml",
335 archivaConfiguration.getAltConfigFilename() );
339 public void testStoreConfigurationFallback()
342 Path baseFile = getTestFile( "target/test/test-file.xml" );
343 Files.deleteIfExists(baseFile);
344 assertFalse( Files.exists(baseFile) );
346 Path userFile = getTestFile( "target/test/test-file-user.xml" );
347 Files.deleteIfExists(userFile);
348 assertFalse( Files.exists(userFile) );
350 Files.createDirectories( baseFile.getParent());
351 FileUtils.writeStringToFile( baseFile.toFile(), "<configuration/>", Charset.forName( "UTF-8" ) );
353 ArchivaConfiguration archivaConfiguration =
354 (ArchivaConfiguration) lookup( ArchivaConfiguration.class, "test-save-user-fallback" );
356 archivaConfiguration.reload();
358 Configuration configuration = new Configuration();
359 configuration.setWebapp( new WebappConfiguration() );
360 configuration.getWebapp().setUi( new UserInterfaceOptions() );
361 configuration.getWebapp().getUi().setAppletFindEnabled( false );
363 archivaConfiguration.save( configuration );
365 assertTrue( "Check file exists", Files.exists(baseFile) );
366 assertFalse( "Check file not created", Files.exists(userFile) );
369 configuration = archivaConfiguration.getConfiguration();
370 assertFalse( "check value", configuration.getWebapp().getUi().isAppletFindEnabled() );
374 public void testStoreConfigurationFailsWhenReadFromBothLocationsNoLists()
377 Path baseFile = getTestFile( "target/test/test-file.xml" );
378 Files.deleteIfExists(baseFile);
379 assertFalse( Files.exists(baseFile) );
381 Path userFile = getTestFile( "target/test/test-file-user.xml" );
382 Files.deleteIfExists(userFile);
383 assertFalse( Files.exists(userFile) );
385 Files.createDirectories( baseFile.getParent() );
386 FileUtils.writeStringToFile( baseFile.toFile(), "<configuration/>", Charset.forName( "UTF-8" ) );
388 Files.createDirectories( userFile.getParent());
389 FileUtils.writeStringToFile( userFile.toFile(), "<configuration/>", Charset.forName( "UTF-8" ) );
391 ArchivaConfiguration archivaConfiguration = lookup( ArchivaConfiguration.class, "test-save-user" );
393 archivaConfiguration.reload();
395 Configuration configuration = archivaConfiguration.getConfiguration();
396 assertTrue( "check value", configuration.getWebapp().getUi().isAppletFindEnabled() );
398 configuration.getWebapp().getUi().setAppletFindEnabled( false );
400 archivaConfiguration.save( configuration );
402 assertTrue( "Check file exists", Files.exists(baseFile) );
403 assertEquals( "Check base file is unchanged", "<configuration/>",
404 FileUtils.readFileToString( baseFile.toFile(), Charset.forName( "UTF-8" ) ) );
405 assertTrue( "Check file exists", Files.exists(userFile) );
406 assertFalse( "Check base file is changed",
407 "<configuration/>".equals( FileUtils.readFileToString( userFile.toFile(), Charset.forName( "UTF-8" ) ) ) );
410 configuration = archivaConfiguration.getConfiguration();
411 assertFalse( "check value", configuration.getWebapp().getUi().isAppletFindEnabled() );
415 public void testStoreConfigurationFailsWhenReadFromBothLocationsUserHasLists()
418 Path baseFile = getTestFile( "target/test/test-file.xml" );
419 Files.deleteIfExists(baseFile);
420 assertFalse( Files.exists(baseFile) );
422 Path userFile = getTestFile( "target/test/test-file-user.xml" );
423 Files.deleteIfExists(userFile);
424 assertFalse( Files.exists(userFile) );
426 Files.createDirectories( userFile.getParent() );
427 FileUtils.copyFile( getTestFile( "src/test/conf/conf-user.xml" ).toFile(), userFile.toFile() );
429 Files.createDirectories(baseFile.getParent());
430 FileUtils.writeStringToFile( baseFile.toFile(), "<configuration/>", Charset.forName( "UTF-8" ) );
432 ArchivaConfiguration archivaConfiguration = lookup( ArchivaConfiguration.class, "test-save-user" );
434 archivaConfiguration.reload();
436 Configuration configuration = archivaConfiguration.getConfiguration();
437 assertTrue( "check value", configuration.getWebapp().getUi().isShowFindArtifacts() );
439 configuration.getWebapp().getUi().setShowFindArtifacts( false );
441 archivaConfiguration.save( configuration );
443 assertTrue( "Check file exists", Files.exists(baseFile) );
444 assertEquals( "Check base file is unchanged", "<configuration/>",
445 FileUtils.readFileToString( baseFile.toFile(), Charset.forName( "UTF-8" ) ) );
446 assertTrue( "Check file exists", Files.exists(userFile) );
447 assertFalse( "Check base file is changed",
448 "<configuration/>".equals( FileUtils.readFileToString( userFile.toFile(), Charset.forName( "UTF-8" ) ) ) );
451 configuration = archivaConfiguration.getConfiguration();
452 assertFalse( "check value", configuration.getWebapp().getUi().isShowFindArtifacts() );
456 public void testStoreConfigurationFailsWhenReadFromBothLocationsAppserverHasLists()
459 Path baseFile = getTestFile( "target/test/test-file.xml" );
460 Files.deleteIfExists(baseFile);
461 assertFalse( Files.exists(baseFile) );
463 Path userFile = getTestFile( "target/test/test-file-user.xml" );
464 Files.deleteIfExists(userFile);
465 assertFalse( Files.exists(userFile) );
467 Files.createDirectories(baseFile.getParent());
468 FileUtils.copyFile( getTestFile( "src/test/conf/conf-base.xml" ).toFile(), baseFile.toFile() );
470 Files.createDirectories(userFile.getParent());
471 FileUtils.writeStringToFile( userFile.toFile(), "<configuration/>", Charset.forName( "UTF-8" ) );
473 ArchivaConfiguration archivaConfiguration = lookup( ArchivaConfiguration.class, "test-save-user" );
475 archivaConfiguration.reload();
477 Configuration configuration = archivaConfiguration.getConfiguration();
478 assertTrue( "check value", configuration.getWebapp().getUi().isAppletFindEnabled() );
480 configuration.getWebapp().getUi().setAppletFindEnabled( false );
484 archivaConfiguration.save( configuration );
485 fail( "Configuration saving should not succeed if it was loaded from two locations" );
487 catch ( IndeterminateConfigurationException e )
489 // check it was reverted
490 configuration = archivaConfiguration.getConfiguration();
491 assertTrue( "check value", configuration.getWebapp().getUi().isAppletFindEnabled() );
496 public void testLoadConfigurationFromInvalidBothLocationsOnDisk()
499 ArchivaConfiguration archivaConfiguration =
500 lookup( ArchivaConfiguration.class, "test-not-allowed-to-write-to-both" );
501 Configuration config = archivaConfiguration.getConfiguration();
505 archivaConfiguration.save( config );
506 fail( "Should have thrown a RegistryException because the configuration can't be saved." );
508 catch ( RegistryException e )
510 /* expected exception */
515 public void testLoadConfigurationFromInvalidUserLocationOnDisk()
518 Path testConfDir = getTestFile( "target/test-appserver-base/conf/" );
519 Files.createDirectories( testConfDir );
521 ArchivaConfiguration archivaConfiguration =
522 lookup( ArchivaConfiguration.class, "test-not-allowed-to-write-to-user" );
523 Configuration config = archivaConfiguration.getConfiguration();
524 archivaConfiguration.save( config );
525 // No Exception == test passes.
526 // Expected Path is: Should not have thrown an exception.
531 public void testConfigurationUpgradeFrom13()
534 ArchivaConfiguration archivaConfiguration = lookup( ArchivaConfiguration.class, "test-upgrade-1.3" );
536 // we just use the defaults when upgrading from 1.3 at this point.
537 Configuration configuration = archivaConfiguration.getConfiguration();
538 assertConfiguration( configuration, 2, 2, 2 );
539 assertEquals( "check network proxies", 0, configuration.getNetworkProxies().size() );
541 ManagedRepositoryConfiguration repository = configuration.getManagedRepositories().get( 0 );
543 assertEquals( "check managed repositories", "${appserver.base}/data/repositories/internal",
544 repository.getLocation() );
545 assertEquals( "check managed repositories", "Archiva Managed Internal Repository", repository.getName() );
546 assertEquals( "check managed repositories", "internal", repository.getId() );
547 assertEquals( "check managed repositories", "default", repository.getLayout() );
548 assertTrue( "check managed repositories", repository.isScanned() );
550 log.info( "knowContentConsumers {}", configuration.getRepositoryScanning().getKnownContentConsumers() );
553 configuration.getRepositoryScanning().getKnownContentConsumers().contains( "update-db-artifact" ) );
554 assertFalse( configuration.getRepositoryScanning().getKnownContentConsumers().contains(
555 "update-db-repository-metadata" ) );
558 configuration.getRepositoryScanning().getKnownContentConsumers().contains( "create-archiva-metadata" ) );
561 configuration.getRepositoryScanning().getKnownContentConsumers().contains( "duplicate-artifacts" ) );
566 public void testCronExpressionsWithComma()
569 Path baseFile = getTestFile( "target/test/test-file.xml" );
570 Files.deleteIfExists(baseFile);
571 assertFalse( Files.exists(baseFile) );
573 Path userFile = getTestFile( "target/test/test-file-user.xml" );
574 Files.deleteIfExists(userFile);
575 assertFalse( Files.exists(userFile) );
577 Files.createDirectories(baseFile.getParent());
578 FileUtils.copyFile( getTestFile( "src/test/conf/escape-cron-expressions.xml" ).toFile(), baseFile.toFile() );
580 Files.createDirectories(userFile.getParent());
581 FileUtils.writeStringToFile( userFile.toFile(), "<configuration/>", Charset.defaultCharset() );
583 final ArchivaConfiguration archivaConfiguration = lookup( ArchivaConfiguration.class, "test-cron-expressions" );
585 archivaConfiguration.reload();
587 Configuration configuration = archivaConfiguration.getConfiguration();
589 ManagedRepositoryConfiguration repository = configuration.getManagedRepositories().get( 0 );
591 assertEquals( "check cron expression", "0 0,30 * * * ?", repository.getRefreshCronExpression().trim() );
593 // add a test listener to confirm it doesn't see the escaped format. We don't need to test the number of calls,
594 // etc. as it's done in other tests
595 archivaConfiguration.addListener( new ConfigurationListener()
598 public void configurationEvent( ConfigurationEvent event )
600 assertEquals( ConfigurationEvent.SAVED, event.getType() );
605 archivaConfiguration.save( configuration );
607 configuration = archivaConfiguration.getConfiguration();
609 // test for the escape character '\' showing up on repositories.jsp
610 repository.setRefreshCronExpression( "0 0,20 0 * * ?" );
612 archivaConfiguration.save( configuration );
614 repository = archivaConfiguration.getConfiguration().findManagedRepositoryById( "snapshots" );
616 assertEquals( "check cron expression", "0 0,20 0 * * ?", repository.getRefreshCronExpression() );
620 public void testRemoveLastElements()
623 Path baseFile = getTestFile( "target/test/test-file.xml" );
624 Files.deleteIfExists(baseFile);
625 assertFalse( Files.exists(baseFile) );
627 Path userFile = getTestFile( "target/test/test-file-user.xml" );
628 Files.deleteIfExists(userFile);
629 assertFalse( Files.exists(userFile) );
631 Files.createDirectories( baseFile.getParent() );
632 FileUtils.copyFile( getTestFile( "src/test/conf/conf-single-list-elements.xml" ).toFile(), baseFile.toFile() );
634 Files.createDirectories( userFile.getParent());
635 FileUtils.writeStringToFile( userFile.toFile(), "<configuration/>", Charset.forName( "UTF-8" ) );
637 ArchivaConfiguration archivaConfiguration = lookup( ArchivaConfiguration.class, "test-remove-central" );
639 archivaConfiguration.reload();
641 Configuration configuration = archivaConfiguration.getConfiguration();
643 RepositoryGroupConfiguration repositoryGroup = configuration.getRepositoryGroups().get( 0 );
644 assertNotNull( repositoryGroup );
645 configuration.removeRepositoryGroup( repositoryGroup );
646 assertTrue( configuration.getRepositoryGroups().isEmpty() );
648 RemoteRepositoryConfiguration repository = configuration.getRemoteRepositoriesAsMap().get( "central" );
649 assertNotNull( repository );
650 configuration.removeRemoteRepository( repository );
651 assertTrue( configuration.getRemoteRepositories().isEmpty() );
653 ManagedRepositoryConfiguration managedRepository =
654 configuration.getManagedRepositoriesAsMap().get( "snapshots" );
655 assertNotNull( managedRepository );
656 configuration.removeManagedRepository( managedRepository );
657 assertTrue( configuration.getManagedRepositories().isEmpty() );
659 ProxyConnectorConfiguration proxyConnector = configuration.getProxyConnectors().get( 0 );
660 assertNotNull( proxyConnector );
661 configuration.removeProxyConnector( proxyConnector );
662 assertTrue( configuration.getProxyConnectors().isEmpty() );
664 NetworkProxyConfiguration networkProxy = configuration.getNetworkProxiesAsMap().get( "proxy" );
665 assertNotNull( networkProxy );
666 configuration.removeNetworkProxy( networkProxy );
667 assertTrue( configuration.getNetworkProxies().isEmpty() );
669 LegacyArtifactPath path = configuration.getLegacyArtifactPaths().get( 0 );
670 assertNotNull( path );
671 configuration.removeLegacyArtifactPath( path );
672 assertTrue( configuration.getLegacyArtifactPaths().isEmpty() );
674 RepositoryScanningConfiguration scanning = configuration.getRepositoryScanning();
675 String consumer = scanning.getKnownContentConsumers().get( 0 );
676 assertNotNull( consumer );
677 scanning.removeKnownContentConsumer( consumer );
679 assertFalse( scanning.getKnownContentConsumers().isEmpty() );
680 consumer = scanning.getInvalidContentConsumers().get( 0 );
681 assertNotNull( consumer );
682 scanning.removeInvalidContentConsumer( consumer );
683 assertTrue( scanning.getInvalidContentConsumers().isEmpty() );
685 archivaConfiguration.save( configuration );
687 archivaConfiguration = lookup( ArchivaConfiguration.class, "test-read-saved" );
688 configuration = archivaConfiguration.getConfiguration();
689 assertNull( configuration.getRemoteRepositoriesAsMap().get( "central" ) );
690 assertTrue( configuration.getRepositoryGroups().isEmpty() );
691 assertNull( configuration.getManagedRepositoriesAsMap().get( "snapshots" ) );
692 assertTrue( configuration.getProxyConnectors().isEmpty() );
693 assertNull( configuration.getNetworkProxiesAsMap().get( "proxy" ) );
694 assertTrue( configuration.getLegacyArtifactPaths().isEmpty() );
695 scanning = configuration.getRepositoryScanning();
696 assertFalse( scanning.getKnownContentConsumers().isEmpty() );
697 assertTrue( scanning.getInvalidContentConsumers().isEmpty() );
701 * [MRM-582] Remote Repositories with empty <username> and <password> fields shouldn't be created in configuration.
704 public void testGetConfigurationFixEmptyRemoteRepoUsernamePassword()
707 ArchivaConfiguration archivaConfiguration = lookup( ArchivaConfiguration.class, "test-configuration" );
709 Configuration configuration = archivaConfiguration.getConfiguration();
710 assertConfiguration( configuration, 2, 2, 2 );
711 assertEquals( "check remote repositories", 2, configuration.getRemoteRepositories().size() );
713 RemoteRepositoryConfiguration repository =
714 configuration.getRemoteRepositoriesAsMap().get( "maven2-repository.dev.java.net" );
716 assertEquals( "remote repository.url", "https://maven2-repository.dev.java.net/nonav/repository",
717 repository.getUrl() );
718 assertEquals( "remote repository.name", "Java.net Repository for Maven 2", repository.getName() );
719 assertEquals( "remote repository.id", "maven2-repository.dev.java.net", repository.getId() );
720 assertEquals( "remote repository.layout", "default", repository.getLayout() );
721 assertNull( "remote repository.username == null", repository.getUsername() );
722 assertNull( "remote repository.password == null", repository.getPassword() );