View Javadoc
1   package org.apache.maven.it;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
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   * This is a test set for <a href="https://issues.apache.org/jira/browse/MNG-2562">MNG-2562</a>.
31   */
32  public class MavenITmng2562Timestamp322Test
33      extends AbstractMavenIntegrationTestCase
34  {
35  
36      public MavenITmng2562Timestamp322Test()
37      {
38          super( "[3.2.2,)" ); // 3.2.2+ only as we changed the timestamp format
39      }
40  
41      public void testitDefaultFormat()
42          throws Exception
43      {
44          File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-2562/default" );
45  
46          Verifier verifier = newVerifier( testDir.getAbsolutePath() );
47          verifier.setAutoclean( false );
48          verifier.deleteDirectory( "target" );
49          verifier.executeGoal( "validate" );
50          verifier.verifyErrorFreeLog();
51          verifier.resetStreams();
52  
53          Date now = new Date();
54  
55          Properties props = verifier.loadProperties( "target/pom.properties" );
56  
57          String timestamp1 = props.getProperty( "project.properties.timestamp1", "" );
58          assertTrue( timestamp1, timestamp1.matches( "\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}Z" ) );
59          Date date = new SimpleDateFormat( "yyyy-MM-dd'T'HH:mm:ss'Z'" ).parse( timestamp1 );
60          assertTrue( now + " vs " + date, Math.abs( now.getTime() - date.getTime() ) < 24 * 60 * 60 * 1000 );
61  
62          String timestamp2 = props.getProperty( "project.properties.timestamp2", "" );
63          assertEquals( timestamp1, timestamp2 );
64      }
65  
66      public void testitCustomFormat()
67          throws Exception
68      {
69          File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-2562/custom" );
70  
71          Verifier verifier = newVerifier( testDir.getAbsolutePath() );
72          verifier.setAutoclean( false );
73          verifier.deleteDirectory( "target" );
74          verifier.executeGoal( "validate" );
75          verifier.verifyErrorFreeLog();
76          verifier.resetStreams();
77  
78          Date now = new Date();
79  
80          Properties props = verifier.loadProperties( "target/pom.properties" );
81  
82          String timestamp1 = props.getProperty( "project.properties.timestamp", "" );
83          Date date = new SimpleDateFormat( "mm:HH dd-MM-yyyy" ).parse( timestamp1 );
84          assertTrue( now + " vs " + date, Math.abs( now.getTime() - date.getTime() ) < 24 * 60 * 60 * 1000 );
85      }
86  
87      public void testitSameValueAcrossModules()
88          throws Exception
89      {
90          File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-2562/reactor" );
91  
92          Verifier verifier = newVerifier( testDir.getAbsolutePath() );
93          verifier.setAutoclean( false );
94          verifier.deleteDirectory( "target" );
95          verifier.deleteDirectory( "child-1/target" );
96          verifier.deleteDirectory( "child-2/target" );
97          verifier.deleteDirectory( "child-3/target" );
98          verifier.executeGoal( "validate" );
99          verifier.verifyErrorFreeLog();
100         verifier.resetStreams();
101 
102         Properties props = verifier.loadProperties( "target/pom.properties" );
103         String timestamp = props.getProperty( "project.properties.timestamp", "" );
104 
105         Properties props1 = verifier.loadProperties( "child-1/target/pom.properties" );
106         String timestamp1 = props1.getProperty( "project.properties.timestamp", "" );
107 
108         Properties props2 = verifier.loadProperties( "child-2/target/pom.properties" );
109         String timestamp2 = props2.getProperty( "project.properties.timestamp", "" );
110 
111         Properties props3 = verifier.loadProperties( "child-3/target/pom.properties" );
112         String timestamp3 = props3.getProperty( "project.properties.timestamp", "" );
113 
114         assertEquals( timestamp, timestamp1 );
115         assertEquals( timestamp, timestamp2 );
116         assertEquals( timestamp, timestamp3 );
117     }
118 
119 }