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