]> source.dussan.org Git - archiva.git/commitdiff
test case improvements
authorBrett Porter <brett@apache.org>
Wed, 15 Dec 2010 03:30:38 +0000 (03:30 +0000)
committerBrett Porter <brett@apache.org>
Wed, 15 Dec 2010 03:30:38 +0000 (03:30 +0000)
Merged from: r1049384-1049390

git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1049406 13f79535-47bb-0310-9956-ffa450edef68

archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/maven/archiva/consumers/core/ArtifactMissingChecksumsConsumerTest.java
archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/maven/archiva/consumers/core/repository/DaysOldRepositoryPurgeTest.java
archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/maven/archiva/consumers/core/repository/RepositoryPurgeConsumerTest.java
archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/resources/test-repo/org/apache/maven/plugins/maven-install-plugin/2.2-SNAPSHOT/maven-install-plugin-2.2-20070510.010101-4.jar [new file with mode: 0644]
archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/resources/test-repo/org/apache/maven/plugins/maven-install-plugin/2.2-SNAPSHOT/maven-install-plugin-2.2-20070510.010101-4.jar.md5 [new file with mode: 0644]
archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/resources/test-repo/org/apache/maven/plugins/maven-install-plugin/2.2-SNAPSHOT/maven-install-plugin-2.2-20070510.010101-4.jar.sha1 [new file with mode: 0644]
archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/resources/test-repo/org/apache/maven/plugins/maven-install-plugin/2.2-SNAPSHOT/maven-install-plugin-2.2-20070510.010101-4.pom [new file with mode: 0644]
archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/resources/test-repo/org/apache/maven/plugins/maven-install-plugin/2.2-SNAPSHOT/maven-install-plugin-2.2-20070510.010101-4.pom.md5 [new file with mode: 0644]
archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/resources/test-repo/org/apache/maven/plugins/maven-install-plugin/2.2-SNAPSHOT/maven-install-plugin-2.2-20070510.010101-4.pom.sha1 [new file with mode: 0644]

index 13bc4ac6b175e1e1eb2d8a5f92f9fd2afb89e901..686cd6a167f18d26cbeec6894a454daab716cd95 100644 (file)
@@ -1,12 +1,13 @@
 package org.apache.maven.archiva.consumers.core;
 
-import java.io.File;
-import java.util.Calendar;
-
 import org.apache.archiva.checksum.ChecksumAlgorithm;
 import org.apache.archiva.checksum.ChecksummedFile;
+import org.apache.commons.io.FileUtils;
 import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
 
+import java.io.File;
+import java.util.Calendar;
+
 /*
  * Licensed to the Apache Software Foundation (ASF) under one
  * or more contributor license agreements.  See the NOTICE file
@@ -54,6 +55,9 @@ public class ArtifactMissingChecksumsConsumerTest
         File sha1File = new File( repoConfig.getLocation(), path + ".sha1" );
         File md5File = new File( repoConfig.getLocation(), path + ".md5" );
 
+        sha1File.delete();
+        md5File.delete();
+
         assertFalse( sha1File.exists() );
         assertFalse( md5File.exists() );
 
@@ -68,6 +72,11 @@ public class ArtifactMissingChecksumsConsumerTest
     public void testExistingIncorrectChecksums()
         throws Exception
     {
+        File newLocation = getTestFile( "target/test-repo" );
+        FileUtils.deleteDirectory( newLocation );
+        FileUtils.copyDirectory( new File( repoConfig.getLocation() ), newLocation );
+        repoConfig.setLocation( newLocation.getAbsolutePath() );
+
         String path = "/incorrect-checksums/1.0/incorrect-checksums-1.0.jar";
 
         File sha1File = new File( repoConfig.getLocation(), path + ".sha1" );
index 83344821c6084618cd2e346d30c8bd822e74b435..78dcb1bf96a82922eb5c13898165612d4acff693 100644 (file)
@@ -19,33 +19,18 @@ package org.apache.maven.archiva.consumers.core.repository;
  * under the License.
  */
 
+import org.apache.commons.lang.time.DateUtils;
+
 import java.io.File;
