Search in sources :

Example 26 with TransactionInfoDTO

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));
}
Also used : BinarySerialization(io.nem.symbol.sdk.api.BinarySerialization) Transaction(io.nem.symbol.sdk.model.transaction.Transaction) TransactionInfoDTO(io.nem.symbol.sdk.openapi.vertx.model.TransactionInfoDTO) Map(java.util.Map) BinarySerializationImpl(io.nem.symbol.sdk.infrastructure.BinarySerializationImpl) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 27 with TransactionInfoDTO

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());
}
Also used : EmbeddedTransactionInfoDTO(io.nem.symbol.sdk.openapi.vertx.model.EmbeddedTransactionInfoDTO) TransactionInfoDTO(io.nem.symbol.sdk.openapi.vertx.model.TransactionInfoDTO) TransactionInfo(io.nem.symbol.sdk.model.transaction.TransactionInfo) EmbeddedTransactionInfoDTO(io.nem.symbol.sdk.openapi.vertx.model.EmbeddedTransactionInfoDTO)

Example 28 with TransactionInfoDTO

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;
    }
}
Also used : EmbeddedTransactionInfoDTO(io.nem.symbol.sdk.openapi.vertx.model.EmbeddedTransactionInfoDTO) TransactionInfoDTO(io.nem.symbol.sdk.openapi.vertx.model.TransactionInfoDTO) TransactionInfo(io.nem.symbol.sdk.model.transaction.TransactionInfo) EmbeddedTransactionInfoDTO(io.nem.symbol.sdk.openapi.vertx.model.EmbeddedTransactionInfoDTO)

Example 29 with TransactionInfoDTO

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())));
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) UnresolvedAddress(io.nem.symbol.sdk.model.account.UnresolvedAddress) ArrayList(java.util.ArrayList) Observable(io.reactivex.Observable) ListenerSubscribeMessage(io.nem.symbol.sdk.infrastructure.ListenerSubscribeMessage) Transaction(io.nem.symbol.sdk.model.transaction.Transaction) CosignatureSignedTransaction(io.nem.symbol.sdk.model.transaction.CosignatureSignedTransaction) TransactionInfoDTO(io.nem.symbol.sdk.openapi.vertx.model.TransactionInfoDTO) NamespaceId(io.nem.symbol.sdk.model.namespace.NamespaceId) TransactionMetaDTO(io.nem.symbol.sdk.openapi.vertx.model.TransactionMetaDTO) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 30 with TransactionInfoDTO

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());
}
Also used : SignedTransaction(io.nem.symbol.sdk.model.transaction.SignedTransaction) TransferTransaction(io.nem.symbol.sdk.model.transaction.TransferTransaction) Transaction(io.nem.symbol.sdk.model.transaction.Transaction) CosignatureSignedTransaction(io.nem.symbol.sdk.model.transaction.CosignatureSignedTransaction) TestHelperVertx.loadTransactionInfoDTO(io.nem.symbol.sdk.infrastructure.vertx.TestHelperVertx.loadTransactionInfoDTO) TransactionInfoDTO(io.nem.symbol.sdk.openapi.vertx.model.TransactionInfoDTO) AnnounceTransactionInfoDTO(io.nem.symbol.sdk.openapi.vertx.model.AnnounceTransactionInfoDTO) Test(org.junit.jupiter.api.Test)

Aggregations

TransactionInfoDTO (io.nem.symbol.sdk.openapi.vertx.model.TransactionInfoDTO)55 Test (org.junit.jupiter.api.Test)46 Transaction (io.nem.symbol.sdk.model.transaction.Transaction)40 TransferTransaction (io.nem.symbol.sdk.model.transaction.TransferTransaction)36 AggregateTransaction (io.nem.symbol.sdk.model.transaction.AggregateTransaction)32 AccountAddressRestrictionTransaction (io.nem.symbol.sdk.model.transaction.AccountAddressRestrictionTransaction)28 AccountMetadataTransaction (io.nem.symbol.sdk.model.transaction.AccountMetadataTransaction)28 AccountMosaicRestrictionTransaction (io.nem.symbol.sdk.model.transaction.AccountMosaicRestrictionTransaction)28 AccountOperationRestrictionTransaction (io.nem.symbol.sdk.model.transaction.AccountOperationRestrictionTransaction)28 MosaicMetadataTransaction (io.nem.symbol.sdk.model.transaction.MosaicMetadataTransaction)28 NamespaceMetadataTransaction (io.nem.symbol.sdk.model.transaction.NamespaceMetadataTransaction)28 AccountKeyLinkTransaction (io.nem.symbol.sdk.model.transaction.AccountKeyLinkTransaction)27 AddressAliasTransaction (io.nem.symbol.sdk.model.transaction.AddressAliasTransaction)27 HashLockTransaction (io.nem.symbol.sdk.model.transaction.HashLockTransaction)27 MosaicAliasTransaction (io.nem.symbol.sdk.model.transaction.MosaicAliasTransaction)27 MosaicDefinitionTransaction (io.nem.symbol.sdk.model.transaction.MosaicDefinitionTransaction)27 MosaicSupplyChangeTransaction (io.nem.symbol.sdk.model.transaction.MosaicSupplyChangeTransaction)27 MultisigAccountModificationTransaction (io.nem.symbol.sdk.model.transaction.MultisigAccountModificationTransaction)27 NamespaceRegistrationTransaction (io.nem.symbol.sdk.model.transaction.NamespaceRegistrationTransaction)27 SecretLockTransaction (io.nem.symbol.sdk.model.transaction.SecretLockTransaction)27