View Javadoc

1   package org.apache.maven.continuum.project.builder.maven;
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.builddefinition.BuildDefinitionService;
24  import org.apache.maven.continuum.execution.ContinuumBuildExecutorConstants;
25  import org.apache.maven.continuum.model.project.BuildDefinition;
26  import org.apache.maven.continuum.model.project.BuildDefinitionTemplate;
27  import org.apache.maven.continuum.model.project.Project;
28  import org.apache.maven.continuum.model.project.ProjectNotifier;
29  import org.apache.maven.continuum.project.builder.ContinuumProjectBuilder;
30  import org.apache.maven.continuum.project.builder.ContinuumProjectBuildingResult;
31  
32  /**
33   * @author <a href="mailto:trygvis@inamo.no">Trygve Laugst&oslash;l</a>
34   * @version $Id: MavenOneContinuumProjectBuilderTest.java 1372260 2012-08-13 04:29:09Z brett $
35   */
36  public class MavenOneContinuumProjectBuilderTest
37      extends AbstractContinuumTest
38  {
39      public void testBuildingAProjectFromMetadataWithACompleteMaven1Pom()
40          throws Exception
41      {
42          ContinuumProjectBuilder projectBuilder = (ContinuumProjectBuilder) lookup( ContinuumProjectBuilder.ROLE,
43                                                                                     MavenOneContinuumProjectBuilder.ID );
44  
45          BuildDefinition bd = new BuildDefinition();
46  
47          bd.setDefaultForProject( true );
48  
49          bd.setGoals( "clean:clean jar:install" );
50  
51          bd.setBuildFile( "project.xml" );
52  
53          bd.setType( ContinuumBuildExecutorConstants.MAVEN_ONE_BUILD_EXECUTOR );
54  
55          bd.setTemplate( true );
56  
57          BuildDefinitionService service = (BuildDefinitionService) lookup( BuildDefinitionService.class );
58  
59          BuildDefinitionTemplate bdt = new BuildDefinitionTemplate();
60          bdt.setName( "maven1" );
61          bd = service.addBuildDefinition( bd );
62          bdt = service.addBuildDefinitionTemplate( bdt );
63          bdt = service.addBuildDefinitionInTemplate( bdt, bd, false );
64  
65          ContinuumProjectBuildingResult result = projectBuilder.buildProjectsFromMetadata( getTestFile(
66              "src/test/resources/projects/maven-1.pom.xml" ).toURL(), null, null, false, bdt, false );
67  
68          assertOnResult( result );
69  
70      }
71  
72      public void testBuildingAProjectFromMetadataWithACompleteMaven1PomWithDefaultBuildDef()
73          throws Exception
74      {
75          ContinuumProjectBuilder projectBuilder = (ContinuumProjectBuilder) lookup( ContinuumProjectBuilder.ROLE,
76                                                                                     MavenOneContinuumProjectBuilder.ID );
77  
78          BuildDefinitionService service = (BuildDefinitionService) lookup( BuildDefinitionService.class );
79  
80          ContinuumProjectBuildingResult result = projectBuilder.buildProjectsFromMetadata( getTestFile(
81              "src/test/resources/projects/maven-1.pom.xml" ).toURL(), null, null, false,
82                                                                                            service.getDefaultMavenOneBuildDefinitionTemplate(),
83                                                                                            false );
84  
85          assertOnResult( result );
86  
87      }
88  
89      protected void assertOnResult( ContinuumProjectBuildingResult result )
90      {
91          assertNotNull( result.getErrors() );
92  
93          assertNotNull( result.getProjects() );
94  
95          for ( String error : result.getErrors() )
96          {
97              System.err.println( error );
98          }
99  
100         assertEquals( "result.warning.length", 0, result.getErrors().size() );
101 
102         assertEquals( "result.projects.length", 1, result.getProjects().size() );
103 
104         Project project = result.getProjects().get( 0 );
105 
106         assertNotNull( project );
107 
108         assertEquals( "Maven", project.getName() );
109 
110         assertEquals( "Java Project Management Tools", project.getDescription() );
111 
112         assertEquals( "scm:svn:http://svn.apache.org/repos/asf:maven/maven-1/core/trunk/", project.getScmUrl() );
113 
114         ProjectNotifier notifier = (ProjectNotifier) project.getNotifiers().get( 0 );
115 
116         assertEquals( "mail", notifier.getType() );
117 
118         assertEquals( "dev@maven.apache.org", notifier.getConfiguration().get( "address" ) );
119 
120         assertEquals( "1.1-SNAPSHOT", project.getVersion() );
121     }
122 }