update test so that it works with future releases on Maven APIs. Test was passing by a side effect of file timestamps that should not have been considered.

git-svn-id: https://svn.apache.org/repos/asf/maven/archiva/trunk@499784 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Brett Porter 2007-01-25 13:34:17 +00:00
parent f1b23c1c34
commit 5fa30be9cf
2 changed files with 47 additions and 10 deletions

View File

@ -28,6 +28,7 @@ import org.apache.maven.artifact.factory.ArtifactFactory;
import org.apache.maven.artifact.repository.ArtifactRepository; import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.repository.ArtifactRepositoryPolicy; import org.apache.maven.artifact.repository.ArtifactRepositoryPolicy;
import org.apache.maven.artifact.repository.metadata.Metadata; import org.apache.maven.artifact.repository.metadata.Metadata;
import org.apache.maven.artifact.repository.metadata.Versioning;
import org.apache.maven.artifact.repository.metadata.io.xpp3.MetadataXpp3Reader; import org.apache.maven.artifact.repository.metadata.io.xpp3.MetadataXpp3Reader;
import org.apache.maven.artifact.repository.metadata.io.xpp3.MetadataXpp3Writer; import org.apache.maven.artifact.repository.metadata.io.xpp3.MetadataXpp3Writer;
import org.apache.maven.model.DistributionManagement; import org.apache.maven.model.DistributionManagement;
@ -54,11 +55,15 @@ import java.io.FileWriter;
import java.io.IOException; import java.io.IOException;
import java.io.Reader; import java.io.Reader;
import java.security.NoSuchAlgorithmException; import java.security.NoSuchAlgorithmException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date; import java.util.Date;
import java.util.Iterator; import java.util.Iterator;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.List; import java.util.List;
import java.util.Locale;
import java.util.Map; import java.util.Map;
import java.util.TimeZone;
/** /**
* An implementation of the proxy handler. This class is not thread safe (the class itself is, but the wagons it uses * An implementation of the proxy handler. This class is not thread safe (the class itself is, but the wagons it uses
@ -97,6 +102,8 @@ public class DefaultProxyRequestHandler
*/ */
private Map/*<String,Wagon>*/ wagons; private Map/*<String,Wagon>*/ wagons;
private static final TimeZone UTC_TIMEZONE = TimeZone.getTimeZone( "UTC" );
public File get( String path, List proxiedRepositories, ArtifactRepository managedRepository ) public File get( String path, List proxiedRepositories, ArtifactRepository managedRepository )
throws ProxyException, ResourceDoesNotExistException throws ProxyException, ResourceDoesNotExistException
{ {
@ -423,6 +430,9 @@ public class DefaultProxyRequestHandler
if ( metadata != null ) if ( metadata != null )
{ {
setLastUpdatedIfEmpty( newMetadata, metadataFile );
setLastUpdatedIfEmpty( metadata, target );
changed = metadata.merge( newMetadata ); changed = metadata.merge( newMetadata );
} }
else else
@ -466,6 +476,20 @@ public class DefaultProxyRequestHandler
} }
} }
private void setLastUpdatedIfEmpty( Metadata metadata, File metadataFile )
{
if ( metadata.getVersioning() == null )
{
metadata.setVersioning( new Versioning() );
}
if ( metadata.getVersioning().getLastUpdated() == null )
{
DateFormat fmt = new SimpleDateFormat( "yyyyMMddHHmmss", Locale.US );
fmt.setTimeZone( UTC_TIMEZONE );
metadata.getVersioning().setLastUpdated( fmt.format( new Date( metadataFile.lastModified() ) ) );
}
}
private void getFileFromRepository( String path, ProxiedArtifactRepository repository, String repositoryCachePath, private void getFileFromRepository( String path, ProxiedArtifactRepository repository, String repositoryCachePath,
ProxyInfo httpProxy, File target, ArtifactRepositoryPolicy policy, ProxyInfo httpProxy, File target, ArtifactRepositoryPolicy policy,
boolean force ) boolean force )

