]> source.dussan.org Git - archiva.git/commitdiff
[MRM-9] more tests
authorBrett Porter <brett@apache.org>
Fri, 27 Jan 2006 05:51:51 +0000 (05:51 +0000)
committerBrett Porter <brett@apache.org>
Fri, 27 Jan 2006 05:51:51 +0000 (05:51 +0000)
git-svn-id: https://svn.apache.org/repos/asf/maven/repository-manager/trunk@372754 13f79535-47bb-0310-9956-ffa450edef68

maven-repository-converter/src/main/java/org/apache/maven/repository/converter/DefaultRepositoryConverter.java
maven-repository-converter/src/main/resources/org/apache/maven/repository/converter/DefaultRepositoryConverter.properties
maven-repository-converter/src/test/java/org/apache/maven/repository/converter/RepositoryConverterTest.java
maven-repository-converter/src/test/source-repository/test/jars/modified-artifact-1.0.0.jar [new file with mode: 0644]
maven-repository-converter/src/test/source-repository/test/poms/modified-artifact-1.0.0.pom [new file with mode: 0644]
maven-repository-converter/src/test/target-repository/test/modified-artifact/1.0.0/modified-artifact-1.0.0.jar [new file with mode: 0644]
maven-repository-converter/src/test/target-repository/test/modified-artifact/1.0.0/modified-artifact-1.0.0.pom [new file with mode: 0644]

index 194c27492f6c4bfacaf0b121480bc0d7831f3788..9b431735fa38ebe0fd39e7068a9d16936d9f3631 100644 (file)
@@ -339,19 +339,27 @@ public class DefaultRepositoryConverter
             if ( !force && targetFile.exists() )
             {
                 matching = FileUtils.contentEquals( sourceFile, targetFile );
+                if ( !matching )
+                {
+                    reporter.addFailure( artifact, getI18NString( "failure.target.already.exists" ) );
+                    result = false;
+                }
             }
-            if ( force || !matching )
+            if ( result )
             {
-                if ( testChecksums( artifact, sourceFile, reporter ) )
+                if ( force || !matching )
                 {
-                    if ( !dryrun )
+                    if ( testChecksums( artifact, sourceFile, reporter ) )
                     {
-                        FileUtils.copyFile( sourceFile, targetFile );
+                        if ( !dryrun )
+                        {
+                            FileUtils.copyFile( sourceFile, targetFile );
+                        }
+                    }
+                    else
+                    {
+                        result = false;
                     }
-                }
-                else
-                {
-                    result = false;
                 }
             }
         }
index 6330e524ca0880f371244a12e8a7a01ad60005bf..90cce86143c12c44fc1eea6177ad8df62bab7fae 100644 (file)
@@ -16,4 +16,5 @@
 
 failure.incorrect.md5=The MD5 checksum value was incorrect.
 failure.incorrect.sha1=The SHA1 checksum value was incorrect.
-warning.missing.pom=The artifact had no POM in the source repository
\ No newline at end of file
+warning.missing.pom=The artifact had no POM in the source repository.
+failure.target.already.exists=The artifact could not be converted because it already exists.
\ No newline at end of file
index 1f67de682bde43861e508000c606a3c323501e53..a4b278beee3d777e5704e4e430a032a7ff15f2ac 100644 (file)
@@ -482,11 +482,43 @@ public class RepositoryConverterTest
     }
 
     public void testModifedArtifactFails()
+        throws InterruptedException, RepositoryConversionException, IOException
     {
         // test that it fails when the source artifact has changed and is different to the existing artifact in the
         // target repository
 
-        // TODO
+        Artifact artifact = createArtifact( "test", "modified-artifact", "1.0.0" );
+        Artifact pomArtifact = createPomArtifact( artifact );
+
+        File sourceFile = new File( sourceRepository.getBasedir(), sourceRepository.pathOf( artifact ) );
+        File sourcePomFile = new File( sourceRepository.getBasedir(), sourceRepository.pathOf( pomArtifact ) );
+        File targetFile = new File( targetRepository.getBasedir(), targetRepository.pathOf( artifact ) );
+        File targetPomFile = new File( targetRepository.getBasedir(), targetRepository.pathOf( pomArtifact ) );
+
+        assertTrue( "Check target file exists", targetFile.exists() );
+        assertTrue( "Check target POM exists", targetPomFile.exists() );
+
+        sourceFile.setLastModified( System.currentTimeMillis() );
+        sourcePomFile.setLastModified( System.currentTimeMillis() );
+
+        long origTime = targetFile.lastModified();
+        long origPomTime = targetPomFile.lastModified();
+
+        // Need to guarantee last modified is not equal
+        Thread.sleep( SLEEP_MILLIS );
+
+        repositoryConverter.convert( artifact, targetRepository, reporter );
+        checkFailure();
+        assertEquals( "Check failure message", getI18nString( "failure.target.already.exists" ),
+                      getFailure().getReason() );
+
+        assertEquals( "Check unmodified", origTime, targetFile.lastModified() );
+        assertEquals( "Check unmodified", origPomTime, targetPomFile.lastModified() );
+
+        ArtifactRepositoryMetadata metadata = new ArtifactRepositoryMetadata( artifact );
+        File metadataFile =
+            new File( targetRepository.getBasedir(), targetRepository.pathOfRemoteRepositoryMetadata( metadata ) );
+        assertFalse( "Check metadata not created", metadataFile.exists() );
     }
 
     public void testForcedUnmodifiedArtifact()
