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