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-4367">MNG-4367</a>.
29   *
30   * @author Benjamin Bentmann
31   */
32  public class MavenITmng4367LayoutAwareMirrorSelectionTest
33      extends AbstractMavenIntegrationTestCase
34  {
35  
36      public MavenITmng4367LayoutAwareMirrorSelectionTest()
37      {
38          super( "[3.0-alpha-3,)" );
39      }
40  
41      /**
42       * Test that mirror selection considers the repo layout if specified for the mirror. If {@code <mirrorOfLayouts>} is
43       * unspecified, should match any layout.
44       *
45       * @throws Exception in case of failure
46       */
47      public void testitNoLayout()
48          throws Exception
49      {
50          File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-4367" );
51  
52          Verifier verifier = newVerifier( testDir.getAbsolutePath() );
53          verifier.setAutoclean( false );
54          verifier.deleteArtifacts( "org.apache.maven.its.mng4367" );
55  
56          Properties filterProps = verifier.newDefaultFilterProperties();
57          filterProps.setProperty( "@repourl@", filterProps.getProperty( "@baseurl@" ) + "/void" );
58          filterProps.setProperty( "@mirrorurl@", filterProps.getProperty( "@baseurl@" ) + "/repo" );
59          filterProps.setProperty( "@layouts@", "" );
60  
61          verifier.addCliOption( "-s" );
62          verifier.addCliOption( "settings-a.xml" );
63          verifier.filterFile( "settings-template.xml", "settings-a.xml", "UTF-8", filterProps );
64          verifier.setLogFileName( "log-a.txt" );
65          verifier.executeGoal( "validate" );
66          verifier.verifyErrorFreeLog();
67          verifier.resetStreams();
68  
69          verifier.assertArtifactPresent( "org.apache.maven.its.mng4367", "dep", "0.1", "jar" );
70      }
71  
72      /**
73       * Test that mirror selection considers the repo layout if specified for the mirror.
74       *
75       * @throws Exception in case of failure
76       */
77      public void testitSpecificLayouts()
78          throws Exception
79      {
80          File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-4367" );
81  
82          Verifier verifier = newVerifier( testDir.getAbsolutePath() );
83          verifier.setAutoclean( false );
84          verifier.deleteArtifacts( "org.apache.maven.its.mng4367" );
85  
86          Properties filterProps = verifier.newDefaultFilterProperties();
87          filterProps.setProperty( "@repourl@", filterProps.getProperty( "@baseurl@" ) + "/void" );
88          filterProps.setProperty( "@mirrorurl@", filterProps.getProperty( "@baseurl@" ) + "/repo" );
89          filterProps.setProperty( "@layouts@", "default,legacy" );
90  
91          verifier.addCliOption( "-s" );
92          verifier.addCliOption( "settings-b.xml" );
93          verifier.filterFile( "settings-template.xml", "settings-b.xml", "UTF-8", filterProps );
94          verifier.setLogFileName( "log-b.txt" );
95          verifier.executeGoal( "validate" );
96          verifier.verifyErrorFreeLog();
97          verifier.resetStreams();
98  
99          verifier.assertArtifactPresent( "org.apache.maven.its.mng4367", "dep", "0.1", "jar" );
100     }
101 
102     /**
103      * Test that mirror selection considers the repo layout if specified for the mirror.
104      *
105      * @throws Exception in case of failure
106      */
107     public void testitNonMatchingLayout()
108         throws Exception
109     {
110         File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-4367" );
111 
112         Verifier verifier = newVerifier( testDir.getAbsolutePath() );
113         verifier.setAutoclean( false );
114         verifier.deleteArtifacts( "org.apache.maven.its.mng4367" );
115 
116         Properties filterProps = verifier.newDefaultFilterProperties();
117         filterProps.setProperty( "@repourl@", filterProps.getProperty( "@baseurl@" ) + "/repo" );
118         filterProps.setProperty( "@mirrorurl@", filterProps.getProperty( "@baseurl@" ) + "/void" );
119         filterProps.setProperty( "@layouts@", "foo" );
120 
121         verifier.addCliOption( "-s" );
122         verifier.addCliOption( "settings-c.xml" );
123         verifier.filterFile( "settings-template.xml", "settings-c.xml", "UTF-8", filterProps );
124         verifier.setLogFileName( "log-c.txt" );
125         verifier.executeGoal( "validate" );
126         verifier.verifyErrorFreeLog();
127         verifier.resetStreams();
128 
129         verifier.assertArtifactPresent( "org.apache.maven.its.mng4367", "dep", "0.1", "jar" );
130     }
131 
132 }