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