1 package org.apache.maven.scm.provider.accurev.command.changelog;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import static org.hamcrest.Matchers.is;
23 import static org.hamcrest.Matchers.isOneOf;
24 import static org.hamcrest.Matchers.not;
25 import static org.hamcrest.Matchers.notNullValue;
26 import static org.hamcrest.Matchers.nullValue;
27 import static org.junit.Assert.assertThat;
28 import static org.mockito.Matchers.any;
29 import static org.mockito.Matchers.eq;
30 import static org.mockito.Mockito.when;
31 import static org.apache.maven.scm.ChangeFileMatcher.changeFile;
32
33 import java.io.File;
34 import java.util.Arrays;
35 import java.util.Collections;
36 import java.util.Date;
37 import java.util.List;
38
39 import org.apache.maven.scm.ChangeFile;
40 import org.apache.maven.scm.ChangeSet;
41 import org.apache.maven.scm.CommandParameter;
42 import org.apache.maven.scm.CommandParameters;
43 import org.apache.maven.scm.ScmException;
44 import org.apache.maven.scm.ScmFileSet;
45 import org.apache.maven.scm.ScmRevision;
46 import org.apache.maven.scm.command.changelog.ChangeLogScmResult;
47 import org.apache.maven.scm.command.changelog.ChangeLogSet;
48 import org.apache.maven.scm.provider.accurev.FileDifference;
49 import org.apache.maven.scm.provider.accurev.Stream;
50 import org.apache.maven.scm.provider.accurev.Transaction;
51 import org.apache.maven.scm.provider.accurev.command.AbstractAccuRevCommandTest;
52 import org.junit.Test;
53
54 public class AccuRevChangeLogCommandTest
55 extends AbstractAccuRevCommandTest
56 {
57 @Test
58 public void testChangeLogBetweenStreamsUnsupported()
59 throws Exception
60 {
61 final ScmFileSet testFileSet = new ScmFileSet( new File( basedir, "project/dir" ) );
62
63 AccuRevChangeLogCommand command = new AccuRevChangeLogCommand( getLogger() );
64
65 CommandParameters params = new CommandParameters();
66 params.setScmVersion( CommandParameter.START_SCM_VERSION, new ScmRevision( "aStream/12" ) );
67 params.setScmVersion( CommandParameter.END_SCM_VERSION, new ScmRevision( "anotherStream/20" ) );
68
69 try
70 {
71 command.changelog( repo, testFileSet, params );
72 fail( "Expected accurev exception" );
73 }
74 catch ( ScmException e )
75 {
76
77 }
78 }
79
80 @Test
81 public void testChangeLogToNow()
82 throws Exception
83 {
84 final ScmFileSet testFileSet = new ScmFileSet( new File( basedir, "project/dir" ) );
85
86
87 List<Transaction> startTransaction = Collections.singletonList( new Transaction( 35L, new Date(), "sometran",
88 "anyone" ) );
89 when( accurev.history( "aStream", "12", null, 1, true, true ) ).thenReturn( startTransaction );
90
91
92 List<Transaction> endTransaction = Collections.singletonList( new Transaction( 42L, new Date(), "sometran",
93 "anyone" ) );
94 when( accurev.history( "aStream", "now", null, 1, true, true ) ).thenReturn( endTransaction );
95
96 Stream basisStream = new Stream( "aStream", 10, "myDepot", 1, "myDepot", getDate( 2008, 1, 1 ), "normal" );
97 when( accurev.showStream( "aStream" ) ).thenReturn( basisStream );
98
99 List<FileDifference> emptyList = Collections.emptyList();
100 when( accurev.diff( "myStream", "12", "42" ) ).thenReturn( emptyList );
101
102 List<Transaction> noTransactions = Collections.emptyList();
103 when( accurev.history( "aStream", "13", "42", 0, false, false ) ).thenReturn( noTransactions );
104
105 AccuRevChangeLogCommand command = new AccuRevChangeLogCommand( getLogger() );
106 CommandParameters params = new CommandParameters();
107 params.setScmVersion( CommandParameter.START_SCM_VERSION, new ScmRevision( "aStream/12" ) );
108
109 assertThat( command.changelog( repo, testFileSet, params ), not( nullValue() ) );
110
111 }
112
113 @Test
114 public void testStandardCase()
115 throws Exception
116 {
117
118
119
120 final ScmFileSet testFileSet = new ScmFileSet( new File( basedir, "project/dir" ) );
121
122
123
124
125
126
127
128
129
130
131 List<Transaction> startTransaction = Collections.singletonList( new Transaction( 35L, new Date(), "sometran",
132 "anyone" ) );
133 when( accurev.history( "myStream", "2009/01/01 10:00:00", null, 1, true, true ) ).thenReturn( startTransaction );
134
135
136 List<Transaction> endTransaction = Collections.singletonList( new Transaction( 42L, new Date(), "sometran",
137 "anyone" ) );
138
139 Stream basisStream = new Stream( "myStream", 10, "myDepot", 1, "myDepot", getDate( 2008, 1, 1 ), "normal" );
140 when( accurev.showStream( "myStream" ) ).thenReturn( basisStream );
141
142 when( accurev.history( "myStream", "2009/01/12 13:00:00", null, 1, true, true ) ).thenReturn( endTransaction );
143
144
145 FileDifference promoted = new FileDifference( 10L, "/promoted/file", "4/2", "/promoted/file", "6/1" );
146 FileDifference removed = new FileDifference( 20L, null, null, "/removed/file", "6/1" );
147 FileDifference created = new FileDifference( 30L, "/created/file", "6/1", null, null );
148 FileDifference moved = new FileDifference( 40L, "/moved/to", "4/2", "/moved/from", "6/1" );
149
150 when( accurev.diff( "myStream", "35", "42" ) ).thenReturn( Arrays.asList( promoted, removed, created, moved ) );
151
152
153
154
155 final Date dateFrom = getDate( 2009, 0, 1, 10, 0, 0, null );
156 final Date dateTo = getDate( 2009, 0, 12, 13, 0, 0, null );
157 final Date keepWhen = getDate( 2009, 0, 2, 9, 0, 0, null );
158 final Date promoteWhen = getDate( 2009, 0, 4, 23, 0, 0, null );
159
160 final Transaction promoteOne = new Transaction( 10L, keepWhen, "promote", "aUser" );
161 promoteOne.addVersion( 5L, "/./kept/file", "10/5", "5/5", "3/2" );
162 promoteOne.setComment( "a Comment" );
163
164 final Transaction promoteTwo = new Transaction( 12L, promoteWhen, "promote", "anOther" );
165 promoteTwo.addVersion( 10L, "/./promoted/file", "10/5", "4/2", null );
166 promoteTwo.setComment( "my Promotion" );
167
168 when( accurev.history( "myStream", "36", "42", 0, false, false ) ).thenReturn( Arrays.asList( promoteOne,
169 promoteTwo ) );
170
171 AccuRevChangeLogCommand command = new AccuRevChangeLogCommand( getLogger() );
172
173 CommandParameters commandParameters = new CommandParameters();
174 commandParameters.setString( CommandParameter.MESSAGE, "A commit message" );
175 commandParameters.setDate( CommandParameter.START_DATE, dateFrom );
176 commandParameters.setDate( CommandParameter.END_DATE, dateTo );
177 ChangeLogScmResult result = command.changelog( repo, testFileSet, commandParameters );
178
179 assertThat( result.isSuccess(), is( true ) );
180 List<ChangeSet> changeSets = result.getChangeLog().getChangeSets();
181 assertThat( changeSets.size(), is( 3 ) );
182 ChangeSet cs = (ChangeSet) changeSets.get( 0 );
183 assertThat( cs.getAuthor(), is( "aUser" ) );
184 assertThat( cs.getComment(), is( "a Comment" ) );
185 assertThat( cs.getDate(), is( keepWhen ) );
186 assertThat( cs.getFiles().size(), is( 1 ) );
187 ChangeFile cf = (ChangeFile) cs.getFiles().get( 0 );
188
189 assertThat( cf.getName(), is( "/./kept/file" ) );
190 assertThat( cf.getRevision(), is( "10/5 (5/5)" ) );
191
192 cs = (ChangeSet) changeSets.get( 2 );
193 assertThat( cs.getAuthor(), is( "various" ) );
194
195
196 assertThat( cs.getComment(), is( "Upstream changes" ) );
197 assertThat( cs.getFiles().size(), is( 3 ) );
198 assertThat( cs.containsFilename( "created/file" ), is( true ) );
199 }
200
201 @Test
202 public void testWorkspaceChangelog()
203 throws Exception
204 {
205
206 final ScmFileSet testFileSet = new ScmFileSet( new File( basedir, "project/dir" ) );
207 final Date keepWhen = getDate( 2009, 0, 2, 9, 0, 0, null );
208 final Date promoteWhen = getDate( 2009, 0, 4, 23, 0, 0, null );
209 final Date fromDate = getDate( 2009, 0, 1, 0, 0, 0, null );
210 final Date toDate = getDate( 2009, 0, 5, 1, 0, 0, null );
211
212
213 List<Transaction> startTransaction = Collections.singletonList( new Transaction( 35L, fromDate, "sometran",
214 "anyone" ) );
215 when( accurev.history( "workspace5", "35", null, 1, true, true ) ).thenReturn( startTransaction );
216
217
218 List<Transaction> endTransaction = Collections.singletonList( new Transaction( 42L, toDate, "sometran",
219 "anyone" ) );
220
221 when( accurev.history( "workspace5", "42", null, 1, true, true ) ).thenReturn( endTransaction );
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243 Stream workspaceStream = new Stream( "workspace5", 5, "stream4", 4, "myDepot", getDate( 2008, 10, 1, 10, 0, 0,
244 null ), "workspace" );
245 when( accurev.showStream( "workspace5" ) ).thenReturn( workspaceStream );
246
247 Stream basisStream = new Stream( "stream4", 4, "myDepot", 1, "myDepot", getDate( 2008, 1, 1 ), "normal" );
248 when( accurev.showStream( "stream4" ) ).thenReturn( basisStream );
249
250
251 FileDifference diffWS3toS2 = new FileDifference( 32L, "/promoted/WS3toS2", "3/2", "/promoted/WS3toS2", "6/1" );
252 FileDifference diffWS5toS4 = new FileDifference( 54L, "/promoted/WS5toS4", "5/3", "/promoted/WS5toS4", "8/1" );
253 FileDifference diffWS7toS4 = new FileDifference( 74L, "/promoted/WS7toS4", "7/12", "/promoted/WS7toS4", "3/13" );
254
255 when( accurev.diff( "stream4", "35", "42" ) )
256 .thenReturn( Arrays.asList( diffWS3toS2, diffWS5toS4, diffWS7toS4 ) );
257
258
259
260 Transaction promoteWS5toS4 = new Transaction( 37L, promoteWhen, "promote", "aUser" );
261 promoteWS5toS4.setComment( "WS5toS4" );
262 promoteWS5toS4.addVersion( 54L, "/./promoted/WS5toS4", "4/5", "5/3", "3/2" );
263
264 Transaction promoteWS7toS4 = new Transaction( 38L, promoteWhen, "promote", "aUser" );
265 promoteWS7toS4.setComment( "WS7toS4" );
266 promoteWS7toS4.addVersion( 74L, "/./promoted/WS7toS4", "4/11", "7/12", "3/2" );
267
268 when( accurev.history( "stream4", "36", "42", 0, false, false ) ).thenReturn( Arrays.asList( promoteWS5toS4,
269 promoteWS7toS4 ) );
270
271 Transaction keepWS5 = new Transaction( 39L, keepWhen, "keep", "anOther" );
272 keepWS5.addVersion( 5L, "/./kept/WS5", "5/7", "5/7", "7/21" );
273 keepWS5.setComment( "keepWS5" );
274
275 when( accurev.history( "workspace5", "36", "42", 0, false, false ) ).thenReturn( Collections
276 .singletonList( keepWS5 ) );
277
278 AccuRevChangeLogCommand command = new AccuRevChangeLogCommand( getLogger() );
279
280 CommandParameters commandParameters = new CommandParameters();
281 commandParameters.setScmVersion( CommandParameter.START_SCM_VERSION, new ScmRevision( "workspace5/35" ) );
282 commandParameters.setScmVersion( CommandParameter.END_SCM_VERSION, new ScmRevision( "workspace5/42" ) );
283 ChangeLogScmResult result = command.changelog( repo, testFileSet, commandParameters );
284
285 assertThat( result.isSuccess(), is( true ) );
286 ChangeLogSet changelog = result.getChangeLog();
287 assertThat( changelog.getStartVersion().getName(), is( "workspace5/35" ) );
288 assertThat( changelog.getEndVersion().getName(), is( "workspace5/42" ) );
289 List<ChangeSet> changesets = changelog.getChangeSets();
290 assertThat( changesets.size(), is( 3 ) );
291
292 for ( ChangeSet changeSet : changesets )
293 {
294 assertThat( changeSet.getComment(), isOneOf( "Upstream changes", "WS7toS4", "keepWS5" ) );
295
296 if ( "Upstream changes".equals( changeSet.getComment() ) )
297 {
298 assertThat( changeSet.getFiles().size(), is( 1 ) );
299 ChangeFile changeFile = (ChangeFile) changeSet.getFiles().get( 0 );
300 assertThat( changeFile, is( changeFile( "/promoted/WS3toS2" ) ) );
301 }
302 }
303 }
304
305 @Test
306 public void testChangeLogFailed()
307 throws Exception
308 {
309
310
311
312 final ScmFileSet testFileSet = new ScmFileSet( new File( basedir, "project/dir" ) );
313
314 final Date dateFrom = getDate( 2009, 0, 01, 10, 00, 00, null );
315 final Date dateTo = getDate( 2009, 0, 12, 13, 00, 00, null );
316
317
318 List<Transaction> startTransaction = Collections.singletonList( new Transaction( 35L, new Date(), "sometran",
319 "anyone" ) );
320 when( accurev.history( "myStream", "2009/01/01 10:00:00", null, 1, true, true ) ).thenReturn( startTransaction );
321
322
323 List<Transaction> endTransaction = Collections.singletonList( new Transaction( 42L, new Date(), "sometran",
324 "anyone" ) );
325
326 when( accurev.history( "myStream", "2009/01/12 13:00:00", null, 1, true, true ) ).thenReturn( endTransaction );
327
328 when(
329 accurev.history( eq( "myStream" ), any( String.class ), any( String.class ), eq( 0 ), eq( false ),
330 eq( false ) ) ).thenReturn( null );
331
332 AccuRevChangeLogCommand command = new AccuRevChangeLogCommand( getLogger() );
333
334 CommandParameters commandParameters = new CommandParameters();
335 commandParameters.setString( CommandParameter.MESSAGE, "A commit message" );
336 commandParameters.setDate( CommandParameter.START_DATE, dateFrom );
337 commandParameters.setDate( CommandParameter.END_DATE, dateTo );
338 ChangeLogScmResult result = command.changelog( repo, testFileSet, commandParameters );
339
340 assertThat( result.isSuccess(), is( false ) );
341 assertThat( result.getProviderMessage(), notNullValue() );
342 }
343 }