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.ArrayList;
26  import java.util.Collections;
27  import java.util.List;
28  import java.util.Properties;
29  
30  /**
31   * This is a test set for <a href="https://issues.apache.org/jira/browse/MNG-4190">MNG-4190</a>.
32   *
33   * @author Benjamin Bentmann
34   */
35  public class MavenITmng4190MirrorRepoMergingTest
36      extends AbstractMavenIntegrationTestCase
37  {
38  
39      public MavenITmng4190MirrorRepoMergingTest()
40      {
41          super( "[3.0-alpha-3,)" );
42      }
43  
44      /**
45       * Test that artifact repositories are merged if they are mirrored by the same repo. If n repos map to one
46       * mirror, there is no point in making n trips to the same mirror. However, the effective/merged repo needs
47       * to account for possibly different policies of the original repos.
48       *
49       * @throws Exception in case of failure
50       */
51      public void testit()
52          throws Exception
53      {
54          File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-4190" );
55  
56          Verifier verifier = newVerifier( testDir.getAbsolutePath() );
57          verifier.setAutoclean( false );
58          verifier.deleteDirectory( "target" );
59          verifier.deleteArtifacts( "org.apache.maven.its.mng4190" );
60          verifier.filterFile( "settings-template.xml", "settings.xml", "UTF-8", verifier.newDefaultFilterProperties() );
61          verifier.addCliOption( "-s" );
62          verifier.addCliOption( "settings.xml" );
63          verifier.executeGoal( "validate" );
64          verifier.verifyErrorFreeLog();
65          verifier.resetStreams();
66  
67          List<String> artifacts = verifier.loadLines( "target/artifacts.txt", "UTF-8" );
68          Collections.sort( artifacts );
69  
70          List<String> expected = new ArrayList<>();
71          expected.add( "org.apache.maven.its.mng4190:a:jar:0.1" );
72          expected.add( "org.apache.maven.its.mng4190:b:jar:0.1-SNAPSHOT" );
73  
74          assertEquals( expected, artifacts );
75  
76          Properties props = verifier.loadProperties( "target/repo.properties" );
77          assertEquals( "1", props.getProperty( "project.remoteArtifactRepositories" ) );
78  
79          assertEquals( "true", props.getProperty( "project.remoteArtifactRepositories.0.releases.enabled" ) );
80          assertEquals( "ignore", props.getProperty( "project.remoteArtifactRepositories.0.releases.checksumPolicy" ) );
81          assertEquals( "daily", props.getProperty( "project.remoteArtifactRepositories.0.releases.updatePolicy" ) );
82  
83          assertEquals( "true", props.getProperty( "project.remoteArtifactRepositories.0.snapshots.enabled" ) );
84          assertEquals( "ignore", props.getProperty( "project.remoteArtifactRepositories.0.snapshots.checksumPolicy" ) );
85          assertEquals( "always", props.getProperty( "project.remoteArtifactRepositories.0.snapshots.updatePolicy" ) );
86      }
87  
88  }