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