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