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 java.io.File;
23  import java.util.Properties;
24  
25  import org.apache.maven.it.util.ResourceExtractor;
26  import org.apache.maven.shared.utils.io.FileUtils;
27  
28  import static org.junit.Assert.assertNotEquals;
29  
30  /**
31   * This is a test set for <a href="https://issues.apache.org/jira/browse/MNG-1751">MNG-1751</a>.
32   *
33   * @author Benjamin Bentmann
34   */
35  public class MavenITmng1751ForcedMetadataUpdateDuringDeploymentTest
36      extends AbstractMavenIntegrationTestCase
37  {
38  
39      public MavenITmng1751ForcedMetadataUpdateDuringDeploymentTest()
40      {
41          super( "[3.0-beta-1,)" );
42      }
43  
44      /**
45       * Verify that deployment always updates the metadata even if its remote timestamp currently refers to
46       * the future.
47       *
48       * @throws Exception in case of failure
49       */
50      public void testit()
51          throws Exception
52      {
53          File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-1751" );
54  
55          File dir = new File( testDir, "repo/org/apache/maven/its/mng1751/dep/0.1-SNAPSHOT" );
56          File templateMetadataFile = new File( dir, "template-metadata.xml" );
57          File metadataFile = new File( dir, "maven-metadata.xml" );
58          FileUtils.copyFile( templateMetadataFile, metadataFile );
59          String checksum = ItUtils.calcHash( metadataFile, "SHA-1" );
60          FileUtils.fileWrite( metadataFile.getPath() + ".sha1", checksum );
61  
62          // phase 1: deploy a new snapshot, this should update the metadata despite its future timestamp
63          Verifier verifier = newVerifier( new File( testDir, "dep" ).getAbsolutePath() );
64          verifier.setAutoclean( false );
65          verifier.deleteArtifacts( "org.apache.maven.its.mng1751" );
66          verifier.executeGoal( "validate" );
67          verifier.verifyErrorFreeLog();
68          verifier.resetStreams();
69  
70          // phase 2: resolve snapshot, if the previous deployment didn't update the metadata, we get the wrong file
71          verifier = newVerifier( new File( testDir, "test" ).getAbsolutePath() );
72          verifier.setAutoclean( false );
73          verifier.deleteArtifacts( "org.apache.maven.its.mng1751" );
74          verifier.filterFile( "settings-template.xml", "settings.xml", "UTF-8", verifier.newDefaultFilterProperties() );
75          verifier.addCliOption( "--settings" );
76          verifier.addCliOption( "settings.xml" );
77          verifier.executeGoal( "validate" );
78          verifier.verifyErrorFreeLog();
79          verifier.resetStreams();
80  
81          Properties checksums = verifier.loadProperties( "target/checksum.properties" );
82          String sha1 = checksums.getProperty( "dep-0.1-SNAPSHOT.jar", "" ).toLowerCase( java.util.Locale.ENGLISH );
83          assertEquals( sha1, 40, sha1.length() );
84          assertNotEquals( "fc081cd365b837dcb01eb9991f21c409b155ea5c", sha1 );
85      }
86  
87  }