1 package org.apache.maven.continuum;
2
3 import org.apache.continuum.AbstractAddProjectTest;
4 import org.apache.maven.continuum.builddefinition.BuildDefinitionService;
5 import org.apache.maven.continuum.model.project.BuildDefinition;
6 import org.apache.maven.continuum.model.project.BuildDefinitionTemplate;
7 import org.apache.maven.continuum.model.project.Project;
8 import org.apache.maven.continuum.model.project.ProjectGroup;
9 import org.apache.maven.continuum.project.builder.ContinuumProjectBuildingResult;
10 import org.slf4j.Logger;
11 import org.slf4j.LoggerFactory;
12
13 import java.io.File;
14 import java.util.Collections;
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39 public class AddMaven2ProjectTest
40 extends AbstractAddProjectTest
41 {
42 protected final Logger log = LoggerFactory.getLogger( getClass() );
43
44 protected BuildDefinitionTemplate bdt;
45
46 protected BuildDefinition bd;
47
48 protected BuildDefinitionService bds;
49
50 @Override
51 protected void setUp()
52 throws Exception
53 {
54 super.setUp();
55 bd = new BuildDefinition();
56 bd.setGoals( "clean deploy" );
57 bd.setBuildFile( "pom.xml" );
58 bd.setDescription( "my foo" );
59 bd.setTemplate( true );
60 bds = (BuildDefinitionService) lookup( BuildDefinitionService.class.getName(),
61 "default" );
62 bd = bds.addBuildDefinition( bd );
63
64 assertEquals( 5, bds.getAllBuildDefinitions().size() );
65
66 bdt = new BuildDefinitionTemplate();
67 bdt.setName( "bdt foo" );
68
69 bdt = bds.addBuildDefinitionTemplate( bdt );
70
71 bdt = bds.addBuildDefinitionInTemplate( bdt, bd, false );
72
73 createLocalRepository();
74 }
75
76 public void testAddProjectToExistingGroupWithBuildDefTemplate()
77 throws Exception
78 {
79
80 ProjectGroup pg = new ProjectGroup();
81 pg.setName( "foo" );
82 pg.setDescription( "foo pg" );
83 getContinuum().addProjectGroup( pg );
84 pg = getContinuum().getAllProjectGroups().get( 1 );
85 assertEquals( 2, getContinuum().getAllProjectGroups().size() );
86 pg = getContinuum().getProjectGroupWithBuildDetails( pg.getId() );
87
88 assertEquals( 1, pg.getBuildDefinitions().size() );
89 assertEquals( "clean install", pg.getBuildDefinitions().get( 0 ).getGoals() );
90
91 File rootPom = getTestFile( "src/test/resources/projects/continuum/continuum-core/pom.xml" );
92
93 assertTrue( rootPom.exists() );
94
95 ContinuumProjectBuildingResult result = getContinuum().addMavenTwoProject(
96 rootPom.toURI().toURL().toExternalForm(), pg.getId(), true, false, false, bdt.getId(), false );
97 assertNotNull( result );
98
99 assertEquals( Collections.emptyList(), result.getErrors() );
100
101 assertEquals( 1, result.getProjects().size() );
102
103 Project project = result.getProjects().get( 0 );
104 project = getContinuum().getProjectWithBuildDetails( project.getId() );
105 assertNotNull( project );
106 log.info( "project buildDef list size : " + project.getBuildDefinitions().size() );
107 assertEquals( 1, project.getBuildDefinitions().size() );
108
109 assertEquals( "clean deploy", project.getBuildDefinitions().get( 0 ).getGoals() );
110 }
111
112 public void testAddProjectWithGroupCreationWithBuildDefTemplate()
113 throws Exception
114 {
115
116
117 File rootPom = getTestFile( "src/test/resources/projects/continuum/continuum-core/pom.xml" );
118
119 assertTrue( rootPom.exists() );
120
121 ContinuumProjectBuildingResult result = getContinuum().addMavenTwoProject(
122 rootPom.toURI().toURL().toExternalForm(), -1, true, false, true, bdt.getId(), false );
123 assertNotNull( result );
124
125 assertEquals( Collections.emptyList(), result.getErrors() );
126
127 assertEquals( 1, result.getProjects().size() );
128 Project project = result.getProjects().get( 0 );
129 assertNotNull( project );
130 project = getContinuum().getProjectWithBuildDetails( project.getId() );
131 log.info( "project buildDef list size : " + project.getBuildDefinitions().size() );
132
133 assertEquals( 0, project.getBuildDefinitions().size() );
134
135 log.info( "all pg size " + getContinuum().getAllProjectGroups().size() );
136 ProjectGroup pg = result.getProjectGroups().get( 0 );
137
138 pg = getContinuum().getProjectGroupWithBuildDetails( pg.getId() );
139
140 log.info( " pg groupId " + pg.getGroupId() );
141
142 log.info( " pg builddefs size " + pg.getBuildDefinitions().size() );
143 log.info( "pg bd goals " + ( (BuildDefinition) pg.getBuildDefinitions().get( 0 ) ).getGoals() );
144 assertEquals( "clean deploy", ( (BuildDefinition) pg.getBuildDefinitions().get( 0 ) ).getGoals() );
145
146 }
147
148 public void testAddProjectWithGroupCreationDefaultBuildDef()
149 throws Exception
150 {
151
152
153 File rootPom = getTestFile( "src/test/resources/projects/continuum/continuum-core/pom.xml" );
154
155 assertTrue( rootPom.exists() );
156
157 ContinuumProjectBuildingResult result = getContinuum().addMavenTwoProject(
158 rootPom.toURI().toURL().toExternalForm(), -1, true, false, true, -1, false );
159 assertNotNull( result );
160
161 assertEquals( Collections.emptyList(), result.getErrors() );
162
163 assertEquals( 1, result.getProjects().size() );
164
165 Project project = result.getProjects().get( 0 );
166 assertNotNull( project );
167
168 assertNotNull( project );
169 project = getContinuum().getProjectWithBuildDetails( project.getId() );
170 log.info( "project buildDef list size : " + project.getBuildDefinitions().size() );
171
172 assertEquals( 0, project.getBuildDefinitions().size() );
173
174 log.info( "all pg size " + getContinuum().getAllProjectGroups().size() );
175 ProjectGroup pg = result.getProjectGroups().get( 0 );
176
177 log.info( getContinuum().getAllProjectGroups().toString() );
178 log.info( " pg id " + Integer.toString( pg.getId() ) );
179
180 pg = getContinuum().getProjectGroupWithBuildDetails( pg.getId() );
181
182
183 assertEquals( "clean install", pg.getBuildDefinitions().get( 0 ).getGoals() );
184
185 }
186
187 public void testAddProjectToExistingGroupDefaultBuildDef()
188 throws Exception
189 {
190 ProjectGroup pg = new ProjectGroup();
191 String groupId = "foo";
192 pg.setName( groupId );
193 pg.setGroupId( groupId );
194 pg.setDescription( "foo pg" );
195 getContinuum().addProjectGroup( pg );
196 pg = getContinuum().getProjectGroupByGroupIdWithBuildDetails( groupId );
197
198 assertEquals( 1, pg.getBuildDefinitions().size() );
199 BuildDefinition buildDefinition = pg.getBuildDefinitions().get( 0 );
200 assertEquals( "clean install", buildDefinition.getGoals() );
201 assertEquals( "--batch-mode --non-recursive", buildDefinition.getArguments() );
202
203 File rootPom = getTestFile( "src/test/resources/projects/continuum/continuum-core/pom.xml" );
204
205 assertTrue( rootPom.exists() );
206
207 ContinuumProjectBuildingResult result = getContinuum().addMavenTwoProject(
208 rootPom.toURI().toURL().toExternalForm(), pg.getId(), true, false, false, -1, false );
209 assertNotNull( result );
210
211 assertEquals( Collections.emptyList(), result.getErrors() );
212
213 assertEquals( 1, result.getProjects().size() );
214
215 Project project = result.getProjects().get( 0 );
216 project = getContinuum().getProjectWithBuildDetails( project.getId() );
217 assertNotNull( project );
218 assertEquals( 1, project.getBuildDefinitions().size() );
219
220 buildDefinition = project.getBuildDefinitions().get( 0 );
221 assertEquals( "clean install", buildDefinition.getGoals() );
222 assertEquals( "--batch-mode", buildDefinition.getArguments() );
223 }
224
225 public void testAddProjectToExistingGroupMatchingBuildDef()
226 throws Exception
227 {
228 ProjectGroup pg = new ProjectGroup();
229 String groupId = "testAddProjectToExistingGroupMatchingBuildDef";
230 pg.setName( groupId );
231 pg.setGroupId( groupId );
232 pg.setDescription( "foo pg" );
233 getContinuum().addProjectGroup( pg );
234 pg = getContinuum().getProjectGroupByGroupIdWithBuildDetails( groupId );
235
236 assertEquals( 1, pg.getBuildDefinitions().size() );
237 BuildDefinition buildDefinition = pg.getBuildDefinitions().get( 0 );
238 buildDefinition.setArguments( "--batch-mode" );
239 bds.updateBuildDefinition( buildDefinition );
240
241 pg = getContinuum().getProjectGroupByGroupIdWithBuildDetails( groupId );
242 buildDefinition = pg.getBuildDefinitions().get( 0 );
243 assertEquals( "clean install", buildDefinition.getGoals() );
244 assertEquals( "--batch-mode", buildDefinition.getArguments() );
245
246 File rootPom = getTestFile( "src/test/resources/projects/continuum/continuum-core/pom.xml" );
247
248 assertTrue( rootPom.exists() );
249
250 ContinuumProjectBuildingResult result = getContinuum().addMavenTwoProject(
251 rootPom.toURI().toURL().toExternalForm(), pg.getId(), true, false, false, -1, false );
252 assertNotNull( result );
253
254 assertEquals( Collections.emptyList(), result.getErrors() );
255
256 assertEquals( 1, result.getProjects().size() );
257
258 Project project = result.getProjects().get( 0 );
259 project = getContinuum().getProjectWithBuildDetails( project.getId() );
260 assertNotNull( project );
261 assertEquals( 0, project.getBuildDefinitions().size() );
262 }
263
264 private Continuum getContinuum()
265 throws Exception
266 {
267 return (Continuum) lookup( Continuum.ROLE );
268 }
269
270 @Override
271 protected String getPlexusConfigLocation()
272 {
273 return "org/apache/maven/continuum/DefaultContinuumTest.xml";
274 }
275
276 @Override
277 protected String getSpringConfigLocation()
278 {
279 return "applicationContextSlf4jPlexusLogger.xml";
280 }
281
282
283 }