forked from Praqma/pretested-integration-plugin
-
Notifications
You must be signed in to change notification settings - Fork 7
/
UseAuthorOfLastCommitIT.java
179 lines (159 loc) · 9.67 KB
/
UseAuthorOfLastCommitIT.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
package org.jenkinsci.plugins.pretestedintegration.integration.scm.git;
import hudson.model.FreeStyleBuild;
import hudson.model.FreeStyleProject;
import hudson.util.RunList;
import java.util.Iterator;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import junit.framework.TestCase;
import org.eclipse.jgit.api.CreateBranchCommand.SetupUpstreamMode;
import org.eclipse.jgit.revwalk.RevCommit;
import org.eclipse.jgit.revwalk.RevWalk;
import org.junit.Test;
/**
* Tests that we use the author of the last commit when integrating
*
* Repository we use for testing can be described as below. It have one initial
* commit, and then two commits with two different authors on a branch. When the
* branch is integrated we expect the author of the last commit to be author of
* the integration commit. We also expect that the committer changes (it will be
* the one running the test suites), so checking it is just changed. * a1b88be -
* (HEAD, origin/ready/twoCommitsBranch, twoCommitsBranch) Added test commit log
* file - second commit by 'Praqma Support Author Two' (0 seconds ago) <Praqma
* Support Author Two>
* * 0174ae0 - Added test commit log file - first commit by 'Praqma Support
* Author One' (0 seconds ago) <Praqma Support Author One>
* * d7743e8 - (origin/master, master) Initial commit - added README (0 seconds
* ago) <Praqma Support>
*
*/
public class UseAuthorOfLastCommitIT extends StaticGitRepositoryTestBase {
/**
* Tests that we use the author of the last commit when integrating - using
* the Squash strategy
*
* For more details see class description above
*
* @throws Exception
*/
@Test
public void authorOfLastCommitUsedIfMoreThanOneCommitSquashStrategy() throws Exception {
/**
* ********************************************************************
* Run test with Jenkins job trying to integrate the feature branch
* ********************************************************************
*/
FreeStyleProject project = TestUtilsFactory.configurePretestedIntegrationPlugin(jenkinsRule, TestUtilsFactory.STRATEGY_TYPE.SQUASH, bareRepository);
TestUtilsFactory.triggerProject(project);
jenkinsRule.waitUntilNoActivityUpTo(120000);
RunList<FreeStyleBuild> builds = project.getBuilds();
for (FreeStyleBuild b : builds) {
String console = jenkinsRule.createWebClient().getPage(b, "console").asXml();
System.out.println("************************************************************************");
System.out.println("* Relevant part of Jenkins console (captured with regexp): ");
// the pattern we want to search for
Pattern p = Pattern.compile("<link rel=\"stylesheet\" type=\"text/css\" href=\"/jenkins/descriptor/hudson.console.ExpandableDetailsNote/style.css\"/>"
+ ".*<pre>(.*)</pre>.*</td>.*</tr>.*</tbody>.*</table>", Pattern.DOTALL);
Matcher m = p.matcher(console);
// if we find a match, get the group
if (m.find()) {
// get the matching group
String capturedText = m.group(1);
// print the group
System.out.format("'%s'\n", capturedText);
} else {
System.out.format("Didn't match any relevant part of the console");
}
}
/**
* ********************************************************************
* Verify integration in different aspect like commit message content
* and actual commits
* ********************************************************************
*/
// Verify number of commits - first count on master after integration
gitrepo.checkout().setName("master").call();
gitrepo.checkout().setName("master").setUpstreamMode(SetupUpstreamMode.TRACK).call();
gitrepo.pull().call();
RevWalk walk = new RevWalk(gitrepo.getRepository());
Iterable<RevCommit> logs = gitrepo.log().call();
Iterator<RevCommit> i = logs.iterator();
// just look at first commit
RevCommit commit = walk.parseCommit(i.next());
System.out.println(String.format("%n******************* Listing and verifying first commit (latest) in repository *******************"));
System.out.println(String.format("%n***** Commit message (start):*****"));
System.out.println(String.format("%s", commit.getFullMessage()));
System.out.println(String.format("***** Commit message (end) *****"));
System.out.println(String.format("* Author is: %s", commit.getAuthorIdent().toExternalString()));
System.out.println(String.format("* Committer is: %s", commit.getCommitterIdent().toExternalString()));
TestCase.assertTrue("Author name did not match expected 'Praqma Support Author Two'", commit.getAuthorIdent().getName().equals("Praqma Support Author Two"));
TestCase.assertTrue("Author email did not match expected 'support@praqma.net'", commit.getAuthorIdent().getEmailAddress().equals("support@praqma.net"));
TestCase.assertFalse("Committer name was not different from original committer 'Praqma Support Author Two' as we would expect", commit.getCommitterIdent().getName().equals("Praqma Support Author Two"));
TestCase.assertFalse("Committer email was not different from original committer 'Praqma Support Author Two' as we would expect", commit.getCommitterIdent().getEmailAddress().equals("support@praqma.net"));
gitrepo.close(); // closing before asserting below
}
/**
* Tests that we use the author of the last commit when integrating - using
* the Accumulated strategy
*
* For more details see class description above
*
* @throws Exception
*/
@Test
public void authorOfLastCommitUsedIfMoreThanOneCommitAccumulatedStrategy() throws Exception {
/**
* ********************************************************************
* Run test with Jenkins job trying to integrate the feature branch
* ********************************************************************
*/
FreeStyleProject project = TestUtilsFactory.configurePretestedIntegrationPlugin(jenkinsRule, TestUtilsFactory.STRATEGY_TYPE.ACCUMULATED, bareRepository);
TestUtilsFactory.triggerProject(project);
jenkinsRule.waitUntilNoActivityUpTo(120000);
RunList<FreeStyleBuild> builds = project.getBuilds();
for (FreeStyleBuild b : builds) {
String console = jenkinsRule.createWebClient().getPage(b, "console").asXml();
System.out.println("************************************************************************");
System.out.println("* Relevant part of Jenkins console (captured with regexp): ");
// the pattern we want to search for
Pattern p = Pattern.compile("<link rel=\"stylesheet\" type=\"text/css\" href=\"/jenkins/descriptor/hudson.console.ExpandableDetailsNote/style.css\"/>"
+ ".*<pre>(.*)</pre>.*</td>.*</tr>.*</tbody>.*</table>", Pattern.DOTALL);
Matcher m = p.matcher(console);
// if we find a match, get the group
if (m.find()) {
// get the matching group
String capturedText = m.group(1);
// print the group
System.out.format("'%s'\n", capturedText);
} else {
System.out.format("Didn't match any relevant part of the console");
}
}
/**
* ********************************************************************
* Verify integration in different aspect like commit message content
* and actual commits
* ********************************************************************
*/
// Verify number of commits - first count on master after integration
gitrepo.checkout().setName("master").call();
gitrepo.checkout().setName("master").setUpstreamMode(SetupUpstreamMode.TRACK).call();
gitrepo.pull().call();
RevWalk walk = new RevWalk(gitrepo.getRepository());
Iterable<RevCommit> logs = gitrepo.log().call();
Iterator<RevCommit> i = logs.iterator();
// just look at first commit
RevCommit commit = walk.parseCommit(i.next());
System.out.println(String.format("%n******************* Listing and verifying first commit (latest) in repository *******************"));
System.out.println(String.format("%n***** Commit message (start):*****"));
System.out.println(String.format("%s", commit.getFullMessage()));
System.out.println(String.format("***** Commit message (end) *****"));
System.out.println(String.format("* Author is: %s", commit.getAuthorIdent().toExternalString()));
System.out.println(String.format("* Committer is: %s", commit.getCommitterIdent().toExternalString()));
TestCase.assertTrue("Author name did not match expected 'Praqma Support Author Two'", commit.getAuthorIdent().getName().equals("Praqma Support Author Two"));
TestCase.assertTrue("Author email did not match expected 'support@praqma.net'", commit.getAuthorIdent().getEmailAddress().equals("support@praqma.net"));
TestCase.assertFalse("Committer name was not different from original committer 'Praqma Support Author Two' as we would expect", commit.getCommitterIdent().getName().equals("Praqma Support Author Two"));
TestCase.assertFalse("Committer email was not different from original committer 'Praqma Support Author Two' as we would expect", commit.getCommitterIdent().getEmailAddress().equals("support@praqma.net"));
gitrepo.close(); // closing before asserting below
}
}