* under the License.
*/
-import junit.framework.TestCase;
import net.sf.ehcache.CacheManager;
import org.apache.archiva.common.plexusbridge.PlexusSisuBridge;
import org.apache.commons.lang.ArrayUtils;
-import org.apache.commons.lang.StringUtils;
import org.apache.maven.archiva.configuration.ArchivaConfiguration;
import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
import org.apache.maven.archiva.configuration.ProxyConnectorConfiguration;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
-import javax.inject.Inject;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.util.Collection;
import java.util.Date;
import java.util.Locale;
+import javax.inject.Inject;
+
+import static org.junit.Assert.*;
/**
* AbstractProxyTestCase
* @version $Id$
*/
@RunWith( SpringJUnit4ClassRunner.class )
-@ContextConfiguration( locations = { "classpath*:/META-INF/spring-context.xml", "classpath:/spring-context.xml" } )
+@ContextConfiguration( locations = {"classpath*:/META-INF/spring-context.xml", "classpath:/spring-context.xml"} )
public abstract class AbstractProxyTestCase
- extends TestCase
{
-
@Inject
protected ApplicationContext applicationContext;
public void setUp()
throws Exception
{
- super.setUp();
-
- config =
- (MockConfiguration) applicationContext.getBean( "archivaConfiguration#mock", ArchivaConfiguration.class );
+ config = (MockConfiguration) applicationContext.getBean( "archivaConfiguration#mock",
+ ArchivaConfiguration.class );
config.getConfiguration().setManagedRepositories( new ArrayList<ManagedRepositoryConfiguration>() );
config.getConfiguration().setRemoteRepositories( new ArrayList<RemoteRepositoryConfiguration>() );
config.getConfiguration().setProxyConnectors( new ArrayList<ProxyConnectorConfiguration>() );
// Setup source repository (using default layout)
- String repoPath = "target/test-repository/managed/" + getName();
+ String name = getClass().getSimpleName();
+ String repoPath = "target/test-repository/managed/" + name;
File repoLocation = new File( repoPath );
- managedDefaultRepository =
- createRepository( ID_DEFAULT_MANAGED, "Default Managed Repository", repoPath, "default" );
+ managedDefaultRepository = createRepository( ID_DEFAULT_MANAGED, "Default Managed Repository", repoPath,
+ "default" );
managedDefaultDir = new File( managedDefaultRepository.getRepoRoot() );
// Setup source repository (using legacy layout)
repoLocation = new File( REPOPATH_LEGACY_MANAGED_TARGET );
- if (repoLocation.exists())
+ if ( repoLocation.exists() )
{
FileUtils.deleteDirectory( repoLocation );
}
copyDirectoryStructure( new File( REPOPATH_LEGACY_MANAGED ), repoLocation );
- managedLegacyRepository =
- createRepository( ID_LEGACY_MANAGED, "Legacy Managed Repository", REPOPATH_LEGACY_MANAGED_TARGET,
- "legacy" );
-
-
+ managedLegacyRepository = createRepository( ID_LEGACY_MANAGED, "Legacy Managed Repository",
+ REPOPATH_LEGACY_MANAGED_TARGET, "legacy" );
managedLegacyDir = new File( managedLegacyRepository.getRepoRoot() );
config.getConfiguration().addManagedRepository( repoConfig );
// Setup target (proxied to) repository.
- saveRemoteRepositoryConfig( ID_PROXIED1, "Proxied Repository 1",
- new File( REPOPATH_PROXIED1 ).toURL().toExternalForm(), "default" );
+ saveRemoteRepositoryConfig( ID_PROXIED1, "Proxied Repository 1", new File(
+ REPOPATH_PROXIED1 ).toURL().toExternalForm(), "default" );
// Setup target (proxied to) repository.
- saveRemoteRepositoryConfig( ID_PROXIED2, "Proxied Repository 2",
- new File( REPOPATH_PROXIED2 ).toURL().toExternalForm(), "default" );
+ saveRemoteRepositoryConfig( ID_PROXIED2, "Proxied Repository 2", new File(
+ REPOPATH_PROXIED2 ).toURL().toExternalForm(), "default" );
// Setup target (proxied to) repository using legacy layout.
- saveRemoteRepositoryConfig( ID_LEGACY_PROXIED, "Proxied Legacy Repository",
- new File( REPOPATH_PROXIED_LEGACY ).toURL().toExternalForm(), "legacy" );
+ saveRemoteRepositoryConfig( ID_LEGACY_PROXIED, "Proxied Legacy Repository", new File(
+ REPOPATH_PROXIED_LEGACY ).toURL().toExternalForm(), "legacy" );
// Setup the proxy handler.
//proxyHandler = applicationContext.getBean (RepositoryProxyConnectors) lookup( RepositoryProxyConnectors.class.getName() );
- proxyHandler =
- applicationContext.getBean( "repositoryProxyConnectors#test", RepositoryProxyConnectors.class );
+ proxyHandler = applicationContext.getBean( "repositoryProxyConnectors#test", RepositoryProxyConnectors.class );
// Setup the wagon mock.
wagonMockControl = MockControl.createNiceControl( Wagon.class );
CacheManager.getInstance().clearAll();
- log.info( "\n.\\ " + getName() + "() \\._________________________________________\n" );
- }
-
- @Override
- public String getName()
- {
- return StringUtils.substringAfterLast( getClass().getName(), "." );
+ log.info( "\n.\\ " + name + "() \\._________________________________________\n" );
}
protected static final ArgumentsMatcher customWagonGetIfNewerMatcher = new ArgumentsMatcher()
{
return false;
}
- return MockControl.ARRAY_MATCHER.matches( ArrayUtils.remove( expected, 1 ),
- ArrayUtils.remove( actual, 1 ) );
+ return MockControl.ARRAY_MATCHER.matches( ArrayUtils.remove( expected, 1 ), ArrayUtils.remove( actual,
+ 1 ) );
}
public String toString( Object[] arguments )
return;
}
- Collection<File> tmpFiles = org.apache.commons.io.FileUtils.listFiles( workingDir, new String[]{ "tmp" }, false );
+ Collection<File> tmpFiles = org.apache.commons.io.FileUtils.listFiles( workingDir, new String[]{"tmp"}, false );
if ( !tmpFiles.isEmpty() )
{
StringBuffer emsg = new StringBuffer();
repo.setLocation( path );
repo.setLayout( layout );
- ManagedRepositoryContent repoContent =
- applicationContext.getBean( "managedRepositoryContent#" + layout, ManagedRepositoryContent.class );
+ ManagedRepositoryContent repoContent = applicationContext.getBean( "managedRepositoryContent#" + layout,
+ ManagedRepositoryContent.class );
repoContent.setRepository( repo );
return repoContent;
}
config.triggerChange( prefix + ".policies.checksum", connectorConfig.getPolicy( "checksum", "" ) );
config.triggerChange( prefix + ".policies.snapshots", connectorConfig.getPolicy( "snapshots", "" ) );
config.triggerChange( prefix + ".policies.cache-failures", connectorConfig.getPolicy( "cache-failures", "" ) );
- config.triggerChange( prefix + ".policies.propagate-errors",
- connectorConfig.getPolicy( "propagate-errors", "" ) );
- config.triggerChange( prefix + ".policies.propagate-errors-on-update",
- connectorConfig.getPolicy( "propagate-errors-on-update", "" ) );
+ config.triggerChange( prefix + ".policies.propagate-errors", connectorConfig.getPolicy( "propagate-errors",
+ "" ) );
+ config.triggerChange( prefix + ".policies.propagate-errors-on-update", connectorConfig.getPolicy(
+ "propagate-errors-on-update", "" ) );
}
protected void saveManagedRepositoryConfig( String id, String name, String path, String layout )
protected void setManagedNewerThanRemote( File managedFile, File remoteFile )
{
- setManagedNewerThanRemote(managedFile, remoteFile, 55000);
+ setManagedNewerThanRemote( managedFile, remoteFile, 55000 );
}
protected void setManagedNewerThanRemote( File managedFile, File remoteFile, long time )
protected void setManagedOlderThanRemote( File managedFile, File remoteFile )
{
- setManagedOlderThanRemote(managedFile, remoteFile, 55000 );
+ setManagedOlderThanRemote( managedFile, remoteFile, 55000 );
}
protected void setManagedOlderThanRemote( File managedFile, File remoteFile, long time )
String managedLegacyPath = managedLegacyDir.getCanonicalPath();
String testFile = file.getCanonicalPath();
- assertTrue(
- "Unit Test Failure: File <" + testFile + "> should be have been defined within the legacy managed path of <"
- + managedLegacyPath + ">", testFile.startsWith( managedLegacyPath ) );
+ assertTrue( "Unit Test Failure: File <" + testFile +
+ "> should be have been defined within the legacy managed path of <" + managedLegacyPath + ">",
+ testFile.startsWith( managedLegacyPath ) );
assertFalse( "File < " + testFile + "> should not exist in managed legacy repository.", file.exists() );
}
String managedDefaultPath = managedDefaultDir.getCanonicalPath();
String testFile = file.getCanonicalPath();
- assertTrue( "Unit Test Failure: File <" + testFile
- + "> should be have been defined within the managed default path of <" + managedDefaultPath
- + ">", testFile.startsWith( managedDefaultPath ) );
+ assertTrue( "Unit Test Failure: File <" + testFile +
+ "> should be have been defined within the managed default path of <" + managedDefaultPath + ">",
+ testFile.startsWith( managedDefaultPath ) );
assertFalse( "File < " + testFile + "> should not exist in managed default repository.", file.exists() );
}
import java.io.File;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNull;
+
/**
* ChecksumTransferTest
*
// Configure Connector (usually done within archiva.xml configuration)
saveConnector( ID_DEFAULT_MANAGED, "proxied1", ChecksumPolicy.IGNORE, ReleasesPolicy.ALWAYS,
SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, true );
-
+
File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
-
- assertNull(downloadedFile);
+
+ assertNull( downloadedFile );
}
@Test
// Configure Connector (usually done within archiva.xml configuration)
saveConnector( ID_DEFAULT_MANAGED, "badproxied", ChecksumPolicy.IGNORE, ReleasesPolicy.ALWAYS,
- SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
+ SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
wagonMock.get( path, new File( expectedFile.getAbsolutePath() + ".tmp" ) );
- wagonMockControl.setMatcher(customWagonGetMatcher);
+ wagonMockControl.setMatcher( customWagonGetMatcher );
wagonMockControl.setVoidCallable();
wagonMock.get( path + ".sha1", new File( expectedFile.getAbsolutePath() + ".sha1.tmp" ) );
- wagonMockControl.setMatcher(customWagonGetMatcher);
+ wagonMockControl.setMatcher( customWagonGetMatcher );
wagonMockControl.setVoidCallable();
wagonMock.get( path + ".md5", new File( expectedFile.getAbsolutePath() + ".md5.tmp" ) );
- wagonMockControl.setMatcher(customWagonGetMatcher);
+ wagonMockControl.setMatcher( customWagonGetMatcher );
wagonMockControl.setThrowable( new ResourceDoesNotExistException( "Resource does not exist." ) );
wagonMockControl.replay();
File expectedFile = new File( managedDefaultDir, path );
File remoteFile = new File( REPOPATH_PROXIED1, path );
-
+
setManagedOlderThanRemote( expectedFile, remoteFile );
ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path );
// Configure Connector (usually done within archiva.xml configuration)
saveConnector( ID_DEFAULT_MANAGED, "proxied1", ChecksumPolicy.IGNORE, ReleasesPolicy.ALWAYS,
- SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO , false );
+ SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
File remoteFile = new File( REPOPATH_PROXIED1, path );
setManagedOlderThanRemote( expectedFile, remoteFile );
-
+
ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path );
// Configure Connector (usually done within archiva.xml configuration)
saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FAIL, ReleasesPolicy.ALWAYS,
- SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO , false );
+ SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
assertNoTempFiles( expectedFile );
// There are no hashcodes on the proxy side to download.
// The FAIL policy will delete the checksums as bad.
-
+
assertChecksums( expectedFile, "invalid checksum file", "invalid checksum file" );
}
File expectedFile = new File( managedDefaultDir, path );
File remoteFile = new File( REPOPATH_PROXIED1, path );
-
+
setManagedOlderThanRemote( expectedFile, remoteFile );
ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path );
// Configure Connector (usually done within archiva.xml configuration)
saveConnector( ID_DEFAULT_MANAGED, "proxied1", ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
- SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO , false );
+ SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );