@Test public void convert2Proto() { MergeResultMessage mergeResultMessage = new MergeResultMessage(); AbstractResultMessage[] msgs = new AbstractResultMessage[1]; final GlobalCommitResponse globalCommitResponse = new GlobalCommitResponse(); globalCommitResponse.setGlobalStatus(GlobalStatus.AsyncCommitting); globalCommitResponse.setMsg("msg"); globalCommitResponse.setResultCode(ResultCode.Failed); globalCommitResponse.setTransactionExceptionCode(TransactionExceptionCode.BranchRegisterFailed); msgs[0] = globalCommitResponse; mergeResultMessage.setMsgs(msgs); MergeResultMessageConvertor convertor = new MergeResultMessageConvertor(); MergedResultMessageProto proto = convertor.convert2Proto(mergeResultMessage); MergeResultMessage real = convertor.convert2Model(proto); GlobalCommitResponse realObj = (GlobalCommitResponse)real.getMsgs()[0]; assertThat((realObj.getTypeCode())).isEqualTo(globalCommitResponse.getTypeCode()); assertThat((realObj.getMsg())).isEqualTo(globalCommitResponse.getMsg()); assertThat((realObj.getResultCode())).isEqualTo(globalCommitResponse.getResultCode()); assertThat((realObj.getTransactionExceptionCode())).isEqualTo( globalCommitResponse.getTransactionExceptionCode()); }
@Override public MergedResultMessageProto convert2Proto(MergeResultMessage mergeResultMessage) { final short typeCode = mergeResultMessage.getTypeCode(); final AbstractMessageProto abstractMessage = AbstractMessageProto.newBuilder().setMessageType( MessageTypeProto.forNumber(typeCode)).build(); List<Any> lists = new ArrayList<>(); for (AbstractMessage msg : mergeResultMessage.msgs) { final PbConvertor pbConvertor = ProtobufConvertManager.getInstance().fetchConvertor( msg.getClass().getName()); lists.add(Any.pack((Message)pbConvertor.convert2Proto(msg))); } MergedResultMessageProto mergedWarpMessageProto = MergedResultMessageProto.newBuilder().setAbstractMessage( abstractMessage) .addAllMsgs(lists) .build(); return mergedWarpMessageProto; }
MergeResultMessageConvertor implements PbConvertor<MergeResultMessage, MergedResultMessageProto> { @Override public MergedResultMessageProto convert2Proto(MergeResultMessage mergeResultMessage) { final short typeCode = mergeResultMessage.getTypeCode(); final AbstractMessageProto abstractMessage = AbstractMessageProto.newBuilder().setMessageType( MessageTypeProto.forNumber(typeCode)).build(); List<Any> lists = new ArrayList<>(); for (AbstractMessage msg : mergeResultMessage.msgs) { final PbConvertor pbConvertor = ProtobufConvertManager.getInstance().fetchConvertor( msg.getClass().getName()); lists.add(Any.pack((Message)pbConvertor.convert2Proto(msg))); } MergedResultMessageProto mergedWarpMessageProto = MergedResultMessageProto.newBuilder().setAbstractMessage( abstractMessage) .addAllMsgs(lists) .build(); return mergedWarpMessageProto; } }
MergeResultMessageConvertor implements PbConvertor<MergeResultMessage, MergedResultMessageProto> { @Override public MergedResultMessageProto convert2Proto(MergeResultMessage mergeResultMessage) { final short typeCode = mergeResultMessage.getTypeCode(); final AbstractMessageProto abstractMessage = AbstractMessageProto.newBuilder().setMessageType( MessageTypeProto.forNumber(typeCode)).build(); List<Any> lists = new ArrayList<>(); for (AbstractMessage msg : mergeResultMessage.msgs) { final PbConvertor pbConvertor = ProtobufConvertManager.getInstance().fetchConvertor( msg.getClass().getName()); lists.add(Any.pack((Message)pbConvertor.convert2Proto(msg))); } MergedResultMessageProto mergedWarpMessageProto = MergedResultMessageProto.newBuilder().setAbstractMessage( abstractMessage) .addAllMsgs(lists) .build(); return mergedWarpMessageProto; }  }
MergeResultMessageConvertor implements PbConvertor<MergeResultMessage, MergedResultMessageProto> { @Override public MergedResultMessageProto convert2Proto(MergeResultMessage mergeResultMessage) { final short typeCode = mergeResultMessage.getTypeCode(); final AbstractMessageProto abstractMessage = AbstractMessageProto.newBuilder().setMessageType( MessageTypeProto.forNumber(typeCode)).build(); List<Any> lists = new ArrayList<>(); for (AbstractMessage msg : mergeResultMessage.msgs) { final PbConvertor pbConvertor = ProtobufConvertManager.getInstance().fetchConvertor( msg.getClass().getName()); lists.add(Any.pack((Message)pbConvertor.convert2Proto(msg))); } MergedResultMessageProto mergedWarpMessageProto = MergedResultMessageProto.newBuilder().setAbstractMessage( abstractMessage) .addAllMsgs(lists) .build(); return mergedWarpMessageProto; }  @Override MergedResultMessageProto convert2Proto(MergeResultMessage mergeResultMessage); @Override MergeResultMessage convert2Model(MergedResultMessageProto mergedResultMessageProto); }
MergeResultMessageConvertor implements PbConvertor<MergeResultMessage, MergedResultMessageProto> { @Override public MergedResultMessageProto convert2Proto(MergeResultMessage mergeResultMessage) { final short typeCode = mergeResultMessage.getTypeCode(); final AbstractMessageProto abstractMessage = AbstractMessageProto.newBuilder().setMessageType( MessageTypeProto.forNumber(typeCode)).build(); List<Any> lists = new ArrayList<>(); for (AbstractMessage msg : mergeResultMessage.msgs) { final PbConvertor pbConvertor = ProtobufConvertManager.getInstance().fetchConvertor( msg.getClass().getName()); lists.add(Any.pack((Message)pbConvertor.convert2Proto(msg))); } MergedResultMessageProto mergedWarpMessageProto = MergedResultMessageProto.newBuilder().setAbstractMessage( abstractMessage) .addAllMsgs(lists) .build(); return mergedWarpMessageProto; }  @Override MergedResultMessageProto convert2Proto(MergeResultMessage mergeResultMessage); @Override MergeResultMessage convert2Model(MergedResultMessageProto mergedResultMessageProto);  }