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.io.IOException;
26  import java.util.List;
27  import java.util.regex.Pattern;
28  
29  /**
30   * This is a test set for <a href="https://issues.apache.org/jira/browse/MNG-5482">MNG-5482</a>.
31   *
32   * It checks that plugins and reports causing errors because of Aether change from Sonatype to Eclipse
33   * get a dedicated message to explain solution to end-users
34   *
35   * @author hboutemy
36   */
37  public class MavenITmng5482AetherNotFoundTest
38      extends AbstractMavenIntegrationTestCase
39  {
40  
41      public MavenITmng5482AetherNotFoundTest()
42      {
43          super( "[3.1-A,)" );
44      }
45  
46      public void testPluginDependency()
47          throws IOException, VerificationException
48      {
49          check( "plugin-dependency" );
50      }
51  
52      public void testPluginSite()
53          throws IOException, VerificationException
54      {
55          check( "plugin-site" );
56      }
57  
58      /*public void testReportMpir()
59          throws IOException, VerificationException
60      {
61          check( "report-mpir" );
62      }*/
63  
64      public void check( String dir )
65          throws IOException, VerificationException
66      {
67          File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-5482/" + dir );
68  
69          Verifier verifier = newVerifier( testDir.getAbsolutePath(), "remote" );
70          verifier.setAutoclean( false );
71  
72          try
73          {
74              verifier.executeGoal( "validate" );
75  
76              fail( "should throw an error during execution." );
77          }
78          catch ( VerificationException e )
79          {
80              // expected...it'd be nice if we could get the specifics of the exception right here...
81          }
82          finally
83          {
84              verifier.resetStreams();
85          }
86  
87          List<String> lines = verifier.loadFile( new File( testDir, "log.txt" ), false );
88  
89          int msg = indexOf( lines, "Caused by: java.lang.ClassNotFoundException: org.sonatype.aether.+" );
90          assertTrue( "ClassNotFoundException message was not found in output.", msg >= 0 );
91  
92          int url = indexOf( lines, ".*http://cwiki.apache.org/confluence/display/MAVEN/AetherClassNotFound.*" );
93          assertTrue( "Url to ClassNotFoundAether was not found in output.", url >= 0 );
94      }
95  
96      private int indexOf( List<String> logLines, String regex )
97      {
98          Pattern pattern = Pattern.compile( regex );
99  
100         for ( int i = 0; i < logLines.size(); i++ )
101         {
102             String logLine = logLines.get( i );
103 
104             if ( pattern.matcher( logLine ).matches() )
105             {
106                 return i;
107             }
108         }
109 
110         return -1;
111     }
112 
113 }