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.apache.maven.archiva.common.utils.FileUtil;
26 import org.codehaus.plexus.registry.RegistryException;
27 import org.codehaus.redback.components.springutils.ComponentContainer;
28 import org.custommonkey.xmlunit.XMLAssert;
29 import org.easymock.MockControl;
30 import org.junit.Test;
31 import org.junit.runner.RunWith;
32 import org.springframework.test.context.ContextConfiguration;
33 import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
35 import javax.inject.Inject;
37 import java.util.List;
41 * Test the configuration store.
43 @RunWith( SpringJUnit4ClassRunner.class )
44 @ContextConfiguration( locations = {"classpath*:/META-INF/spring-context.xml","classpath:/spring-context.xml"} )
45 public class ArchivaConfigurationTest
50 private ComponentContainer componentContainer;
52 public static File getTestFile( String path )
54 return new File( FileUtil.getBasedir(), path );
60 protected String getSpringConfigLocation()
62 return "org/apache/maven/archiva/configuration/spring-context.xml";
65 protected <T> T lookup(Class<T> clazz, String hint)
67 return componentContainer.getComponent( clazz, hint );
70 protected <T> T lookup(Class<T> clazz)
72 return componentContainer.getComponent( clazz );
76 public void testGetConfigurationFromRegistryWithASingleNamedConfigurationResource()
79 ArchivaConfiguration archivaConfiguration =
80 (ArchivaConfiguration) lookup( ArchivaConfiguration.class, "test-configuration" );
82 Configuration configuration = archivaConfiguration.getConfiguration();
83 assertConfiguration( configuration );
84 assertEquals( "check network proxies", 1, configuration.getNetworkProxies().size() );
86 ManagedRepositoryConfiguration repository =
87 (ManagedRepositoryConfiguration) configuration.getManagedRepositories().get( 0 );
89 assertEquals( "check managed repositories", "${appserver.base}/repositories/internal",
90 repository.getLocation() );
91 assertEquals( "check managed repositories", "Archiva Managed Internal Repository", repository.getName() );
92 assertEquals( "check managed repositories", "internal", repository.getId() );
93 assertEquals( "check managed repositories", "default", repository.getLayout() );
94 assertTrue( "check managed repositories", repository.isScanned() );
98 public void testGetConfigurationFromDefaults()
101 ArchivaConfiguration archivaConfiguration =
102 (ArchivaConfiguration) lookup( ArchivaConfiguration.class, "test-defaults" );
104 Configuration configuration = archivaConfiguration.getConfiguration();
105 assertConfiguration( configuration );
106 assertEquals( "check network proxies", 0, configuration.getNetworkProxies().size() );
108 ManagedRepositoryConfiguration repository =
109 (ManagedRepositoryConfiguration) configuration.getManagedRepositories().get( 0 );
111 assertEquals( "check managed repositories", "${appserver.base}/data/repositories/internal",
112 repository.getLocation() );
113 assertEquals( "check managed repositories", "Archiva Managed Internal Repository", repository.getName() );
114 assertEquals( "check managed repositories", "internal", repository.getId() );
115 assertEquals( "check managed repositories", "default", repository.getLayout() );
116 assertTrue( "check managed repositories", repository.isScanned() );
119 // test for [MRM-789]
121 public void testGetConfigurationFromDefaultsWithDefaultRepoLocationAlreadyExisting()
124 File repo = new File( FileUtil.getBasedir(), "/target/test-classes/existing_snapshots" );
127 repo = new File( FileUtil.getBasedir(), "/target/test-classes/existing_internal" );
130 String existingTestDefaultArchivaConfigFile = FileUtils.readFileToString(
131 getTestFile( "target/test-classes/org/apache/maven/archiva/configuration/test-default-archiva.xml" ) );
132 existingTestDefaultArchivaConfigFile =
133 StringUtils.replace( existingTestDefaultArchivaConfigFile, "${appserver.base}", FileUtil.getBasedir() );
135 File generatedTestDefaultArchivaConfigFile =
136 new File( FileUtil.getBasedir(), "target/test-classes/org/apache/maven/archiva/configuration/default-archiva.xml" );
138 FileUtils.writeStringToFile( generatedTestDefaultArchivaConfigFile, existingTestDefaultArchivaConfigFile,
141 ArchivaConfiguration archivaConfiguration = (ArchivaConfiguration) lookup( ArchivaConfiguration.class,
142 "test-defaults-default-repo-location-exists" );
144 Configuration configuration = archivaConfiguration.getConfiguration();
145 assertConfiguration( configuration );
147 ManagedRepositoryConfiguration repository =
148 (ManagedRepositoryConfiguration) configuration.getManagedRepositories().get( 0 );
149 assertTrue( "check managed repositories", repository.getLocation().endsWith( "data/repositories/internal" ) );
151 generatedTestDefaultArchivaConfigFile.delete();
152 assertFalse( generatedTestDefaultArchivaConfigFile.exists() );
156 * Ensures that the provided configuration matches the details present in the archiva-default.xml file.
158 private void assertConfiguration( Configuration configuration )
161 FileTypes filetypes = (FileTypes) lookup( FileTypes.class );
163 assertEquals( "check repositories", 2, configuration.getManagedRepositories().size() );
164 assertEquals( "check repositories", 2, configuration.getRemoteRepositories().size() );
165 assertEquals( "check proxy connectors", 2, configuration.getProxyConnectors().size() );
167 RepositoryScanningConfiguration repoScanning = configuration.getRepositoryScanning();
168 assertNotNull( "check repository scanning", repoScanning );
169 assertEquals( "check file types", 4, repoScanning.getFileTypes().size() );
170 assertEquals( "check known consumers", 9, repoScanning.getKnownContentConsumers().size() );
171 assertEquals( "check invalid consumers", 1, repoScanning.getInvalidContentConsumers().size() );
173 List<String> patterns = filetypes.getFileTypePatterns( "artifacts" );
174 assertNotNull( "check 'artifacts' file type", patterns );
175 assertEquals( "check 'artifacts' patterns", 13, patterns.size() );
177 DatabaseScanningConfiguration dbScanning = configuration.getDatabaseScanning();
178 assertNotNull( "check database scanning", dbScanning );
179 assertEquals( "check unprocessed consumers", 6, dbScanning.getUnprocessedConsumers().size() );
180 assertEquals( "check cleanup consumers", 3, dbScanning.getCleanupConsumers().size() );
182 WebappConfiguration webapp = configuration.getWebapp();
183 assertNotNull( "check webapp", webapp );
185 UserInterfaceOptions ui = webapp.getUi();
186 assertNotNull( "check webapp ui", ui );
187 assertTrue( "check showFindArtifacts", ui.isShowFindArtifacts() );
188 assertTrue( "check appletFindEnabled", ui.isAppletFindEnabled() );
192 public void testGetConfigurationFromRegistryWithTwoConfigurationResources()
195 ArchivaConfiguration archivaConfiguration =
196 (ArchivaConfiguration) lookup( ArchivaConfiguration.class, "test-configuration-both" );
198 Configuration configuration = archivaConfiguration.getConfiguration();
201 assertEquals( "check repositories", 2, configuration.getManagedRepositories().size() );
202 assertEquals( "check repositories", 2, configuration.getRemoteRepositories().size() );
204 assertEquals( "check proxy connectors", 2, configuration.getProxyConnectors().size() );
206 WebappConfiguration webapp = configuration.getWebapp();
207 assertNotNull( "check webapp", webapp );
209 UserInterfaceOptions ui = webapp.getUi();
210 assertNotNull( "check webapp ui", ui );
212 assertFalse( "check showFindArtifacts", ui.isShowFindArtifacts() );
214 assertFalse( "check appletFindEnabled", ui.isAppletFindEnabled() );
218 public void testGetConfigurationSystemOverride()
222 System.setProperty( "org.apache.maven.archiva.webapp.ui.appletFindEnabled", "false" );
224 ArchivaConfiguration archivaConfiguration =
225 (ArchivaConfiguration) lookup( ArchivaConfiguration.class, "test-configuration" );
227 archivaConfiguration.reload();
231 Configuration configuration = archivaConfiguration.getConfiguration();
233 assertFalse( "check boolean", configuration.getWebapp().getUi().isAppletFindEnabled() );
237 System.getProperties().remove( "org.apache.maven.archiva.webapp.ui.appletFindEnabled" );
242 public void testStoreConfiguration()
245 File file = getTestFile( "target/test/test-file.xml" );
247 assertFalse( file.exists() );
249 // TODO: remove with commons-configuration 1.4
250 //file.getParentFile().mkdirs();
251 //FileUtils.writeStringToFile( file, "<configuration/>", null );
253 DefaultArchivaConfiguration archivaConfiguration =
254 (DefaultArchivaConfiguration) lookup( ArchivaConfiguration.class, "test-save" );
256 archivaConfiguration.reload();
258 Configuration configuration = new Configuration();
259 configuration.setVersion( "1" );
260 configuration.setWebapp( new WebappConfiguration() );
261 configuration.getWebapp().setUi( new UserInterfaceOptions() );
262 configuration.getWebapp().getUi().setAppletFindEnabled( false );
264 // add a change listener
265 MockControl control = createConfigurationListenerMockControl();
266 ConfigurationListener listener = (ConfigurationListener) control.getMock();
267 archivaConfiguration.addListener( listener );
269 listener.configurationEvent( new ConfigurationEvent( ConfigurationEvent.SAVED ) );
270 control.setVoidCallable();
274 archivaConfiguration.save( configuration );
278 assertTrue( "Check file exists", file.exists() );
281 configuration = archivaConfiguration.getConfiguration();
282 assertFalse( "check value", configuration.getWebapp().getUi().isAppletFindEnabled() );
285 archivaConfiguration =
286 (DefaultArchivaConfiguration) lookup( ArchivaConfiguration.class, "test-read-saved" );
288 archivaConfiguration.reload();
289 configuration = archivaConfiguration.getConfiguration();
290 assertFalse( "check value", configuration.getWebapp().getUi().isAppletFindEnabled() );
293 private static MockControl createConfigurationListenerMockControl()
295 return MockControl.createControl( ConfigurationListener.class );
299 public void testStoreConfigurationUser()
302 File baseFile = getTestFile( "target/test/test-file.xml" );
304 assertFalse( baseFile.exists() );
306 File userFile = getTestFile( "target/test/test-file-user.xml" );
308 assertFalse( userFile.exists() );
310 userFile.getParentFile().mkdirs();
311 FileUtils.writeStringToFile( userFile, "<configuration/>", null );
313 ArchivaConfiguration archivaConfiguration =
314 (ArchivaConfiguration) lookup( ArchivaConfiguration.class, "test-save-user" );
316 Configuration configuration = new Configuration();
317 configuration.setWebapp( new WebappConfiguration() );
318 configuration.getWebapp().setUi( new UserInterfaceOptions() );
319 configuration.getWebapp().getUi().setAppletFindEnabled( false );
321 archivaConfiguration.save( configuration );
323 assertTrue( "Check file exists", userFile.exists() );
324 assertFalse( "Check file not created", baseFile.exists() );
327 configuration = archivaConfiguration.getConfiguration();
328 assertFalse( "check value", configuration.getWebapp().getUi().isAppletFindEnabled() );
332 public void testStoreConfigurationLoadedFromDefaults()
335 File baseFile = getTestFile( "target/test/test-file.xml" );
337 assertFalse( baseFile.exists() );
339 File userFile = getTestFile( "target/test/test-file-user.xml" );
341 assertFalse( userFile.exists() );
343 ArchivaConfiguration archivaConfiguration =
344 (ArchivaConfiguration) lookup( ArchivaConfiguration.class, "test-save-user-defaults" );
346 archivaConfiguration.reload();
348 Configuration configuration = new Configuration();
349 configuration.setWebapp( new WebappConfiguration() );
350 configuration.getWebapp().setUi( new UserInterfaceOptions() );
351 configuration.getWebapp().getUi().setAppletFindEnabled( false );
353 // add a change listener
354 MockControl control = createConfigurationListenerMockControl();
355 ConfigurationListener listener = (ConfigurationListener) control.getMock();
356 archivaConfiguration.addListener( listener );
358 listener.configurationEvent( new ConfigurationEvent( ConfigurationEvent.SAVED ) );
360 control.setVoidCallable( 1 );
364 archivaConfiguration.save( configuration );
368 assertTrue( "Check file exists", userFile.exists() );
369 assertFalse( "Check file not created", baseFile.exists() );
372 configuration = archivaConfiguration.getConfiguration();
373 assertFalse( "check value", configuration.getWebapp().getUi().isAppletFindEnabled() );
377 public void testDefaultUserConfigFilename()
380 DefaultArchivaConfiguration archivaConfiguration =
381 (DefaultArchivaConfiguration) lookup( ArchivaConfiguration.class, "default" );
383 archivaConfiguration.reload();
385 assertEquals( System.getProperty( "user.home" ) + "/.m2/archiva.xml",
386 archivaConfiguration.getUserConfigFilename() );
387 assertEquals( System.getProperty( "appserver.base", "${appserver.base}" ) + "/conf/archiva.xml",
388 archivaConfiguration.getAltConfigFilename() );
392 public void testStoreConfigurationFallback()
395 File baseFile = getTestFile( "target/test/test-file.xml" );
397 assertFalse( baseFile.exists() );
399 File userFile = getTestFile( "target/test/test-file-user.xml" );
401 assertFalse( userFile.exists() );
403 baseFile.getParentFile().mkdirs();
404 FileUtils.writeStringToFile( baseFile, "<configuration/>", null );
406 ArchivaConfiguration archivaConfiguration =
407 (ArchivaConfiguration) lookup( ArchivaConfiguration.class, "test-save-user-fallback" );
409 archivaConfiguration.reload();
411 Configuration configuration = new Configuration();
412 configuration.setWebapp( new WebappConfiguration() );
413 configuration.getWebapp().setUi( new UserInterfaceOptions() );
414 configuration.getWebapp().getUi().setAppletFindEnabled( false );
416 archivaConfiguration.save( configuration );
418 assertTrue( "Check file exists", baseFile.exists() );
419 assertFalse( "Check file not created", userFile.exists() );
423 configuration = archivaConfiguration.getConfiguration();
424 assertFalse( "check value", configuration.getWebapp().getUi().isAppletFindEnabled() );
428 public void testStoreConfigurationFailsWhenReadFromBothLocationsNoLists()
431 File baseFile = getTestFile( "target/test/test-file.xml" );
433 assertFalse( baseFile.exists() );
435 File userFile = getTestFile( "target/test/test-file-user.xml" );
437 assertFalse( userFile.exists() );
439 baseFile.getParentFile().mkdirs();
440 FileUtils.writeStringToFile( baseFile, "<configuration/>", null );
442 userFile.getParentFile().mkdirs();
443 FileUtils.writeStringToFile( userFile, "<configuration/>", null );
445 ArchivaConfiguration archivaConfiguration =
446 (ArchivaConfiguration) lookup( ArchivaConfiguration.class, "test-save-user" );
448 archivaConfiguration.reload();
450 Configuration configuration = archivaConfiguration.getConfiguration();
451 assertTrue( "check value", configuration.getWebapp().getUi().isAppletFindEnabled() );
453 configuration.getWebapp().getUi().setAppletFindEnabled( false );
455 archivaConfiguration.save( configuration );
457 assertTrue( "Check file exists", baseFile.exists() );
458 assertEquals( "Check base file is unchanged", "<configuration/>",
459 FileUtils.readFileToString( baseFile, null ) );
460 assertTrue( "Check file exists", userFile.exists() );
461 assertFalse( "Check base file is changed",
462 "<configuration/>".equals( FileUtils.readFileToString( userFile, null ) ) );
465 configuration = archivaConfiguration.getConfiguration();
466 assertFalse( "check value", configuration.getWebapp().getUi().isAppletFindEnabled() );
470 public void testStoreConfigurationFailsWhenReadFromBothLocationsUserHasLists()
473 File baseFile = getTestFile( "target/test/test-file.xml" );
475 assertFalse( baseFile.exists() );
477 File userFile = getTestFile( "target/test/test-file-user.xml" );
479 assertFalse( userFile.exists() );
481 userFile.getParentFile().mkdirs();
482 FileUtils.copyFile( getTestFile( "src/test/conf/conf-user.xml" ), userFile );
484 baseFile.getParentFile().mkdirs();
485 FileUtils.writeStringToFile( baseFile, "<configuration/>", null );
487 ArchivaConfiguration archivaConfiguration =
488 (ArchivaConfiguration) lookup( ArchivaConfiguration.class, "test-save-user" );
490 archivaConfiguration.reload();
492 Configuration configuration = archivaConfiguration.getConfiguration();
493 assertTrue( "check value", configuration.getWebapp().getUi().isShowFindArtifacts() );
495 configuration.getWebapp().getUi().setShowFindArtifacts( false );
497 archivaConfiguration.save( configuration );
499 assertTrue( "Check file exists", baseFile.exists() );
500 assertEquals( "Check base file is unchanged", "<configuration/>",
501 FileUtils.readFileToString( baseFile, null ) );
502 assertTrue( "Check file exists", userFile.exists() );
503 assertFalse( "Check base file is changed",
504 "<configuration/>".equals( FileUtils.readFileToString( userFile, null ) ) );
507 configuration = archivaConfiguration.getConfiguration();
508 assertFalse( "check value", configuration.getWebapp().getUi().isShowFindArtifacts() );
512 public void testStoreConfigurationFailsWhenReadFromBothLocationsAppserverHasLists()
515 File baseFile = getTestFile( "target/test/test-file.xml" );
517 assertFalse( baseFile.exists() );
519 File userFile = getTestFile( "target/test/test-file-user.xml" );
521 assertFalse( userFile.exists() );
523 baseFile.getParentFile().mkdirs();
524 FileUtils.copyFile( getTestFile( "src/test/conf/conf-base.xml" ), baseFile );
526 userFile.getParentFile().mkdirs();
527 FileUtils.writeStringToFile( userFile, "<configuration/>", null );
529 ArchivaConfiguration archivaConfiguration =
530 (ArchivaConfiguration) lookup( ArchivaConfiguration.class, "test-save-user" );
532 archivaConfiguration.reload();
534 Configuration configuration = archivaConfiguration.getConfiguration();
535 assertTrue( "check value", configuration.getWebapp().getUi().isAppletFindEnabled() );
537 configuration.getWebapp().getUi().setAppletFindEnabled( false );
541 archivaConfiguration.save( configuration );
542 fail( "Configuration saving should not succeed if it was loaded from two locations" );
544 catch ( IndeterminateConfigurationException e )
546 // check it was reverted
547 configuration = archivaConfiguration.getConfiguration();
548 assertTrue( "check value", configuration.getWebapp().getUi().isAppletFindEnabled() );
553 public void testLoadConfigurationFromInvalidBothLocationsOnDisk()
556 ArchivaConfiguration archivaConfiguration =
557 (ArchivaConfiguration) lookup( ArchivaConfiguration.class, "test-not-allowed-to-write-to-both" );
558 Configuration config = archivaConfiguration.getConfiguration();
562 archivaConfiguration.save( config );
563 fail( "Should have thrown a RegistryException because the configuration can't be saved." );
565 catch ( RegistryException e )
567 /* expected exception */
572 public void testLoadConfigurationFromInvalidUserLocationOnDisk()
575 File testConfDir = getTestFile( "target/test-appserver-base/conf/" );
576 testConfDir.mkdirs();
578 ArchivaConfiguration archivaConfiguration =
579 (ArchivaConfiguration) lookup( ArchivaConfiguration.class, "test-not-allowed-to-write-to-user" );
580 Configuration config = archivaConfiguration.getConfiguration();
581 archivaConfiguration.save( config );
582 // No Exception == test passes.
583 // Expected Path is: Should not have thrown an exception.
587 public void testConfigurationUpgradeFrom09()
590 ArchivaConfiguration archivaConfiguration =
591 (ArchivaConfiguration) lookup( ArchivaConfiguration.class, "test-upgrade-09" );
593 // we just use the defaults when upgrading from 0.9 at this point.
594 Configuration configuration = archivaConfiguration.getConfiguration();
595 assertConfiguration( configuration );
596 assertEquals( "check network proxies", 0, configuration.getNetworkProxies().size() );
598 ManagedRepositoryConfiguration repository =
599 (ManagedRepositoryConfiguration) configuration.getManagedRepositories().get( 0 );
601 assertEquals( "check managed repositories", "${appserver.base}/data/repositories/internal",
602 repository.getLocation() );
603 assertEquals( "check managed repositories", "Archiva Managed Internal Repository", repository.getName() );
604 assertEquals( "check managed repositories", "internal", repository.getId() );
605 assertEquals( "check managed repositories", "default", repository.getLayout() );
606 assertTrue( "check managed repositories", repository.isScanned() );
610 public void testAutoDetectV1()
613 // Setup the autodetect-v1.xml file in the target directory (so we can save/load it)
614 File userFile = getTestFile( "target/test-autodetect-v1/archiva-user.xml" );
616 assertFalse( userFile.exists() );
618 userFile.getParentFile().mkdirs();
619 FileUtils.copyFile( getTestFile( "src/test/conf/autodetect-v1.xml" ), userFile );
621 // Load the original (unconverted) archiva.xml
622 ArchivaConfiguration archivaConfiguration =
623 (ArchivaConfiguration) lookup( ArchivaConfiguration.class, "test-autodetect-v1" );
625 archivaConfiguration.reload();
627 Configuration configuration = archivaConfiguration.getConfiguration();
628 assertConfiguration( configuration );
629 assertEquals( "check network proxies", 1, configuration.getNetworkProxies().size() );
631 ManagedRepositoryConfiguration repository =
632 (ManagedRepositoryConfiguration) configuration.getManagedRepositories().get( 0 );
634 assertEquals( "check managed repositories", "${appserver.base}/repositories/internal",
635 repository.getLocation() );
636 assertEquals( "check managed repositories", "Archiva Managed Internal Repository", repository.getName() );
637 assertEquals( "check managed repositories", "internal", repository.getId() );
638 assertEquals( "check managed repositories", "default", repository.getLayout() );
639 assertTrue( "check managed repositories", repository.isScanned() );
641 // Test that only 1 set of repositories exist.
642 assertEquals( "check managed repositories size.", 2, configuration.getManagedRepositories().size() );
643 assertEquals( "check remote repositories size.", 2, configuration.getRemoteRepositories().size() );
644 assertEquals( "check v1 repositories size.", 0, configuration.getRepositories().size() );
647 archivaConfiguration.save( configuration );
650 //release( archivaConfiguration );
653 archivaConfiguration =
654 (ArchivaConfiguration) lookup( ArchivaConfiguration.class, "test-autodetect-v1" );
655 configuration = archivaConfiguration.getConfiguration();
657 // Test that only 1 set of repositories exist.
658 assertEquals( "check managed repositories size.", 2, configuration.getManagedRepositories().size() );
659 assertEquals( "check managed repositories size.", 2, configuration.getManagedRepositoriesAsMap().size() );
660 assertEquals( "check remote repositories size.", 2, configuration.getRemoteRepositories().size() );
661 assertEquals( "check remote repositories size.", 2, configuration.getRemoteRepositoriesAsMap().size() );
662 assertEquals( "check v1 repositories size.", 0, configuration.getRepositories().size() );
664 String actualXML = FileUtils.readFileToString( userFile, null );
665 XMLAssert.assertXpathNotExists( "//configuration/repositories/repository", actualXML );
666 XMLAssert.assertXpathNotExists( "//configuration/repositories", actualXML );
670 public void testArchivaV1()
673 ArchivaConfiguration archivaConfiguration =
674 (ArchivaConfiguration) lookup( ArchivaConfiguration.class, "test-archiva-v1" );
676 Configuration configuration = archivaConfiguration.getConfiguration();
677 assertConfiguration( configuration );
678 assertEquals( "check network proxies", 1, configuration.getNetworkProxies().size() );
680 assertEquals( "check managed repositories", 2, configuration.getManagedRepositories().size() );
681 assertEquals( "check v1 repositories size.", 0, configuration.getRepositories().size() );
683 Map<String, ManagedRepositoryConfiguration> map = configuration.getManagedRepositoriesAsMap();
685 ManagedRepositoryConfiguration repository = map.get( "internal" );
686 assertEquals( "check managed repositories", "${appserver.base}/repositories/internal",
687 repository.getLocation() );
688 assertEquals( "check managed repositories", "Archiva Managed Internal Repository", repository.getName() );
689 assertEquals( "check managed repositories", "internal", repository.getId() );
690 assertEquals( "check managed repositories", "default", repository.getLayout() );
691 assertTrue( "check managed repositories", repository.isScanned() );
692 assertFalse( "check managed repositories", repository.isSnapshots() );
694 repository = map.get( "snapshots" );
695 assertEquals( "check managed repositories", "${appserver.base}/repositories/snapshots",
696 repository.getLocation() );
697 assertEquals( "check managed repositories", "Archiva Managed Snapshot Repository", repository.getName() );
698 assertEquals( "check managed repositories", "snapshots", repository.getId() );
699 assertEquals( "check managed repositories", "default", repository.getLayout() );
700 assertFalse( "check managed repositories", repository.isScanned() );
701 assertTrue( "check managed repositories", repository.isSnapshots() );
705 public void testCronExpressionsWithComma()
708 File baseFile = getTestFile( "target/test/test-file.xml" );
710 assertFalse( baseFile.exists() );
712 File userFile = getTestFile( "target/test/test-file-user.xml" );
714 assertFalse( userFile.exists() );
716 baseFile.getParentFile().mkdirs();
717 FileUtils.copyFile( getTestFile( "src/test/conf/escape-cron-expressions.xml" ), baseFile );
719 userFile.getParentFile().mkdirs();
720 FileUtils.writeStringToFile( userFile, "<configuration/>", null );
722 final ArchivaConfiguration archivaConfiguration =
723 lookup( ArchivaConfiguration.class, "test-cron-expressions" );
725 archivaConfiguration.reload();
727 Configuration configuration = archivaConfiguration.getConfiguration();
729 ManagedRepositoryConfiguration repository =
730 (ManagedRepositoryConfiguration) configuration.getManagedRepositories().get( 0 );
732 assertEquals( "check cron expression", "0 0,30 * * * ?", repository.getRefreshCronExpression().trim() );
734 configuration.getDatabaseScanning().setCronExpression( "0 0,15 0 * * ?" );
736 // add a test listener to confirm it doesn't see the escaped format. We don't need to test the number of calls,
737 // etc. as it's done in other tests
738 archivaConfiguration.addListener( new ConfigurationListener()
740 public void configurationEvent( ConfigurationEvent event )
742 assertEquals( ConfigurationEvent.SAVED, event.getType() );
744 Configuration configuration = archivaConfiguration.getConfiguration();
746 assertEquals( "check cron expression", "0 0,15 0 * * ?",
747 configuration.getDatabaseScanning().getCronExpression() );
751 archivaConfiguration.save( configuration );
753 configuration = archivaConfiguration.getConfiguration();
755 assertEquals( "check cron expression", "0 0,15 0 * * ?",
756 configuration.getDatabaseScanning().getCronExpression() );
758 // test for the escape character '\' showing up on repositories.jsp
759 repository.setRefreshCronExpression( "0 0,20 0 * * ?" );
761 archivaConfiguration.save( configuration );
763 repository = archivaConfiguration.getConfiguration().findManagedRepositoryById( "snapshots" );
765 assertEquals( "check cron expression", "0 0,20 0 * * ?", repository.getRefreshCronExpression() );
769 public void testRemoveLastElements()
772 File baseFile = getTestFile( "target/test/test-file.xml" );
774 assertFalse( baseFile.exists() );
776 File userFile = getTestFile( "target/test/test-file-user.xml" );
778 assertFalse( userFile.exists() );
780 baseFile.getParentFile().mkdirs();
781 FileUtils.copyFile( getTestFile( "src/test/conf/conf-single-list-elements.xml" ), baseFile );
783 userFile.getParentFile().mkdirs();
784 FileUtils.writeStringToFile( userFile, "<configuration/>", null );
786 ArchivaConfiguration archivaConfiguration =
787 (ArchivaConfiguration) lookup( ArchivaConfiguration.class, "test-remove-central" );
789 archivaConfiguration.reload();
791 Configuration configuration = archivaConfiguration.getConfiguration();
793 RepositoryGroupConfiguration repositoryGroup =
794 (RepositoryGroupConfiguration) configuration.getRepositoryGroups().get( 0 );
795 assertNotNull( repositoryGroup );
796 configuration.removeRepositoryGroup( repositoryGroup );
797 assertTrue( configuration.getRepositoryGroups().isEmpty() );
799 RemoteRepositoryConfiguration repository = configuration.getRemoteRepositoriesAsMap().get( "central" );
800 assertNotNull( repository );
801 configuration.removeRemoteRepository( repository );
802 assertTrue( configuration.getRemoteRepositories().isEmpty() );
804 ManagedRepositoryConfiguration managedRepository =
805 configuration.getManagedRepositoriesAsMap().get( "snapshots" );
806 assertNotNull( managedRepository );
807 configuration.removeManagedRepository( managedRepository );
808 assertTrue( configuration.getManagedRepositories().isEmpty() );
810 ProxyConnectorConfiguration proxyConnector =
811 (ProxyConnectorConfiguration) configuration.getProxyConnectors().get( 0 );
812 assertNotNull( proxyConnector );
813 configuration.removeProxyConnector( proxyConnector );
814 assertTrue( configuration.getProxyConnectors().isEmpty() );
816 NetworkProxyConfiguration networkProxy = configuration.getNetworkProxiesAsMap().get( "proxy" );
817 assertNotNull( networkProxy );
818 configuration.removeNetworkProxy( networkProxy );
819 assertTrue( configuration.getNetworkProxies().isEmpty() );
821 LegacyArtifactPath path = (LegacyArtifactPath) configuration.getLegacyArtifactPaths().get( 0 );
822 assertNotNull( path );
823 configuration.removeLegacyArtifactPath( path );
824 assertTrue( configuration.getLegacyArtifactPaths().isEmpty() );
826 RepositoryScanningConfiguration scanning = configuration.getRepositoryScanning();
827 String consumer = (String) scanning.getKnownContentConsumers().get( 0 );
828 assertNotNull( consumer );
829 scanning.removeKnownContentConsumer( consumer );
830 assertTrue( scanning.getKnownContentConsumers().isEmpty() );
831 consumer = (String) scanning.getInvalidContentConsumers().get( 0 );
832 assertNotNull( consumer );
833 scanning.removeInvalidContentConsumer( consumer );
834 assertTrue( scanning.getInvalidContentConsumers().isEmpty() );
836 DatabaseScanningConfiguration databaseScanning = configuration.getDatabaseScanning();
837 consumer = (String) databaseScanning.getCleanupConsumers().get( 0 );
838 assertNotNull( consumer );
839 databaseScanning.removeCleanupConsumer( consumer );
840 assertTrue( databaseScanning.getCleanupConsumers().isEmpty() );
841 consumer = (String) databaseScanning.getUnprocessedConsumers().get( 0 );
842 assertNotNull( consumer );
843 databaseScanning.removeUnprocessedConsumer( consumer );
844 assertTrue( databaseScanning.getUnprocessedConsumers().isEmpty() );
846 archivaConfiguration.save( configuration );
848 archivaConfiguration = (ArchivaConfiguration) lookup( ArchivaConfiguration.class, "test-read-saved" );
849 configuration = archivaConfiguration.getConfiguration();
850 assertNull( configuration.getRemoteRepositoriesAsMap().get( "central" ) );
851 assertTrue( configuration.getRepositoryGroups().isEmpty() );
852 assertNull( configuration.getManagedRepositoriesAsMap().get( "snapshots" ) );
853 assertTrue( configuration.getProxyConnectors().isEmpty() );
854 assertNull( configuration.getNetworkProxiesAsMap().get( "proxy" ) );
855 assertTrue( configuration.getLegacyArtifactPaths().isEmpty() );
856 scanning = configuration.getRepositoryScanning();
857 assertTrue( scanning.getKnownContentConsumers().isEmpty() );
858 assertTrue( scanning.getInvalidContentConsumers().isEmpty() );
859 databaseScanning = configuration.getDatabaseScanning();
860 assertTrue( databaseScanning.getCleanupConsumers().isEmpty() );
861 assertTrue( databaseScanning.getUnprocessedConsumers().isEmpty() );
865 * [MRM-582] Remote Repositories with empty <username> and <password> fields shouldn't be created in configuration.
868 public void testGetConfigurationFixEmptyRemoteRepoUsernamePassword()
871 ArchivaConfiguration archivaConfiguration =
872 (ArchivaConfiguration) lookup( ArchivaConfiguration.class, "test-configuration" );
874 archivaConfiguration.reload();
875 Configuration configuration = archivaConfiguration.getConfiguration();
876 assertConfiguration( configuration );
877 assertEquals( "check remote repositories", 2, configuration.getRemoteRepositories().size() );
879 RemoteRepositoryConfiguration repository =
880 (RemoteRepositoryConfiguration) configuration.getRemoteRepositoriesAsMap().get(
881 "maven2-repository.dev.java.net" );
883 assertEquals( "remote repository.url", "https://maven2-repository.dev.java.net/nonav/repository",
884 repository.getUrl() );
885 assertEquals( "remote repository.name", "Java.net Repository for Maven 2", repository.getName() );
886 assertEquals( "remote repository.id", "maven2-repository.dev.java.net", repository.getId() );
887 assertEquals( "remote repository.layout", "default", repository.getLayout() );
888 assertNull( "remote repository.username == null", repository.getUsername() );
889 assertNull( "remote repository.password == null", repository.getPassword() );