View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.maven.it;
20  
21  import java.io.File;
22  import java.util.List;
23  import java.util.regex.Pattern;
24  import org.apache.maven.it.util.ResourceExtractor;
25  
26  /**
27   * Integration tests for <a href="https://issues.apache.org/jira/browse/MNG-4463">MNG-4463</a>.
28   *
29   * @author Christian Schulte
30   */
31  public class MavenITmng4463DependencyManagementImportVersionRanges
32      extends AbstractMavenIntegrationTestCase
33  {
34  
35      public MavenITmng4463DependencyManagementImportVersionRanges()
36      {
37          super( "[4.0.0-alpha-1,)" );
38      }
39  
40      public void testInclusiveUpperBoundResolvesToHighestVersion()
41          throws Exception
42      {
43          final File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-4463/inclusive-upper-bound" );
44          final Verifier verifier = newVerifier( testDir.getAbsolutePath(), "remote" );
45          verifier.setAutoclean( false );
46          verifier.deleteDirectory( "target" );
47          verifier.executeGoal( "validate" );
48          verifier.verifyErrorFreeLog();
49          verifier.resetStreams();
50  
51          final List<String> artifacts = verifier.loadLines( "target/compile.txt", "UTF-8" );
52          assertTrue( artifacts.toString(), artifacts.contains( "org.apache.maven:maven-plugin-api:jar:3.0" ) );
53      }
54  
55      public void testExclusiveUpperBoundResolvesToHighestVersion()
56          throws Exception
57      {
58          final File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-4463/exclusive-upper-bound" );
59          final Verifier verifier = newVerifier( testDir.getAbsolutePath(), "remote" );
60          verifier.setAutoclean( false );
61          verifier.deleteDirectory( "target" );
62          verifier.executeGoal( "validate" );
63          verifier.verifyErrorFreeLog();
64          verifier.resetStreams();
65  
66          List<String> artifacts = verifier.loadLines( "target/compile.txt", "UTF-8" );
67          assertTrue( artifacts.toString(), artifacts.contains( "org.apache.maven:maven-plugin-api:jar:3.0" ) );
68      }
69  
70      public void testFailureWithoutUpperBound()
71          throws Exception
72      {
73          final File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-4463/no-upper-bound" );
74          final Verifier verifier = newVerifier( testDir.getAbsolutePath(), "remote" );
75  
76          try
77          {
78              verifier.setAutoclean( false );
79              verifier.deleteDirectory( "target" );
80              verifier.executeGoal( "validate" );
81              fail( "Expected 'VerificationException' not thrown." );
82          }
83          catch ( final VerificationException e )
84          {
85              final List<String> lines = verifier.loadFile( new File( testDir, "log.txt" ), false );
86              assertTrue( "Expected error message not found.",
87                          indexOf( lines, ".*dependency version range.*does not specify an upper bound.*" ) >= 0 );
88          }
89          finally
90          {
91              verifier.resetStreams();
92          }
93      }
94  
95      private static int indexOf( final List<String> logLines, final String regex )
96      {
97          final Pattern pattern = Pattern.compile( regex );
98  
99          for ( int i = 0, l0 = logLines.size(); i < l0; i++ )
100         {
101             if ( pattern.matcher( logLines.get( i ) ).matches() )
102             {
103                 return i;
104             }
105         }
106 
107         return -1;
108     }
109 
110 }