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