1 package org.apache.maven.continuum.execution.maven.m1;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import org.apache.maven.continuum.AbstractContinuumTest;
23 import org.apache.maven.continuum.execution.manager.BuildExecutorManager;
24 import org.apache.maven.continuum.model.project.Project;
25 import org.apache.maven.continuum.model.project.ProjectNotifier;
26 import org.codehaus.plexus.util.FileUtils;
27
28 import java.io.File;
29 import java.util.ArrayList;
30 import java.util.List;
31 import java.util.Properties;
32
33
34
35
36
37 public class MavenOneBuildExecutorTest
38 extends AbstractContinuumTest
39 {
40 private File checkOut;
41
42 private MavenOneBuildExecutor executor;
43
44 protected void setUp()
45 throws Exception
46 {
47 super.setUp();
48
49 BuildExecutorManager builderManager = (BuildExecutorManager) lookup( BuildExecutorManager.ROLE );
50
51 executor = (MavenOneBuildExecutor) builderManager.getBuildExecutor( MavenOneBuildExecutor.ID );
52
53
54
55
56
57 checkOut = getTestFile( "target/test-checkout" );
58
59 if ( !checkOut.exists() )
60 {
61 assertTrue( checkOut.mkdirs() );
62 }
63
64 FileUtils.cleanDirectory( checkOut );
65
66 }
67
68 public void testUpdatingAProjectFromScmWithAExistingProjectAndAEmptyMaven1Pom()
69 throws Exception
70 {
71 FileUtils.fileWrite( new File( checkOut, "project.xml" ).getAbsolutePath(), "<project/>" );
72
73
74
75
76
77 Project project = new Project();
78
79 project.setName( "Maven" );
80
81 project.setGroupId( "org.apache.maven" );
82
83 project.setArtifactId( "maven" );
84
85 project.setScmUrl( "scm:svn:http://svn.apache.org/repos/asf:maven/maven-1/core/trunk/" );
86
87 ProjectNotifier notifier = new ProjectNotifier();
88
89 Properties props = new Properties();
90
91 props.put( "address", "dev@maven.apache.org" );
92
93 notifier.setConfiguration( props );
94
95 notifier.setFrom( ProjectNotifier.FROM_USER );
96
97 List<ProjectNotifier> notifiers = new ArrayList<ProjectNotifier>();
98
99 notifiers.add( notifier );
100
101 project.setNotifiers( notifiers );
102
103 project.setVersion( "1.1-SNAPSHOT" );
104
105
106
107
108
109 executor.updateProjectFromCheckOut( checkOut, project, null, null );
110
111
112
113
114
115 assertNotNull( project );
116
117 assertEquals( "Maven", project.getName() );
118
119 assertEquals( "scm:svn:http://svn.apache.org/repos/asf:maven/maven-1/core/trunk/", project.getScmUrl() );
120
121 ProjectNotifier actualNotifier = (ProjectNotifier) project.getNotifiers().get( 0 );
122
123 assertEquals( "dev@maven.apache.org", actualNotifier.getConfiguration().get( "address" ) );
124
125 assertEquals( "1.1-SNAPSHOT", project.getVersion() );
126 }
127
128 public void testUpdatingAProjectWithNagEMailAddress()
129 throws Exception
130 {
131 FileUtils.fileWrite( new File( checkOut, "project.xml" ).getAbsolutePath(),
132 "<project><build><nagEmailAddress>myuser@myhost.org</nagEmailAddress></build></project>" );
133
134
135
136
137
138 Project project = new Project();
139
140 project.setName( "Maven" );
141
142 project.setGroupId( "org.apache.maven" );
143
144 project.setArtifactId( "maven" );
145
146 project.setScmUrl( "scm:svn:http://svn.apache.org/repos/asf:maven/maven-1/core/trunk/" );
147
148 project.setVersion( "1.1-SNAPSHOT" );
149
150
151
152
153
154 executor.updateProjectFromCheckOut( checkOut, project, null, null );
155
156
157
158
159
160 assertNotNull( project );
161
162 assertEquals( "Maven", project.getName() );
163
164 assertEquals( 1, project.getNotifiers().size() );
165
166 ProjectNotifier actualNotifier = (ProjectNotifier) project.getNotifiers().get( 0 );
167
168 assertEquals( "myuser@myhost.org", actualNotifier.getConfiguration().get( "address" ) );
169
170
171
172
173
174 executor.updateProjectFromCheckOut( checkOut, project, null, null );
175
176
177
178
179
180 assertEquals( 1, project.getNotifiers().size() );
181
182 actualNotifier = (ProjectNotifier) project.getNotifiers().get( 0 );
183
184 assertEquals( "myuser@myhost.org", actualNotifier.getConfiguration().get( "address" ) );
185 }
186
187 public void testUpdatingAProjectWithNagEMailAddressAndOneNotifier()
188 throws Exception
189 {
190 FileUtils.fileWrite( new File( checkOut, "project.xml" ).getAbsolutePath(),
191 "<project><build><nagEmailAddress>myuser@myhost.org</nagEmailAddress></build></project>" );
192
193
194
195
196
197 Project project = new Project();
198
199 project.setName( "Maven" );
200
201 project.setGroupId( "org.apache.maven" );
202
203 project.setArtifactId( "maven" );
204
205 project.setScmUrl( "scm:svn:http://svn.apache.org/repos/asf:maven/maven-1/core/trunk/" );
206
207 ProjectNotifier notifier = new ProjectNotifier();
208
209 Properties props = new Properties();
210
211 props.put( "address", "dev@maven.apache.org" );
212
213 notifier.setConfiguration( props );
214
215 notifier.setFrom( ProjectNotifier.FROM_USER );
216
217 List<ProjectNotifier> notifiers = new ArrayList<ProjectNotifier>();
218
219 notifiers.add( notifier );
220
221 project.setNotifiers( notifiers );
222
223 project.setVersion( "1.1-SNAPSHOT" );
224
225
226
227
228
229 executor.updateProjectFromCheckOut( checkOut, project, null, null );
230
231
232
233
234
235 assertNotNull( project );
236
237 assertEquals( "Maven", project.getName() );
238
239 assertEquals( 2, project.getNotifiers().size() );
240
241 ProjectNotifier actualNotifier = (ProjectNotifier) project.getNotifiers().get( 0 );
242
243 assertEquals( "myuser@myhost.org", actualNotifier.getConfiguration().get( "address" ) );
244
245 actualNotifier = (ProjectNotifier) project.getNotifiers().get( 1 );
246
247 assertEquals( "dev@maven.apache.org", actualNotifier.getConfiguration().get( "address" ) );
248
249
250
251
252
253 executor.updateProjectFromCheckOut( checkOut, project, null, null );
254
255
256
257
258
259 assertEquals( 2, project.getNotifiers().size() );
260
261 actualNotifier = (ProjectNotifier) project.getNotifiers().get( 0 );
262
263 assertEquals( "myuser@myhost.org", actualNotifier.getConfiguration().get( "address" ) );
264
265 actualNotifier = (ProjectNotifier) project.getNotifiers().get( 1 );
266
267 assertEquals( "dev@maven.apache.org", actualNotifier.getConfiguration().get( "address" ) );
268 }
269
270 public void testUpdatingAProjectWithOneNotifier()
271 throws Exception
272 {
273 FileUtils.fileWrite( new File( checkOut, "project.xml" ).getAbsolutePath(), "<project/>" );
274
275
276
277
278
279 Project project = new Project();
280
281 project.setName( "Maven" );
282
283 project.setGroupId( "org.apache.maven" );
284
285 project.setArtifactId( "maven" );
286
287 project.setScmUrl( "scm:svn:http://svn.apache.org/repos/asf:maven/maven-1/core/trunk/" );
288
289 ProjectNotifier notifier = new ProjectNotifier();
290
291 Properties props = new Properties();
292
293 props.put( "address", "dev@maven.apache.org" );
294
295 notifier.setConfiguration( props );
296
297 notifier.setFrom( ProjectNotifier.FROM_USER );
298
299 List<ProjectNotifier> notifiers = new ArrayList<ProjectNotifier>();
300
301 notifiers.add( notifier );
302
303 project.setNotifiers( notifiers );
304
305 project.setVersion( "1.1-SNAPSHOT" );
306
307
308
309
310
311 executor.updateProjectFromCheckOut( checkOut, project, null, null );
312
313
314
315
316
317 assertNotNull( project );
318
319 assertEquals( "Maven", project.getName() );
320
321 assertEquals( 1, project.getNotifiers().size() );
322
323 ProjectNotifier actualNotifier = (ProjectNotifier) project.getNotifiers().get( 0 );
324
325 assertEquals( "dev@maven.apache.org", actualNotifier.getConfiguration().get( "address" ) );
326
327
328
329
330
331 executor.updateProjectFromCheckOut( checkOut, project, null, null );
332
333
334
335
336
337 assertEquals( 1, project.getNotifiers().size() );
338
339 actualNotifier = (ProjectNotifier) project.getNotifiers().get( 0 );
340
341 assertEquals( "dev@maven.apache.org", actualNotifier.getConfiguration().get( "address" ) );
342 }
343 }