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 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", file.exists() );
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 File baseFile = getTestFile( "target/test/test-file.xml" );
256 assertFalse( baseFile.exists() );
258 File userFile = getTestFile( "target/test/test-file-user.xml" );
260 assertFalse( userFile.exists() );
262 userFile.getParentFile().mkdirs();
263 FileUtils.writeStringToFile( userFile, "<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", userFile.exists() );
275 assertFalse( "Check file not created", baseFile.exists() );
278 configuration = archivaConfiguration.getConfiguration();
279 assertFalse( "check value", configuration.getWebapp().getUi().isAppletFindEnabled() );
283 public void testStoreConfigurationLoadedFromDefaults()
286 File baseFile = getTestFile( "target/test/test-file.xml" );
288 assertFalse( baseFile.exists() );
290 File userFile = getTestFile( "target/test/test-file-user.xml" );
292 assertFalse( userFile.exists() );
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", userFile.exists() );
316 assertFalse( "Check file not created", baseFile.exists() );
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 File baseFile = getTestFile( "target/test/test-file.xml" );
344 assertFalse( baseFile.exists() );
346 File userFile = getTestFile( "target/test/test-file-user.xml" );
348 assertFalse( userFile.exists() );
350 baseFile.getParentFile().mkdirs();
351 FileUtils.writeStringToFile( baseFile, "<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", baseFile.exists() );
366 assertFalse( "Check file not created", userFile.exists() );
369 configuration = archivaConfiguration.getConfiguration();
370 assertFalse( "check value", configuration.getWebapp().getUi().isAppletFindEnabled() );
374 public void testStoreConfigurationFailsWhenReadFromBothLocationsNoLists()
377 File baseFile = getTestFile( "target/test/test-file.xml" );
379 assertFalse( baseFile.exists() );
381 File userFile = getTestFile( "target/test/test-file-user.xml" );
383 assertFalse( userFile.exists() );
385 baseFile.getParentFile().mkdirs();
386 FileUtils.writeStringToFile( baseFile, "<configuration/>", Charset.forName( "UTF-8" ) );
388 userFile.getParentFile().mkdirs();
389 FileUtils.writeStringToFile( userFile, "<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", baseFile.exists() );
403 assertEquals( "Check base file is unchanged", "<configuration/>",
404 FileUtils.readFileToString( baseFile, Charset.forName( "UTF-8" ) ) );
405 assertTrue( "Check file exists", userFile.exists() );
406 assertFalse( "Check base file is changed",
407 "<configuration/>".equals( FileUtils.readFileToString( userFile, Charset.forName( "UTF-8" ) ) ) );
410 configuration = archivaConfiguration.getConfiguration();
411 assertFalse( "check value", configuration.getWebapp().getUi().isAppletFindEnabled() );
415 public void testStoreConfigurationFailsWhenReadFromBothLocationsUserHasLists()
418 File baseFile = getTestFile( "target/test/test-file.xml" );
420 assertFalse( baseFile.exists() );
422 File userFile = getTestFile( "target/test/test-file-user.xml" );
424 assertFalse( userFile.exists() );
426 userFile.getParentFile().mkdirs();
427 FileUtils.copyFile( getTestFile( "src/test/conf/conf-user.xml" ), userFile );
429 baseFile.getParentFile().mkdirs();
430 FileUtils.writeStringToFile( baseFile, "<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", baseFile.exists() );
444 assertEquals( "Check base file is unchanged", "<configuration/>",
445 FileUtils.readFileToString( baseFile, Charset.forName( "UTF-8" ) ) );
446 assertTrue( "Check file exists", userFile.exists() );
447 assertFalse( "Check base file is changed",
448 "<configuration/>".equals( FileUtils.readFileToString( userFile, Charset.forName( "UTF-8" ) ) ) );
451 configuration = archivaConfiguration.getConfiguration();
452 assertFalse( "check value", configuration.getWebapp().getUi().isShowFindArtifacts() );
456 public void testStoreConfigurationFailsWhenReadFromBothLocationsAppserverHasLists()
459 File baseFile = getTestFile( "target/test/test-file.xml" );
461 assertFalse( baseFile.exists() );
463 File userFile = getTestFile( "target/test/test-file-user.xml" );
465 assertFalse( userFile.exists() );
467 baseFile.getParentFile().mkdirs();
468 FileUtils.copyFile( getTestFile( "src/test/conf/conf-base.xml" ), baseFile );
470 userFile.getParentFile().mkdirs();
471 FileUtils.writeStringToFile( userFile, "<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 File testConfDir = getTestFile( "target/test-appserver-base/conf/" );
519 testConfDir.mkdirs();
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.
530 public void testConfigurationUpgradeFrom09()
533 ArchivaConfiguration archivaConfiguration = lookup( ArchivaConfiguration.class, "test-upgrade-09" );
535 // we just use the defaults when upgrading from 0.9 at this point.
536 Configuration configuration = archivaConfiguration.getConfiguration();
537 // test-upgrade-09 contains a managed with id: local so it's 3 managed
538 assertConfiguration( configuration, 3, 1, 1 );
539 assertEquals( "check network proxies", 0, configuration.getNetworkProxies().size() );
541 ManagedRepositoryConfiguration repository = configuration.getManagedRepositories().get( 0 );
543 assertEquals( "check managed repositories", "${appserver.base}/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() );
552 public void testConfigurationUpgradeFrom13()
555 ArchivaConfiguration archivaConfiguration = lookup( ArchivaConfiguration.class, "test-upgrade-1.3" );
557 // we just use the defaults when upgrading from 1.3 at this point.
558 Configuration configuration = archivaConfiguration.getConfiguration();
559 assertConfiguration( configuration, 2, 2, 2 );
560 assertEquals( "check network proxies", 0, configuration.getNetworkProxies().size() );
562 ManagedRepositoryConfiguration repository = configuration.getManagedRepositories().get( 0 );
564 assertEquals( "check managed repositories", "${appserver.base}/data/repositories/internal",
565 repository.getLocation() );
566 assertEquals( "check managed repositories", "Archiva Managed Internal Repository", repository.getName() );
567 assertEquals( "check managed repositories", "internal", repository.getId() );
568 assertEquals( "check managed repositories", "default", repository.getLayout() );
569 assertTrue( "check managed repositories", repository.isScanned() );
571 log.info( "knowContentConsumers {}", configuration.getRepositoryScanning().getKnownContentConsumers() );
574 configuration.getRepositoryScanning().getKnownContentConsumers().contains( "update-db-artifact" ) );
575 assertFalse( configuration.getRepositoryScanning().getKnownContentConsumers().contains(
576 "update-db-repository-metadata" ) );
579 configuration.getRepositoryScanning().getKnownContentConsumers().contains( "create-archiva-metadata" ) );
582 configuration.getRepositoryScanning().getKnownContentConsumers().contains( "duplicate-artifacts" ) );
586 public void testAutoDetectV1()
589 // Setup the autodetect-v1.xml file in the target directory (so we can save/load it)
590 File userFile = getTestFile( "target/test-autodetect-v1/archiva-user.xml" );
592 assertFalse( userFile.exists() );
594 userFile.getParentFile().mkdirs();
595 FileUtils.copyFile( getTestFile( "src/test/conf/autodetect-v1.xml" ), userFile );
597 // Load the original (unconverted) archiva.xml
598 ArchivaConfiguration archivaConfiguration = lookup( ArchivaConfiguration.class, "test-autodetect-v1" );
600 archivaConfiguration.reload();
602 Configuration configuration = archivaConfiguration.getConfiguration();
603 assertConfiguration( configuration, 2, 2, 2 );
604 assertEquals( "check network proxies", 1, configuration.getNetworkProxies().size() );
606 ManagedRepositoryConfiguration repository = configuration.getManagedRepositories().get( 0 );
608 assertEquals( "check managed repositories", "${appserver.base}/repositories/internal",
609 repository.getLocation() );
610 assertEquals( "check managed repositories", "Archiva Managed Internal Repository", repository.getName() );
611 assertEquals( "check managed repositories", "internal", repository.getId() );
612 assertEquals( "check managed repositories", "default", repository.getLayout() );
613 assertTrue( "check managed repositories", repository.isScanned() );
615 // Test that only 1 set of repositories exist.
616 assertEquals( "check managed repositories size.", 2, configuration.getManagedRepositories().size() );
617 assertEquals( "check remote repositories size.", 2, configuration.getRemoteRepositories().size() );
618 assertEquals( "check v1 repositories size.", 0, configuration.getRepositories().size() );
621 archivaConfiguration.save( configuration );
624 archivaConfiguration = lookup( ArchivaConfiguration.class, "test-autodetect-v1" );
625 configuration = archivaConfiguration.getConfiguration();
627 // Test that only 1 set of repositories exist.
628 assertEquals( "check managed repositories size.", 2, configuration.getManagedRepositories().size() );
629 assertEquals( "check managed repositories size.", 2, configuration.getManagedRepositoriesAsMap().size() );
630 assertEquals( "check remote repositories size.", 2, configuration.getRemoteRepositories().size() );
631 assertEquals( "check remote repositories size.", 2, configuration.getRemoteRepositoriesAsMap().size() );
632 assertEquals( "check v1 repositories size.", 0, configuration.getRepositories().size() );
634 String actualXML = FileUtils.readFileToString( userFile, Charset.forName( "UTF-8" ) );
635 XMLAssert.assertXpathNotExists( "//configuration/repositories/repository", actualXML );
636 XMLAssert.assertXpathNotExists( "//configuration/repositories", actualXML );
640 public void testArchivaV1()
643 ArchivaConfiguration archivaConfiguration = lookup( ArchivaConfiguration.class, "test-archiva-v1" );
645 Configuration configuration = archivaConfiguration.getConfiguration();
646 assertConfiguration( configuration, 2, 2, 2 );
647 assertEquals( "check network proxies", 1, configuration.getNetworkProxies().size() );
649 assertEquals( "check managed repositories", 2, configuration.getManagedRepositories().size() );
650 assertEquals( "check v1 repositories size.", 0, configuration.getRepositories().size() );
652 Map<String, ManagedRepositoryConfiguration> map = configuration.getManagedRepositoriesAsMap();
654 ManagedRepositoryConfiguration repository = map.get( "internal" );
655 assertEquals( "check managed repositories", "${appserver.base}/repositories/internal",
656 repository.getLocation() );
657 assertEquals( "check managed repositories", "Archiva Managed Internal Repository", repository.getName() );
658 assertEquals( "check managed repositories", "internal", repository.getId() );
659 assertEquals( "check managed repositories", "default", repository.getLayout() );
660 assertTrue( "check managed repositories", repository.isScanned() );
661 assertFalse( "check managed repositories", repository.isSnapshots() );
663 repository = map.get( "snapshots" );
664 assertEquals( "check managed repositories", "${appserver.base}/repositories/snapshots",
665 repository.getLocation() );
666 assertEquals( "check managed repositories", "Archiva Managed Snapshot Repository", repository.getName() );
667 assertEquals( "check managed repositories", "snapshots", repository.getId() );
668 assertEquals( "check managed repositories", "default", repository.getLayout() );
669 assertFalse( "check managed repositories", repository.isScanned() );
670 assertTrue( "check managed repositories", repository.isSnapshots() );
674 public void testCronExpressionsWithComma()
677 File baseFile = getTestFile( "target/test/test-file.xml" );
679 assertFalse( baseFile.exists() );
681 File userFile = getTestFile( "target/test/test-file-user.xml" );
683 assertFalse( userFile.exists() );
685 baseFile.getParentFile().mkdirs();
686 FileUtils.copyFile( getTestFile( "src/test/conf/escape-cron-expressions.xml" ), baseFile );
688 userFile.getParentFile().mkdirs();
689 FileUtils.writeStringToFile( userFile, "<configuration/>", Charset.defaultCharset() );
691 final ArchivaConfiguration archivaConfiguration = lookup( ArchivaConfiguration.class, "test-cron-expressions" );
693 archivaConfiguration.reload();
695 Configuration configuration = archivaConfiguration.getConfiguration();
697 ManagedRepositoryConfiguration repository = configuration.getManagedRepositories().get( 0 );
699 assertEquals( "check cron expression", "0 0,30 * * * ?", repository.getRefreshCronExpression().trim() );
701 // add a test listener to confirm it doesn't see the escaped format. We don't need to test the number of calls,
702 // etc. as it's done in other tests
703 archivaConfiguration.addListener( new ConfigurationListener()
706 public void configurationEvent( ConfigurationEvent event )
708 assertEquals( ConfigurationEvent.SAVED, event.getType() );
713 archivaConfiguration.save( configuration );
715 configuration = archivaConfiguration.getConfiguration();
717 // test for the escape character '\' showing up on repositories.jsp
718 repository.setRefreshCronExpression( "0 0,20 0 * * ?" );
720 archivaConfiguration.save( configuration );
722 repository = archivaConfiguration.getConfiguration().findManagedRepositoryById( "snapshots" );
724 assertEquals( "check cron expression", "0 0,20 0 * * ?", repository.getRefreshCronExpression() );
728 public void testRemoveLastElements()
731 File baseFile = getTestFile( "target/test/test-file.xml" );
733 assertFalse( baseFile.exists() );
735 File userFile = getTestFile( "target/test/test-file-user.xml" );
737 assertFalse( userFile.exists() );
739 baseFile.getParentFile().mkdirs();
740 FileUtils.copyFile( getTestFile( "src/test/conf/conf-single-list-elements.xml" ), baseFile );
742 userFile.getParentFile().mkdirs();
743 FileUtils.writeStringToFile( userFile, "<configuration/>", Charset.forName( "UTF-8" ) );
745 ArchivaConfiguration archivaConfiguration = lookup( ArchivaConfiguration.class, "test-remove-central" );
747 archivaConfiguration.reload();
749 Configuration configuration = archivaConfiguration.getConfiguration();
751 RepositoryGroupConfiguration repositoryGroup = configuration.getRepositoryGroups().get( 0 );
752 assertNotNull( repositoryGroup );
753 configuration.removeRepositoryGroup( repositoryGroup );
754 assertTrue( configuration.getRepositoryGroups().isEmpty() );
756 RemoteRepositoryConfiguration repository = configuration.getRemoteRepositoriesAsMap().get( "central" );
757 assertNotNull( repository );
758 configuration.removeRemoteRepository( repository );
759 assertTrue( configuration.getRemoteRepositories().isEmpty() );
761 ManagedRepositoryConfiguration managedRepository =
762 configuration.getManagedRepositoriesAsMap().get( "snapshots" );
763 assertNotNull( managedRepository );
764 configuration.removeManagedRepository( managedRepository );
765 assertTrue( configuration.getManagedRepositories().isEmpty() );
767 ProxyConnectorConfiguration proxyConnector = configuration.getProxyConnectors().get( 0 );
768 assertNotNull( proxyConnector );
769 configuration.removeProxyConnector( proxyConnector );
770 assertTrue( configuration.getProxyConnectors().isEmpty() );
772 NetworkProxyConfiguration networkProxy = configuration.getNetworkProxiesAsMap().get( "proxy" );
773 assertNotNull( networkProxy );
774 configuration.removeNetworkProxy( networkProxy );
775 assertTrue( configuration.getNetworkProxies().isEmpty() );
777 LegacyArtifactPath path = configuration.getLegacyArtifactPaths().get( 0 );
778 assertNotNull( path );
779 configuration.removeLegacyArtifactPath( path );
780 assertTrue( configuration.getLegacyArtifactPaths().isEmpty() );
782 RepositoryScanningConfiguration scanning = configuration.getRepositoryScanning();
783 String consumer = scanning.getKnownContentConsumers().get( 0 );
784 assertNotNull( consumer );
785 scanning.removeKnownContentConsumer( consumer );
787 assertFalse( scanning.getKnownContentConsumers().isEmpty() );
788 consumer = scanning.getInvalidContentConsumers().get( 0 );
789 assertNotNull( consumer );
790 scanning.removeInvalidContentConsumer( consumer );
791 assertTrue( scanning.getInvalidContentConsumers().isEmpty() );
793 archivaConfiguration.save( configuration );
795 archivaConfiguration = lookup( ArchivaConfiguration.class, "test-read-saved" );
796 configuration = archivaConfiguration.getConfiguration();
797 assertNull( configuration.getRemoteRepositoriesAsMap().get( "central" ) );
798 assertTrue( configuration.getRepositoryGroups().isEmpty() );
799 assertNull( configuration.getManagedRepositoriesAsMap().get( "snapshots" ) );
800 assertTrue( configuration.getProxyConnectors().isEmpty() );
801 assertNull( configuration.getNetworkProxiesAsMap().get( "proxy" ) );
802 assertTrue( configuration.getLegacyArtifactPaths().isEmpty() );
803 scanning = configuration.getRepositoryScanning();
804 assertFalse( scanning.getKnownContentConsumers().isEmpty() );
805 assertTrue( scanning.getInvalidContentConsumers().isEmpty() );
809 * [MRM-582] Remote Repositories with empty <username> and <password> fields shouldn't be created in configuration.
812 public void testGetConfigurationFixEmptyRemoteRepoUsernamePassword()
815 ArchivaConfiguration archivaConfiguration = lookup( ArchivaConfiguration.class, "test-configuration" );
817 archivaConfiguration.reload();
818 Configuration configuration = archivaConfiguration.getConfiguration();
819 assertConfiguration( configuration, 2, 2, 2 );
820 assertEquals( "check remote repositories", 2, configuration.getRemoteRepositories().size() );
822 RemoteRepositoryConfiguration repository =
823 configuration.getRemoteRepositoriesAsMap().get( "maven2-repository.dev.java.net" );
825 assertEquals( "remote repository.url", "https://maven2-repository.dev.java.net/nonav/repository",
826 repository.getUrl() );
827 assertEquals( "remote repository.name", "Java.net Repository for Maven 2", repository.getName() );
828 assertEquals( "remote repository.id", "maven2-repository.dev.java.net", repository.getId() );
829 assertEquals( "remote repository.layout", "default", repository.getLayout() );
830 assertNull( "remote repository.username == null", repository.getUsername() );
831 assertNull( "remote repository.password == null", repository.getPassword() );