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-479">MNG-479</a>.
29   *
30   * @author Benjamin Bentmann
31   *
32   */
33  public class MavenITmng0479OverrideCentralRepoTest
34      extends AbstractMavenIntegrationTestCase
35  {
36      public MavenITmng0479OverrideCentralRepoTest()
37      {
38          super( "[2.0.3,3.0-alpha-1),[3.0-beta-3,)" );
39      }
40  
41      /**
42       *  Verify that using the same repo id allows to override "central". This test checks the effective model.
43       *
44       * @throws Exception in case of failure
45       */
46      public void testitModel()
47          throws Exception
48      {
49          File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-0479" );
50  
51          // Phase 1: Ensure the test plugin is downloaded before the test cuts off access to central
52          File child1 = new File( testDir, "setup" );
53          Verifier verifier = newVerifier( child1.getAbsolutePath() );
54          verifier.setAutoclean( false );
55          verifier.deleteDirectory( "target" );
56  
57          verifier.executeGoal( "org.apache.maven.its.plugins:maven-it-plugin-expression:2.1-SNAPSHOT:eval" );
58          verifier.verifyErrorFreeLog();
59          verifier.resetStreams();
60  
61          // Phase 2: Now run the test
62          File child2 = new File( testDir, "test" );
63          verifier = newVerifier( child2.getAbsolutePath() );
64          verifier.setAutoclean( false );
65          verifier.deleteDirectory( "target" );
66  
67          verifier.filterFile( "settings-template.xml", "settings.xml", "UTF-8", verifier.newDefaultFilterProperties() );
68          verifier.addCliOption( "--settings" );
69          verifier.addCliOption( "settings.xml" );
70          verifier.executeGoal( "org.apache.maven.its.plugins:maven-it-plugin-expression:2.1-SNAPSHOT:eval" );
71          verifier.verifyErrorFreeLog();
72          verifier.resetStreams();
73  
74          verifier.assertFilePresent( "target/expression.properties" );
75          Properties props = verifier.loadProperties( "target/expression.properties" );
76  
77          int count = Integer.parseInt( props.getProperty( "project.repositories", "0" ) );
78          assertTrue( count > 0 );
79          for ( int i = 0; i < count; i++ )
80          {
81              String key = "project.repositories." + i;
82              if ( "central".equals( props.getProperty( key + ".id" ) ) )
83              {
84                  assertEquals( "mng-0479", props.getProperty( key + ".name" ) );
85                  assertTrue( props.getProperty( key + ".url" ).endsWith( "/target/mng-0479" ) );
86  
87                  assertEquals( "false", props.getProperty( key + ".releases.enabled" ) );
88                  assertEquals( "ignore", props.getProperty( key + ".releases.checksumPolicy" ) );
89                  assertEquals( "always", props.getProperty( key + ".releases.updatePolicy" ) );
90  
91                  assertEquals( "true", props.getProperty( key + ".snapshots.enabled" ) );
92                  assertEquals( "fail", props.getProperty( key + ".snapshots.checksumPolicy" ) );
93                  assertEquals( "never", props.getProperty( key + ".snapshots.updatePolicy" ) );
94              }
95          }
96  
97          count = Integer.parseInt( props.getProperty( "project.pluginRepositories", "0" ) );
98          for ( int i = 0; i < count; i++ )
99          {
100             String key = "project.pluginRepositories." + i;
101             if ( "central".equals( props.getProperty( key + ".id" ) ) )
102             {
103                 assertEquals( "mng-0479", props.getProperty( key + ".name" ) );
104                 assertTrue( props.getProperty( key + ".url" ).endsWith( "/target/mng-0479" ) );
105 
106                 assertEquals( "false", props.getProperty( key + ".releases.enabled" ) );
107                 assertEquals( "ignore", props.getProperty( key + ".releases.checksumPolicy" ) );
108                 assertEquals( "always", props.getProperty( key + ".releases.updatePolicy" ) );
109 
110                 assertEquals( "true", props.getProperty( key + ".snapshots.enabled" ) );
111                 assertEquals( "fail", props.getProperty( key + ".snapshots.checksumPolicy" ) );
112                 assertEquals( "never", props.getProperty( key + ".snapshots.updatePolicy" ) );
113             }
114         }
115     }
116 
117     /**
118      *  Verify that using the same repo id allows to override "central". This test checks the actual repo access.
119      *
120      * @throws Exception in case of failure
121      */
122     public void testitResolution()
123         throws Exception
124     {
125         File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-0479" );
126 
127         Verifier verifier = newVerifier( new File( testDir, "test-1" ).getAbsolutePath() );
128         verifier.setAutoclean( false );
129         verifier.deleteDirectory( "target" );
130         verifier.deleteArtifacts( "org.apache.maven.its.mng0479" );
131         verifier.filterFile( "settings-template.xml", "settings.xml", "UTF-8", verifier.newDefaultFilterProperties() );
132         verifier.addCliOption( "--settings" );
133         verifier.addCliOption( "settings.xml" );
134         verifier.executeGoal( "validate" );
135         verifier.verifyErrorFreeLog();
136         verifier.resetStreams();
137 
138         verifier.assertFilePresent( "target/touch.txt" );
139         verifier.assertArtifactPresent( "org.apache.maven.its.mng0479", "parent", "0.1-SNAPSHOT", "pom" );
140         verifier.assertArtifactPresent( "org.apache.maven.its.mng0479", "a", "0.1-SNAPSHOT", "jar" );
141         verifier.assertArtifactPresent( "org.apache.maven.its.mng0479", "a", "0.1-SNAPSHOT", "pom" );
142         verifier.assertArtifactPresent( "org.apache.maven.its.mng0479", "a-parent", "0.1-SNAPSHOT", "pom" );
143         verifier.assertArtifactPresent( "org.apache.maven.its.mng0479", "b", "0.1-SNAPSHOT", "jar" );
144         verifier.assertArtifactPresent( "org.apache.maven.its.mng0479", "b", "0.1-SNAPSHOT", "pom" );
145 
146         verifier = newVerifier( new File( testDir, "test-2" ).getAbsolutePath() );
147         verifier.setAutoclean( false );
148         verifier.deleteDirectory( "target" );
149         verifier.filterFile( "settings-template.xml", "settings.xml", "UTF-8", verifier.newDefaultFilterProperties() );
150         verifier.addCliOption( "--settings" );
151         verifier.addCliOption( "settings.xml" );
152         try
153         {
154             verifier.executeGoal( "validate" );
155             verifier.verifyErrorFreeLog();
156             fail( "Build should have failed to resolve parent POM" );
157         }
158         catch ( VerificationException e )
159         {
160             // expected
161         }
162         verifier.resetStreams();
163 
164         verifier.assertArtifactNotPresent( "org.apache.maven.its.mng0479", "parent", "0.1", "pom" );
165 
166         verifier = newVerifier( new File( testDir, "test-3" ).getAbsolutePath() );
167         verifier.setAutoclean( false );
168         verifier.deleteDirectory( "target" );
169         verifier.filterFile( "settings-template.xml", "settings.xml", "UTF-8", verifier.newDefaultFilterProperties() );
170         verifier.addCliOption( "--settings" );
171         verifier.addCliOption( "settings.xml" );
172         try
173         {
174             verifier.executeGoal( "org.apache.maven.its.mng0479:maven-mng0479-plugin:0.1-SNAPSHOT:touch" );
175             verifier.verifyErrorFreeLog();
176             fail( "Build should have failed to resolve direct dependency" );
177         }
178         catch ( VerificationException e )
179         {
180             // expected
181         }
182         verifier.resetStreams();
183 
184         verifier.assertArtifactNotPresent( "org.apache.maven.its.mng0479", "a", "0.1", "jar" );
185         verifier.assertArtifactNotPresent( "org.apache.maven.its.mng0479", "a", "0.1", "pom" );
186 
187         verifier = newVerifier( new File( testDir, "test-4" ).getAbsolutePath() );
188         verifier.setAutoclean( false );
189         verifier.deleteDirectory( "target" );
190         verifier.filterFile( "settings-template.xml", "settings.xml", "UTF-8", verifier.newDefaultFilterProperties() );
191         verifier.addCliOption( "--settings" );
192         verifier.addCliOption( "settings.xml" );
193         try
194         {
195             verifier.executeGoal( "org.apache.maven.its.mng0479:maven-mng0479-plugin:0.1-SNAPSHOT:touch" );
196             verifier.verifyErrorFreeLog();
197             fail( "Build should have failed to resolve transitive dependency" );
198         }
199         catch ( VerificationException e )
200         {
201             // expected
202         }
203         verifier.resetStreams();
204 
205         verifier.assertArtifactNotPresent( "org.apache.maven.its.mng0479", "b", "0.1", "jar" );
206         verifier.assertArtifactNotPresent( "org.apache.maven.its.mng0479", "b", "0.1", "pom" );
207     }
208 
209 }