1 package org.apache.maven.it;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import org.apache.maven.it.Verifier;
23 import org.apache.maven.it.util.FileUtils;
24 import org.apache.maven.it.util.ResourceExtractor;
25
26 import java.io.File;
27 import java.util.Date;
28 import java.util.TimeZone;
29 import java.text.SimpleDateFormat;
30
31
32
33
34
35
36
37 public class MavenITmng2790LastUpdatedMetadataTest
38 extends AbstractMavenIntegrationTestCase
39 {
40
41 public MavenITmng2790LastUpdatedMetadataTest()
42 {
43 super( "(2.0.4,)" );
44 }
45
46
47
48
49 public void testitMNG2790()
50 throws Exception
51 {
52 File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-2790" );
53
54 Date now = new Date();
55
56
57
58
59 Verifier verifier = newVerifier( testDir.getAbsolutePath() );
60 verifier.deleteArtifacts( "org.apache.maven.its.mng2790" );
61 verifier.setAutoclean( false );
62 verifier.executeGoal( "validate" );
63 verifier.verifyErrorFreeLog();
64 verifier.resetStreams();
65
66 File metadataArtifactVersionFile =
67 new File( verifier.getArtifactMetadataPath( "org.apache.maven.its.mng2790", "project", "1.0-SNAPSHOT" ) );
68 File metadataArtifactFile =
69 new File( verifier.getArtifactMetadataPath( "org.apache.maven.its.mng2790", "project" ) );
70
71 Date artifactVersionLastUpdated1 = getLastUpdated( metadataArtifactVersionFile );
72 Date artifactLastUpdated1 = getLastUpdated( metadataArtifactFile );
73
74
75 assertTrue( artifactVersionLastUpdated1 + " ~ " + now,
76 Math.abs( artifactVersionLastUpdated1.getTime() - now.getTime() ) < 10 * 60 * 1000 );
77 assertTrue( artifactLastUpdated1 + " ~ " + now,
78 Math.abs( artifactLastUpdated1.getTime() - now.getTime() ) < 10 * 60 * 1000 );
79
80
81 Thread.sleep( 1000 );
82
83
84
85
86 verifier = newVerifier( testDir.getAbsolutePath() );
87 verifier.setAutoclean( false );
88 verifier.executeGoal( "validate" );
89 verifier.verifyErrorFreeLog();
90 verifier.resetStreams();
91
92 Date artifactVersionLastUpdated2 = getLastUpdated( metadataArtifactVersionFile );
93 Date artifactLastUpdated2 = getLastUpdated( metadataArtifactFile );
94
95
96 assertTrue( artifactVersionLastUpdated1 + " < " + artifactVersionLastUpdated2,
97 artifactVersionLastUpdated2.after( artifactVersionLastUpdated1 ) );
98 assertTrue( artifactLastUpdated1 + " < " + artifactLastUpdated2,
99 artifactLastUpdated2.after( artifactLastUpdated1 ) );
100 }
101
102 private Date getLastUpdated( File metadataFile )
103 throws Exception
104 {
105 String xml = FileUtils.fileRead( metadataFile, "UTF-8" );
106 String timestamp = xml.replaceAll( "(?s)\\A.*<lastUpdated>\\s*([0-9]++)\\s*</lastUpdated>.*\\z", "$1" );
107 SimpleDateFormat format = new SimpleDateFormat( "yyyyMMddHHmmss" );
108 format.setTimeZone( TimeZone.getTimeZone( "UTC" ) );
109 return format.parse( timestamp );
110 }
111
112 }