]> source.dussan.org Git - archiva.git/commitdiff
use JUnit 4 API
authorBrett Porter <brett@apache.org>
Thu, 16 Jun 2011 07:27:51 +0000 (07:27 +0000)
committerBrett Porter <brett@apache.org>
Thu, 16 Jun 2011 07:27:51 +0000 (07:27 +0000)
git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1136302 13f79535-47bb-0310-9956-ffa450edef68

archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/maven/archiva/proxy/AbstractProxyTestCase.java
archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/maven/archiva/proxy/CacheFailuresTransferTest.java
archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/maven/archiva/proxy/ChecksumTransferTest.java
archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/maven/archiva/proxy/ErrorHandlingTest.java
archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/maven/archiva/proxy/HttpProxyTransferTest.java
archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/maven/archiva/proxy/ManagedDefaultTransferTest.java
archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/maven/archiva/proxy/ManagedLegacyTransferTest.java
archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/maven/archiva/proxy/MetadataTransferTest.java
archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/maven/archiva/proxy/SnapshotTransferTest.java

index 574358476fd79fa1d392aa6a19cc579476ce621e..fc6ed6a24680f7961a87b68f1b2cdc6375876d4f 100644 (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() );
     }
index fd951e44e4d5803677f2046373c7bd9aa687c7b5..d6ddb995a53d9b3baa66a5f13697ed45945c0e25 100644 (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
index 12554ea3db1f020ec0e3e29cbec233768f791381..8befed7a94e5ffd0fbb415aa00a04db471bc25b4 100644 (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
  *
@@ -54,10 +57,10 @@ public class 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
@@ -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();
 
@@ -470,14 +473,14 @@ public class ChecksumTransferTest
 
         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 );
 
@@ -499,12 +502,12 @@ public class ChecksumTransferTest
         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 );
 
@@ -512,7 +515,7 @@ public class ChecksumTransferTest
         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" );
     }
 
@@ -525,14 +528,14 @@ public class ChecksumTransferTest
 
         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 );
 
index 2c236a0c19da285f094cc59c99635d6d7d0013e9..32f552965134530e6d6a2a444ffd7aa599fb3b8b 100644 (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();
     }
 
index d0166d1e8ca4e49c872f8bcf4c25aa110990f5ff..e021d96b2b50c51604803acea29b2a1ec71ce148 100644 (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
index f1998971d3a20f0730d73844a6145eb158538f3c..a9ed4a122e37e8d1670996e7bd1a7278e17ac808 100644 (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 
  *