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