use of io.nem.symbol.sdk.openapi.vertx.model.TransactionInfoDTO in project nem2-sdk-java by nemtech.
the class TransactionMapperSerializationVertxTest method testDtoToModelMapping.
@ParameterizedTest
@MethodSource("transactionJsonFiles")
void testDtoToModelMapping(String jsonFilename) {
String json = TestHelperVertx.loadResource(jsonFilename);
TransactionInfoDTO originalTransactionInfo = jsonHelper.parse(json, TransactionInfoDTO.class);
Transaction transactionModel = transactionMapper.mapFromDto(originalTransactionInfo);
Assertions.assertNotNull(transactionModel);
TransactionInfoDTO mappedTransactionInfo = (TransactionInfoDTO) transactionMapper.mapToDto(transactionModel);
Map<String, Object> transactionMap = jsonHelper.convert(mappedTransactionInfo.getTransaction(), Map.class);
Map<String, Object> originalTransactionMap = jsonHelper.convert(originalTransactionInfo.getTransaction(), Map.class);
originalTransactionMap.put("size", transactionModel.getSize());
originalTransactionInfo.setTransaction(originalTransactionMap);
// Patching the sort
mappedTransactionInfo.setTransaction(transactionMap);
mappedTransactionInfo.setMeta(jsonHelper.convert(mappedTransactionInfo.getMeta(), Map.class));
Assertions.assertEquals(jsonHelper.prettyPrint(originalTransactionInfo), jsonHelper.prettyPrint(mappedTransactionInfo));
BinarySerialization serialization = new BinarySerializationImpl();
Transaction transaction = transactionMapper.mapFromDto(mappedTransactionInfo);
byte[] serialize1 = serialization.serialize(transactionModel);
byte[] serialize2 = serialization.serialize(transaction);
Assertions.assertEquals(ConvertUtils.toHex(serialize1), ConvertUtils.toHex(serialize2));
removeMeta(originalTransactionInfo);
byte[] serialize3 = serialization.serialize(transactionModel);
Assertions.assertEquals(ConvertUtils.toHex(serialize1), ConvertUtils.toHex(serialize3));
Transaction deserialized3 = serialization.deserialize(serialize3);
TransactionInfoDTO deserializedTransaction = (TransactionInfoDTO) transactionMapper.mapToDto(deserialized3, false);
deserializedTransaction.setTransaction(jsonHelper.convert(deserializedTransaction.getTransaction(), Map.class));
removeMeta(deserializedTransaction);
Assertions.assertEquals(jsonHelper.prettyPrint(originalTransactionInfo), jsonHelper.prettyPrint(deserializedTransaction));
}
use of io.nem.symbol.sdk.openapi.vertx.model.TransactionInfoDTO in project nem2-sdk-java by nemtech.
the class AbstractTransactionMapper method mapToFactoryFromDto.
@Override
public TransactionFactory<T> mapToFactoryFromDto(Object object) {
if (object instanceof EmbeddedTransactionInfoDTO) {
EmbeddedTransactionInfoDTO transactionInfoDTO = (EmbeddedTransactionInfoDTO) object;
TransactionInfo transactionInfo = createTransactionInfo(transactionInfoDTO.getMeta(), transactionInfoDTO.getId());
return createFactory(transactionInfo, transactionInfoDTO.getTransaction());
}
TransactionInfoDTO transactionInfoDTO = this.jsonHelper.convert(object, TransactionInfoDTO.class);
TransactionInfo transactionInfo = createTransactionInfo(transactionInfoDTO.getMeta(), transactionInfoDTO.getId());
return createFactory(transactionInfo, transactionInfoDTO.getTransaction());
}
use of io.nem.symbol.sdk.openapi.vertx.model.TransactionInfoDTO in project nem2-sdk-java by nemtech.
the class AbstractTransactionMapper method mapToDto.
@Override
public Object mapToDto(Transaction transaction, Boolean embedded) {
if (transaction.getTransactionInfo().flatMap(TransactionInfo::getAggregateHash).isPresent() || Boolean.TRUE.equals(embedded)) {
EmbeddedTransactionInfoDTO dto = new EmbeddedTransactionInfoDTO();
dto.setMeta(createTransactionInfoEmbedded(transaction));
dto.setId(transaction.getRecordId().orElse(null));
dto.setTransaction(mapTransaction(transaction, true));
return dto;
} else {
TransactionInfoDTO dto = new TransactionInfoDTO();
dto.setMeta(createTransactionInfo(transaction));
dto.setId(transaction.getRecordId().orElse(null));
dto.setTransaction(mapTransaction(transaction, false));
return dto;
}
}
use of io.nem.symbol.sdk.openapi.vertx.model.TransactionInfoDTO in project nem2-sdk-java by nemtech.
the class ListenerVertxTest method subscribeAlias.
@ParameterizedTest
@ValueSource(strings = { "CONFIRMED_ADDED", "AGGREGATE_BONDED_ADDED", "UNCONFIRMED_ADDED" })
public void subscribeAlias(ListenerChannel channel) throws InterruptedException, ExecutionException, TimeoutException {
String channelName = channel.toString();
simulateWebSocketStartup();
TransactionInfoDTO transactionInfo = TestHelperVertx.loadTransactionInfoDTO("transferEmptyMessage.json");
NamespaceId namespaceId = NamespaceId.createFromName("alias");
ObjectNode transactionInfoDtoJsonObject = jsonHelper.convert(transactionInfo, ObjectNode.class);
List<Transaction> transactions = new ArrayList<>();
BiFunction<UnresolvedAddress, String, Observable<? extends Transaction>> subscriber = channel == ListenerChannel.CONFIRMED_ADDED ? listener::confirmed : channel == ListenerChannel.UNCONFIRMED_ADDED ? listener::unconfirmedAdded : listener::aggregateBondedAdded;
TransactionMetaDTO meta = jsonHelper.convert(transactionInfo.getMeta(), TransactionMetaDTO.class);
subscriber.apply(namespaceId, meta.getHash()).forEach(transactions::add);
handle(transactionInfoDtoJsonObject, channelName + "/" + namespaceId.plain());
Assertions.assertEquals(1, transactions.size());
Mockito.verify(webSocketMock).handler(Mockito.any());
Mockito.verify(webSocketMock).writeTextMessage(jsonHelper.print(new ListenerSubscribeMessage(this.wsId, channelName + "/" + namespaceId.plain())));
Mockito.verify(webSocketMock).writeTextMessage(jsonHelper.print(new ListenerSubscribeMessage(this.wsId, channelName + "/" + namespaceId.plain())));
}
use of io.nem.symbol.sdk.openapi.vertx.model.TransactionInfoDTO in project nem2-sdk-java by nemtech.
the class TransactionRepositoryVertxImplTest method shouldGetTransactionUnconfirmed.
@Test
public void shouldGetTransactionUnconfirmed() throws Exception {
TransactionInfoDTO transactionInfoDTO = TestHelperVertx.loadTransactionInfoDTO("aggregateMosaicCreationTransaction.json", TransactionInfoDTO.class);
String hash = jsonHelper.getString(transactionInfoDTO, "meta", "hash");
mockRemoteCall(transactionInfoDTO);
Transaction transaction = repository.getTransaction(TransactionGroup.UNCONFIRMED, hash).toFuture().get();
Assertions.assertNotNull(transaction);
Assertions.assertEquals(hash, transaction.getTransactionInfo().get().getHash().get());
Assertions.assertEquals(TransactionGroup.UNCONFIRMED, transaction.getGroup().get());
}
Aggregations