aboutsummaryrefslogtreecommitdiffstats
path: root/maven-repository-converter
diff options
context:
space:
mode:
authorBrett Porter <brett@apache.org>2006-01-27 05:51:51 +0000
committerBrett Porter <brett@apache.org>2006-01-27 05:51:51 +0000
commit9ecb2cca1784749fef4988b8d2004eeec37e003e (patch)
treefcdb79804f74126029f218d41b3463203df83bda /maven-repository-converter
parent1be6c22bce7ad84e6e5181ecbf4267abf7beaaa5 (diff)
downloadarchiva-9ecb2cca1784749fef4988b8d2004eeec37e003e.tar.gz
archiva-9ecb2cca1784749fef4988b8d2004eeec37e003e.zip
[MRM-9] more tests
git-svn-id: https://svn.apache.org/repos/asf/maven/repository-manager/trunk@372754 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'maven-repository-converter')
-rw-r--r--maven-repository-converter/src/main/java/org/apache/maven/repository/converter/DefaultRepositoryConverter.java24
-rw-r--r--maven-repository-converter/src/main/resources/org/apache/maven/repository/converter/DefaultRepositoryConverter.properties3
-rw-r--r--maven-repository-converter/src/test/java/org/apache/maven/repository/converter/RepositoryConverterTest.java39
-rw-r--r--maven-repository-converter/src/test/source-repository/test/jars/modified-artifact-1.0.0.jar1
-rw-r--r--maven-repository-converter/src/test/source-repository/test/poms/modified-artifact-1.0.0.pom22
-rw-r--r--maven-repository-converter/src/test/target-repository/test/modified-artifact/1.0.0/modified-artifact-1.0.0.jar1
-rw-r--r--maven-repository-converter/src/test/target-repository/test/modified-artifact/1.0.0/modified-artifact-1.0.0.pom22
7 files changed, 102 insertions, 10 deletions
diff --git a/maven-repository-converter/src/main/java/org/apache/maven/repository/converter/DefaultRepositoryConverter.java b/maven-repository-converter/src/main/java/org/apache/maven/repository/converter/DefaultRepositoryConverter.java
index 194c27492..9b431735f 100644
--- a/maven-repository-converter/src/main/java/org/apache/maven/repository/converter/DefaultRepositoryConverter.java
+++ b/maven-repository-converter/src/main/java/org/apache/maven/repository/converter/DefaultRepositoryConverter.java
@@ -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;
}
}
}
diff --git a/maven-repository-converter/src/main/resources/org/apache/maven/repository/converter/DefaultRepositoryConverter.properties b/maven-repository-converter/src/main/resources/org/apache/maven/repository/converter/DefaultRepositoryConverter.properties
index 6330e524c..90cce8614 100644
--- a/maven-repository-converter/src/main/resources/org/apache/maven/repository/converter/DefaultRepositoryConverter.properties
+++ b/maven-repository-converter/src/main/resources/org/apache/maven/repository/converter/DefaultRepositoryConverter.properties
@@ -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
diff --git a/maven-repository-converter/src/test/java/org/apache/maven/repository/converter/RepositoryConverterTest.java b/maven-repository-converter/src/test/java/org/apache/maven/repository/converter/RepositoryConverterTest.java
index 1f67de682..a4b278bee 100644
--- a/maven-repository-converter/src/test/java/org/apache/maven/repository/converter/RepositoryConverterTest.java
+++ b/maven-repository-converter/src/test/java/org/apache/maven/repository/converter/RepositoryConverterTest.java
@@ -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
index 000000000..2e0996000
--- /dev/null
+++ b/maven-repository-converter/src/test/source-repository/test/jars/modified-artifact-1.0.0.jar
@@ -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
index 000000000..fcfdaacb4
--- /dev/null
+++ b/maven-repository-converter/src/test/source-repository/test/poms/modified-artifact-1.0.0.pom
@@ -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
index 000000000..27597bc21
--- /dev/null
+++ b/maven-repository-converter/src/test/target-repository/test/modified-artifact/1.0.0/modified-artifact-1.0.0.jar
@@ -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
index 000000000..fcfdaacb4
--- /dev/null
+++ b/maven-repository-converter/src/test/target-repository/test/modified-artifact/1.0.0/modified-artifact-1.0.0.pom
@@ -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>