use of io.seata.serializer.protobuf.generated.BranchCommitRequestProto in project seata by seata.
the class BranchCommitRequestConvertorTest method convert2Proto.
@Test
public void convert2Proto() {
BranchCommitRequest branchCommitRequest = new BranchCommitRequest();
branchCommitRequest.setBranchType(BranchType.AT);
branchCommitRequest.setXid("xid");
branchCommitRequest.setResourceId("resourceId");
branchCommitRequest.setBranchId(123);
branchCommitRequest.setApplicationData("app");
BranchCommitRequestConvertor branchCommitRequestConvertor = new BranchCommitRequestConvertor();
BranchCommitRequestProto proto = branchCommitRequestConvertor.convert2Proto(branchCommitRequest);
BranchCommitRequest realRequest = branchCommitRequestConvertor.convert2Model(proto);
assertThat(realRequest.getTypeCode()).isEqualTo(branchCommitRequest.getTypeCode());
assertThat(realRequest.getBranchType()).isEqualTo(branchCommitRequest.getBranchType());
assertThat(realRequest.getXid()).isEqualTo(branchCommitRequest.getXid());
assertThat(realRequest.getResourceId()).isEqualTo(branchCommitRequest.getResourceId());
assertThat(realRequest.getBranchId()).isEqualTo(branchCommitRequest.getBranchId());
assertThat(realRequest.getApplicationData()).isEqualTo(branchCommitRequest.getApplicationData());
}
use of io.seata.serializer.protobuf.generated.BranchCommitRequestProto in project seata by seata.
the class BranchCommitRequestConvertor method convert2Proto.
@Override
public BranchCommitRequestProto convert2Proto(BranchCommitRequest branchCommitRequest) {
final short typeCode = branchCommitRequest.getTypeCode();
final AbstractMessageProto abstractMessage = AbstractMessageProto.newBuilder().setMessageType(MessageTypeProto.forNumber(typeCode)).build();
final AbstractTransactionRequestProto abstractTransactionRequestProto = AbstractTransactionRequestProto.newBuilder().setAbstractMessage(abstractMessage).build();
final String applicationData = branchCommitRequest.getApplicationData();
final AbstractBranchEndRequestProto abstractBranchEndRequestProto = AbstractBranchEndRequestProto.newBuilder().setAbstractTransactionRequest(abstractTransactionRequestProto).setXid(branchCommitRequest.getXid()).setBranchId(branchCommitRequest.getBranchId()).setBranchType(BranchTypeProto.valueOf(branchCommitRequest.getBranchType().name())).setApplicationData(applicationData == null ? "" : applicationData).setResourceId(branchCommitRequest.getResourceId()).build();
BranchCommitRequestProto result = BranchCommitRequestProto.newBuilder().setAbstractBranchEndRequest(abstractBranchEndRequestProto).build();
return result;
}
Aggregations