- added unit test for updating metadata - added unit test sample artifacts - applied the submitted patch Submitted by: Gwen Harold Autencio git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@824220 13f79535-47bb-0310-9956-ffa450edef68tags/archiva-1.3
@@ -19,14 +19,15 @@ package org.apache.maven.archiva.repository.scanner.functors; | |||
* under the License. | |||
*/ | |||
import java.io.File; | |||
import java.util.List; | |||
import org.apache.commons.collections.Predicate; | |||
import org.apache.commons.io.FilenameUtils; | |||
import org.apache.maven.archiva.common.utils.BaseFile; | |||
import org.apache.maven.archiva.consumers.RepositoryContentConsumer; | |||
import org.codehaus.plexus.util.SelectorUtils; | |||
import java.util.List; | |||
/** | |||
* ConsumerWantsFilePredicate | |||
* | |||
@@ -62,8 +63,19 @@ public class ConsumerWantsFilePredicate | |||
// Timestamp finished points to the last successful scan, not this current one. | |||
if ( basefile.lastModified() < changesSince ) | |||
{ | |||
// Skip file as no change has occured. | |||
satisfies = false; | |||
// MRM-1246 | |||
// compares the lastModified of the version-level (basefile) and the project-level (parent) metadata | |||
File parent = basefile.getParentFile().getParentFile(); | |||
if ( parent.lastModified() > basefile.lastModified() ) | |||
{ | |||
satisfies = true; | |||
} | |||
else | |||
{ | |||
// Skip file as no change has occurred. | |||
satisfies = false; | |||
} | |||
} | |||
} | |||
} |
@@ -130,6 +130,30 @@ public class MetadataToolsTest | |||
// } | |||
// } | |||
public void testUpdateProjectNonExistingVersion() | |||
throws Exception | |||
{ | |||
ManagedRepositoryContent testRepo = createTestRepoContent(); | |||
ProjectReference reference = new ProjectReference(); | |||
reference.setGroupId( "org.apache.archiva.metadata.tests" ); | |||
reference.setArtifactId( "missing_artifact" ); | |||
prepTestRepo( testRepo, reference ); | |||
// check metadata prior to update -- should contain the non-existing artifact version | |||
assertProjectMetadata( testRepo, reference, "missing_artifact", new String[] { | |||
"1.0-SNAPSHOT", | |||
"1.1-SNAPSHOT", | |||
"1.2-SNAPSHOT" }, "1.2-SNAPSHOT" , null ); | |||
tools.updateMetadata( testRepo, reference ); | |||
// metadata should not contain the non-existing artifact version -- 1.1-SNAPSHOT | |||
assertProjectMetadata( testRepo, reference, "missing_artifact", new String[] { | |||
"1.0-SNAPSHOT", | |||
"1.2-SNAPSHOT" }, "1.2-SNAPSHOT" , null ); | |||
} | |||
public void testUpdateProjectMissingMultipleVersions() | |||
throws Exception | |||
{ | |||
@@ -422,6 +446,40 @@ public class MetadataToolsTest | |||
assertMetadata( buf.toString(), testRepo, reference ); | |||
} | |||
private void assertProjectMetadata( ManagedRepositoryContent testRepo, ProjectReference reference, String artifactId, | |||
String[] expectedVersions, String latestVersion, String releaseVersion ) | |||
throws Exception | |||
{ | |||
StringBuilder buf = new StringBuilder(); | |||
buf.append( "<metadata>\n" ); | |||
buf.append( " <groupId>" ).append( reference.getGroupId() ).append( "</groupId>\n" ); | |||
buf.append( " <artifactId>" ).append( reference.getArtifactId() ).append( "</artifactId>\n" ); | |||
if ( expectedVersions != null ) | |||
{ | |||
buf.append( " <versioning>\n" ); | |||
if ( latestVersion != null ) | |||
{ | |||
buf.append( " <latest>" ).append( latestVersion ).append( "</latest>\n" ); | |||
} | |||
if ( releaseVersion != null ) | |||
{ | |||
buf.append( " <release>" ).append( releaseVersion ).append( "</release>\n" ); | |||
} | |||
buf.append( " <versions>\n" ); | |||
for ( int i = 0; i < expectedVersions.length; i++ ) | |||
{ | |||
buf.append( " <version>" ).append( expectedVersions[i] ).append( "</version>\n" ); | |||
} | |||
buf.append( " </versions>\n" ); | |||
buf.append( " </versioning>\n" ); | |||
} | |||
buf.append( "</metadata>" ); | |||
assertMetadata( buf.toString(), testRepo, reference ); | |||
} | |||
private void assertUpdatedReleaseVersionMetadata( String artifactId, String version ) | |||
throws Exception | |||
{ |
@@ -140,7 +140,7 @@ public class RepositoryScannerTest | |||
assertNotNull( "Stats should not be null.", stats ); | |||
assertEquals( "Stats.totalFileCount", 4, stats.getTotalFileCount() ); | |||
assertEquals( "Stats.newFileCount", 3, stats.getNewFileCount() ); | |||
assertEquals( "Processed Count", 2, consumer.getProcessCount() ); | |||
assertEquals( "Processed Count", 3, consumer.getProcessCount() ); | |||
assertEquals( "Processed Count (of invalid items)", 1, badconsumer.getProcessCount() ); | |||
} | |||
@@ -0,0 +1,13 @@ | |||
<?xml version="1.0" encoding="UTF-8"?> | |||
<metadata> | |||
<groupId>org.apache.archiva.metadata.tests</groupId> | |||
<artifactId>missing_artifact</artifactId> | |||
<version>1.0-SNAPSHOT</version> | |||
<versioning> | |||
<snapshot> | |||
<buildNumber>1</buildNumber> | |||
<timestamp>20091007.132409</timestamp> | |||
</snapshot> | |||
</versioning> | |||
</metadata> |
@@ -0,0 +1,6 @@ | |||
<?xml version="1.0" encoding="UTF-8"?><project> | |||
<modelVersion>4.0.0</modelVersion> | |||
<groupId>org.apache.archiva.metadata.tests</groupId> | |||
<artifactId>missing_artifact</artifactId> | |||
<version>1.0-SNAPSHOT</version> | |||
</project> |
@@ -0,0 +1,11 @@ | |||
<?xml version="1.0" encoding="UTF-8"?><metadata> | |||
<groupId>org.apache.archiva.metadata.tests</groupId> | |||
<artifactId>missing_artifact</artifactId> | |||
<version>1.2-SNAPSHOT</version> | |||
<versioning> | |||
<snapshot> | |||
<timestamp>20091011.133751</timestamp> | |||
<buildNumber>1</buildNumber> | |||
</snapshot> | |||
</versioning> | |||
</metadata> |
@@ -0,0 +1,6 @@ | |||
<?xml version="1.0" encoding="UTF-8"?><project> | |||
<modelVersion>4.0.0</modelVersion> | |||
<groupId>org.apache.archiva.metadata.tests</groupId> | |||
<artifactId>missing_artifact</artifactId> | |||
<version>1.2-SNAPSHOT</version> | |||
</project> |
@@ -0,0 +1,12 @@ | |||
<?xml version="1.0" encoding="UTF-8"?><metadata> | |||
<groupId>org.apache.archiva.metadata.tests</groupId> | |||
<artifactId>missing_artifact</artifactId> | |||
<versioning> | |||
<latest>1.2-SNAPSHOT</latest> | |||
<versions> | |||
<version>1.0-SNAPSHOT</version> | |||
<version>1.1-SNAPSHOT</version> | |||
<version>1.2-SNAPSHOT</version> | |||
</versions> | |||
</versioning> | |||
</metadata> |