1 | |
package org.apache.maven.scm.tck.command.blame; |
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.scm.ScmFileSet; |
23 | |
import org.apache.maven.scm.ScmTckTestCase; |
24 | |
import org.apache.maven.scm.ScmTestCase; |
25 | |
import org.apache.maven.scm.command.blame.BlameLine; |
26 | |
import org.apache.maven.scm.command.blame.BlameScmResult; |
27 | |
import org.apache.maven.scm.command.checkin.CheckInScmResult; |
28 | |
import org.apache.maven.scm.manager.ScmManager; |
29 | |
import org.apache.maven.scm.provider.ScmProvider; |
30 | |
import org.apache.maven.scm.repository.ScmRepository; |
31 | |
|
32 | |
import java.util.Date; |
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | 0 | public abstract class BlameCommandTckTest |
38 | |
extends ScmTckTestCase |
39 | |
{ |
40 | |
private static final String COMMIT_MSG = "Second changelog"; |
41 | |
|
42 | |
public void testBlameCommand() |
43 | |
throws Exception |
44 | |
{ |
45 | 0 | ScmRepository repository = getScmRepository(); |
46 | 0 | ScmManager manager = getScmManager(); |
47 | 0 | ScmProvider provider = manager.getProviderByRepository( getScmRepository() ); |
48 | 0 | ScmFileSet fileSet = new ScmFileSet( getWorkingCopy() ); |
49 | |
|
50 | |
BlameScmResult result; |
51 | |
BlameLine line; |
52 | |
|
53 | |
|
54 | 0 | result = manager.blame( repository, fileSet, "readme.txt" ); |
55 | 0 | assertNotNull( "The command returned a null result.", result ); |
56 | 0 | assertResultIsSuccess( result ); |
57 | 0 | assertEquals( "Expected 1 line in blame", 1, result.getLines().size() ); |
58 | 0 | line = result.getLines().get( 0 ); |
59 | 0 | String initialRevision = line.getRevision(); |
60 | |
|
61 | |
|
62 | 0 | Date timeBeforeSecond = new Date(); |
63 | |
|
64 | 0 | Thread.sleep( 2000 ); |
65 | |
|
66 | 0 | ScmTestCase.makeFile( getWorkingCopy(), "/readme.txt", "changed readme.txt" ); |
67 | 0 | CheckInScmResult checkInResult = provider.checkIn( getScmRepository(), fileSet, COMMIT_MSG ); |
68 | 0 | assertTrue( "Unable to checkin changes to the repository", checkInResult.isSuccess() ); |
69 | |
|
70 | 0 | result = manager.blame( repository, fileSet, "readme.txt" ); |
71 | |
|
72 | |
|
73 | 0 | Thread.sleep( 2000 ); |
74 | 0 | Date timeAfterSecond = new Date(); |
75 | |
|
76 | 0 | assertNotNull( "The command returned a null result.", result ); |
77 | 0 | assertResultIsSuccess( result ); |
78 | |
|
79 | 0 | assertEquals( "Expected 1 line in blame", 1, result.getLines().size() ); |
80 | 0 | line = result.getLines().get( 0 ); |
81 | |
|
82 | 0 | assertNotNull( "Expected not null author", line.getAuthor() ); |
83 | 0 | assertNotNull( "Expected not null revision", line.getRevision() ); |
84 | 0 | assertNotNull( "Expected not null date", line.getDate() ); |
85 | |
|
86 | 0 | assertTrue( "Expected another revision", !initialRevision.equals( line.getRevision() ) ); |
87 | 0 | if ( isTestDateTime() ) |
88 | |
{ |
89 | 0 | assertDateBetween( timeBeforeSecond, timeAfterSecond, line.getDate() ); |
90 | |
} |
91 | |
|
92 | |
|
93 | 0 | result = manager.blame( repository, fileSet, "pom.xml" ); |
94 | |
|
95 | 0 | assertNotNull( "The command returned a null result.", result ); |
96 | |
|
97 | 0 | assertResultIsSuccess( result ); |
98 | |
|
99 | 0 | verifyResult( result ); |
100 | 0 | } |
101 | |
|
102 | |
protected boolean isTestDateTime() |
103 | |
{ |
104 | 0 | return true; |
105 | |
} |
106 | |
|
107 | |
protected void assertDateBetween( Date start, Date end, Date actual ) |
108 | |
{ |
109 | 0 | assertTrue( "Expected date between " + start + " and " + end + ", but was " + actual, |
110 | |
start.before( actual ) && actual.before( end ) ); |
111 | 0 | } |
112 | |
|
113 | |
protected abstract void verifyResult( BlameScmResult result ); |
114 | |
} |