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;
}
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());
}
Aggregations