Split tests of RobotCommentsIT into smaller units
Change-Id: I8a9291c522f69366c66ae06e3a4a2e93c295b50a
This commit is contained in:
@@ -26,6 +26,7 @@ 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.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Collections;
|
||||
@@ -34,73 +35,95 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class RobotCommentsIT extends AbstractDaemonTest {
|
||||
private String changeId;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
PushOneCommit.Result changeResult = createChange();
|
||||
changeId = changeResult.getChangeId();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void comments() throws Exception {
|
||||
public void retrievingRobotCommentsBeforeAddingAnyDoesNotRaiseAnException()
|
||||
throws Exception {
|
||||
assume().that(notesMigration.enabled()).isTrue();
|
||||
|
||||
PushOneCommit.Result r = createChange();
|
||||
|
||||
Map<String, List<RobotCommentInfo>> out = gApi.changes()
|
||||
.id(r.getChangeId())
|
||||
.revision(r.getCommit().name())
|
||||
Map<String, List<RobotCommentInfo>> robotComments = gApi.changes()
|
||||
.id(changeId)
|
||||
.current()
|
||||
.robotComments();
|
||||
assertThat(out).isEmpty();
|
||||
|
||||
assertThat(robotComments).isNotNull();
|
||||
assertThat(robotComments).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void addedRobotCommentsCanBeRetrieved() throws Exception {
|
||||
assume().that(notesMigration.enabled()).isTrue();
|
||||
|
||||
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);
|
||||
|
||||
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 noOptionalFields() throws Exception {
|
||||
assume().that(notesMigration.enabled()).isTrue();
|
||||
|
||||
PushOneCommit.Result r = createChange();
|
||||
RobotCommentInput in = createRobotCommentInputWithMandatoryFields();
|
||||
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);
|
||||
addRobotComment(changeId, in);
|
||||
|
||||
Map<String, List<RobotCommentInfo>> out = gApi.changes()
|
||||
.id(r.getChangeId())
|
||||
.revision(r.getCommit().name())
|
||||
.id(changeId)
|
||||
.current()
|
||||
.robotComments();
|
||||
|
||||
assertThat(out).hasSize(1);
|
||||
RobotCommentInfo comment = Iterables.getOnlyElement(out.get(in.path));
|
||||
assertRobotComment(comment, in, false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void robotCommentsCanBeRetrievedAsList() throws Exception {
|
||||
assume().that(notesMigration.enabled()).isTrue();
|
||||
|
||||
RobotCommentInput robotCommentInput = createRobotCommentInput();
|
||||
addRobotComment(changeId, robotCommentInput);
|
||||
|
||||
List<RobotCommentInfo> robotCommentInfos = gApi.changes()
|
||||
.id(changeId)
|
||||
.current()
|
||||
.robotCommentsAsList();
|
||||
|
||||
assertThat(robotCommentInfos).hasSize(1);
|
||||
RobotCommentInfo robotCommentInfo =
|
||||
Iterables.getOnlyElement(robotCommentInfos);
|
||||
assertRobotComment(robotCommentInfo, robotCommentInput);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void specificRobotCommentCanBeRetrieved() throws Exception {
|
||||
assume().that(notesMigration.enabled()).isTrue();
|
||||
|
||||
RobotCommentInput robotCommentInput = createRobotCommentInput();
|
||||
addRobotComment(changeId, robotCommentInput);
|
||||
|
||||
List<RobotCommentInfo> robotCommentInfos = gApi.changes()
|
||||
.id(changeId)
|
||||
.current()
|
||||
.robotCommentsAsList();
|
||||
RobotCommentInfo robotCommentInfo =
|
||||
Iterables.getOnlyElement(robotCommentInfos);
|
||||
|
||||
RobotCommentInfo specificRobotCommentInfo = gApi.changes()
|
||||
.id(changeId)
|
||||
.current()
|
||||
.robotComment(robotCommentInfo.id)
|
||||
.get();
|
||||
assertRobotComment(specificRobotCommentInfo, robotCommentInput);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void robotCommentWithoutOptionalFieldsCanBeAdded() throws Exception {
|
||||
assume().that(notesMigration.enabled()).isTrue();
|
||||
|
||||
RobotCommentInput in = createRobotCommentInputWithMandatoryFields();
|
||||
addRobotComment(changeId, in);
|
||||
|
||||
Map<String, List<RobotCommentInfo>> out = gApi.changes()
|
||||
.id(changeId)
|
||||
.current()
|
||||
.robotComments();
|
||||
assertThat(out).hasSize(1);
|
||||
RobotCommentInfo comment = Iterables.getOnlyElement(out.get(in.path));
|
||||
@@ -108,10 +131,9 @@ public class RobotCommentsIT extends AbstractDaemonTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void robotCommentsNotSupported() throws Exception {
|
||||
public void robotCommentsNotSupportedWithoutNoteDb() 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<>();
|
||||
@@ -122,7 +144,7 @@ public class RobotCommentsIT extends AbstractDaemonTest {
|
||||
exception.expect(MethodNotAllowedException.class);
|
||||
exception.expectMessage("robot comments not supported");
|
||||
gApi.changes()
|
||||
.id(r.getChangeId())
|
||||
.id(changeId)
|
||||
.current()
|
||||
.review(reviewInput);
|
||||
}
|
||||
@@ -146,6 +168,18 @@ public class RobotCommentsIT extends AbstractDaemonTest {
|
||||
return in;
|
||||
}
|
||||
|
||||
private void addRobotComment(String targetChangeId,
|
||||
RobotCommentInput robotCommentInput) throws Exception {
|
||||
ReviewInput reviewInput = new ReviewInput();
|
||||
reviewInput.robotComments = Collections.singletonMap(robotCommentInput.path,
|
||||
Collections.singletonList(robotCommentInput));
|
||||
reviewInput.message = "robot comment test";
|
||||
gApi.changes()
|
||||
.id(targetChangeId)
|
||||
.current()
|
||||
.review(reviewInput);
|
||||
}
|
||||
|
||||
private void assertRobotComment(RobotCommentInfo c,
|
||||
RobotCommentInput expected) {
|
||||
assertRobotComment(c, expected, true);
|
||||
|
||||
Reference in New Issue
Block a user