-import java.io.IOException;
+import java.text.SimpleDateFormat;
 import java.util.Calendar;
 import java.util.Collections;
 
-import org.apache.commons.lang.time.DateUtils;
-
 /**
  */
 public class DaysOldRepositoryPurgeTest
     extends AbstractRepositoryPurgeTest
 {
-    private static final String[] extensions =
-        new String[] { "-5.jar", "-5.pom", "-6.jar", "-6.pom", "-7.jar", "-7.pom" };
-
-    private String year;
-
-    private String mon;
-
-    private String day;
-
-    private String hr;
-
-    private String min;
-
-    private String sec;
-
     private void setLastModified( String dirPath, long lastModified )
     {
         File dir = new File( dirPath );
@@ -76,10 +61,14 @@ public class DaysOldRepositoryPurgeTest
                                  "2.2-SNAPSHOT", "maven-install-plugin-2.2-SNAPSHOT.jar" );
         listener.deleteArtifact( getRepository().getId(), "org.apache.maven.plugins", "maven-install-plugin",
                                  "2.2-SNAPSHOT", "maven-install-plugin-2.2-SNAPSHOT.pom" );
+        listener.deleteArtifact( getRepository().getId(), "org.apache.maven.plugins", "maven-install-plugin",
+                                 "2.2-20061118.060401-2", "maven-install-plugin-2.2-20061118.060401-2.jar" );
+        listener.deleteArtifact( getRepository().getId(), "org.apache.maven.plugins", "maven-install-plugin",
+                                 "2.2-20061118.060401-2", "maven-install-plugin-2.2-20061118.060401-2.pom" );
         listenerControl.replay();
-        
+
         repoPurge.process( PATH_TO_BY_DAYS_OLD_ARTIFACT );
-        
+
         listenerControl.verify();
 
         assertDeleted( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-SNAPSHOT.jar" );
@@ -97,12 +86,19 @@ public class DaysOldRepositoryPurgeTest
         assertExists( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20070513.034619-5.pom.md5" );
         assertExists( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20070513.034619-5.pom.sha1" );
 
-        assertExists( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20061118.060401-2.jar" );
-        assertExists( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20061118.060401-2.jar.md5" );
-        assertExists( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20061118.060401-2.jar.sha1" );
-        assertExists( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20061118.060401-2.pom" );
-        assertExists( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20061118.060401-2.pom.md5" );
-        assertExists( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20061118.060401-2.pom.sha1" );
+        assertExists( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20070510.010101-4.jar" );
+        assertExists( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20070510.010101-4.jar.md5" );
+        assertExists( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20070510.010101-4.jar.sha1" );
+        assertExists( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20070510.010101-4.pom" );
+        assertExists( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20070510.010101-4.pom.md5" );
+        assertExists( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20070510.010101-4.pom.sha1" );
+
+        assertDeleted( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20061118.060401-2.jar" );
+        assertDeleted( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20061118.060401-2.jar.md5" );
+        assertDeleted( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20061118.060401-2.jar.sha1" );
+        assertDeleted( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20061118.060401-2.pom" );
+        assertDeleted( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20061118.060401-2.pom.md5" );
+        assertDeleted( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20061118.060401-2.pom.sha1" );
     }
 
     public void testOrderOfDeletion()
@@ -110,7 +106,7 @@ public class DaysOldRepositoryPurgeTest
     {
         repoPurge =
             new DaysOldRepositoryPurge( getRepository(), getRepoConfiguration( TEST_REPO_ID, TEST_REPO_NAME ).getDaysOlder(),
-                                        getRepoConfiguration( TEST_REPO_ID, TEST_REPO_NAME ).getRetentionCount(), 
+                                        getRepoConfiguration( TEST_REPO_ID, TEST_REPO_NAME ).getRetentionCount(),
                                         Collections.singletonList( listener ) );
 
         String repoRoot = prepareTestRepos();
@@ -125,7 +121,7 @@ public class DaysOldRepositoryPurgeTest
         listener.deleteArtifact( getRepository().getId(), "org.apache.maven.plugins", "maven-assembly-plugin",
                                  "1.1.2-20070427.065136-1", "maven-assembly-plugin-1.1.2-20070427.065136-1.pom" );
         listenerControl.replay();
-        
+
         repoPurge.process( PATH_TO_TEST_ORDER_OF_DELETION );
 
         listenerControl.verify();
@@ -169,47 +165,21 @@ public class DaysOldRepositoryPurgeTest
         Calendar currentDate = Calendar.getInstance( DateUtils.UTC_TIME_ZONE );
         setLastModified( versionRoot, currentDate.getTimeInMillis() );
 
-        year = String.valueOf( currentDate.get( Calendar.YEAR ) );
-        mon = String.valueOf( currentDate.get( Calendar.MONTH ) + 1 );
-        day = String.valueOf( currentDate.get( Calendar.DATE ) );
-        hr = String.valueOf( currentDate.get( Calendar.HOUR ) );
-        min = String.valueOf( currentDate.get( Calendar.MINUTE ) );
-        sec = String.valueOf( currentDate.get( Calendar.SECOND ) );
-
-        if ( mon.length() == 1 )
-        {
-            mon = "0" + mon;
-        }
-
-        if ( day.length() == 1 )
-        {
-            day = "0" + day;
-        }
-
-        if ( hr.length() == 1 )
-        {
-            hr = "0" + hr;
-        }
-
-        if ( min.length() == 1 )
-        {
-            min = "0" + min;
-        }
+        String timestamp = new SimpleDateFormat( "yyyyMMdd.HHmmss" ).format( currentDate.getTime() );
 
-        if ( sec.length() == 1 )
+        for ( int i = 5; i <= 7; i++ )
         {
-            sec = "0" + sec;
+            new File( versionRoot, "/plexus-utils-1.4.3-" + timestamp + "-" + i + ".jar" ).createNewFile();
+            new File( versionRoot, "/plexus-utils-1.4.3-" + timestamp + "-" + i + ".pom" ).createNewFile();
         }
 
-        createFiles( versionRoot );
-
         // test listeners for the correct artifacts
         listener.deleteArtifact( getRepository().getId(), "org.codehaus.plexus", "plexus-utils",
                                  "1.4.3-20070113.163208-4", "plexus-utils-1.4.3-20070113.163208-4.jar" );
         listener.deleteArtifact( getRepository().getId(), "org.codehaus.plexus", "plexus-utils",
                                  "1.4.3-20070113.163208-4", "plexus-utils-1.4.3-20070113.163208-4.pom" );
         listenerControl.replay();
-        
+
         repoPurge.process( PATH_TO_BY_DAYS_OLD_METADATA_DRIVEN_ARTIFACT );
 
         listenerControl.verify();
@@ -225,20 +195,10 @@ public class DaysOldRepositoryPurgeTest
         assertExists( versionRoot + "/plexus-utils-1.4.3-SNAPSHOT.jar" );
         assertExists( versionRoot + "/plexus-utils-1.4.3-SNAPSHOT.pom" );
 
-        for ( String extension : extensions )
-        {
-            assertExists( versionRoot + "/plexus-utils-1.4.3-" + year + mon + day + "." + hr + min + sec + extension );
-        }
-    }
-
-    private void createFiles( String versionRoot )
-        throws IOException
-    {
-        for ( String extension : extensions )
+        for ( int i = 5; i <= 7; i++ )
         {
-            File file =
-                new File( versionRoot, "/plexus-utils-1.4.3-" + year + mon + day + "." + hr + min + sec + extension );
-            file.createNewFile();
+            assertExists( versionRoot + "/plexus-utils-1.4.3-" + timestamp + "-" + i + ".jar" );
+            assertExists( versionRoot + "/plexus-utils-1.4.3-" + timestamp + "-" + i + ".pom" );
         }
     }
 
index be2a3fac031b6ed8e119da2a72464c5849fea64a..4dbf95da6ea23b15b1bf22e20fe00c3c9b3479c3 100644 (file)
@@ -19,8 +19,6 @@ package org.apache.maven.archiva.consumers.core.repository;
  * under the License.
  */
 
-import java.io.File;
-
 import org.apache.commons.io.FileUtils;
 import org.apache.maven.archiva.common.utils.BaseFile;
 import org.apache.maven.archiva.configuration.ArchivaConfiguration;
@@ -32,6 +30,8 @@ import org.apache.maven.archiva.consumers.KnownRepositoryContentConsumer;
 import org.apache.maven.archiva.consumers.functors.ConsumerWantsFilePredicate;
 import org.custommonkey.xmlunit.XMLAssert;
 
+import java.io.File;
+
 /**
  */
 public class RepositoryPurgeConsumerTest
@@ -182,13 +182,20 @@ public class RepositoryPurgeConsumerTest
         assertExists( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20070513.034619-5.pom" );
         assertExists( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20070513.034619-5.pom.md5" );
         assertExists( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20070513.034619-5.pom.sha1" );
-
-        assertExists( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20061118.060401-2.jar" );
-        assertExists( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20061118.060401-2.jar.md5" );
-        assertExists( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20061118.060401-2.jar.sha1" );
-        assertExists( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20061118.060401-2.pom" );
-        assertExists( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20061118.060401-2.pom.md5" );
-        assertExists( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20061118.060401-2.pom.sha1" );
+        
+        assertExists( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20070510.010101-4.jar" );
+        assertExists( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20070510.010101-4.jar.md5" );
+        assertExists( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20070510.010101-4.jar.sha1" );
+        assertExists( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20070510.010101-4.pom" );
+        assertExists( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20070510.010101-4.pom.md5" );
+        assertExists( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20070510.010101-4.pom.sha1" );
+
+        assertDeleted( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20061118.060401-2.jar" );
+        assertDeleted( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20061118.060401-2.jar.md5" );
+        assertDeleted( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20061118.060401-2.jar.sha1" );
+        assertDeleted( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20061118.060401-2.pom" );
+        assertDeleted( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20061118.060401-2.pom.md5" );
+        assertDeleted( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20061118.060401-2.pom.sha1" );
     }
 
     /**
diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/resources/test-repo/org/apache/maven/plugins/maven-install-plugin/2.2-SNAPSHOT/maven-install-plugin-2.2-20070510.010101-4.jar b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/resources/test-repo/org/apache/maven/plugins/maven-install-plugin/2.2-SNAPSHOT/maven-install-plugin-2.2-20070510.010101-4.jar
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/resources/test-repo/org/apache/maven/plugins/maven-install-plugin/2.2-SNAPSHOT/maven-install-plugin-2.2-20070510.010101-4.jar.md5 b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/resources/test-repo/org/apache/maven/plugins/maven-install-plugin/2.2-SNAPSHOT/maven-install-plugin-2.2-20070510.010101-4.jar.md5
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/resources/test-repo/org/apache/maven/plugins/maven-install-plugin/2.2-SNAPSHOT/maven-install-plugin-2.2-20070510.010101-4.jar.sha1 b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/resources/test-repo/org/apache/maven/plugins/maven-install-plugin/2.2-SNAPSHOT/maven-install-plugin-2.2-20070510.010101-4.jar.sha1
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/resources/test-repo/org/apache/maven/plugins/maven-install-plugin/2.2-SNAPSHOT/maven-install-plugin-2.2-20070510.010101-4.pom b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/resources/test-repo/org/apache/maven/plugins/maven-install-plugin/2.2-SNAPSHOT/maven-install-plugin-2.2-20070510.010101-4.pom
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/resources/test-repo/org/apache/maven/plugins/maven-install-plugin/2.2-SNAPSHOT/maven-install-plugin-2.2-20070510.010101-4.pom.md5 b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/resources/test-repo/org/apache/maven/plugins/maven-install-plugin/2.2-SNAPSHOT/maven-install-plugin-2.2-20070510.010101-4.pom.md5
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/resources/test-repo/org/apache/maven/plugins/maven-install-plugin/2.2-SNAPSHOT/maven-install-plugin-2.2-20070510.010101-4.pom.sha1 b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/resources/test-repo/org/apache/maven/plugins/maven-install-plugin/2.2-SNAPSHOT/maven-install-plugin-2.2-20070510.010101-4.pom.sha1
new file mode 100644 (file)
index 0000000..e69de29