@Test public void convert2Proto() { BranchRollbackRequest branchRegisterRequest = new BranchRollbackRequest(); branchRegisterRequest.setApplicationData("data"); branchRegisterRequest.setBranchType(BranchType.AT); branchRegisterRequest.setResourceId("resourceId"); branchRegisterRequest.setXid("xid"); branchRegisterRequest.setBranchId(123); BranchRollbackRequestConvertor convertor = new BranchRollbackRequestConvertor(); BranchRollbackRequestProto proto = convertor.convert2Proto( branchRegisterRequest); BranchRollbackRequest real = convertor.convert2Model(proto); assertThat((real.getTypeCode())).isEqualTo(branchRegisterRequest.getTypeCode()); assertThat((real.getApplicationData())).isEqualTo(branchRegisterRequest.getApplicationData()); assertThat((real.getBranchType())).isEqualTo(branchRegisterRequest.getBranchType()); assertThat((real.getXid())).isEqualTo(branchRegisterRequest.getXid()); assertThat((real.getResourceId())).isEqualTo(branchRegisterRequest.getResourceId()); assertThat((real.getBranchId())).isEqualTo(branchRegisterRequest.getBranchId()); }
@Override public BranchRollbackRequestProto convert2Proto(BranchRollbackRequest branchRollbackRequest) { final short typeCode = branchRollbackRequest.getTypeCode(); final AbstractMessageProto abstractMessage = AbstractMessageProto.newBuilder().setMessageType( MessageTypeProto.forNumber(typeCode)).build(); final AbstractTransactionRequestProto abstractTransactionRequestProto = AbstractTransactionRequestProto .newBuilder().setAbstractMessage( abstractMessage).build(); final String applicationData = branchRollbackRequest.getApplicationData(); final String resourceId = branchRollbackRequest.getResourceId(); final AbstractBranchEndRequestProto abstractBranchEndRequestProto = AbstractBranchEndRequestProto .newBuilder(). setAbstractTransactionRequest(abstractTransactionRequestProto) .setXid(branchRollbackRequest.getXid()) .setBranchId(branchRollbackRequest.getBranchId()) .setBranchType(BranchTypeProto.valueOf(branchRollbackRequest.getBranchType().name())) .setApplicationData(applicationData==null?"":applicationData) .setResourceId(resourceId == null ? "" : resourceId) .build(); BranchRollbackRequestProto result = BranchRollbackRequestProto.newBuilder().setAbstractBranchEndRequest( abstractBranchEndRequestProto).build(); return result; }
BranchRollbackRequestConvertor implements PbConvertor<BranchRollbackRequest, BranchRollbackRequestProto> { @Override public BranchRollbackRequestProto convert2Proto(BranchRollbackRequest branchRollbackRequest) { final short typeCode = branchRollbackRequest.getTypeCode(); final AbstractMessageProto abstractMessage = AbstractMessageProto.newBuilder().setMessageType( MessageTypeProto.forNumber(typeCode)).build(); final AbstractTransactionRequestProto abstractTransactionRequestProto = AbstractTransactionRequestProto .newBuilder().setAbstractMessage( abstractMessage).build(); final String applicationData = branchRollbackRequest.getApplicationData(); final String resourceId = branchRollbackRequest.getResourceId(); final AbstractBranchEndRequestProto abstractBranchEndRequestProto = AbstractBranchEndRequestProto .newBuilder(). setAbstractTransactionRequest(abstractTransactionRequestProto) .setXid(branchRollbackRequest.getXid()) .setBranchId(branchRollbackRequest.getBranchId()) .setBranchType(BranchTypeProto.valueOf(branchRollbackRequest.getBranchType().name())) .setApplicationData(applicationData==null?"":applicationData) .setResourceId(resourceId == null ? "" : resourceId) .build(); BranchRollbackRequestProto result = BranchRollbackRequestProto.newBuilder().setAbstractBranchEndRequest( abstractBranchEndRequestProto).build(); return result; } }
BranchRollbackRequestConvertor implements PbConvertor<BranchRollbackRequest, BranchRollbackRequestProto> { @Override public BranchRollbackRequestProto convert2Proto(BranchRollbackRequest branchRollbackRequest) { final short typeCode = branchRollbackRequest.getTypeCode(); final AbstractMessageProto abstractMessage = AbstractMessageProto.newBuilder().setMessageType( MessageTypeProto.forNumber(typeCode)).build(); final AbstractTransactionRequestProto abstractTransactionRequestProto = AbstractTransactionRequestProto .newBuilder().setAbstractMessage( abstractMessage).build(); final String applicationData = branchRollbackRequest.getApplicationData(); final String resourceId = branchRollbackRequest.getResourceId(); final AbstractBranchEndRequestProto abstractBranchEndRequestProto = AbstractBranchEndRequestProto .newBuilder(). setAbstractTransactionRequest(abstractTransactionRequestProto) .setXid(branchRollbackRequest.getXid()) .setBranchId(branchRollbackRequest.getBranchId()) .setBranchType(BranchTypeProto.valueOf(branchRollbackRequest.getBranchType().name())) .setApplicationData(applicationData==null?"":applicationData) .setResourceId(resourceId == null ? "" : resourceId) .build(); BranchRollbackRequestProto result = BranchRollbackRequestProto.newBuilder().setAbstractBranchEndRequest( abstractBranchEndRequestProto).build(); return result; }  }
BranchRollbackRequestConvertor implements PbConvertor<BranchRollbackRequest, BranchRollbackRequestProto> { @Override public BranchRollbackRequestProto convert2Proto(BranchRollbackRequest branchRollbackRequest) { final short typeCode = branchRollbackRequest.getTypeCode(); final AbstractMessageProto abstractMessage = AbstractMessageProto.newBuilder().setMessageType( MessageTypeProto.forNumber(typeCode)).build(); final AbstractTransactionRequestProto abstractTransactionRequestProto = AbstractTransactionRequestProto .newBuilder().setAbstractMessage( abstractMessage).build(); final String applicationData = branchRollbackRequest.getApplicationData(); final String resourceId = branchRollbackRequest.getResourceId(); final AbstractBranchEndRequestProto abstractBranchEndRequestProto = AbstractBranchEndRequestProto .newBuilder(). setAbstractTransactionRequest(abstractTransactionRequestProto) .setXid(branchRollbackRequest.getXid()) .setBranchId(branchRollbackRequest.getBranchId()) .setBranchType(BranchTypeProto.valueOf(branchRollbackRequest.getBranchType().name())) .setApplicationData(applicationData==null?"":applicationData) .setResourceId(resourceId == null ? "" : resourceId) .build(); BranchRollbackRequestProto result = BranchRollbackRequestProto.newBuilder().setAbstractBranchEndRequest( abstractBranchEndRequestProto).build(); return result; }  @Override BranchRollbackRequestProto convert2Proto(BranchRollbackRequest branchRollbackRequest); @Override BranchRollbackRequest convert2Model(BranchRollbackRequestProto branchRollbackRequestProto); }
BranchRollbackRequestConvertor implements PbConvertor<BranchRollbackRequest, BranchRollbackRequestProto> { @Override public BranchRollbackRequestProto convert2Proto(BranchRollbackRequest branchRollbackRequest) { final short typeCode = branchRollbackRequest.getTypeCode(); final AbstractMessageProto abstractMessage = AbstractMessageProto.newBuilder().setMessageType( MessageTypeProto.forNumber(typeCode)).build(); final AbstractTransactionRequestProto abstractTransactionRequestProto = AbstractTransactionRequestProto .newBuilder().setAbstractMessage( abstractMessage).build(); final String applicationData = branchRollbackRequest.getApplicationData(); final String resourceId = branchRollbackRequest.getResourceId(); final AbstractBranchEndRequestProto abstractBranchEndRequestProto = AbstractBranchEndRequestProto .newBuilder(). setAbstractTransactionRequest(abstractTransactionRequestProto) .setXid(branchRollbackRequest.getXid()) .setBranchId(branchRollbackRequest.getBranchId()) .setBranchType(BranchTypeProto.valueOf(branchRollbackRequest.getBranchType().name())) .setApplicationData(applicationData==null?"":applicationData) .setResourceId(resourceId == null ? "" : resourceId) .build(); BranchRollbackRequestProto result = BranchRollbackRequestProto.newBuilder().setAbstractBranchEndRequest( abstractBranchEndRequestProto).build(); return result; }  @Override BranchRollbackRequestProto convert2Proto(BranchRollbackRequest branchRollbackRequest); @Override BranchRollbackRequest convert2Model(BranchRollbackRequestProto branchRollbackRequestProto);  }