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.List;
26  import java.util.Properties;
27  
28  /**
29   * This is a test set for <a href="https://issues.apache.org/jira/browse/MNG-4091">MNG-4091</a>:
30   * Bad plugin descriptor error handling
31   */
32  public class MavenITmng4091BadPluginDescriptorTest
33      extends AbstractMavenIntegrationTestCase
34  {
35  
36      public MavenITmng4091BadPluginDescriptorTest()
37      {
38          super( "[2.1.0,)" ); // only test in 2.1.0+
39      }
40  
41      public void testitMNG4091_InvalidDescriptor()
42          throws Exception
43      {
44          File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-4091/invalid" );
45  
46          Verifier verifier = newVerifier( testDir.getAbsolutePath() );
47          verifier.setAutoclean( false );
48  
49          try
50          {
51              verifier.executeGoal( "validate" );
52  
53              fail( "should throw an error during execution." );
54          }
55          catch ( VerificationException e )
56          {
57              // expected...it'd be nice if we could get the specifics of the exception right here...
58          }
59          finally
60          {
61              verifier.resetStreams();
62          }
63  
64          List<String> logFile = verifier.loadFile( verifier.getBasedir(), verifier.getLogFileName(), false );
65  
66          String msg = "Plugin's descriptor contains the wrong version: 2.0-SNAPSHOT";
67  
68          boolean foundMessage = false;
69          for ( String line : logFile )
70          {
71              if ( line.contains( msg ) )
72              {
73                  foundMessage = true;
74                  break;
75              }
76          }
77  
78          assertTrue( "User-friendly message was not found in output.", foundMessage );
79      }
80  
81      public void testitMNG4091_PluginDependency()
82          throws Exception
83      {
84          File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-4091/plugin-dependency" );
85  
86          Verifier verifier = newVerifier( testDir.getAbsolutePath() );
87          verifier.setAutoclean( false );
88  
89          verifier.executeGoal( "validate" );
90          verifier.verifyErrorFreeLog();
91          verifier.resetStreams();
92  
93          Properties props = verifier.loadProperties( "target/plugin-dependency.properties" );
94          assertTrue( props.isEmpty() );
95      }
96  }
97