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.Properties;
26  
27  /**
28   * This is a test set for <a href="https://issues.apache.org/jira/browse/MNG-4231">MNG-4231</a>.
29   *
30   * @author Benjamin Bentmann
31   */
32  public class MavenITmng4231SnapshotUpdatePolicyTest
33      extends AbstractMavenIntegrationTestCase
34  {
35  
36      public MavenITmng4231SnapshotUpdatePolicyTest()
37      {
38          super( ALL_MAVEN_VERSIONS );
39      }
40  
41      /**
42       * Test the update policy "always" for snapshot dependencies is respected.
43       *
44       * @throws Exception in case of failure
45       */
46      public void testitAlways()
47          throws Exception
48      {
49          File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-4231" );
50  
51          Verifier verifier = newVerifier( testDir.getAbsolutePath() );
52          verifier.setAutoclean( false );
53          verifier.deleteArtifacts( "org.apache.maven.its.mng4231" );
54          verifier.addCliOption( "-s" );
55          verifier.addCliOption( "settings.xml" );
56  
57          Properties filterProps = verifier.newDefaultFilterProperties();
58          filterProps.setProperty( "@updates@", "always" );
59  
60          filterProps.setProperty( "@repo@", "repo-1" );
61          verifier.filterFile( "settings-template.xml", "settings.xml", "UTF-8", filterProps );
62          verifier.setLogFileName( "log-always-1.txt" );
63          verifier.executeGoal( "validate" );
64          verifier.verifyErrorFreeLog();
65  
66          filterProps.setProperty( "@repo@", "repo-2" );
67          verifier.filterFile( "settings-template.xml", "settings.xml", "UTF-8", filterProps );
68          verifier.setLogFileName( "log-always-2.txt" );
69          verifier.deleteDirectory( "target" );
70          verifier.executeGoal( "validate" );
71          verifier.verifyErrorFreeLog();
72  
73          verifier.resetStreams();
74  
75          Properties checksums = verifier.loadProperties( "target/checksum.properties" );
76          assertChecksum( "db3f17644e813af768ae6e82a6d0a2f29aef8988", "a-0.1-SNAPSHOT.jar", checksums );
77          assertChecksum( "5e3265f3ed55e8b217ff9db444fd8d888962a990", "b-0.1-SNAPSHOT.jar", checksums );
78      }
79  
80      /**
81       * Test the update policy "never" for snapshot dependencies is respected.
82       *
83       * @throws Exception in case of failure
84       */
85      public void testitNever()
86          throws Exception
87      {
88          File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-4231" );
89  
90          Verifier verifier = newVerifier( testDir.getAbsolutePath() );
91          verifier.setAutoclean( false );
92          verifier.deleteArtifacts( "org.apache.maven.its.mng4231" );
93          verifier.addCliOption( "-s" );
94          verifier.addCliOption( "settings.xml" );
95  
96          Properties filterProps = verifier.newDefaultFilterProperties();
97          filterProps.setProperty( "@updates@", "never" );
98  
99          filterProps.setProperty( "@repo@", "repo-1" );
100         verifier.filterFile( "settings-template.xml", "settings.xml", "UTF-8", filterProps );
101         verifier.setLogFileName( "log-never-1.txt" );
102         verifier.executeGoal( "validate" );
103         verifier.verifyErrorFreeLog();
104 
105         filterProps.setProperty( "@repo@", "repo-2" );
106         verifier.filterFile( "settings-template.xml", "settings.xml", "UTF-8", filterProps );
107         verifier.setLogFileName( "log-never-2.txt" );
108         verifier.deleteDirectory( "target" );
109         verifier.executeGoal( "validate" );
110         verifier.verifyErrorFreeLog();
111 
112         verifier.resetStreams();
113 
114         Properties checksums = verifier.loadProperties( "target/checksum.properties" );
115         assertChecksum( "ec6c9ea65766cc272df0ee26076240d6a93047d5", "a-0.1-SNAPSHOT.jar", checksums );
116         assertChecksum( "", "b-0.1-SNAPSHOT.jar", checksums );
117     }
118 
119     private void assertChecksum( String checksum, String jar, Properties checksums )
120     {
121         assertEquals( checksum, checksums.getProperty( jar, "" ).toLowerCase( java.util.Locale.ENGLISH ) );
122     }
123 
124 }