View Javadoc

1   package org.apache.maven.shared.release.util;
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.codehaus.plexus.PlexusTestCase;
23  import org.codehaus.plexus.logging.Logger;
24  import org.codehaus.plexus.logging.LoggerManager;
25  
26  import java.io.File;
27  import java.net.URL;
28  
29  
30  /**
31   * @author <a href="mailto:struberg@yahoo.de">Mark Struberg</a>
32   */
33  public class PomFinderTest extends PlexusTestCase
34  {
35      private Logger logger = null;
36  
37      protected void setUp() throws Exception
38      {
39          super.setUp();
40          LoggerManager lm = (LoggerManager) lookup(LoggerManager.ROLE);
41          logger = lm.getLoggerForComponent(LoggerManager.ROLE); //X TODO use a better ROLE!
42      }
43  
44      public void testPomFinderParser() throws Exception
45      {
46          PomFinder pf = new PomFinder( logger );
47  
48          boolean found = pf.parsePom( new File( "src/test/resources/pomfinder/pomNothere.xml" ) );
49          assertFalse( found );
50  
51          URL pomUrl = getClassLoader().getResource("pomfinder/pom1.xml");
52          assertNotNull( pomUrl );
53  
54          File pomFile = new File( pomUrl.getFile() );
55          found = pf.parsePom( pomFile );
56          assertTrue("pomFile not found pomUrl " + pomUrl + ", pomFile " + pomFile.getPath() , found );
57  
58          {
59              File foundPom = pf.findMatchingPom( pomFile.getParentFile() );
60              assertNotNull( foundPom );
61  
62              assertEquals( pomFile.getAbsolutePath(), foundPom.getAbsolutePath() );
63          }
64  
65          {
66              // try from 1 directory higher
67              File foundPom = pf.findMatchingPom( pomFile.getParentFile().getParentFile() );
68              assertNotNull( foundPom );
69  
70              assertEquals( pomFile.getAbsolutePath(), foundPom.getAbsolutePath() );
71          }
72      }
73  
74  }