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