use of com.google.gerrit.entities.ChangeMessage in project gerrit by GerritCodeReview.
the class ImpersonationIT method runAsWithOnBehalfOf.
@Test
public void runAsWithOnBehalfOf() throws Exception {
// - Has the same restrictions as on_behalf_of (e.g. requires labels).
// - Takes the effective user from on_behalf_of (user).
// - Takes the real user from the real caller, not the intermediate
// X-Gerrit-RunAs user (user2).
allowRunAs();
allowCodeReviewOnBehalfOf();
TestAccount user2 = accountCreator.user2();
PushOneCommit.Result r = createChange();
ReviewInput in = new ReviewInput();
in.onBehalfOf = user.id().toString();
in.message = "Message on behalf of";
String endpoint = "/changes/" + r.getChangeId() + "/revisions/current/review";
RestResponse res = adminRestSession.postWithHeaders(endpoint, in, runAsHeader(user2.id()));
res.assertForbidden();
assertThat(res.getEntityContent()).isEqualTo("label required to post review on behalf of \"" + in.onBehalfOf + '"');
in.label("Code-Review", 1);
adminRestSession.postWithHeaders(endpoint, in, runAsHeader(user2.id())).assertOK();
PatchSetApproval psa = Iterables.getOnlyElement(r.getChange().approvals().values());
assertThat(psa.patchSetId().get()).isEqualTo(1);
assertThat(psa.label()).isEqualTo("Code-Review");
assertThat(psa.accountId()).isEqualTo(user.id());
assertThat(psa.value()).isEqualTo(1);
// not user2
assertThat(psa.realAccountId()).isEqualTo(admin.id());
ChangeData cd = r.getChange();
ChangeMessage m = Iterables.getLast(cmUtil.byChange(cd.notes()));
assertThat(m.getMessage()).endsWith(in.message);
assertThat(m.getAuthor()).isEqualTo(user.id());
// not user2
assertThat(m.getRealAuthor()).isEqualTo(admin.id());
}
use of com.google.gerrit.entities.ChangeMessage in project gerrit by GerritCodeReview.
the class ChangeMessageProtoConverterTest method mainValuesConvertedToProto.
@Test
public void mainValuesConvertedToProto() {
ChangeMessage changeMessage = ChangeMessage.create(ChangeMessage.key(Change.id(543), "change-message-21"), Account.id(63), Instant.ofEpochMilli(9876543), PatchSet.id(Change.id(34), 13));
Entities.ChangeMessage proto = changeMessageProtoConverter.toProto(changeMessage);
Entities.ChangeMessage expectedProto = Entities.ChangeMessage.newBuilder().setKey(Entities.ChangeMessage_Key.newBuilder().setChangeId(Entities.Change_Id.newBuilder().setId(543)).setUuid("change-message-21")).setAuthorId(Entities.Account_Id.newBuilder().setId(63)).setWrittenOn(9876543).setPatchset(Entities.PatchSet_Id.newBuilder().setChangeId(Entities.Change_Id.newBuilder().setId(34)).setId(13)).build();
assertThat(proto).isEqualTo(expectedProto);
}
use of com.google.gerrit.entities.ChangeMessage in project gerrit by GerritCodeReview.
the class ChangeMessageProtoConverterTest method realAuthorIsNotAutomaticallySetToAuthorWhenConvertedToProto.
// This test documents a special behavior which is necessary to ensure binary compatibility.
@Test
public void realAuthorIsNotAutomaticallySetToAuthorWhenConvertedToProto() {
ChangeMessage changeMessage = ChangeMessage.create(ChangeMessage.key(Change.id(543), "change-message-21"), Account.id(63), null, null);
Entities.ChangeMessage proto = changeMessageProtoConverter.toProto(changeMessage);
Entities.ChangeMessage expectedProto = Entities.ChangeMessage.newBuilder().setKey(Entities.ChangeMessage_Key.newBuilder().setChangeId(Entities.Change_Id.newBuilder().setId(543)).setUuid("change-message-21")).setAuthorId(Entities.Account_Id.newBuilder().setId(63)).build();
assertThat(proto).isEqualTo(expectedProto);
}
use of com.google.gerrit.entities.ChangeMessage in project gerrit by GerritCodeReview.
the class ChangeMessageProtoConverterTest method mandatoryValuesConvertedToProto.
@Test
public void mandatoryValuesConvertedToProto() {
// writtenOn may not be null according to the column definition but it's optional for the
// protobuf definition. -> assume as optional and hence test null
ChangeMessage changeMessage = ChangeMessage.create(ChangeMessage.key(Change.id(543), "change-message-21"), null, null, null);
Entities.ChangeMessage proto = changeMessageProtoConverter.toProto(changeMessage);
Entities.ChangeMessage expectedProto = Entities.ChangeMessage.newBuilder().setKey(Entities.ChangeMessage_Key.newBuilder().setChangeId(Entities.Change_Id.newBuilder().setId(543)).setUuid("change-message-21")).build();
assertThat(proto).isEqualTo(expectedProto);
}
use of com.google.gerrit.entities.ChangeMessage in project gerrit by GerritCodeReview.
the class ChangeMessageProtoConverterTest method mandatoryValuesConvertedToProtoAndBackAgain.
@Test
public void mandatoryValuesConvertedToProtoAndBackAgain() {
ChangeMessage changeMessage = ChangeMessage.create(ChangeMessage.key(Change.id(543), "change-message-21"), null, null, null);
ChangeMessage convertedChangeMessage = changeMessageProtoConverter.fromProto(changeMessageProtoConverter.toProto(changeMessage));
assertThat(convertedChangeMessage).isEqualTo(changeMessage);
}
Aggregations