View Javadoc

1   package org.apache.maven.continuum;
2   
3   import java.io.File;
4   
5   import org.apache.maven.continuum.builddefinition.BuildDefinitionService;
6   import org.apache.maven.continuum.model.project.BuildDefinition;
7   import org.apache.maven.continuum.model.project.BuildDefinitionTemplate;
8   import org.apache.maven.continuum.model.project.Project;
9   import org.apache.maven.continuum.model.project.ProjectGroup;
10  import org.apache.maven.continuum.project.builder.ContinuumProjectBuildingResult;
11  import org.slf4j.Logger;
12  import org.slf4j.LoggerFactory;
13  
14  /*
15   * Licensed to the Apache Software Foundation (ASF) under one
16   * or more contributor license agreements.  See the NOTICE file
17   * distributed with this work for additional information
18   * regarding copyright ownership.  The ASF licenses this file
19   * to you under the Apache License, Version 2.0 (the
20   * "License"); you may not use this file except in compliance
21   * with the License.  You may obtain a copy of the License at
22   *
23   *   http://www.apache.org/licenses/LICENSE-2.0
24   *
25   * Unless required by applicable law or agreed to in writing,
26   * software distributed under the License is distributed on an
27   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
28   * KIND, either express or implied.  See the License for the
29   * specific language governing permissions and limitations
30   * under the License.
31   */
32  /**
33   * @author olamy
34   * @since 
35   * @version $Id: AddMaven2ProjectTest.java 764863 2009-04-14 16:28:12Z evenisse $
36   */
37  public class AddMaven2ProjectTest
38      extends AbstractContinuumTest
39  {
40      protected final Logger log = LoggerFactory.getLogger( getClass() );
41  
42      protected BuildDefinitionTemplate bdt;
43  
44      protected BuildDefinition bd;
45      
46      @Override
47      protected void setUp()
48          throws Exception
49      {
50          super.setUp();
51          bd = new BuildDefinition();
52          bd.setGoals( "clean deploy" );
53          bd.setBuildFile( "pom.xml" );
54          bd.setDescription( "my foo" );
55          bd.setTemplate( true );
56          BuildDefinitionService bds = (BuildDefinitionService) lookup( BuildDefinitionService.class.getName(), "default" );
57          bd = bds.addBuildDefinition( bd );
58          
59          
60          assertEquals( 5, bds.getAllBuildDefinitions().size() );
61  
62          bdt = new BuildDefinitionTemplate();
63          bdt.setName( "bdt foo" );
64          
65          bdt = bds.addBuildDefinitionTemplate( bdt );
66          
67          bdt = bds.addBuildDefinitionInTemplate( bdt, bd, false );        
68      }    
69      
70      
71      
72      public void testAddProjectToExistingGroupWithBuildDefTemplate()
73          throws Exception
74      {
75  
76          ProjectGroup pg = new ProjectGroup();
77          pg.setName( "foo" );
78          pg.setDescription( "foo pg" );
79          getContinuum().addProjectGroup( pg );
80          pg = getContinuum().getAllProjectGroups().get( 1 );
81          assertEquals( 2, getContinuum().getAllProjectGroups().size() );
82          pg = getContinuum().getProjectGroupWithBuildDetails( pg.getId() );
83          // group created with the m2 default build def 
84          assertEquals( 1, pg.getBuildDefinitions().size() );
85          
86  
87          File rootPom = getTestFile( "src/test/resources/projects/continuum/continuum-core/pom.xml" );
88  
89          assertTrue( rootPom.exists() );
90          //String url = getTestFile( "src/test-projects/project1/pom.xml" ).toURL().toExternalForm();
91          ContinuumProjectBuildingResult result = getContinuum().addMavenTwoProject(
92                                                                                     rootPom.toURI().toURL()
93                                                                                         .toExternalForm(), pg.getId(),
94                                                                                     true, false, false, bdt.getId() );
95          assertNotNull( result );
96  
97          assertEquals( 1, result.getProjects().size() );
98  
99          Project project = result.getProjects().get( 0 );
100         project = getContinuum().getProjectWithBuildDetails( project.getId() );
101         assertNotNull( project );
102         pg = getContinuum().getProjectGroupWithBuildDetails( pg.getId() );
103         log.info( "project buildDef list size : " + project.getBuildDefinitions().size() );
104         // project with the build def coming from template
105         assertEquals( 1, project.getBuildDefinitions().size() );
106         assertEquals( "clean deploy", ( (BuildDefinition) project.getBuildDefinitions().get( 0 ) ).getGoals() );
107     }
108     
109     public void testAddProjectWithGroupCreationWithBuildDefTemplate()
110         throws Exception
111     {
112 
113         //bdt = bds.addBuildDefinitionInTemplate( bdt, bd, true );
114         File rootPom = getTestFile( "src/test/resources/projects/continuum/continuum-core/pom.xml" );
115 
116         assertTrue( rootPom.exists() );
117 
118         ContinuumProjectBuildingResult result = getContinuum().addMavenTwoProject(
119                                                                                    rootPom.toURI().toURL()
120                                                                                        .toExternalForm(), -1, true,
121                                                                                    false, true, bdt.getId() );
122         assertNotNull( result );
123 
124         assertEquals( 1, result.getProjects().size() );
125         Project project = result.getProjects().get( 0 );
126         assertNotNull( project );
127         project = getContinuum().getProjectWithBuildDetails( project.getId() );
128         log.info( "project buildDef list size : " + project.getBuildDefinitions().size() );
129         // build def only at the group level du to group creation 
130         assertEquals( 0, project.getBuildDefinitions().size() );
131         
132         log.info( "all pg size " + getContinuum().getAllProjectGroups().size() );
133         ProjectGroup pg = result.getProjectGroups().get( 0 );
134 
135         pg = getContinuum().getProjectGroupWithBuildDetails( pg.getId() );
136 
137         log.info( " pg groupId " + pg.getGroupId() );
138         //@ group level the db from template must be used
139         log.info( " pg builddefs size " + pg.getBuildDefinitions().size() );
140         log.info( "pg bd goals " + ( (BuildDefinition) pg.getBuildDefinitions().get( 0 ) ).getGoals() );
141         assertEquals( "clean deploy", ( (BuildDefinition) pg.getBuildDefinitions().get( 0 ) ).getGoals() );
142         
143     }    
144     
145     public void testAddProjectWithGroupCreationDefaultBuildDef()
146         throws Exception
147     {
148 
149         //bdt = bds.addBuildDefinitionInTemplate( bdt, bd, true );
150         File rootPom = getTestFile( "src/test/resources/projects/continuum/continuum-core/pom.xml" );
151 
152         assertTrue( rootPom.exists() );
153 
154         ContinuumProjectBuildingResult result = getContinuum().addMavenTwoProject(
155                                                                                    rootPom.toURI().toURL()
156                                                                                        .toExternalForm(), -1, true,
157                                                                                    false, true, -1 );
158         assertNotNull( result );
159 
160         assertEquals( 1, result.getProjects().size() );
161 
162         Project project = result.getProjects().get( 0 );
163         assertNotNull( project );
164         
165         assertNotNull( project );
166         project = getContinuum().getProjectWithBuildDetails( project.getId() );
167         log.info( "project buildDef list size : " + project.getBuildDefinitions().size() );
168         // only build def at group level
169         assertEquals( 0, project.getBuildDefinitions().size() );
170         
171         log.info( "all pg size " + getContinuum().getAllProjectGroups().size() );
172         ProjectGroup pg = result.getProjectGroups().get( 0 );
173 
174         log.info( getContinuum().getAllProjectGroups().toString() );
175         log.info( " pg id " + Integer.toString( pg.getId() ) );
176 
177         pg = getContinuum().getProjectGroupWithBuildDetails( pg.getId() );
178 
179         log.info( " pg groupId " + pg.getGroupId() );
180         //@ group level the db from template must be used
181         log.info( " mg builddefs size " + pg.getBuildDefinitions().size() );
182         log.info( "pg bd goals " + ( (BuildDefinition) pg.getBuildDefinitions().get( 0 ) ).getGoals() );
183         assertEquals( "clean install", ( (BuildDefinition) pg.getBuildDefinitions().get( 0 ) ).getGoals() );
184 
185     }       
186 
187     public void testAddProjectToExistingGroupDefaultBuildDef()
188         throws Exception
189     {
190 
191         ProjectGroup pg = new ProjectGroup();
192         pg.setName( "foo" );
193         pg.setDescription( "foo pg" );
194         getContinuum().addProjectGroup( pg );
195         pg = getContinuum().getAllProjectGroups().get( 1 );
196         assertEquals( 2, getContinuum().getAllProjectGroups().size() );
197 
198         File rootPom = getTestFile( "src/test/resources/projects/continuum/continuum-core/pom.xml" );
199 
200         assertTrue( rootPom.exists() );
201         //String url = getTestFile( "src/test-projects/project1/pom.xml" ).toURL().toExternalForm();
202         ContinuumProjectBuildingResult result = getContinuum().addMavenTwoProject(
203                                                                                    rootPom.toURI().toURL()
204                                                                                        .toExternalForm(), pg.getId(),
205                                                                                    true, false, false, -1 );
206         assertNotNull( result );
207 
208         assertEquals( 1, result.getProjects().size() );
209 
210         Project project = result.getProjects().get( 0 );
211         project = getContinuum().getProjectWithBuildDetails( project.getId() );
212         assertNotNull( project );
213         pg = getContinuum().getProjectGroupWithBuildDetails( pg.getId() );
214         log.info( "project buildDef list size : " + project.getBuildDefinitions().size() );
215         assertEquals( 0, project.getBuildDefinitions().size() );
216         pg = result.getProjectGroups().get( 0 );
217 
218         pg = getContinuum().getProjectGroupWithBuildDetails( pg.getId() );
219         
220         assertEquals( "clean install", ( (BuildDefinition) pg.getBuildDefinitions().get( 0 ) ).getGoals() );
221     }
222     
223     
224     private Continuum getContinuum()
225         throws Exception
226     {
227         return (Continuum) lookup( Continuum.ROLE );
228     }
229 
230     @Override
231     protected String getPlexusConfigLocation()
232     {
233         return "org/apache/maven/continuum/DefaultContinuumTest.xml";
234     }
235 
236     @Override
237     protected String getSpringConfigLocation()
238     {
239         return "applicationContextSlf4jPlexusLogger.xml";
240     }    
241     
242     
243 }