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 junit.framework.TestCase;
23 import org.apache.commons.io.FileUtils;
24 import org.apache.commons.lang.StringUtils;
25 import org.apache.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/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/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 WebappConfiguration webapp = configuration.getWebapp();
178 assertNotNull( "check webapp", webapp );
180 UserInterfaceOptions ui = webapp.getUi();
181 assertNotNull( "check webapp ui", ui );
182 assertTrue( "check showFindArtifacts", ui.isShowFindArtifacts() );
183 assertTrue( "check appletFindEnabled", ui.isAppletFindEnabled() );
187 public void testGetConfigurationFromRegistryWithTwoConfigurationResources()
190 ArchivaConfiguration archivaConfiguration =
191 (ArchivaConfiguration) lookup( ArchivaConfiguration.class, "test-configuration-both" );
193 Configuration configuration = archivaConfiguration.getConfiguration();
196 assertEquals( "check repositories", 2, configuration.getManagedRepositories().size() );
197 assertEquals( "check repositories", 2, configuration.getRemoteRepositories().size() );
199 assertEquals( "check proxy connectors", 2, configuration.getProxyConnectors().size() );
201 WebappConfiguration webapp = configuration.getWebapp();
202 assertNotNull( "check webapp", webapp );
204 UserInterfaceOptions ui = webapp.getUi();
205 assertNotNull( "check webapp ui", ui );
207 assertFalse( "check showFindArtifacts", ui.isShowFindArtifacts() );
209 assertFalse( "check appletFindEnabled", ui.isAppletFindEnabled() );
213 public void testGetConfigurationSystemOverride()
217 System.setProperty( "org.apache.maven.archiva.webapp.ui.appletFindEnabled", "false" );
219 ArchivaConfiguration archivaConfiguration =
220 (ArchivaConfiguration) lookup( ArchivaConfiguration.class, "test-configuration" );
222 archivaConfiguration.reload();
226 Configuration configuration = archivaConfiguration.getConfiguration();
228 assertFalse( "check boolean", configuration.getWebapp().getUi().isAppletFindEnabled() );
232 System.getProperties().remove( "org.apache.maven.archiva.webapp.ui.appletFindEnabled" );
237 public void testStoreConfiguration()
240 File file = getTestFile( "target/test/test-file.xml" );
242 assertFalse( file.exists() );
244 // TODO: remove with commons-configuration 1.4
245 //file.getParentFile().mkdirs();
246 //FileUtils.writeStringToFile( file, "<configuration/>", null );
248 DefaultArchivaConfiguration archivaConfiguration =
249 (DefaultArchivaConfiguration) lookup( ArchivaConfiguration.class, "test-save" );
251 archivaConfiguration.reload();
253 Configuration configuration = new Configuration();
254 configuration.setVersion( "1" );
255 configuration.setWebapp( new WebappConfiguration() );
256 configuration.getWebapp().setUi( new UserInterfaceOptions() );
257 configuration.getWebapp().getUi().setAppletFindEnabled( false );
259 // add a change listener
260 MockControl control = createConfigurationListenerMockControl();
261 ConfigurationListener listener = (ConfigurationListener) control.getMock();
262 archivaConfiguration.addListener( listener );
264 listener.configurationEvent( new ConfigurationEvent( ConfigurationEvent.SAVED ) );
265 control.setVoidCallable();
269 archivaConfiguration.save( configuration );
273 assertTrue( "Check file exists", file.exists() );
276 configuration = archivaConfiguration.getConfiguration();
277 assertFalse( "check value", configuration.getWebapp().getUi().isAppletFindEnabled() );
280 archivaConfiguration =
281 (DefaultArchivaConfiguration) lookup( ArchivaConfiguration.class, "test-read-saved" );
283 archivaConfiguration.reload();
284 configuration = archivaConfiguration.getConfiguration();
285 assertFalse( "check value", configuration.getWebapp().getUi().isAppletFindEnabled() );
288 private static MockControl createConfigurationListenerMockControl()
290 return MockControl.createControl( ConfigurationListener.class );
294 public void testStoreConfigurationUser()
297 File baseFile = getTestFile( "target/test/test-file.xml" );
299 assertFalse( baseFile.exists() );
301 File userFile = getTestFile( "target/test/test-file-user.xml" );
303 assertFalse( userFile.exists() );
305 userFile.getParentFile().mkdirs();
306 FileUtils.writeStringToFile( userFile, "<configuration/>", null );
308 ArchivaConfiguration archivaConfiguration =
309 (ArchivaConfiguration) lookup( ArchivaConfiguration.class, "test-save-user" );
311 Configuration configuration = new Configuration();
312 configuration.setWebapp( new WebappConfiguration() );
313 configuration.getWebapp().setUi( new UserInterfaceOptions() );
314 configuration.getWebapp().getUi().setAppletFindEnabled( false );
316 archivaConfiguration.save( configuration );
318 assertTrue( "Check file exists", userFile.exists() );
319 assertFalse( "Check file not created", baseFile.exists() );
322 configuration = archivaConfiguration.getConfiguration();
323 assertFalse( "check value", configuration.getWebapp().getUi().isAppletFindEnabled() );
327 public void testStoreConfigurationLoadedFromDefaults()
330 File baseFile = getTestFile( "target/test/test-file.xml" );
332 assertFalse( baseFile.exists() );
334 File userFile = getTestFile( "target/test/test-file-user.xml" );
336 assertFalse( userFile.exists() );
338 ArchivaConfiguration archivaConfiguration =
339 (ArchivaConfiguration) lookup( ArchivaConfiguration.class, "test-save-user-defaults" );
341 archivaConfiguration.reload();
343 Configuration configuration = new Configuration();
344 configuration.setWebapp( new WebappConfiguration() );
345 configuration.getWebapp().setUi( new UserInterfaceOptions() );
346 configuration.getWebapp().getUi().setAppletFindEnabled( false );
348 // add a change listener
349 MockControl control = createConfigurationListenerMockControl();
350 ConfigurationListener listener = (ConfigurationListener) control.getMock();
351 archivaConfiguration.addListener( listener );
353 listener.configurationEvent( new ConfigurationEvent( ConfigurationEvent.SAVED ) );
355 control.setVoidCallable( 1 );
359 archivaConfiguration.save( configuration );
363 assertTrue( "Check file exists", userFile.exists() );
364 assertFalse( "Check file not created", baseFile.exists() );
367 configuration = archivaConfiguration.getConfiguration();
368 assertFalse( "check value", configuration.getWebapp().getUi().isAppletFindEnabled() );
372 public void testDefaultUserConfigFilename()
375 DefaultArchivaConfiguration archivaConfiguration =
376 (DefaultArchivaConfiguration) lookup( ArchivaConfiguration.class, "default" );
378 archivaConfiguration.reload();
380 assertEquals( System.getProperty( "user.home" ) + "/.m2/archiva.xml",
381 archivaConfiguration.getUserConfigFilename() );
382 assertEquals( System.getProperty( "appserver.base", "${appserver.base}" ) + "/conf/archiva.xml",
383 archivaConfiguration.getAltConfigFilename() );
387 public void testStoreConfigurationFallback()
390 File baseFile = getTestFile( "target/test/test-file.xml" );
392 assertFalse( baseFile.exists() );
394 File userFile = getTestFile( "target/test/test-file-user.xml" );
396 assertFalse( userFile.exists() );
398 baseFile.getParentFile().mkdirs();
399 FileUtils.writeStringToFile( baseFile, "<configuration/>", null );
401 ArchivaConfiguration archivaConfiguration =
402 (ArchivaConfiguration) lookup( ArchivaConfiguration.class, "test-save-user-fallback" );
404 archivaConfiguration.reload();
406 Configuration configuration = new Configuration();
407 configuration.setWebapp( new WebappConfiguration() );
408 configuration.getWebapp().setUi( new UserInterfaceOptions() );
409 configuration.getWebapp().getUi().setAppletFindEnabled( false );
411 archivaConfiguration.save( configuration );
413 assertTrue( "Check file exists", baseFile.exists() );
414 assertFalse( "Check file not created", userFile.exists() );
418 configuration = archivaConfiguration.getConfiguration();
419 assertFalse( "check value", configuration.getWebapp().getUi().isAppletFindEnabled() );
423 public void testStoreConfigurationFailsWhenReadFromBothLocationsNoLists()
426 File baseFile = getTestFile( "target/test/test-file.xml" );
428 assertFalse( baseFile.exists() );
430 File userFile = getTestFile( "target/test/test-file-user.xml" );
432 assertFalse( userFile.exists() );
434 baseFile.getParentFile().mkdirs();
435 FileUtils.writeStringToFile( baseFile, "<configuration/>", null );
437 userFile.getParentFile().mkdirs();
438 FileUtils.writeStringToFile( userFile, "<configuration/>", null );
440 ArchivaConfiguration archivaConfiguration =
441 (ArchivaConfiguration) lookup( ArchivaConfiguration.class, "test-save-user" );
443 archivaConfiguration.reload();
445 Configuration configuration = archivaConfiguration.getConfiguration();
446 assertTrue( "check value", configuration.getWebapp().getUi().isAppletFindEnabled() );
448 configuration.getWebapp().getUi().setAppletFindEnabled( false );
450 archivaConfiguration.save( configuration );
452 assertTrue( "Check file exists", baseFile.exists() );
453 assertEquals( "Check base file is unchanged", "<configuration/>",
454 FileUtils.readFileToString( baseFile, null ) );
455 assertTrue( "Check file exists", userFile.exists() );
456 assertFalse( "Check base file is changed",
457 "<configuration/>".equals( FileUtils.readFileToString( userFile, null ) ) );
460 configuration = archivaConfiguration.getConfiguration();
461 assertFalse( "check value", configuration.getWebapp().getUi().isAppletFindEnabled() );
465 public void testStoreConfigurationFailsWhenReadFromBothLocationsUserHasLists()
468 File baseFile = getTestFile( "target/test/test-file.xml" );
470 assertFalse( baseFile.exists() );
472 File userFile = getTestFile( "target/test/test-file-user.xml" );
474 assertFalse( userFile.exists() );
476 userFile.getParentFile().mkdirs();
477 FileUtils.copyFile( getTestFile( "src/test/conf/conf-user.xml" ), userFile );
479 baseFile.getParentFile().mkdirs();
480 FileUtils.writeStringToFile( baseFile, "<configuration/>", null );
482 ArchivaConfiguration archivaConfiguration =
483 (ArchivaConfiguration) lookup( ArchivaConfiguration.class, "test-save-user" );
485 archivaConfiguration.reload();
487 Configuration configuration = archivaConfiguration.getConfiguration();
488 assertTrue( "check value", configuration.getWebapp().getUi().isShowFindArtifacts() );
490 configuration.getWebapp().getUi().setShowFindArtifacts( false );
492 archivaConfiguration.save( configuration );
494 assertTrue( "Check file exists", baseFile.exists() );
495 assertEquals( "Check base file is unchanged", "<configuration/>",
496 FileUtils.readFileToString( baseFile, null ) );
497 assertTrue( "Check file exists", userFile.exists() );
498 assertFalse( "Check base file is changed",
499 "<configuration/>".equals( FileUtils.readFileToString( userFile, null ) ) );
502 configuration = archivaConfiguration.getConfiguration();
503 assertFalse( "check value", configuration.getWebapp().getUi().isShowFindArtifacts() );
507 public void testStoreConfigurationFailsWhenReadFromBothLocationsAppserverHasLists()
510 File baseFile = getTestFile( "target/test/test-file.xml" );
512 assertFalse( baseFile.exists() );
514 File userFile = getTestFile( "target/test/test-file-user.xml" );
516 assertFalse( userFile.exists() );
518 baseFile.getParentFile().mkdirs();
519 FileUtils.copyFile( getTestFile( "src/test/conf/conf-base.xml" ), baseFile );
521 userFile.getParentFile().mkdirs();
522 FileUtils.writeStringToFile( userFile, "<configuration/>", null );
524 ArchivaConfiguration archivaConfiguration =
525 (ArchivaConfiguration) lookup( ArchivaConfiguration.class, "test-save-user" );
527 archivaConfiguration.reload();
529 Configuration configuration = archivaConfiguration.getConfiguration();
530 assertTrue( "check value", configuration.getWebapp().getUi().isAppletFindEnabled() );
532 configuration.getWebapp().getUi().setAppletFindEnabled( false );
536 archivaConfiguration.save( configuration );
537 fail( "Configuration saving should not succeed if it was loaded from two locations" );
539 catch ( IndeterminateConfigurationException e )
541 // check it was reverted
542 configuration = archivaConfiguration.getConfiguration();
543 assertTrue( "check value", configuration.getWebapp().getUi().isAppletFindEnabled() );
548 public void testLoadConfigurationFromInvalidBothLocationsOnDisk()
551 ArchivaConfiguration archivaConfiguration =
552 (ArchivaConfiguration) lookup( ArchivaConfiguration.class, "test-not-allowed-to-write-to-both" );
553 Configuration config = archivaConfiguration.getConfiguration();
557 archivaConfiguration.save( config );
558 fail( "Should have thrown a RegistryException because the configuration can't be saved." );
560 catch ( RegistryException e )
562 /* expected exception */
567 public void testLoadConfigurationFromInvalidUserLocationOnDisk()
570 File testConfDir = getTestFile( "target/test-appserver-base/conf/" );
571 testConfDir.mkdirs();
573 ArchivaConfiguration archivaConfiguration =
574 (ArchivaConfiguration) lookup( ArchivaConfiguration.class, "test-not-allowed-to-write-to-user" );
575 Configuration config = archivaConfiguration.getConfiguration();
576 archivaConfiguration.save( config );
577 // No Exception == test passes.
578 // Expected Path is: Should not have thrown an exception.
582 public void testConfigurationUpgradeFrom09()
585 ArchivaConfiguration archivaConfiguration =
586 (ArchivaConfiguration) lookup( ArchivaConfiguration.class, "test-upgrade-09" );
588 // we just use the defaults when upgrading from 0.9 at this point.
589 Configuration configuration = archivaConfiguration.getConfiguration();
590 assertConfiguration( configuration );
591 assertEquals( "check network proxies", 0, configuration.getNetworkProxies().size() );
593 ManagedRepositoryConfiguration repository =
594 (ManagedRepositoryConfiguration) configuration.getManagedRepositories().get( 0 );
596 assertEquals( "check managed repositories", "${appserver.base}/data/repositories/internal",
597 repository.getLocation() );
598 assertEquals( "check managed repositories", "Archiva Managed Internal Repository", repository.getName() );
599 assertEquals( "check managed repositories", "internal", repository.getId() );
600 assertEquals( "check managed repositories", "default", repository.getLayout() );
601 assertTrue( "check managed repositories", repository.isScanned() );
605 public void testAutoDetectV1()
608 // Setup the autodetect-v1.xml file in the target directory (so we can save/load it)
609 File userFile = getTestFile( "target/test-autodetect-v1/archiva-user.xml" );
611 assertFalse( userFile.exists() );
613 userFile.getParentFile().mkdirs();
614 FileUtils.copyFile( getTestFile( "src/test/conf/autodetect-v1.xml" ), userFile );
616 // Load the original (unconverted) archiva.xml
617 ArchivaConfiguration archivaConfiguration =
618 (ArchivaConfiguration) lookup( ArchivaConfiguration.class, "test-autodetect-v1" );
620 archivaConfiguration.reload();
622 Configuration configuration = archivaConfiguration.getConfiguration();
623 assertConfiguration( configuration );
624 assertEquals( "check network proxies", 1, configuration.getNetworkProxies().size() );
626 ManagedRepositoryConfiguration repository =
627 (ManagedRepositoryConfiguration) configuration.getManagedRepositories().get( 0 );
629 assertEquals( "check managed repositories", "${appserver.base}/repositories/internal",
630 repository.getLocation() );
631 assertEquals( "check managed repositories", "Archiva Managed Internal Repository", repository.getName() );
632 assertEquals( "check managed repositories", "internal", repository.getId() );
633 assertEquals( "check managed repositories", "default", repository.getLayout() );
634 assertTrue( "check managed repositories", repository.isScanned() );
636 // Test that only 1 set of repositories exist.
637 assertEquals( "check managed repositories size.", 2, configuration.getManagedRepositories().size() );
638 assertEquals( "check remote repositories size.", 2, configuration.getRemoteRepositories().size() );
639 assertEquals( "check v1 repositories size.", 0, configuration.getRepositories().size() );
642 archivaConfiguration.save( configuration );
645 //release( archivaConfiguration );
648 archivaConfiguration =
649 (ArchivaConfiguration) lookup( ArchivaConfiguration.class, "test-autodetect-v1" );
650 configuration = archivaConfiguration.getConfiguration();
652 // Test that only 1 set of repositories exist.
653 assertEquals( "check managed repositories size.", 2, configuration.getManagedRepositories().size() );
654 assertEquals( "check managed repositories size.", 2, configuration.getManagedRepositoriesAsMap().size() );
655 assertEquals( "check remote repositories size.", 2, configuration.getRemoteRepositories().size() );
656 assertEquals( "check remote repositories size.", 2, configuration.getRemoteRepositoriesAsMap().size() );
657 assertEquals( "check v1 repositories size.", 0, configuration.getRepositories().size() );
659 String actualXML = FileUtils.readFileToString( userFile, null );
660 XMLAssert.assertXpathNotExists( "//configuration/repositories/repository", actualXML );
661 XMLAssert.assertXpathNotExists( "//configuration/repositories", actualXML );
665 public void testArchivaV1()
668 ArchivaConfiguration archivaConfiguration =
669 (ArchivaConfiguration) lookup( ArchivaConfiguration.class, "test-archiva-v1" );
671 Configuration configuration = archivaConfiguration.getConfiguration();
672 assertConfiguration( configuration );
673 assertEquals( "check network proxies", 1, configuration.getNetworkProxies().size() );
675 assertEquals( "check managed repositories", 2, configuration.getManagedRepositories().size() );
676 assertEquals( "check v1 repositories size.", 0, configuration.getRepositories().size() );
678 Map<String, ManagedRepositoryConfiguration> map = configuration.getManagedRepositoriesAsMap();
680 ManagedRepositoryConfiguration repository = map.get( "internal" );
681 assertEquals( "check managed repositories", "${appserver.base}/repositories/internal",
682 repository.getLocation() );
683 assertEquals( "check managed repositories", "Archiva Managed Internal Repository", repository.getName() );
684 assertEquals( "check managed repositories", "internal", repository.getId() );
685 assertEquals( "check managed repositories", "default", repository.getLayout() );
686 assertTrue( "check managed repositories", repository.isScanned() );
687 assertFalse( "check managed repositories", repository.isSnapshots() );
689 repository = map.get( "snapshots" );
690 assertEquals( "check managed repositories", "${appserver.base}/repositories/snapshots",
691 repository.getLocation() );
692 assertEquals( "check managed repositories", "Archiva Managed Snapshot Repository", repository.getName() );
693 assertEquals( "check managed repositories", "snapshots", repository.getId() );
694 assertEquals( "check managed repositories", "default", repository.getLayout() );
695 assertFalse( "check managed repositories", repository.isScanned() );
696 assertTrue( "check managed repositories", repository.isSnapshots() );
700 public void testCronExpressionsWithComma()
703 File baseFile = getTestFile( "target/test/test-file.xml" );
705 assertFalse( baseFile.exists() );
707 File userFile = getTestFile( "target/test/test-file-user.xml" );
709 assertFalse( userFile.exists() );
711 baseFile.getParentFile().mkdirs();
712 FileUtils.copyFile( getTestFile( "src/test/conf/escape-cron-expressions.xml" ), baseFile );
714 userFile.getParentFile().mkdirs();
715 FileUtils.writeStringToFile( userFile, "<configuration/>", null );
717 final ArchivaConfiguration archivaConfiguration =
718 lookup( ArchivaConfiguration.class, "test-cron-expressions" );
720 archivaConfiguration.reload();
722 Configuration configuration = archivaConfiguration.getConfiguration();
724 ManagedRepositoryConfiguration repository =
725 (ManagedRepositoryConfiguration) configuration.getManagedRepositories().get( 0 );
727 assertEquals( "check cron expression", "0 0,30 * * * ?", repository.getRefreshCronExpression().trim() );
730 // add a test listener to confirm it doesn't see the escaped format. We don't need to test the number of calls,
731 // etc. as it's done in other tests
732 archivaConfiguration.addListener( new ConfigurationListener()
734 public void configurationEvent( ConfigurationEvent event )
736 assertEquals( ConfigurationEvent.SAVED, event.getType() );
741 archivaConfiguration.save( configuration );
743 configuration = archivaConfiguration.getConfiguration();
745 // test for the escape character '\' showing up on repositories.jsp
746 repository.setRefreshCronExpression( "0 0,20 0 * * ?" );
748 archivaConfiguration.save( configuration );
750 repository = archivaConfiguration.getConfiguration().findManagedRepositoryById( "snapshots" );
752 assertEquals( "check cron expression", "0 0,20 0 * * ?", repository.getRefreshCronExpression() );
756 public void testRemoveLastElements()
759 File baseFile = getTestFile( "target/test/test-file.xml" );
761 assertFalse( baseFile.exists() );
763 File userFile = getTestFile( "target/test/test-file-user.xml" );
765 assertFalse( userFile.exists() );
767 baseFile.getParentFile().mkdirs();
768 FileUtils.copyFile( getTestFile( "src/test/conf/conf-single-list-elements.xml" ), baseFile );
770 userFile.getParentFile().mkdirs();
771 FileUtils.writeStringToFile( userFile, "<configuration/>", null );
773 ArchivaConfiguration archivaConfiguration =
774 (ArchivaConfiguration) lookup( ArchivaConfiguration.class, "test-remove-central" );
776 archivaConfiguration.reload();
778 Configuration configuration = archivaConfiguration.getConfiguration();
780 RepositoryGroupConfiguration repositoryGroup =
781 (RepositoryGroupConfiguration) configuration.getRepositoryGroups().get( 0 );
782 assertNotNull( repositoryGroup );
783 configuration.removeRepositoryGroup( repositoryGroup );
784 assertTrue( configuration.getRepositoryGroups().isEmpty() );
786 RemoteRepositoryConfiguration repository = configuration.getRemoteRepositoriesAsMap().get( "central" );
787 assertNotNull( repository );
788 configuration.removeRemoteRepository( repository );
789 assertTrue( configuration.getRemoteRepositories().isEmpty() );
791 ManagedRepositoryConfiguration managedRepository =
792 configuration.getManagedRepositoriesAsMap().get( "snapshots" );
793 assertNotNull( managedRepository );
794 configuration.removeManagedRepository( managedRepository );
795 assertTrue( configuration.getManagedRepositories().isEmpty() );
797 ProxyConnectorConfiguration proxyConnector =
798 (ProxyConnectorConfiguration) configuration.getProxyConnectors().get( 0 );
799 assertNotNull( proxyConnector );
800 configuration.removeProxyConnector( proxyConnector );
801 assertTrue( configuration.getProxyConnectors().isEmpty() );
803 NetworkProxyConfiguration networkProxy = configuration.getNetworkProxiesAsMap().get( "proxy" );
804 assertNotNull( networkProxy );
805 configuration.removeNetworkProxy( networkProxy );
806 assertTrue( configuration.getNetworkProxies().isEmpty() );
808 LegacyArtifactPath path = (LegacyArtifactPath) configuration.getLegacyArtifactPaths().get( 0 );
809 assertNotNull( path );
810 configuration.removeLegacyArtifactPath( path );
811 assertTrue( configuration.getLegacyArtifactPaths().isEmpty() );
813 RepositoryScanningConfiguration scanning = configuration.getRepositoryScanning();
814 String consumer = (String) scanning.getKnownContentConsumers().get( 0 );
815 assertNotNull( consumer );
816 scanning.removeKnownContentConsumer( consumer );
817 assertTrue( scanning.getKnownContentConsumers().isEmpty() );
818 consumer = (String) scanning.getInvalidContentConsumers().get( 0 );
819 assertNotNull( consumer );
820 scanning.removeInvalidContentConsumer( consumer );
821 assertTrue( scanning.getInvalidContentConsumers().isEmpty() );
823 archivaConfiguration.save( configuration );
825 archivaConfiguration = (ArchivaConfiguration) lookup( ArchivaConfiguration.class, "test-read-saved" );
826 configuration = archivaConfiguration.getConfiguration();
827 assertNull( configuration.getRemoteRepositoriesAsMap().get( "central" ) );
828 assertTrue( configuration.getRepositoryGroups().isEmpty() );
829 assertNull( configuration.getManagedRepositoriesAsMap().get( "snapshots" ) );
830 assertTrue( configuration.getProxyConnectors().isEmpty() );
831 assertNull( configuration.getNetworkProxiesAsMap().get( "proxy" ) );
832 assertTrue( configuration.getLegacyArtifactPaths().isEmpty() );
833 scanning = configuration.getRepositoryScanning();
834 assertTrue( scanning.getKnownContentConsumers().isEmpty() );
835 assertTrue( scanning.getInvalidContentConsumers().isEmpty() );
839 * [MRM-582] Remote Repositories with empty <username> and <password> fields shouldn't be created in configuration.
842 public void testGetConfigurationFixEmptyRemoteRepoUsernamePassword()
845 ArchivaConfiguration archivaConfiguration =
846 (ArchivaConfiguration) lookup( ArchivaConfiguration.class, "test-configuration" );
848 archivaConfiguration.reload();
849 Configuration configuration = archivaConfiguration.getConfiguration();
850 assertConfiguration( configuration );
851 assertEquals( "check remote repositories", 2, configuration.getRemoteRepositories().size() );
853 RemoteRepositoryConfiguration repository =
854 (RemoteRepositoryConfiguration) configuration.getRemoteRepositoriesAsMap().get(
855 "maven2-repository.dev.java.net" );
857 assertEquals( "remote repository.url", "https://maven2-repository.dev.java.net/nonav/repository",
858 repository.getUrl() );
859 assertEquals( "remote repository.name", "Java.net Repository for Maven 2", repository.getName() );
860 assertEquals( "remote repository.id", "maven2-repository.dev.java.net", repository.getId() );
861 assertEquals( "remote repository.layout", "default", repository.getLayout() );
862 assertNull( "remote repository.username == null", repository.getUsername() );
863 assertNull( "remote repository.password == null", repository.getPassword() );