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.common.RobotCommentInfo;
|
||||||
import com.google.gerrit.extensions.restapi.MethodNotAllowedException;
|
import com.google.gerrit.extensions.restapi.MethodNotAllowedException;
|
||||||
|
|
||||||
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
@@ -34,73 +35,95 @@ import java.util.List;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public class RobotCommentsIT extends AbstractDaemonTest {
|
public class RobotCommentsIT extends AbstractDaemonTest {
|
||||||
|
private String changeId;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setUp() throws Exception {
|
||||||
|
PushOneCommit.Result changeResult = createChange();
|
||||||
|
changeId = changeResult.getChangeId();
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void comments() throws Exception {
|
public void retrievingRobotCommentsBeforeAddingAnyDoesNotRaiseAnException()
|
||||||
|
throws Exception {
|
||||||
assume().that(notesMigration.enabled()).isTrue();
|
assume().that(notesMigration.enabled()).isTrue();
|
||||||
|
|
||||||
PushOneCommit.Result r = createChange();
|
Map<String, List<RobotCommentInfo>> robotComments = gApi.changes()
|
||||||
|
.id(changeId)
|
||||||
Map<String, List<RobotCommentInfo>> out = gApi.changes()
|
.current()
|
||||||
.id(r.getChangeId())
|
|
||||||
.revision(r.getCommit().name())
|
|
||||||
.robotComments();
|
.robotComments();
|
||||||
assertThat(out).isEmpty();
|
|
||||||
|
assertThat(robotComments).isNotNull();
|
||||||
|
assertThat(robotComments).isEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void addedRobotCommentsCanBeRetrieved() throws Exception {
|
||||||
|
assume().that(notesMigration.enabled()).isTrue();
|
||||||
|
|
||||||
RobotCommentInput in = createRobotCommentInput();
|
RobotCommentInput in = createRobotCommentInput();
|
||||||
ReviewInput reviewInput = new ReviewInput();
|
addRobotComment(changeId, in);
|
||||||
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);
|
|
||||||
|
|
||||||
Map<String, List<RobotCommentInfo>> out = gApi.changes()
|
Map<String, List<RobotCommentInfo>> out = gApi.changes()
|
||||||
.id(r.getChangeId())
|
.id(changeId)
|
||||||
.revision(r.getCommit().name())
|
.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();
|
.robotComments();
|
||||||
assertThat(out).hasSize(1);
|
assertThat(out).hasSize(1);
|
||||||
RobotCommentInfo comment = Iterables.getOnlyElement(out.get(in.path));
|
RobotCommentInfo comment = Iterables.getOnlyElement(out.get(in.path));
|
||||||
@@ -108,10 +131,9 @@ public class RobotCommentsIT extends AbstractDaemonTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void robotCommentsNotSupported() throws Exception {
|
public void robotCommentsNotSupportedWithoutNoteDb() throws Exception {
|
||||||
assume().that(notesMigration.enabled()).isFalse();
|
assume().that(notesMigration.enabled()).isFalse();
|
||||||
|
|
||||||
PushOneCommit.Result r = createChange();
|
|
||||||
RobotCommentInput in = createRobotCommentInput();
|
RobotCommentInput in = createRobotCommentInput();
|
||||||
ReviewInput reviewInput = new ReviewInput();
|
ReviewInput reviewInput = new ReviewInput();
|
||||||
Map<String, List<RobotCommentInput>> robotComments = new HashMap<>();
|
Map<String, List<RobotCommentInput>> robotComments = new HashMap<>();
|
||||||
@@ -122,7 +144,7 @@ public class RobotCommentsIT extends AbstractDaemonTest {
|
|||||||
exception.expect(MethodNotAllowedException.class);
|
exception.expect(MethodNotAllowedException.class);
|
||||||
exception.expectMessage("robot comments not supported");
|
exception.expectMessage("robot comments not supported");
|
||||||
gApi.changes()
|
gApi.changes()
|
||||||
.id(r.getChangeId())
|
.id(changeId)
|
||||||
.current()
|
.current()
|
||||||
.review(reviewInput);
|
.review(reviewInput);
|
||||||
}
|
}
|
||||||
@@ -146,6 +168,18 @@ public class RobotCommentsIT extends AbstractDaemonTest {
|
|||||||
return in;
|
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,
|
private void assertRobotComment(RobotCommentInfo c,
|
||||||
RobotCommentInput expected) {
|
RobotCommentInput expected) {
|
||||||
assertRobotComment(c, expected, true);
|
assertRobotComment(c, expected, true);
|
||||||
|
|||||||
Reference in New Issue
Block a user