diff --git a/its/core-it-suite/src/test/java/org/apache/maven/it/IntegrationTestSuite.java b/its/core-it-suite/src/test/java/org/apache/maven/it/IntegrationTestSuite.java index 6c17d0f88b..1345883c00 100644 --- a/its/core-it-suite/src/test/java/org/apache/maven/it/IntegrationTestSuite.java +++ b/its/core-it-suite/src/test/java/org/apache/maven/it/IntegrationTestSuite.java @@ -134,6 +134,7 @@ MavenITmng3645POMSyntaxErrorTest suite.addTestSuite( MavenITmng2892Test.class ); suite.addTestSuite( MavenITmng2878Test.class ); suite.addTestSuite( MavenITmng2861RelocationsAndRanges.class ); + suite.addTestSuite( MavenITmng2790Test.class ); suite.addTestSuite( MavenITmng2749Test.class ); suite.addTestSuite( MavenITmng2744checksumVerificationTest.class ); suite.addTestSuite( MavenITmng2739RequiredRepositoryElements.class ); diff --git a/its/core-it-suite/src/test/java/org/apache/maven/it/MavenIT0108SnapshotUpdateTest.java b/its/core-it-suite/src/test/java/org/apache/maven/it/MavenIT0108SnapshotUpdateTest.java index 5cf8227d79..d9c388201f 100644 --- a/its/core-it-suite/src/test/java/org/apache/maven/it/MavenIT0108SnapshotUpdateTest.java +++ b/its/core-it-suite/src/test/java/org/apache/maven/it/MavenIT0108SnapshotUpdateTest.java @@ -201,56 +201,11 @@ public class MavenIT0108SnapshotUpdateTest verifier.resetStreams(); } - public void testSnapshotLocalMetadataUpdatedOnInstall() - throws Exception - { - File localMetadata = - getMetadataFile( "org/apache/maven/its/snapshotUpdate", "maven-it-snapshot-update", "1.0-SNAPSHOT" ); - - localMetadata.delete(); - assertFalse( localMetadata.exists() ); - - verifier.executeGoal( "install" ); - - verifier.verifyErrorFreeLog(); - verifier.resetStreams(); - - assertLocalMetadataIsToday( localMetadata ); - - Calendar cal = Calendar.getInstance(); - cal.add( Calendar.YEAR, -1 ); - FileUtils.fileWrite( localMetadata.getAbsolutePath(), constructLocalMetadata( - "org.apache.maven.its.snapshotUpdate", "maven-it-snapshot-update", cal.getTimeInMillis(), true ) ); - - verifier.executeGoal( "install" ); - - assertLocalMetadataIsToday( localMetadata ); - - verifier.verifyErrorFreeLog(); - verifier.resetStreams(); - } - private File getMetadataFile( String groupId, String artifactId, String version ) { return new File( verifier.localRepo, groupId + "/" + artifactId + "/" + version + "/maven-metadata-local.xml" ); } - private void assertLocalMetadataIsToday( File localMetadata ) - throws IOException - { - String actual = stripTime( FileUtils.fileRead( localMetadata ) ); - String expected = stripTime( constructLocalMetadata( "org.apache.maven.its.snapshotUpdate", - "maven-it-snapshot-update", System.currentTimeMillis(), - true ) ); - - assertEquals( expected, actual ); - } - - private static String stripTime( String s ) - { - return s.replaceAll( "(.*)[0-9]{6}(.*)", "$1$2" ); - } - private void assertArtifactContents( String s ) throws IOException { diff --git a/its/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng2790Test.java b/its/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng2790Test.java new file mode 100644 index 0000000000..e7aad39f9a --- /dev/null +++ b/its/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng2790Test.java @@ -0,0 +1,109 @@ +package org.apache.maven.it; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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. + */ + +import org.apache.maven.it.Verifier; +import org.apache.maven.it.util.FileUtils; +import org.apache.maven.it.util.ResourceExtractor; + +import java.io.File; +import java.util.Date; +import java.util.Properties; +import java.util.TimeZone; +import java.text.SimpleDateFormat; + +/** + * This is a test set for MNG-2790. + * + * @author Benjamin Bentmann + * @version $Id$ + */ +public class MavenITmng2790Test + extends AbstractMavenIntegrationTestCase +{ + + public MavenITmng2790Test() + { + super( "(2.0.4,)" ); + } + + /** + * Verify that the field lastUpdated of existing local repo metadata is updated upon install of new a snapshot. + */ + public void testitMNG2790() + throws Exception + { + File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-2790" ); + + Date now = new Date(); + + /* + * Phase 1: Install initial snapshot into local repo. + */ + Verifier verifier = new Verifier( testDir.getAbsolutePath() ); + File metadataArtifactVersionFile = + new File( verifier.getArtifactMetadataPath( "org.apache.maven.its.mng2790", "project", "1.0-SNAPSHOT" ) ); + File metadataArtifactFile = + new File( verifier.getArtifactMetadataPath( "org.apache.maven.its.mng2790", "project" ) ); + FileUtils.deleteDirectory( metadataArtifactFile.getParentFile() ); + verifier.setAutoclean( false ); + verifier.executeGoal( "validate" ); + verifier.verifyErrorFreeLog(); + verifier.resetStreams(); + + Date artifactVersionLastUpdated1 = getLastUpdated( metadataArtifactVersionFile ); + Date artifactLastUpdated1 = getLastUpdated( metadataArtifactFile ); + + // sanity check: timestamps shouldn't differ by more than 10 min from now (i.e. timezone is UTC) + assertTrue( artifactVersionLastUpdated1 + " ~ " + now, + Math.abs( artifactVersionLastUpdated1.getTime() - now.getTime() ) < 10 * 60 * 1000 ); + assertTrue( artifactLastUpdated1 + " ~ " + now, + Math.abs( artifactLastUpdated1.getTime() - now.getTime() ) < 10 * 60 * 1000 ); + + /* + * Phase 2: Re-install snapshot and check for proper timestamp update in local metadata. + */ + verifier = new Verifier( testDir.getAbsolutePath() ); + verifier.setAutoclean( false ); + verifier.executeGoal( "validate" ); + verifier.verifyErrorFreeLog(); + verifier.resetStreams(); + + Date artifactVersionLastUpdated2 = getLastUpdated( metadataArtifactVersionFile ); + Date artifactLastUpdated2 = getLastUpdated( metadataArtifactFile ); + + // check that new timestamps are strictly later than from original install + assertTrue( artifactVersionLastUpdated1 + " < " + artifactVersionLastUpdated2, + artifactVersionLastUpdated2.after( artifactVersionLastUpdated1 ) ); + assertTrue( artifactLastUpdated1 + " < " + artifactLastUpdated2, + artifactLastUpdated2.after( artifactLastUpdated1 ) ); + } + + private Date getLastUpdated( File metadataFile ) + throws Exception + { + String xml = FileUtils.fileRead( metadataFile, "UTF-8" ); + String timestamp = xml.replaceAll( "(?s)\\A.*\\s*([0-9]++)\\s*.*\\z", "$1" ); + SimpleDateFormat format = new SimpleDateFormat( "yyyyMMddHHmmss" ); + format.setTimeZone( TimeZone.getTimeZone( "UTC" ) ); + return format.parse( timestamp ); + } + +} diff --git a/its/core-it-suite/src/test/resources/mng-2790/pom.xml b/its/core-it-suite/src/test/resources/mng-2790/pom.xml new file mode 100644 index 0000000000..ecaabe1f35 --- /dev/null +++ b/its/core-it-suite/src/test/resources/mng-2790/pom.xml @@ -0,0 +1,57 @@ + + + + + + 4.0.0 + + org.apache.maven.its.mng2790 + project + + 1.0-SNAPSHOT + + Maven Integration Test :: MNG-2790 + + Verify that the field lastUpdated of existing local repo metadata is updated upon install of new a snapshot. + + + + + + org.apache.maven.its.plugins + maven-it-plugin-artifact + 2.1-SNAPSHOT + + + install + validate + + snapshot.jar + + + set + install + + + + + + + diff --git a/its/core-it-suite/src/test/resources/mng-2790/snapshot.jar b/its/core-it-suite/src/test/resources/mng-2790/snapshot.jar new file mode 100644 index 0000000000..da9625e101 Binary files /dev/null and b/its/core-it-suite/src/test/resources/mng-2790/snapshot.jar differ