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