use JUnit 4 API

git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1136302 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Brett Porter 2011-06-16 07:27:51 +00:00
parent af8d62f38f
commit 9ae8d172b2
9 changed files with 78 additions and 78 deletions

View File

@ -19,11 +19,9 @@ package org.apache.maven.archiva.proxy;
* 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;
@ -47,7 +45,6 @@ import org.springframework.context.ApplicationContext;
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;
@ -59,6 +56,9 @@ import java.util.Calendar;
import java.util.Collection;
import java.util.Date;
import java.util.Locale;
import javax.inject.Inject;
import static org.junit.Assert.*;
/**
* AbstractProxyTestCase
@ -66,11 +66,9 @@ import java.util.Locale;
* @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;
@ -134,21 +132,20 @@ public abstract class AbstractProxyTestCase
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() );
@ -158,17 +155,14 @@ public abstract class AbstractProxyTestCase
// 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() );
@ -177,22 +171,21 @@ public abstract class AbstractProxyTestCase
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 );
@ -204,13 +197,7 @@ public abstract class AbstractProxyTestCase
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()
@ -222,8 +209,8 @@ public abstract class AbstractProxyTestCase
{
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 )
@ -325,7 +312,7 @@ public abstract class AbstractProxyTestCase
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();
@ -419,8 +406,8 @@ public abstract class AbstractProxyTestCase
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;
}
@ -502,10 +489,10 @@ public abstract class AbstractProxyTestCase
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 )
@ -616,7 +603,7 @@ public abstract class AbstractProxyTestCase
protected void setManagedNewerThanRemote( File managedFile, File remoteFile )
{
setManagedNewerThanRemote(managedFile, remoteFile, 55000);
setManagedNewerThanRemote( managedFile, remoteFile, 55000 );
}
protected void setManagedNewerThanRemote( File managedFile, File remoteFile, long time )
@ -631,7 +618,7 @@ public abstract class AbstractProxyTestCase
protected void setManagedOlderThanRemote( File managedFile, File remoteFile )
{
setManagedOlderThanRemote(managedFile, remoteFile, 55000 );
setManagedOlderThanRemote( managedFile, remoteFile, 55000 );
}
protected void setManagedOlderThanRemote( File managedFile, File remoteFile, long time )
@ -657,9 +644,9 @@ public abstract class AbstractProxyTestCase
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() );
}
@ -670,9 +657,9 @@ public abstract class AbstractProxyTestCase
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() );
}

View File

@ -29,8 +29,11 @@ import org.apache.maven.archiva.policies.urlcache.UrlFailureCache;
import org.apache.maven.wagon.ResourceDoesNotExistException;
import org.junit.Test;
import javax.inject.Inject;
import java.io.File;
import javax.inject.Inject;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
/**
* CacheFailuresTransferTest

View File

@ -30,6 +30,9 @@ import org.junit.Test;
import java.io.File;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
/**
* ChecksumTransferTest
*
@ -57,7 +60,7 @@ public class ChecksumTransferTest
File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
assertNull(downloadedFile);
assertNull( downloadedFile );
}
@Test
@ -430,16 +433,16 @@ public class ChecksumTransferTest
// 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();
@ -477,7 +480,7 @@ public class ChecksumTransferTest
// 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 );
@ -504,7 +507,7 @@ public class ChecksumTransferTest
// 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 );
@ -532,7 +535,7 @@ public class ChecksumTransferTest
// 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 );

View File

@ -34,6 +34,8 @@ import org.junit.Test;
import java.io.File;
import static org.junit.Assert.*;
/**
* ErrorHandlingTest
*

View File

@ -19,7 +19,6 @@ package org.apache.maven.archiva.proxy;
* under the License.
*/
import junit.framework.TestCase;
import org.apache.commons.io.FileUtils;
import org.apache.maven.archiva.configuration.ArchivaConfiguration;
import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
@ -53,15 +52,16 @@ import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import static org.junit.Assert.*;
/**
* Integration test for connecting over a HTTP proxy.
*
* @version $Id: ManagedDefaultTransferTest.java 677852 2008-07-18 08:16:24Z brett $
*/
@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 class HttpProxyTransferTest
extends TestCase
{
private static final String PROXY_ID = "proxy";
@ -86,8 +86,6 @@ public class HttpProxyTransferTest
public void setUp()
throws Exception
{
super.setUp();
proxyHandler = applicationContext.getBean( "repositoryProxyConnectors#test", RepositoryProxyConnectors.class );
config = applicationContext.getBean( "archivaConfiguration#mock", ArchivaConfiguration.class );
@ -97,7 +95,7 @@ public class HttpProxyTransferTest
config.getConfiguration().getProxyConnectors().clear();
// Setup source repository (using default layout)
String repoPath = "target/test-repository/managed/" + getName();
String repoPath = "target/test-repository/managed/" + getClass().getSimpleName();
File destRepoDir = new File( repoPath );
@ -116,8 +114,8 @@ public class HttpProxyTransferTest
repo.setLocation( repoPath );
repo.setLayout( "default" );
ManagedRepositoryContent repoContent =
applicationContext.getBean( "managedRepositoryContent#default", ManagedRepositoryContent.class );
ManagedRepositoryContent repoContent = applicationContext.getBean( "managedRepositoryContent#default",
ManagedRepositoryContent.class );
repoContent.setRepository( repo );
managedDefaultRepository = repoContent;
@ -167,8 +165,6 @@ public class HttpProxyTransferTest
public void tearDown()
throws Exception
{
super.tearDown();
server.stop();
}

View File

@ -31,6 +31,8 @@ import org.junit.Test;
import java.io.File;
import static org.junit.Assert.*;
/**
* ManagedDefaultTransferTest
*

View File

@ -28,6 +28,8 @@ import org.junit.Test;
import java.io.File;
import static org.junit.Assert.assertTrue;
/**
* ManagedLegacyTransferTest
*

View File

@ -41,12 +41,14 @@ import org.custommonkey.xmlunit.Diff;
import org.junit.Before;
import org.junit.Test;
import javax.inject.Inject;
import javax.inject.Named;
import java.io.File;
import java.io.StringWriter;
import java.util.ArrayList;
import java.util.Arrays;
import javax.inject.Inject;
import javax.inject.Named;
import static org.junit.Assert.*;
/**
* MetadataTransferTest - Tests the various fetching / merging concepts surrounding the maven-metadata.xml files

View File

@ -28,6 +28,9 @@ import org.junit.Test;
import java.io.File;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
/**
* SnapshotTransferTest
*