Search in sources :

Example 1 with BranchReportRequestProto

use of io.seata.serializer.protobuf.generated.BranchReportRequestProto in project seata by seata.

the class BranchReportRequestConvertor method convert2Proto.

@Override
public BranchReportRequestProto convert2Proto(BranchReportRequest branchReportRequest) {
    final short typeCode = branchReportRequest.getTypeCode();
    final AbstractMessageProto abstractMessage = AbstractMessageProto.newBuilder().setMessageType(MessageTypeProto.forNumber(typeCode)).build();
    final AbstractTransactionRequestProto abstractTransactionRequestProto = AbstractTransactionRequestProto.newBuilder().setAbstractMessage(abstractMessage).build();
    final String applicationData = branchReportRequest.getApplicationData();
    final String resourceId = branchReportRequest.getResourceId();
    BranchReportRequestProto result = BranchReportRequestProto.newBuilder().setAbstractTransactionRequest(abstractTransactionRequestProto).setXid(branchReportRequest.getXid()).setBranchId(branchReportRequest.getBranchId()).setBranchType(BranchTypeProto.valueOf(branchReportRequest.getBranchType().name())).setApplicationData(applicationData == null ? "" : applicationData).setResourceId(resourceId == null ? "" : resourceId).setStatus(BranchStatusProto.valueOf(branchReportRequest.getStatus().name())).build();
    return result;
}
Also used : BranchReportRequestProto(io.seata.serializer.protobuf.generated.BranchReportRequestProto) AbstractMessageProto(io.seata.serializer.protobuf.generated.AbstractMessageProto) AbstractTransactionRequestProto(io.seata.serializer.protobuf.generated.AbstractTransactionRequestProto)

Example 2 with BranchReportRequestProto

use of io.seata.serializer.protobuf.generated.BranchReportRequestProto in project seata by seata.

the class BranchReportRequestConvertorTest method convert2Proto.

@Test
public void convert2Proto() {
    BranchReportRequest branchReportRequest = new BranchReportRequest();
    branchReportRequest.setApplicationData("data");
    branchReportRequest.setBranchId(123);
    branchReportRequest.setResourceId("resourceId");
    branchReportRequest.setXid("xid");
    branchReportRequest.setBranchType(BranchType.AT);
    branchReportRequest.setStatus(BranchStatus.PhaseOne_Done);
    BranchReportRequestConvertor convertor = new BranchReportRequestConvertor();
    BranchReportRequestProto proto = convertor.convert2Proto(branchReportRequest);
    BranchReportRequest real = convertor.convert2Model(proto);
    assertThat(real.getBranchType()).isEqualTo(branchReportRequest.getBranchType());
    assertThat(real.getXid()).isEqualTo(branchReportRequest.getXid());
    assertThat(real.getResourceId()).isEqualTo(branchReportRequest.getResourceId());
    assertThat(real.getBranchId()).isEqualTo(branchReportRequest.getBranchId());
    assertThat(real.getApplicationData()).isEqualTo(branchReportRequest.getApplicationData());
    assertThat(real.getStatus()).isEqualTo(branchReportRequest.getStatus());
}
Also used : BranchReportRequestProto(io.seata.serializer.protobuf.generated.BranchReportRequestProto) BranchReportRequest(io.seata.core.protocol.transaction.BranchReportRequest) Test(org.junit.jupiter.api.Test)

Aggregations

BranchReportRequestProto (io.seata.serializer.protobuf.generated.BranchReportRequestProto)2 BranchReportRequest (io.seata.core.protocol.transaction.BranchReportRequest)1 AbstractMessageProto (io.seata.serializer.protobuf.generated.AbstractMessageProto)1 AbstractTransactionRequestProto (io.seata.serializer.protobuf.generated.AbstractTransactionRequestProto)1 Test (org.junit.jupiter.api.Test)1