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