View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.maven.continuum.execution.maven.m2;
20  
21  import java.io.File;
22  
23  import org.apache.maven.continuum.AbstractContinuumTest;
24  import org.apache.maven.continuum.project.builder.ContinuumProjectBuildingResult;
25  import org.apache.maven.project.MavenProject;
26  import org.codehaus.plexus.util.StringUtils;
27  import org.slf4j.Logger;
28  import org.slf4j.LoggerFactory;
29  
30  /**
31   * @author <a href="mailto:olamy@apache.org">olamy</a>
32   * @version $Id: TestMavenBuilderHelper.java 764863 2009-04-14 16:28:12Z evenisse $
33   * @since 6 juin 2008
34   */
35  public class TestMavenBuilderHelper
36      extends AbstractContinuumTest
37  {
38      private static final Logger log = LoggerFactory.getLogger( TestMavenBuilderHelper.class );
39  
40      public void testgetMavenProject()
41          throws Exception
42      {
43          MavenBuilderHelper mavenBuilderHelper = (MavenBuilderHelper) lookup( MavenBuilderHelper.ROLE, "default" );
44          ContinuumProjectBuildingResult result = new ContinuumProjectBuildingResult();
45          File file = new File( getBasedir(), "src/test-poms/pom.xml" );
46          MavenProject project = mavenBuilderHelper.getMavenProject( result, file );
47          assertNotNull( project );
48  
49          assertEquals( "plexus", project.getGroupId() );
50          assertEquals( "continuum-project2", project.getArtifactId() );
51          assertEquals( "This is a sample pom for test purposes", project.getDescription() );
52          assertNotNull( project.getScm() );
53          assertTrue( project.getDependencies().isEmpty() );
54          assertTrue( result.getErrors().isEmpty() );
55      }
56  
57      public void testgetMavenProjectMissingDeps()
58          throws Exception
59      {
60          MavenBuilderHelper mavenBuilderHelper = (MavenBuilderHelper) lookup( MavenBuilderHelper.ROLE, "default" );
61          ContinuumProjectBuildingResult result = new ContinuumProjectBuildingResult();
62          File file = new File( getBasedir(), "src/test-poms/pom-unknown-dependency.xml" );
63          mavenBuilderHelper.getMavenProject( result, file );
64          assertFalse( result.getErrors().isEmpty() );
65          String errorsAsString = result.getErrorsAsString();
66          assertFalse( StringUtils.isEmpty( errorsAsString ) );
67          log.info( "errorAsString " + errorsAsString );
68          assertTrue( errorsAsString.contains( "ghd:non-exists:pom:2.6.267676-beta-754-alpha-95" ) );
69          log.info( "errors " + result.getErrors() );
70      }
71  }