1 package org.apache.maven.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 junit.framework.TestCase;
23 import org.apache.commons.io.FileUtils;
24 import org.apache.commons.lang.StringUtils;
25 import org.codehaus.plexus.registry.RegistryException;
26 import org.codehaus.redback.components.springutils.ComponentContainer;
27 import org.custommonkey.xmlunit.XMLAssert;
28 import org.easymock.MockControl;
29 import org.junit.Test;
30 import org.junit.runner.RunWith;
31 import org.springframework.test.context.ContextConfiguration;
32 import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
34 import javax.inject.Inject;
36 import java.util.List;
40 * Test the configuration store.
42 @RunWith( SpringJUnit4ClassRunner.class )
43 @ContextConfiguration( locations = {"classpath*:/META-INF/spring-context.xml","classpath:/spring-context.xml"} )
44 public class ArchivaConfigurationTest
49 private ComponentContainer componentContainer;
51 public static String getBasedir()
53 String basedir = System.getProperty( "basedir" );
54 if ( basedir == null )
56 basedir = new File( "" ).getAbsolutePath();
62 public static File getTestFile( String path )
64 return new File( getBasedir(), path );
70 protected String getSpringConfigLocation()
72 return "org/apache/maven/archiva/configuration/spring-context.xml";
75 protected <T> T lookup(Class<T> clazz, String hint)
77 return componentContainer.getComponent( clazz, hint );
80 protected <T> T lookup(Class<T> clazz)
82 return componentContainer.getComponent( clazz );
86 public void testGetConfigurationFromRegistryWithASingleNamedConfigurationResource()
89 ArchivaConfiguration archivaConfiguration =
90 (ArchivaConfiguration) lookup( ArchivaConfiguration.class, "test-configuration" );
92 Configuration configuration = archivaConfiguration.getConfiguration();
93 assertConfiguration( configuration );
94 assertEquals( "check network proxies", 1, configuration.getNetworkProxies().size() );
96 ManagedRepositoryConfiguration repository =
97 (ManagedRepositoryConfiguration) configuration.getManagedRepositories().get( 0 );
99 assertEquals( "check managed repositories", "${appserver.base}/repositories/internal",
100 repository.getLocation() );
101 assertEquals( "check managed repositories", "Archiva Managed Internal Repository", repository.getName() );
102 assertEquals( "check managed repositories", "internal", repository.getId() );
103 assertEquals( "check managed repositories", "default", repository.getLayout() );
104 assertTrue( "check managed repositories", repository.isScanned() );
108 public void testGetConfigurationFromDefaults()
111 ArchivaConfiguration archivaConfiguration =
112 (ArchivaConfiguration) lookup( ArchivaConfiguration.class, "test-defaults" );
114 Configuration configuration = archivaConfiguration.getConfiguration();
115 assertConfiguration( configuration );
116 assertEquals( "check network proxies", 0, configuration.getNetworkProxies().size() );
118 ManagedRepositoryConfiguration repository =
119 (ManagedRepositoryConfiguration) configuration.getManagedRepositories().get( 0 );
121 assertEquals( "check managed repositories", "${appserver.base}/data/repositories/internal",
122 repository.getLocation() );
123 assertEquals( "check managed repositories", "Archiva Managed Internal Repository", repository.getName() );
124 assertEquals( "check managed repositories", "internal", repository.getId() );
125 assertEquals( "check managed repositories", "default", repository.getLayout() );
126 assertTrue( "check managed repositories", repository.isScanned() );
129 // test for [MRM-789]
131 public void testGetConfigurationFromDefaultsWithDefaultRepoLocationAlreadyExisting()
134 File repo = new File( getBasedir(), "/target/test-classes/existing_snapshots" );
137 repo = new File( getBasedir(), "/target/test-classes/existing_internal" );
140 String existingTestDefaultArchivaConfigFile = FileUtils.readFileToString(
141 getTestFile( "target/test-classes/org/apache/maven/archiva/configuration/test-default-archiva.xml" ) );
142 existingTestDefaultArchivaConfigFile =
143 StringUtils.replace( existingTestDefaultArchivaConfigFile, "${appserver.base}", getBasedir() );
145 File generatedTestDefaultArchivaConfigFile =
146 new File( getBasedir(), "target/test-classes/org/apache/maven/archiva/configuration/default-archiva.xml" );
148 FileUtils.writeStringToFile( generatedTestDefaultArchivaConfigFile, existingTestDefaultArchivaConfigFile,
151 ArchivaConfiguration archivaConfiguration = (ArchivaConfiguration) lookup( ArchivaConfiguration.class,
152 "test-defaults-default-repo-location-exists" );
154 Configuration configuration = archivaConfiguration.getConfiguration();
155 assertConfiguration( configuration );
157 ManagedRepositoryConfiguration repository =
158 (ManagedRepositoryConfiguration) configuration.getManagedRepositories().get( 0 );
159 assertTrue( "check managed repositories", repository.getLocation().endsWith( "data/repositories/internal" ) );
161 generatedTestDefaultArchivaConfigFile.delete();
162 assertFalse( generatedTestDefaultArchivaConfigFile.exists() );
166 * Ensures that the provided configuration matches the details present in the archiva-default.xml file.
168 private void assertConfiguration( Configuration configuration )
171 FileTypes filetypes = (FileTypes) lookup( FileTypes.class );
173 assertEquals( "check repositories", 2, configuration.getManagedRepositories().size() );
174 assertEquals( "check repositories", 2, configuration.getRemoteRepositories().size() );
175 assertEquals( "check proxy connectors", 2, configuration.getProxyConnectors().size() );
177 RepositoryScanningConfiguration repoScanning = configuration.getRepositoryScanning();
178 assertNotNull( "check repository scanning", repoScanning );
179 assertEquals( "check file types", 4, repoScanning.getFileTypes().size() );
180 assertEquals( "check known consumers", 9, repoScanning.getKnownContentConsumers().size() );
181 assertEquals( "check invalid consumers", 1, repoScanning.getInvalidContentConsumers().size() );
183 List<String> patterns = filetypes.getFileTypePatterns( "artifacts" );
184 assertNotNull( "check 'artifacts' file type", patterns );
185 assertEquals( "check 'artifacts' patterns", 13, patterns.size() );
187 DatabaseScanningConfiguration dbScanning = configuration.getDatabaseScanning();
188 assertNotNull( "check database scanning", dbScanning );
189 assertEquals( "check unprocessed consumers", 6, dbScanning.getUnprocessedConsumers().size() );
190 assertEquals( "check cleanup consumers", 3, dbScanning.getCleanupConsumers().size() );
192 WebappConfiguration webapp = configuration.getWebapp();
193 assertNotNull( "check webapp", webapp );
195 UserInterfaceOptions ui = webapp.getUi();
196 assertNotNull( "check webapp ui", ui );
197 assertTrue( "check showFindArtifacts", ui.isShowFindArtifacts() );
198 assertTrue( "check appletFindEnabled", ui.isAppletFindEnabled() );
202 public void testGetConfigurationFromRegistryWithTwoConfigurationResources()
205 ArchivaConfiguration archivaConfiguration =
206 (ArchivaConfiguration) lookup( ArchivaConfiguration.class, "test-configuration-both" );
208 Configuration configuration = archivaConfiguration.getConfiguration();
211 assertEquals( "check repositories", 2, configuration.getManagedRepositories().size() );
212 assertEquals( "check repositories", 2, configuration.getRemoteRepositories().size() );
214 assertEquals( "check proxy connectors", 2, configuration.getProxyConnectors().size() );
216 WebappConfiguration webapp = configuration.getWebapp();
217 assertNotNull( "check webapp", webapp );
219 UserInterfaceOptions ui = webapp.getUi();
220 assertNotNull( "check webapp ui", ui );
222 assertFalse( "check showFindArtifacts", ui.isShowFindArtifacts() );
224 assertFalse( "check appletFindEnabled", ui.isAppletFindEnabled() );
228 public void testGetConfigurationSystemOverride()
232 System.setProperty( "org.apache.maven.archiva.webapp.ui.appletFindEnabled", "false" );
234 ArchivaConfiguration archivaConfiguration =
235 (ArchivaConfiguration) lookup( ArchivaConfiguration.class, "test-configuration" );
237 archivaConfiguration.reload();
241 Configuration configuration = archivaConfiguration.getConfiguration();
243 assertFalse( "check boolean", configuration.getWebapp().getUi().isAppletFindEnabled() );
247 System.getProperties().remove( "org.apache.maven.archiva.webapp.ui.appletFindEnabled" );
252 public void testStoreConfiguration()
255 File file = getTestFile( "target/test/test-file.xml" );
257 assertFalse( file.exists() );
259 // TODO: remove with commons-configuration 1.4
260 //file.getParentFile().mkdirs();
261 //FileUtils.writeStringToFile( file, "<configuration/>", null );
263 DefaultArchivaConfiguration archivaConfiguration =
264 (DefaultArchivaConfiguration) lookup( ArchivaConfiguration.class, "test-save" );
266 archivaConfiguration.reload();
268 Configuration configuration = new Configuration();
269 configuration.setVersion( "1" );
270 configuration.setWebapp( new WebappConfiguration() );
271 configuration.getWebapp().setUi( new UserInterfaceOptions() );
272 configuration.getWebapp().getUi().setAppletFindEnabled( false );
274 // add a change listener
275 MockControl control = createConfigurationListenerMockControl();
276 ConfigurationListener listener = (ConfigurationListener) control.getMock();
277 archivaConfiguration.addListener( listener );
279 listener.configurationEvent( new ConfigurationEvent( ConfigurationEvent.SAVED ) );
280 control.setVoidCallable();
284 archivaConfiguration.save( configuration );
288 assertTrue( "Check file exists", file.exists() );
291 configuration = archivaConfiguration.getConfiguration();
292 assertFalse( "check value", configuration.getWebapp().getUi().isAppletFindEnabled() );
295 archivaConfiguration =
296 (DefaultArchivaConfiguration) lookup( ArchivaConfiguration.class, "test-read-saved" );
298 archivaConfiguration.reload();
299 configuration = archivaConfiguration.getConfiguration();
300 assertFalse( "check value", configuration.getWebapp().getUi().isAppletFindEnabled() );
303 private static MockControl createConfigurationListenerMockControl()
305 return MockControl.createControl( ConfigurationListener.class );
309 public void testStoreConfigurationUser()
312 File baseFile = getTestFile( "target/test/test-file.xml" );
314 assertFalse( baseFile.exists() );
316 File userFile = getTestFile( "target/test/test-file-user.xml" );
318 assertFalse( userFile.exists() );
320 userFile.getParentFile().mkdirs();
321 FileUtils.writeStringToFile( userFile, "<configuration/>", null );
323 ArchivaConfiguration archivaConfiguration =
324 (ArchivaConfiguration) lookup( ArchivaConfiguration.class, "test-save-user" );
326 Configuration configuration = new Configuration();
327 configuration.setWebapp( new WebappConfiguration() );
328 configuration.getWebapp().setUi( new UserInterfaceOptions() );
329 configuration.getWebapp().getUi().setAppletFindEnabled( false );
331 archivaConfiguration.save( configuration );
333 assertTrue( "Check file exists", userFile.exists() );
334 assertFalse( "Check file not created", baseFile.exists() );
337 configuration = archivaConfiguration.getConfiguration();
338 assertFalse( "check value", configuration.getWebapp().getUi().isAppletFindEnabled() );
342 public void testStoreConfigurationLoadedFromDefaults()
345 File baseFile = getTestFile( "target/test/test-file.xml" );
347 assertFalse( baseFile.exists() );
349 File userFile = getTestFile( "target/test/test-file-user.xml" );
351 assertFalse( userFile.exists() );
353 ArchivaConfiguration archivaConfiguration =
354 (ArchivaConfiguration) lookup( ArchivaConfiguration.class, "test-save-user-defaults" );
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 // add a change listener
364 MockControl control = createConfigurationListenerMockControl();
365 ConfigurationListener listener = (ConfigurationListener) control.getMock();
366 archivaConfiguration.addListener( listener );
368 listener.configurationEvent( new ConfigurationEvent( ConfigurationEvent.SAVED ) );
370 control.setVoidCallable( 1 );
374 archivaConfiguration.save( configuration );
378 assertTrue( "Check file exists", userFile.exists() );
379 assertFalse( "Check file not created", baseFile.exists() );
382 configuration = archivaConfiguration.getConfiguration();
383 assertFalse( "check value", configuration.getWebapp().getUi().isAppletFindEnabled() );
387 public void testDefaultUserConfigFilename()
390 DefaultArchivaConfiguration archivaConfiguration =
391 (DefaultArchivaConfiguration) lookup( ArchivaConfiguration.class, "default" );
393 archivaConfiguration.reload();
395 assertEquals( System.getProperty( "user.home" ) + "/.m2/archiva.xml",
396 archivaConfiguration.getUserConfigFilename() );
397 assertEquals( System.getProperty( "appserver.base", "${appserver.base}" ) + "/conf/archiva.xml",
398 archivaConfiguration.getAltConfigFilename() );
402 public void testStoreConfigurationFallback()
405 File baseFile = getTestFile( "target/test/test-file.xml" );
407 assertFalse( baseFile.exists() );
409 File userFile = getTestFile( "target/test/test-file-user.xml" );
411 assertFalse( userFile.exists() );
413 baseFile.getParentFile().mkdirs();
414 FileUtils.writeStringToFile( baseFile, "<configuration/>", null );
416 ArchivaConfiguration archivaConfiguration =
417 (ArchivaConfiguration) lookup( ArchivaConfiguration.class, "test-save-user-fallback" );
419 archivaConfiguration.reload();
421 Configuration configuration = new Configuration();
422 configuration.setWebapp( new WebappConfiguration() );
423 configuration.getWebapp().setUi( new UserInterfaceOptions() );
424 configuration.getWebapp().getUi().setAppletFindEnabled( false );
426 archivaConfiguration.save( configuration );
428 assertTrue( "Check file exists", baseFile.exists() );
429 assertFalse( "Check file not created", userFile.exists() );
433 configuration = archivaConfiguration.getConfiguration();
434 assertFalse( "check value", configuration.getWebapp().getUi().isAppletFindEnabled() );
438 public void testStoreConfigurationFailsWhenReadFromBothLocationsNoLists()
441 File baseFile = getTestFile( "target/test/test-file.xml" );
443 assertFalse( baseFile.exists() );
445 File userFile = getTestFile( "target/test/test-file-user.xml" );
447 assertFalse( userFile.exists() );
449 baseFile.getParentFile().mkdirs();
450 FileUtils.writeStringToFile( baseFile, "<configuration/>", null );
452 userFile.getParentFile().mkdirs();
453 FileUtils.writeStringToFile( userFile, "<configuration/>", null );
455 ArchivaConfiguration archivaConfiguration =
456 (ArchivaConfiguration) lookup( ArchivaConfiguration.class, "test-save-user" );
458 archivaConfiguration.reload();
460 Configuration configuration = archivaConfiguration.getConfiguration();
461 assertTrue( "check value", configuration.getWebapp().getUi().isAppletFindEnabled() );
463 configuration.getWebapp().getUi().setAppletFindEnabled( false );
465 archivaConfiguration.save( configuration );
467 assertTrue( "Check file exists", baseFile.exists() );
468 assertEquals( "Check base file is unchanged", "<configuration/>",
469 FileUtils.readFileToString( baseFile, null ) );
470 assertTrue( "Check file exists", userFile.exists() );
471 assertFalse( "Check base file is changed",
472 "<configuration/>".equals( FileUtils.readFileToString( userFile, null ) ) );
475 configuration = archivaConfiguration.getConfiguration();
476 assertFalse( "check value", configuration.getWebapp().getUi().isAppletFindEnabled() );
480 public void testStoreConfigurationFailsWhenReadFromBothLocationsUserHasLists()
483 File baseFile = getTestFile( "target/test/test-file.xml" );
485 assertFalse( baseFile.exists() );
487 File userFile = getTestFile( "target/test/test-file-user.xml" );
489 assertFalse( userFile.exists() );
491 userFile.getParentFile().mkdirs();
492 FileUtils.copyFile( getTestFile( "src/test/conf/conf-user.xml" ), userFile );
494 baseFile.getParentFile().mkdirs();
495 FileUtils.writeStringToFile( baseFile, "<configuration/>", null );
497 ArchivaConfiguration archivaConfiguration =
498 (ArchivaConfiguration) lookup( ArchivaConfiguration.class, "test-save-user" );
500 archivaConfiguration.reload();
502 Configuration configuration = archivaConfiguration.getConfiguration();
503 assertTrue( "check value", configuration.getWebapp().getUi().isShowFindArtifacts() );
505 configuration.getWebapp().getUi().setShowFindArtifacts( false );
507 archivaConfiguration.save( configuration );
509 assertTrue( "Check file exists", baseFile.exists() );
510 assertEquals( "Check base file is unchanged", "<configuration/>",
511 FileUtils.readFileToString( baseFile, null ) );
512 assertTrue( "Check file exists", userFile.exists() );
513 assertFalse( "Check base file is changed",
514 "<configuration/>".equals( FileUtils.readFileToString( userFile, null ) ) );
517 configuration = archivaConfiguration.getConfiguration();
518 assertFalse( "check value", configuration.getWebapp().getUi().isShowFindArtifacts() );
522 public void testStoreConfigurationFailsWhenReadFromBothLocationsAppserverHasLists()
525 File baseFile = getTestFile( "target/test/test-file.xml" );
527 assertFalse( baseFile.exists() );
529 File userFile = getTestFile( "target/test/test-file-user.xml" );
531 assertFalse( userFile.exists() );
533 baseFile.getParentFile().mkdirs();
534 FileUtils.copyFile( getTestFile( "src/test/conf/conf-base.xml" ), baseFile );
536 userFile.getParentFile().mkdirs();
537 FileUtils.writeStringToFile( userFile, "<configuration/>", null );
539 ArchivaConfiguration archivaConfiguration =
540 (ArchivaConfiguration) lookup( ArchivaConfiguration.class, "test-save-user" );
542 archivaConfiguration.reload();
544 Configuration configuration = archivaConfiguration.getConfiguration();
545 assertTrue( "check value", configuration.getWebapp().getUi().isAppletFindEnabled() );
547 configuration.getWebapp().getUi().setAppletFindEnabled( false );
551 archivaConfiguration.save( configuration );
552 fail( "Configuration saving should not succeed if it was loaded from two locations" );
554 catch ( IndeterminateConfigurationException e )
556 // check it was reverted
557 configuration = archivaConfiguration.getConfiguration();
558 assertTrue( "check value", configuration.getWebapp().getUi().isAppletFindEnabled() );
563 public void testLoadConfigurationFromInvalidBothLocationsOnDisk()
566 ArchivaConfiguration archivaConfiguration =
567 (ArchivaConfiguration) lookup( ArchivaConfiguration.class, "test-not-allowed-to-write-to-both" );
568 Configuration config = archivaConfiguration.getConfiguration();
572 archivaConfiguration.save( config );
573 fail( "Should have thrown a RegistryException because the configuration can't be saved." );
575 catch ( RegistryException e )
577 /* expected exception */
582 public void testLoadConfigurationFromInvalidUserLocationOnDisk()
585 File testConfDir = getTestFile( "target/test-appserver-base/conf/" );
586 testConfDir.mkdirs();
588 ArchivaConfiguration archivaConfiguration =
589 (ArchivaConfiguration) lookup( ArchivaConfiguration.class, "test-not-allowed-to-write-to-user" );
590 Configuration config = archivaConfiguration.getConfiguration();
591 archivaConfiguration.save( config );
592 // No Exception == test passes.
593 // Expected Path is: Should not have thrown an exception.
597 public void testConfigurationUpgradeFrom09()
600 ArchivaConfiguration archivaConfiguration =
601 (ArchivaConfiguration) lookup( ArchivaConfiguration.class, "test-upgrade-09" );
603 // we just use the defaults when upgrading from 0.9 at this point.
604 Configuration configuration = archivaConfiguration.getConfiguration();
605 assertConfiguration( configuration );
606 assertEquals( "check network proxies", 0, configuration.getNetworkProxies().size() );
608 ManagedRepositoryConfiguration repository =
609 (ManagedRepositoryConfiguration) configuration.getManagedRepositories().get( 0 );
611 assertEquals( "check managed repositories", "${appserver.base}/data/repositories/internal",
612 repository.getLocation() );
613 assertEquals( "check managed repositories", "Archiva Managed Internal Repository", repository.getName() );
614 assertEquals( "check managed repositories", "internal", repository.getId() );
615 assertEquals( "check managed repositories", "default", repository.getLayout() );
616 assertTrue( "check managed repositories", repository.isScanned() );
620 public void testAutoDetectV1()
623 // Setup the autodetect-v1.xml file in the target directory (so we can save/load it)
624 File userFile = getTestFile( "target/test-autodetect-v1/archiva-user.xml" );
626 assertFalse( userFile.exists() );
628 userFile.getParentFile().mkdirs();
629 FileUtils.copyFile( getTestFile( "src/test/conf/autodetect-v1.xml" ), userFile );
631 // Load the original (unconverted) archiva.xml
632 ArchivaConfiguration archivaConfiguration =
633 (ArchivaConfiguration) lookup( ArchivaConfiguration.class, "test-autodetect-v1" );
635 archivaConfiguration.reload();
637 Configuration configuration = archivaConfiguration.getConfiguration();
638 assertConfiguration( configuration );
639 assertEquals( "check network proxies", 1, configuration.getNetworkProxies().size() );
641 ManagedRepositoryConfiguration repository =
642 (ManagedRepositoryConfiguration) configuration.getManagedRepositories().get( 0 );
644 assertEquals( "check managed repositories", "${appserver.base}/repositories/internal",
645 repository.getLocation() );
646 assertEquals( "check managed repositories", "Archiva Managed Internal Repository", repository.getName() );
647 assertEquals( "check managed repositories", "internal", repository.getId() );
648 assertEquals( "check managed repositories", "default", repository.getLayout() );
649 assertTrue( "check managed repositories", repository.isScanned() );
651 // Test that only 1 set of repositories exist.
652 assertEquals( "check managed repositories size.", 2, configuration.getManagedRepositories().size() );
653 assertEquals( "check remote repositories size.", 2, configuration.getRemoteRepositories().size() );
654 assertEquals( "check v1 repositories size.", 0, configuration.getRepositories().size() );
657 archivaConfiguration.save( configuration );
660 //release( archivaConfiguration );
663 archivaConfiguration =
664 (ArchivaConfiguration) lookup( ArchivaConfiguration.class, "test-autodetect-v1" );
665 configuration = archivaConfiguration.getConfiguration();
667 // Test that only 1 set of repositories exist.
668 assertEquals( "check managed repositories size.", 2, configuration.getManagedRepositories().size() );
669 assertEquals( "check managed repositories size.", 2, configuration.getManagedRepositoriesAsMap().size() );
670 assertEquals( "check remote repositories size.", 2, configuration.getRemoteRepositories().size() );
671 assertEquals( "check remote repositories size.", 2, configuration.getRemoteRepositoriesAsMap().size() );
672 assertEquals( "check v1 repositories size.", 0, configuration.getRepositories().size() );
674 String actualXML = FileUtils.readFileToString( userFile, null );
675 XMLAssert.assertXpathNotExists( "//configuration/repositories/repository", actualXML );
676 XMLAssert.assertXpathNotExists( "//configuration/repositories", actualXML );
680 public void testArchivaV1()
683 ArchivaConfiguration archivaConfiguration =
684 (ArchivaConfiguration) lookup( ArchivaConfiguration.class, "test-archiva-v1" );
686 Configuration configuration = archivaConfiguration.getConfiguration();
687 assertConfiguration( configuration );
688 assertEquals( "check network proxies", 1, configuration.getNetworkProxies().size() );
690 assertEquals( "check managed repositories", 2, configuration.getManagedRepositories().size() );
691 assertEquals( "check v1 repositories size.", 0, configuration.getRepositories().size() );
693 Map<String, ManagedRepositoryConfiguration> map = configuration.getManagedRepositoriesAsMap();
695 ManagedRepositoryConfiguration repository = map.get( "internal" );
696 assertEquals( "check managed repositories", "${appserver.base}/repositories/internal",
697 repository.getLocation() );
698 assertEquals( "check managed repositories", "Archiva Managed Internal Repository", repository.getName() );
699 assertEquals( "check managed repositories", "internal", repository.getId() );
700 assertEquals( "check managed repositories", "default", repository.getLayout() );
701 assertTrue( "check managed repositories", repository.isScanned() );
702 assertFalse( "check managed repositories", repository.isSnapshots() );
704 repository = map.get( "snapshots" );
705 assertEquals( "check managed repositories", "${appserver.base}/repositories/snapshots",
706 repository.getLocation() );
707 assertEquals( "check managed repositories", "Archiva Managed Snapshot Repository", repository.getName() );
708 assertEquals( "check managed repositories", "snapshots", repository.getId() );
709 assertEquals( "check managed repositories", "default", repository.getLayout() );
710 assertFalse( "check managed repositories", repository.isScanned() );
711 assertTrue( "check managed repositories", repository.isSnapshots() );
715 public void testCronExpressionsWithComma()
718 File baseFile = getTestFile( "target/test/test-file.xml" );
720 assertFalse( baseFile.exists() );
722 File userFile = getTestFile( "target/test/test-file-user.xml" );
724 assertFalse( userFile.exists() );
726 baseFile.getParentFile().mkdirs();
727 FileUtils.copyFile( getTestFile( "src/test/conf/escape-cron-expressions.xml" ), baseFile );
729 userFile.getParentFile().mkdirs();
730 FileUtils.writeStringToFile( userFile, "<configuration/>", null );
732 final ArchivaConfiguration archivaConfiguration =
733 lookup( ArchivaConfiguration.class, "test-cron-expressions" );
735 archivaConfiguration.reload();
737 Configuration configuration = archivaConfiguration.getConfiguration();
739 ManagedRepositoryConfiguration repository =
740 (ManagedRepositoryConfiguration) configuration.getManagedRepositories().get( 0 );
742 assertEquals( "check cron expression", "0 0,30 * * * ?", repository.getRefreshCronExpression().trim() );
744 configuration.getDatabaseScanning().setCronExpression( "0 0,15 0 * * ?" );
746 // add a test listener to confirm it doesn't see the escaped format. We don't need to test the number of calls,
747 // etc. as it's done in other tests
748 archivaConfiguration.addListener( new ConfigurationListener()
750 public void configurationEvent( ConfigurationEvent event )
752 assertEquals( ConfigurationEvent.SAVED, event.getType() );
754 Configuration configuration = archivaConfiguration.getConfiguration();
756 assertEquals( "check cron expression", "0 0,15 0 * * ?",
757 configuration.getDatabaseScanning().getCronExpression() );
761 archivaConfiguration.save( configuration );
763 configuration = archivaConfiguration.getConfiguration();
765 assertEquals( "check cron expression", "0 0,15 0 * * ?",
766 configuration.getDatabaseScanning().getCronExpression() );
768 // test for the escape character '\' showing up on repositories.jsp
769 repository.setRefreshCronExpression( "0 0,20 0 * * ?" );
771 archivaConfiguration.save( configuration );
773 repository = archivaConfiguration.getConfiguration().findManagedRepositoryById( "snapshots" );
775 assertEquals( "check cron expression", "0 0,20 0 * * ?", repository.getRefreshCronExpression() );
779 public void testRemoveLastElements()
782 File baseFile = getTestFile( "target/test/test-file.xml" );
784 assertFalse( baseFile.exists() );
786 File userFile = getTestFile( "target/test/test-file-user.xml" );
788 assertFalse( userFile.exists() );
790 baseFile.getParentFile().mkdirs();
791 FileUtils.copyFile( getTestFile( "src/test/conf/conf-single-list-elements.xml" ), baseFile );
793 userFile.getParentFile().mkdirs();
794 FileUtils.writeStringToFile( userFile, "<configuration/>", null );
796 ArchivaConfiguration archivaConfiguration =
797 (ArchivaConfiguration) lookup( ArchivaConfiguration.class, "test-remove-central" );
799 archivaConfiguration.reload();
801 Configuration configuration = archivaConfiguration.getConfiguration();
803 RepositoryGroupConfiguration repositoryGroup =
804 (RepositoryGroupConfiguration) configuration.getRepositoryGroups().get( 0 );
805 assertNotNull( repositoryGroup );
806 configuration.removeRepositoryGroup( repositoryGroup );
807 assertTrue( configuration.getRepositoryGroups().isEmpty() );
809 RemoteRepositoryConfiguration repository = configuration.getRemoteRepositoriesAsMap().get( "central" );
810 assertNotNull( repository );
811 configuration.removeRemoteRepository( repository );
812 assertTrue( configuration.getRemoteRepositories().isEmpty() );
814 ManagedRepositoryConfiguration managedRepository =
815 configuration.getManagedRepositoriesAsMap().get( "snapshots" );
816 assertNotNull( managedRepository );
817 configuration.removeManagedRepository( managedRepository );
818 assertTrue( configuration.getManagedRepositories().isEmpty() );
820 ProxyConnectorConfiguration proxyConnector =
821 (ProxyConnectorConfiguration) configuration.getProxyConnectors().get( 0 );
822 assertNotNull( proxyConnector );
823 configuration.removeProxyConnector( proxyConnector );
824 assertTrue( configuration.getProxyConnectors().isEmpty() );
826 NetworkProxyConfiguration networkProxy = configuration.getNetworkProxiesAsMap().get( "proxy" );
827 assertNotNull( networkProxy );
828 configuration.removeNetworkProxy( networkProxy );
829 assertTrue( configuration.getNetworkProxies().isEmpty() );
831 LegacyArtifactPath path = (LegacyArtifactPath) configuration.getLegacyArtifactPaths().get( 0 );
832 assertNotNull( path );
833 configuration.removeLegacyArtifactPath( path );
834 assertTrue( configuration.getLegacyArtifactPaths().isEmpty() );
836 RepositoryScanningConfiguration scanning = configuration.getRepositoryScanning();
837 String consumer = (String) scanning.getKnownContentConsumers().get( 0 );
838 assertNotNull( consumer );
839 scanning.removeKnownContentConsumer( consumer );
840 assertTrue( scanning.getKnownContentConsumers().isEmpty() );
841 consumer = (String) scanning.getInvalidContentConsumers().get( 0 );
842 assertNotNull( consumer );
843 scanning.removeInvalidContentConsumer( consumer );
844 assertTrue( scanning.getInvalidContentConsumers().isEmpty() );
846 DatabaseScanningConfiguration databaseScanning = configuration.getDatabaseScanning();
847 consumer = (String) databaseScanning.getCleanupConsumers().get( 0 );
848 assertNotNull( consumer );
849 databaseScanning.removeCleanupConsumer( consumer );
850 assertTrue( databaseScanning.getCleanupConsumers().isEmpty() );
851 consumer = (String) databaseScanning.getUnprocessedConsumers().get( 0 );
852 assertNotNull( consumer );
853 databaseScanning.removeUnprocessedConsumer( consumer );
854 assertTrue( databaseScanning.getUnprocessedConsumers().isEmpty() );
856 archivaConfiguration.save( configuration );
858 archivaConfiguration = (ArchivaConfiguration) lookup( ArchivaConfiguration.class, "test-read-saved" );
859 configuration = archivaConfiguration.getConfiguration();
860 assertNull( configuration.getRemoteRepositoriesAsMap().get( "central" ) );
861 assertTrue( configuration.getRepositoryGroups().isEmpty() );
862 assertNull( configuration.getManagedRepositoriesAsMap().get( "snapshots" ) );
863 assertTrue( configuration.getProxyConnectors().isEmpty() );
864 assertNull( configuration.getNetworkProxiesAsMap().get( "proxy" ) );
865 assertTrue( configuration.getLegacyArtifactPaths().isEmpty() );
866 scanning = configuration.getRepositoryScanning();
867 assertTrue( scanning.getKnownContentConsumers().isEmpty() );
868 assertTrue( scanning.getInvalidContentConsumers().isEmpty() );
869 databaseScanning = configuration.getDatabaseScanning();
870 assertTrue( databaseScanning.getCleanupConsumers().isEmpty() );
871 assertTrue( databaseScanning.getUnprocessedConsumers().isEmpty() );
875 * [MRM-582] Remote Repositories with empty <username> and <password> fields shouldn't be created in configuration.
878 public void testGetConfigurationFixEmptyRemoteRepoUsernamePassword()
881 ArchivaConfiguration archivaConfiguration =
882 (ArchivaConfiguration) lookup( ArchivaConfiguration.class, "test-configuration" );
884 archivaConfiguration.reload();
885 Configuration configuration = archivaConfiguration.getConfiguration();
886 assertConfiguration( configuration );
887 assertEquals( "check remote repositories", 2, configuration.getRemoteRepositories().size() );
889 RemoteRepositoryConfiguration repository =
890 (RemoteRepositoryConfiguration) configuration.getRemoteRepositoriesAsMap().get(
891 "maven2-repository.dev.java.net" );
893 assertEquals( "remote repository.url", "https://maven2-repository.dev.java.net/nonav/repository",
894 repository.getUrl() );
895 assertEquals( "remote repository.name", "Java.net Repository for Maven 2", repository.getName() );
896 assertEquals( "remote repository.id", "maven2-repository.dev.java.net", repository.getId() );
897 assertEquals( "remote repository.layout", "default", repository.getLayout() );
898 assertNull( "remote repository.username == null", repository.getUsername() );
899 assertNull( "remote repository.password == null", repository.getPassword() );