View Javadoc

1   package org.apache.maven.continuum.execution.maven.m2;
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.continuum.AbstractContinuumTest;
23  import org.apache.maven.continuum.project.builder.ContinuumProjectBuildingResult;
24  import org.apache.maven.project.MavenProject;
25  import org.codehaus.plexus.util.StringUtils;
26  import org.slf4j.Logger;
27  import org.slf4j.LoggerFactory;
28  
29  import java.io.File;
30  
31  /**
32   * @author <a href="mailto:olamy@apache.org">olamy</a>
33   * @version $Id: TestMavenBuilderHelper.java 1372267 2012-08-13 05:47:30Z brett $
34   * @since 6 juin 2008
35   */
36  public class TestMavenBuilderHelper
37      extends AbstractContinuumTest
38  {
39      private static final Logger log = LoggerFactory.getLogger( TestMavenBuilderHelper.class );
40  
41      public void testgetMavenProject()
42          throws Exception
43      {
44          MavenBuilderHelper mavenBuilderHelper = (MavenBuilderHelper) lookup( MavenBuilderHelper.ROLE, "default" );
45          ContinuumProjectBuildingResult result = new ContinuumProjectBuildingResult();
46          File file = new File( getBasedir(), "src/test-poms/pom.xml" );
47          MavenProject project = mavenBuilderHelper.getMavenProject( result, file );
48          assertNotNull( project );
49  
50          assertEquals( "plexus", project.getGroupId() );
51          assertEquals( "continuum-project2", project.getArtifactId() );
52          assertEquals( "This is a sample pom for test purposes", project.getDescription() );
53          assertNotNull( project.getScm() );
54          assertTrue( project.getDependencies().isEmpty() );
55          assertTrue( result.getErrors().isEmpty() );
56      }
57  
58      public void testgetMavenProjectMissingDeps()
59          throws Exception
60      {
61          MavenBuilderHelper mavenBuilderHelper = (MavenBuilderHelper) lookup( MavenBuilderHelper.ROLE, "default" );
62          ContinuumProjectBuildingResult result = new ContinuumProjectBuildingResult();
63          File file = new File( getBasedir(), "src/test-poms/pom-unknown-dependency.xml" );
64          mavenBuilderHelper.getMavenProject( result, file );
65          assertFalse( result.getErrors().isEmpty() );
66          String errorsAsString = result.getErrorsAsString();
67          assertFalse( StringUtils.isEmpty( errorsAsString ) );
68          log.info( "errorAsString " + errorsAsString );
69          assertTrue( errorsAsString.contains( "ghd:non-exists:pom:2.6.267676-beta-754-alpha-95" ) );
70          log.info( "errors " + result.getErrors() );
71      }
72  }