@@ -521,6 +553,11 @@ public class RepositoryConverterTest
 
         assertFalse( "Check modified", origTime == targetFile.lastModified() );
         assertFalse( "Check modified", origPomTime == targetPomFile.lastModified() );
+
+        ArtifactRepositoryMetadata metadata = new ArtifactRepositoryMetadata( artifact );
+        File metadataFile =
+            new File( targetRepository.getBasedir(), targetRepository.pathOfRemoteRepositoryMetadata( metadata ) );
+        assertTrue( "Check metadata created", metadataFile.exists() );
     }
 
     public void testDryRunSuccess()
diff --git a/maven-repository-converter/src/test/source-repository/test/jars/modified-artifact-1.0.0.jar b/maven-repository-converter/src/test/source-repository/test/jars/modified-artifact-1.0.0.jar
new file mode 100644 (file)
index 0000000..2e09960
--- /dev/null
@@ -0,0 +1 @@
+modified
diff --git a/maven-repository-converter/src/test/source-repository/test/poms/modified-artifact-1.0.0.pom b/maven-repository-converter/src/test/source-repository/test/poms/modified-artifact-1.0.0.pom
new file mode 100644 (file)
index 0000000..fcfdaac
--- /dev/null
@@ -0,0 +1,22 @@
+<!--
+  ~ Copyright 2005-2006 The Apache Software Foundation.
+  ~
+  ~ Licensed under the Apache License, Version 2.0 (the "License");
+  ~ you may not use this file except in compliance with the License.
+  ~ You may obtain a copy of the License at
+  ~
+  ~      http://www.apache.org/licenses/LICENSE-2.0
+  ~
+  ~ Unless required by applicable law or agreed to in writing, software
+  ~ distributed under the License is distributed on an "AS IS" BASIS,
+  ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  ~ See the License for the specific language governing permissions and
+  ~ limitations under the License.
+  -->
+
+<project>
+  <modelVersion>4.0.0</modelVersion>
+  <artifactId>modified-artifact</artifactId>
+  <groupId>test</groupId>
+  <currentVersion>1.0.0</currentVersion>
+</project>
diff --git a/maven-repository-converter/src/test/target-repository/test/modified-artifact/1.0.0/modified-artifact-1.0.0.jar b/maven-repository-converter/src/test/target-repository/test/modified-artifact/1.0.0/modified-artifact-1.0.0.jar
new file mode 100644 (file)
index 0000000..27597bc
--- /dev/null
@@ -0,0 +1 @@
+unmodified
diff --git a/maven-repository-converter/src/test/target-repository/test/modified-artifact/1.0.0/modified-artifact-1.0.0.pom b/maven-repository-converter/src/test/target-repository/test/modified-artifact/1.0.0/modified-artifact-1.0.0.pom
new file mode 100644 (file)
index 0000000..fcfdaac
--- /dev/null
@@ -0,0 +1,22 @@
+<!--
+  ~ Copyright 2005-2006 The Apache Software Foundation.
+  ~
+  ~ Licensed under the Apache License, Version 2.0 (the "License");
+  ~ you may not use this file except in compliance with the License.
+  ~ You may obtain a copy of the License at
+  ~
+  ~      http://www.apache.org/licenses/LICENSE-2.0
+  ~
+  ~ Unless required by applicable law or agreed to in writing, software
+  ~ distributed under the License is distributed on an "AS IS" BASIS,
+  ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  ~ See the License for the specific language governing permissions and
+  ~ limitations under the License.
+  -->
+
+<project>
+  <modelVersion>4.0.0</modelVersion>
+  <artifactId>modified-artifact</artifactId>
+  <groupId>test</groupId>
+  <currentVersion>1.0.0</currentVersion>
+</project>