-
Notifications
You must be signed in to change notification settings - Fork 198
/
RobotCommentsIT.java
130 lines (111 loc) · 4.44 KB
/
RobotCommentsIT.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
// Copyright (C) 2016 The Android Open Source Project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package com.google.gerrit.acceptance.api.revision;
import static com.google.common.truth.Truth.assertThat;
import static com.google.common.truth.TruthJUnit.assume;
import static com.google.gerrit.acceptance.PushOneCommit.FILE_NAME;
import com.google.common.collect.Iterables;
import com.google.gerrit.acceptance.AbstractDaemonTest;
import com.google.gerrit.acceptance.PushOneCommit;
import com.google.gerrit.extensions.api.changes.ReviewInput;
import com.google.gerrit.extensions.api.changes.ReviewInput.RobotCommentInput;
import com.google.gerrit.extensions.common.RobotCommentInfo;
import com.google.gerrit.extensions.restapi.MethodNotAllowedException;
import org.junit.Test;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class RobotCommentsIT extends AbstractDaemonTest {
@Test
public void comments() throws Exception {
assume().that(notesMigration.enabled()).isTrue();
PushOneCommit.Result r = createChange();
RobotCommentInput in = createRobotCommentInput();
ReviewInput reviewInput = new ReviewInput();
Map<String, List<RobotCommentInput>> robotComments = new HashMap<>();
robotComments.put(in.path, Collections.singletonList(in));
reviewInput.robotComments = robotComments;
reviewInput.message = "comment test";
gApi.changes()
.id(r.getChangeId())
.current()
.review(reviewInput);
Map<String, List<RobotCommentInfo>> out = gApi.changes()
.id(r.getChangeId())
.revision(r.getCommit().name())
.robotComments();
assertThat(out).hasSize(1);
RobotCommentInfo comment = Iterables.getOnlyElement(out.get(in.path));
assertRobotComment(comment, in, false);
List<RobotCommentInfo> list = gApi.changes()
.id(r.getChangeId())
.revision(r.getCommit().name())
.robotCommentsAsList();
assertThat(list).hasSize(1);
RobotCommentInfo comment2 = list.get(0);
assertRobotComment(comment2, in);
RobotCommentInfo comment3 = gApi.changes()
.id(r.getChangeId())
.revision(r.getCommit().name())
.robotComment(comment.id)
.get();
assertRobotComment(comment3, in);
}
@Test
public void robotCommentsNotSupported() throws Exception {
assume().that(notesMigration.enabled()).isFalse();
PushOneCommit.Result r = createChange();
RobotCommentInput in = createRobotCommentInput();
ReviewInput reviewInput = new ReviewInput();
Map<String, List<RobotCommentInput>> robotComments = new HashMap<>();
robotComments.put(FILE_NAME, Collections.singletonList(in));
reviewInput.robotComments = robotComments;
reviewInput.message = "comment test";
exception.expect(MethodNotAllowedException.class);
exception.expectMessage("robot comments not supported");
gApi.changes()
.id(r.getChangeId())
.current()
.review(reviewInput);
}
private RobotCommentInput createRobotCommentInput() {
RobotCommentInput in = new RobotCommentInput();
in.robotId = "happyRobot";
in.robotRunId = "1";
in.url = "http://www.happy-robot.com";
in.line = 1;
in.message = "nit: trailing whitespace";
in.path = FILE_NAME;
return in;
}
private void assertRobotComment(RobotCommentInfo c,
RobotCommentInput expected) {
assertRobotComment(c, expected, true);
}
private void assertRobotComment(RobotCommentInfo c,
RobotCommentInput expected, boolean expectPath) {
assertThat(c.robotId).isEqualTo(expected.robotId);
assertThat(c.robotRunId).isEqualTo(expected.robotRunId);
assertThat(c.url).isEqualTo(expected.url);
assertThat(c.line).isEqualTo(expected.line);
assertThat(c.message).isEqualTo(expected.message);
assertThat(c.author.email).isEqualTo(admin.email);
if (expectPath) {
assertThat(c.path).isEqualTo(expected.path);
} else {
assertThat(c.path).isNull();
}
}
}