Search in sources :

Example 21 with ChangeMessage

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());
}
Also used : RestResponse(com.google.gerrit.acceptance.RestResponse) ChangeMessage(com.google.gerrit.entities.ChangeMessage) TestAccount(com.google.gerrit.acceptance.TestAccount) ReviewInput(com.google.gerrit.extensions.api.changes.ReviewInput) PatchSetApproval(com.google.gerrit.entities.PatchSetApproval) ChangeData(com.google.gerrit.server.query.change.ChangeData) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 22 with ChangeMessage

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);
}
Also used : ChangeMessage(com.google.gerrit.entities.ChangeMessage) Entities(com.google.gerrit.proto.Entities) Test(org.junit.Test)

Example 23 with ChangeMessage

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);
}
Also used : ChangeMessage(com.google.gerrit.entities.ChangeMessage) Entities(com.google.gerrit.proto.Entities) Test(org.junit.Test)

Example 24 with ChangeMessage

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);
}
Also used : ChangeMessage(com.google.gerrit.entities.ChangeMessage) Entities(com.google.gerrit.proto.Entities) Test(org.junit.Test)

Example 25 with ChangeMessage

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);
}
Also used : ChangeMessage(com.google.gerrit.entities.ChangeMessage) Test(org.junit.Test)

Aggregations

ChangeMessage (com.google.gerrit.entities.ChangeMessage)31 Test (org.junit.Test)23 Change (com.google.gerrit.entities.Change)13 PatchSetApproval (com.google.gerrit.entities.PatchSetApproval)6 List (java.util.List)5 Account (com.google.gerrit.entities.Account)4 LabelId (com.google.gerrit.entities.LabelId)4 Entities (com.google.gerrit.proto.Entities)4 CurrentUser (com.google.gerrit.server.CurrentUser)4 Inject (com.google.inject.Inject)4 ImmutableList (com.google.common.collect.ImmutableList)3 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)3 ImmutableMap (com.google.common.collect.ImmutableMap)3 Truth.assertThat (com.google.common.truth.Truth.assertThat)3 AttentionSetUpdate (com.google.gerrit.entities.AttentionSetUpdate)3 Operation (com.google.gerrit.entities.AttentionSetUpdate.Operation)3 CODE_REVIEW (com.google.gerrit.entities.LabelId.CODE_REVIEW)3 VERIFIED (com.google.gerrit.entities.LabelId.VERIFIED)3 RefNames (com.google.gerrit.entities.RefNames)3 SubmitRecord (com.google.gerrit.entities.SubmitRecord)3