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.util.ResourceExtractor;
23
24 import java.io.File;
25 import java.util.Date;
26 import java.util.Properties;
27 import java.text.SimpleDateFormat;
28
29
30
31
32
33
34 public class MavenITmng2562TimestampTest
35 extends AbstractMavenIntegrationTestCase
36 {
37
38 public MavenITmng2562TimestampTest()
39 {
40 super( "[2.1.0-M1,3.2.2)" );
41 }
42
43 public void testitDefaultFormat()
44 throws Exception
45 {
46 File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-2562/default" );
47
48 Verifier verifier = newVerifier( testDir.getAbsolutePath() );
49 verifier.setAutoclean( false );
50 verifier.deleteDirectory( "target" );
51 verifier.executeGoal( "validate" );
52 verifier.verifyErrorFreeLog();
53 verifier.resetStreams();
54
55 Date now = new Date();
56
57 Properties props = verifier.loadProperties( "target/pom.properties" );
58
59 String timestamp1 = props.getProperty( "project.properties.timestamp1", "" );
60 assertTrue( timestamp1, timestamp1.matches( "[0-9]{8}-[0-9]{4}" ) );
61 Date date = new SimpleDateFormat( "yyyyMMdd-HHmm" ).parse( timestamp1 );
62 assertTrue( now + " vs " + date, Math.abs( now.getTime() - date.getTime() ) < 24 * 60 * 60 * 1000 );
63
64 String timestamp2 = props.getProperty( "project.properties.timestamp2", "" );
65 assertEquals( timestamp1, timestamp2 );
66 }
67
68 public void testitCustomFormat()
69 throws Exception
70 {
71 File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-2562/custom" );
72
73 Verifier verifier = newVerifier( testDir.getAbsolutePath() );
74 verifier.setAutoclean( false );
75 verifier.deleteDirectory( "target" );
76 verifier.executeGoal( "validate" );
77 verifier.verifyErrorFreeLog();
78 verifier.resetStreams();
79
80 Date now = new Date();
81
82 Properties props = verifier.loadProperties( "target/pom.properties" );
83
84 String timestamp1 = props.getProperty( "project.properties.timestamp", "" );
85 Date date = new SimpleDateFormat( "mm:HH dd-MM-yyyy" ).parse( timestamp1 );
86 assertTrue( now + " vs " + date, Math.abs( now.getTime() - date.getTime() ) < 24 * 60 * 60 * 1000 );
87 }
88
89 public void testitSameValueAcrossModules()
90 throws Exception
91 {
92 File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-2562/reactor" );
93
94 Verifier verifier = newVerifier( testDir.getAbsolutePath() );
95 verifier.setAutoclean( false );
96 verifier.deleteDirectory( "target" );
97 verifier.deleteDirectory( "child-1/target" );
98 verifier.deleteDirectory( "child-2/target" );
99 verifier.deleteDirectory( "child-3/target" );
100 verifier.executeGoal( "validate" );
101 verifier.verifyErrorFreeLog();
102 verifier.resetStreams();
103
104 Properties props = verifier.loadProperties( "target/pom.properties" );
105 String timestamp = props.getProperty( "project.properties.timestamp", "" );
106
107 Properties props1 = verifier.loadProperties( "child-1/target/pom.properties" );
108 String timestamp1 = props1.getProperty( "project.properties.timestamp", "" );
109
110 Properties props2 = verifier.loadProperties( "child-2/target/pom.properties" );
111 String timestamp2 = props2.getProperty( "project.properties.timestamp", "" );
112
113 Properties props3 = verifier.loadProperties( "child-3/target/pom.properties" );
114 String timestamp3 = props3.getProperty( "project.properties.timestamp", "" );
115
116 assertEquals( timestamp, timestamp1 );
117 assertEquals( timestamp, timestamp2 );
118 assertEquals( timestamp, timestamp3 );
119 }
120
121 }