View File

@ -39,6 +39,7 @@ import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.io.StringWriter; import java.io.StringWriter;
import java.net.MalformedURLException; import java.net.MalformedURLException;
import java.text.DateFormat;
import java.text.ParseException; import java.text.ParseException;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.ArrayList; import java.util.ArrayList;
@ -49,6 +50,7 @@ import java.util.Date;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Locale; import java.util.Locale;
import java.util.TimeZone;
/** /**
* Test the proxy handler. * Test the proxy handler.
@ -88,6 +90,8 @@ public class ProxyRequestHandlerTest
private static final ArtifactRepositoryPolicy ALWAYS_UPDATE_POLICY = private static final ArtifactRepositoryPolicy ALWAYS_UPDATE_POLICY =
new ArtifactRepositoryPolicy( true, ArtifactRepositoryPolicy.UPDATE_POLICY_ALWAYS, null ); new ArtifactRepositoryPolicy( true, ArtifactRepositoryPolicy.UPDATE_POLICY_ALWAYS, null );
private static final TimeZone UTC_TIMEZONE = TimeZone.getTimeZone( "UTC" );
protected void setUp() protected void setUp()
throws Exception throws Exception
{ {
@ -1010,7 +1014,7 @@ public class ProxyRequestHandlerTest
assertTrue( "Check file created", file.exists() ); assertTrue( "Check file created", file.exists() );
String expectedContents = getExpectedMetadata( "get-merged-metadata", getVersioning( String expectedContents = getExpectedMetadata( "get-merged-metadata", getVersioning(
Arrays.asList( new String[]{"0.9", "1.0", "2.0", "3.0", "5.0", "4.0"} ) ) ); Arrays.asList( new String[]{"0.9", "1.0", "2.0", "3.0", "5.0", "4.0"} ), file ) );
assertEquals( "Check content matches", expectedContents, FileUtils.readFileToString( file, null ) ); assertEquals( "Check content matches", expectedContents, FileUtils.readFileToString( file, null ) );
} }
@ -1099,8 +1103,8 @@ public class ProxyRequestHandlerTest
assertEquals( "Check file matches", expectedFile, file ); assertEquals( "Check file matches", expectedFile, file );
assertTrue( "Check file created", file.exists() ); assertTrue( "Check file created", file.exists() );
String expectedContents = String expectedContents = getExpectedMetadata( "get-updated-metadata", getVersioning(
getExpectedMetadata( "get-updated-metadata", getVersioning( Arrays.asList( new String[]{"1.0", "2.0"} ) ) ); Arrays.asList( new String[]{"1.0", "2.0"} ), file ) );
assertEquals( "Check content matches", expectedContents, FileUtils.readFileToString( file, null ) ); assertEquals( "Check content matches", expectedContents, FileUtils.readFileToString( file, null ) );
assertFalse( "Check content doesn't match proxy version", assertFalse( "Check content doesn't match proxy version",
@ -1126,7 +1130,7 @@ public class ProxyRequestHandlerTest
assertTrue( "Check file created", file.exists() ); assertTrue( "Check file created", file.exists() );
String expectedContents = String expectedContents =
getExpectedMetadata( "get-updated-metadata", "1.0-SNAPSHOT", getVersioning( "20050831.111213", 2 ) ); getExpectedMetadata( "get-updated-metadata", "1.0-SNAPSHOT", getVersioning( "20050831.111213", 2, file ) );
assertEquals( "Check content matches", expectedContents, FileUtils.readFileToString( file, null ) ); assertEquals( "Check content matches", expectedContents, FileUtils.readFileToString( file, null ) );
assertFalse( "Check content doesn't match proxy version", assertFalse( "Check content doesn't match proxy version",
@ -1173,8 +1177,8 @@ public class ProxyRequestHandlerTest
assertEquals( "Check file matches", expectedFile, file ); assertEquals( "Check file matches", expectedFile, file );
assertTrue( "Check file created", file.exists() ); assertTrue( "Check file created", file.exists() );
String expectedContents = String expectedContents = getExpectedMetadata( "get-updated-metadata", getVersioning(
getExpectedMetadata( "get-updated-metadata", getVersioning( Arrays.asList( new String[]{"1.0", "2.0"} ) ) ); Arrays.asList( new String[]{"1.0", "2.0"} ), file ) );
assertEquals( "Check content matches", expectedContents, FileUtils.readFileToString( file, null ) ); assertEquals( "Check content matches", expectedContents, FileUtils.readFileToString( file, null ) );
assertFalse( "Check content doesn't match old version", assertFalse( "Check content doesn't match old version",
unexpectedContents.equals( FileUtils.readFileToString( file, null ) ) ); unexpectedContents.equals( FileUtils.readFileToString( file, null ) ) );
@ -1194,8 +1198,8 @@ public class ProxyRequestHandlerTest
assertEquals( "Check file matches", expectedFile, file ); assertEquals( "Check file matches", expectedFile, file );
assertTrue( "Check file created", file.exists() ); assertTrue( "Check file created", file.exists() );
String expectedContents = String expectedContents = getExpectedMetadata( "get-updated-metadata", getVersioning(
getExpectedMetadata( "get-updated-metadata", getVersioning( Arrays.asList( new String[]{"1.0", "2.0"} ) ) ); Arrays.asList( new String[]{"1.0", "2.0"} ), file ) );
assertEquals( "Check content matches", expectedContents, FileUtils.readFileToString( file, null ) ); assertEquals( "Check content matches", expectedContents, FileUtils.readFileToString( file, null ) );
assertFalse( "Check content doesn't match old version", assertFalse( "Check content doesn't match old version",
@ -1767,7 +1771,7 @@ public class ProxyRequestHandlerTest
assertEquals( "Check file matches", expectedFile, file ); assertEquals( "Check file matches", expectedFile, file );
} }
private static Versioning getVersioning( List versions ) private static Versioning getVersioning( List versions, File file )
{ {
Versioning versioning = new Versioning(); Versioning versioning = new Versioning();
for ( Iterator i = versions.iterator(); i.hasNext(); ) for ( Iterator i = versions.iterator(); i.hasNext(); )
@ -1775,6 +1779,7 @@ public class ProxyRequestHandlerTest
String v = (String) i.next(); String v = (String) i.next();
versioning.addVersion( v ); versioning.addVersion( v );
} }
setLastUpdatedTimestamp( versioning, file );
return versioning; return versioning;
} }
@ -1806,15 +1811,23 @@ public class ProxyRequestHandlerTest
return getExpectedMetadata( artifactId, version, null ); return getExpectedMetadata( artifactId, version, null );
} }
private static Versioning getVersioning( String timestamp, int buildNumber ) private static Versioning getVersioning( String timestamp, int buildNumber, File file )
{ {
Versioning versioning = new Versioning(); Versioning versioning = new Versioning();
versioning.setSnapshot( new Snapshot() ); versioning.setSnapshot( new Snapshot() );
versioning.getSnapshot().setTimestamp( timestamp ); versioning.getSnapshot().setTimestamp( timestamp );
versioning.getSnapshot().setBuildNumber( buildNumber ); versioning.getSnapshot().setBuildNumber( buildNumber );
setLastUpdatedTimestamp( versioning, file );
return versioning; return versioning;
} }
private static void setLastUpdatedTimestamp( Versioning versioning, File file )
{
DateFormat fmt = new SimpleDateFormat( "yyyyMMddHHmmss", Locale.US );
fmt.setTimeZone( UTC_TIMEZONE );
versioning.setLastUpdated( fmt.format( new Date( file.lastModified() ) ) );
}
private static Date getPastDate() private static Date getPastDate()
throws ParseException throws ParseException
{ {