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  
27  /**
28   * This is a test set for <a href="https://issues.apache.org/jira/browse/MNG-2739">MNG-2739</a>.
29   * todo Fill in a better description of what this test verifies!
30   *
31   * @author <a href="mailto:brianf@apache.org">Brian Fox</a>
32   * @author jdcasey
33   */
34  public class MavenITmng2739RequiredRepositoryElementsTest
35      extends AbstractMavenIntegrationTestCase
36  {
37      public MavenITmng2739RequiredRepositoryElementsTest()
38      {
39          super( "(2.0.9,)" ); // only test in 2.0.9+
40      }
41  
42      public void testitMNG2739_RepositoryId()
43          throws Exception
44      {
45          File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-2739/repo-id" );
46  
47          Verifier verifier;
48  
49          verifier = newVerifier( testDir.getAbsolutePath() );
50          verifier.setAutoclean( false );
51  
52          try
53          {
54              verifier.executeGoal( "validate" );
55  
56              fail(
57                  "POM should NOT validate: repository <id/> element is missing in: " + new File( testDir, "pom.xml" ) );
58          }
59          catch ( VerificationException e )
60          {
61              // expected
62          }
63  
64          verifier.resetStreams();
65  
66          List<String> listing = verifier.loadFile( new File( testDir, "log.txt" ), false );
67          boolean foundNpe = false;
68          for ( String line : listing )
69          {
70              if ( line.contains( "NullPointerException" ) )
71              {
72                  foundNpe = true;
73                  break;
74              }
75          }
76  
77          assertFalse( "Missing repository-id should not result in a NullPointerException.", foundNpe );
78      }
79  
80      public void testitMNG2739_RepositoryUrl()
81          throws Exception
82      {
83          // The testdir is computed from the location of this
84          // file.
85          File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-2739/repo-url" );
86  
87          Verifier verifier;
88  
89          verifier = newVerifier( testDir.getAbsolutePath() );
90          verifier.setAutoclean( false );
91  
92          try
93          {
94              verifier.executeGoal( "validate" );
95  
96              fail(
97                  "POM should NOT validate: repository <url/> element is missing in: " + new File( testDir, "pom.xml" ) );
98          }
99          catch ( VerificationException e )
100         {
101             // expected
102         }
103 
104         verifier.resetStreams();
105 
106         List<String> listing = verifier.loadFile( new File( testDir, "log.txt" ), false );
107         boolean foundNpe = false;
108         for ( String line : listing )
109         {
110             if ( line.contains( "NullPointerException" ) )
111             {
112                 foundNpe = true;
113                 break;
114             }
115         }
116 
117         assertFalse( "Missing repository-url should not result in a NullPointerException.", foundNpe );
118     }
119 }