/** * Copyright (c) 2008-2011 Sonatype, Inc. * All rights reserved. Includes the third-party code listed at http://www.sonatype.com/products/nexus/attributions. * * This program is free software: you can redistribute it and/or modify it only under the terms of the GNU Affero General * Public License Version 3 as published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License Version 3 * for more details. * * You should have received a copy of the GNU Affero General Public License Version 3 along with this program. If not, see * http://www.gnu.org/licenses. * * Sonatype Nexus (TM) Open Source Version is available from Sonatype, Inc. Sonatype and Sonatype Nexus are trademarks of * Sonatype, Inc. Apache Maven is a trademark of the Apache Foundation. M2Eclipse is a trademark of the Eclipse Foundation. * All other trademarks are the property of their respective owners. */ package org.sonatype.nexus.proxy.repository; import junit.framework.Assert; import org.codehaus.plexus.util.xml.Xpp3Dom; import org.sonatype.nexus.configuration.model.CLocalStorage; import org.sonatype.nexus.configuration.model.CRepository; import org.sonatype.nexus.configuration.model.DefaultCRepository; import org.sonatype.nexus.proxy.AbstractNexusTestCase; import org.sonatype.nexus.proxy.maven.RepositoryPolicy; import org.sonatype.nexus.proxy.maven.maven2.M2RepositoryConfiguration; public class DefaultRepositoryConfiguratorTest extends AbstractNexusTestCase { public void testExpireNFCOnUpdate() throws Exception { Repository oldRepository = this.lookup( Repository.class, "maven2" ); CRepository cRepo = new DefaultCRepository(); cRepo.setId( "test-repo" ); cRepo.setLocalStatus( LocalStatus.IN_SERVICE.toString() ); cRepo.setNotFoundCacheTTL( 1 ); cRepo.setLocalStorage( new CLocalStorage() ); cRepo.getLocalStorage().setProvider( "file" ); cRepo.setProviderRole( Repository.class.getName() ); cRepo.setProviderHint( "maven2" ); Xpp3Dom ex = new Xpp3Dom( "externalConfiguration" ); cRepo.setExternalConfiguration( ex ); M2RepositoryConfiguration extConf = new M2RepositoryConfiguration( ex ); extConf.setRepositoryPolicy( RepositoryPolicy.RELEASE ); oldRepository.configure( cRepo ); oldRepository.getNotFoundCache().put( "test-path", "test-object" ); // make sure the item is in NFC Assert.assertTrue( oldRepository.getNotFoundCache().contains( "test-path" ) ); // change config cRepo.setNotFoundCacheTTL( 2 ); oldRepository.configure( cRepo ); // make sure the item is NOT in NFC Assert.assertFalse( oldRepository.getNotFoundCache().contains( "test-path" ) ); } public void testExpireNFCOnUpdateWithNFCDisabled() throws Exception { Repository oldRepository = this.lookup( Repository.class, "maven2" ); CRepository cRepo = new DefaultCRepository(); cRepo.setId( "test-repo" ); cRepo.setLocalStatus( LocalStatus.IN_SERVICE.toString() ); cRepo.setNotFoundCacheTTL( 1 ); cRepo.setLocalStorage( new CLocalStorage() ); cRepo.getLocalStorage().setProvider( "file" ); Xpp3Dom ex = new Xpp3Dom( "externalConfiguration" ); cRepo.setExternalConfiguration( ex ); M2RepositoryConfiguration extConf = new M2RepositoryConfiguration( ex ); extConf.setRepositoryPolicy( RepositoryPolicy.RELEASE ); cRepo.setProviderRole( Repository.class.getName() ); cRepo.setProviderHint( "maven2" ); oldRepository.configure( cRepo ); oldRepository.getNotFoundCache().put( "test-path", "test-object" ); // make sure the item is in NFC // (cache is disabled ) // NOTE: we don't care if it in the cache right now, because the retrieve item does not return it. // Assert.assertFalse( oldRepository.getNotFoundCache().contains( "test-path" ) ); oldRepository.configure( cRepo ); // make sure the item is NOT in NFC Assert.assertFalse( oldRepository.getNotFoundCache().contains( "test-path" ) ); } public void testDoNotStoreDefaultLocalStorage() throws Exception { Repository repository = this.lookup( Repository.class, "maven2" ); CRepository cRepo = new DefaultCRepository(); cRepo.setId( "test-repo" ); cRepo.setLocalStatus( LocalStatus.IN_SERVICE.toString() ); cRepo.setNotFoundCacheTTL( 1 ); cRepo.setLocalStorage( new CLocalStorage() ); cRepo.getLocalStorage().setProvider( "file" ); cRepo.setProviderRole( Repository.class.getName() ); cRepo.setProviderHint( "maven2" ); Xpp3Dom ex = new Xpp3Dom( "externalConfiguration" ); cRepo.setExternalConfiguration( ex ); M2RepositoryConfiguration extConf = new M2RepositoryConfiguration( ex ); extConf.setRepositoryPolicy( RepositoryPolicy.RELEASE ); repository.configure( cRepo ); Assert.assertNotNull( repository.getLocalUrl() ); Assert.assertNull( cRepo.getLocalStorage().getUrl() ); } }