mirror of https://github.com/apache/maven.git
o Extracted part of it0108 to its own test to reduce test complexity and for better association with corresponding issue
git-svn-id: https://svn.apache.org/repos/asf/maven/core-integration-testing/trunk@707865 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
2aaefcc395
commit
4275fdcd42
|
@ -134,6 +134,7 @@ MavenITmng3645POMSyntaxErrorTest
|
||||||
suite.addTestSuite( MavenITmng2892Test.class );
|
suite.addTestSuite( MavenITmng2892Test.class );
|
||||||
suite.addTestSuite( MavenITmng2878Test.class );
|
suite.addTestSuite( MavenITmng2878Test.class );
|
||||||
suite.addTestSuite( MavenITmng2861RelocationsAndRanges.class );
|
suite.addTestSuite( MavenITmng2861RelocationsAndRanges.class );
|
||||||
|
suite.addTestSuite( MavenITmng2790Test.class );
|
||||||
suite.addTestSuite( MavenITmng2749Test.class );
|
suite.addTestSuite( MavenITmng2749Test.class );
|
||||||
suite.addTestSuite( MavenITmng2744checksumVerificationTest.class );
|
suite.addTestSuite( MavenITmng2744checksumVerificationTest.class );
|
||||||
suite.addTestSuite( MavenITmng2739RequiredRepositoryElements.class );
|
suite.addTestSuite( MavenITmng2739RequiredRepositoryElements.class );
|
||||||
|
|
|
@ -201,56 +201,11 @@ public class MavenIT0108SnapshotUpdateTest
|
||||||
verifier.resetStreams();
|
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 )
|
private File getMetadataFile( String groupId, String artifactId, String version )
|
||||||
{
|
{
|
||||||
return new File( verifier.localRepo, groupId + "/" + artifactId + "/" + version + "/maven-metadata-local.xml" );
|
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}(</lastUpdated>.*)", "$1$2" );
|
|
||||||
}
|
|
||||||
|
|
||||||
private void assertArtifactContents( String s )
|
private void assertArtifactContents( String s )
|
||||||
throws IOException
|
throws IOException
|
||||||
{
|
{
|
||||||
|
|
|
@ -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 <a href="http://jira.codehaus.org/browse/MNG-2790">MNG-2790</a>.
|
||||||
|
*
|
||||||
|
* @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.*<lastUpdated>\\s*([0-9]++)\\s*</lastUpdated>.*\\z", "$1" );
|
||||||
|
SimpleDateFormat format = new SimpleDateFormat( "yyyyMMddHHmmss" );
|
||||||
|
format.setTimeZone( TimeZone.getTimeZone( "UTC" ) );
|
||||||
|
return format.parse( timestamp );
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,57 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
|
||||||
|
<!--
|
||||||
|
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.
|
||||||
|
-->
|
||||||
|
|
||||||
|
<project>
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
<groupId>org.apache.maven.its.mng2790</groupId>
|
||||||
|
<artifactId>project</artifactId>
|
||||||
|
<!-- NOTE: It is part of the test design that this is a snapshot version -->
|
||||||
|
<version>1.0-SNAPSHOT</version>
|
||||||
|
|
||||||
|
<name>Maven Integration Test :: MNG-2790</name>
|
||||||
|
<description>
|
||||||
|
Verify that the field lastUpdated of existing local repo metadata is updated upon install of new a snapshot.
|
||||||
|
</description>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.its.plugins</groupId>
|
||||||
|
<artifactId>maven-it-plugin-artifact</artifactId>
|
||||||
|
<version>2.1-SNAPSHOT</version>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<id>install</id>
|
||||||
|
<phase>validate</phase>
|
||||||
|
<configuration>
|
||||||
|
<mainFile>snapshot.jar</mainFile>
|
||||||
|
</configuration>
|
||||||
|
<goals>
|
||||||
|
<goal>set</goal>
|
||||||
|
<goal>install</goal>
|
||||||
|
</goals>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
</project>
|
Binary file not shown.
Loading…
Reference in New Issue