1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.scm.tck.command.changelog;
20
21 import java.util.Collections;
22 import java.util.Date;
23 import java.util.List;
24
25 import org.apache.maven.scm.ChangeSet;
26 import org.apache.maven.scm.ScmBranch;
27 import org.apache.maven.scm.ScmFileSet;
28 import org.apache.maven.scm.ScmTagParameters;
29 import org.apache.maven.scm.ScmTckTestCase;
30 import org.apache.maven.scm.ScmTestCase;
31 import org.apache.maven.scm.command.changelog.ChangeLogScmRequest;
32 import org.apache.maven.scm.command.changelog.ChangeLogScmResult;
33 import org.apache.maven.scm.command.checkin.CheckInScmResult;
34 import org.apache.maven.scm.command.tag.TagScmResult;
35 import org.apache.maven.scm.provider.ScmProvider;
36 import org.junit.Test;
37
38 import static org.junit.Assert.assertEquals;
39 import static org.junit.Assert.assertTrue;
40
41
42
43
44
45
46
47
48
49
50
51 public abstract class ChangeLogCommandTckTest extends ScmTckTestCase {
52 private static final String COMMIT_MSG = "Second changelog";
53 private static final String COMMIT_TAG = "v3.14";
54
55
56
57
58
59 public boolean isTagAnExtraCommit() {
60 return false;
61 }
62
63 @Test
64 public void testChangeLogCommand() throws Exception {
65 Thread.sleep(1000);
66 ScmProvider provider = getScmManager().getProviderByRepository(getScmRepository());
67 ScmFileSet fileSet = new ScmFileSet(getWorkingCopy());
68
69 ChangeLogScmResult firstResult =
70 provider.changeLog(getScmRepository(), fileSet, null, null, 0, (ScmBranch) null, null);
71 assertTrue(
72 firstResult.getProviderMessage() + ": " + firstResult.getCommandLine() + "\n"
73 + firstResult.getCommandOutput(),
74 firstResult.isSuccess());
75
76
77 int firstLogSize = firstResult.getChangeLog().getChangeSets().size();
78 assertTrue("Unexpected initial log size", firstLogSize >= 1);
79
80
81 Date timeBeforeSecond = new Date();
82
83
84 Thread.sleep(2000);
85
86
87 this.edit(getWorkingCopy(), "readme.txt", null, getScmRepository());
88 ScmTestCase.makeFile(getWorkingCopy(), "/readme.txt", "changed readme.txt");
89 CheckInScmResult checkInResult = provider.checkIn(getScmRepository(), fileSet, COMMIT_MSG);
90 assertTrue("Unable to checkin changes to the repository", checkInResult.isSuccess());
91
92 ScmTagParameters scmTagParameters = new ScmTagParameters();
93 TagScmResult tagResult = provider.tag(getScmRepository(), fileSet, COMMIT_TAG, scmTagParameters);
94 assertTrue("Unable to tag the changes in the repository", tagResult.isSuccess());
95
96 ChangeLogScmRequest changeLogScmRequest = new ChangeLogScmRequest(getScmRepository(), fileSet);
97 ChangeLogScmResult secondResult = provider.changeLog(changeLogScmRequest);
98 assertTrue(secondResult.getProviderMessage(), secondResult.isSuccess());
99
100 List<ChangeSet> changeSets = secondResult.getChangeLog().getChangeSets();
101
102 int expectedChangeSets = firstLogSize + 1;
103 boolean lastCommitIsCausedByTagging = false;
104 int lastCodeCommitIndex = 0;
105
106 if (isTagAnExtraCommit()) {
107
108 lastCommitIsCausedByTagging = true;
109 expectedChangeSets += 1;
110 lastCodeCommitIndex = 1;
111 }
112
113 assertEquals(expectedChangeSets, changeSets.size());
114
115
116 ChangeSet changeSetWithTag = changeSets.get(lastCodeCommitIndex);
117 assertEquals(Collections.singletonList(COMMIT_TAG), changeSetWithTag.getTags());
118
119
120 Date currentTime = new Date();
121 changeLogScmRequest = new ChangeLogScmRequest(getScmRepository(), fileSet);
122 changeLogScmRequest.setStartDate(timeBeforeSecond);
123 changeLogScmRequest.setEndDate(currentTime);
124 changeLogScmRequest.setScmBranch(new ScmBranch(""));
125 ChangeLogScmResult thirdResult = provider.changeLog(changeLogScmRequest);
126
127
128 assertTrue(thirdResult.getProviderMessage(), thirdResult.isSuccess());
129
130 List<ChangeSet> thirdChangeSets = thirdResult.getChangeLog().getChangeSets();
131 assertEquals(lastCommitIsCausedByTagging ? 2 : 1, thirdChangeSets.size());
132 ChangeSet changeset = thirdChangeSets.get(lastCodeCommitIndex);
133 assertTrue(changeset.getDate().after(timeBeforeSecond));
134 assertTrue(changeset.getComment().startsWith(COMMIT_MSG));
135 }
136 }