use of io.nem.symbol.sdk.openapi.okhttp_gson.model.TransactionInfoDTO in project nem2-sdk-java by nemtech.
the class TransactionMapperSerializationOkHttpTest method testDtoToModelMapping.
@ParameterizedTest
@MethodSource("transactionJsonFiles")
void testDtoToModelMapping(String jsonFilename) {
String json = TestHelperOkHttp.loadResource(jsonFilename);
TransactionInfoDTO originalTransactionInfo = jsonHelper.parse(json, TransactionInfoDTO.class);
Transaction transactionModel = transactionMapper.mapFromDto(originalTransactionInfo);
Integer version = jsonHelper.getInteger(originalTransactionInfo, "transaction", "version");
Integer type = jsonHelper.getInteger(originalTransactionInfo, "transaction", "type");
Integer network = jsonHelper.getInteger(originalTransactionInfo, "transaction", "network");
Assertions.assertEquals(transactionModel.getVersion(), version);
Assertions.assertEquals(transactionModel.getType().getValue(), type);
Assertions.assertEquals(transactionModel.getNetworkType().getValue(), network);
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));
BinarySerialization serialization = new BinarySerializationImpl();
String serialized = ConvertUtils.toHex(serialization.serialize(transactionModel));
TransactionBuilder builder = TransactionBuilderHelper.loadFromBinary(SerializationUtils.toDataInput(serialization.serialize(transactionModel)));
System.out.println(ConvertUtils.toHex(builder.serialize()));
serialization.deserialize(serialization.serialize(transactionModel));
Assertions.assertEquals(jsonHelper.prettyPrint(originalTransactionInfo), jsonHelper.prettyPrint(mappedTransactionInfo));
Assertions.assertEquals(serialized, ConvertUtils.toHex(serialization.serialize(transactionMapper.mapFromDto(mappedTransactionInfo))));
originalTransactionInfo.setMeta(null);
Map<String, Object> transactionJson = (Map<String, Object>) originalTransactionInfo.getTransaction();
if (transactionJson.containsKey("transactions")) {
List<Map<String, Object>> transactionsJson = (List<Map<String, Object>>) transactionJson.get("transactions");
transactionsJson.forEach(t -> t.remove("meta"));
}
}
use of io.nem.symbol.sdk.openapi.okhttp_gson.model.TransactionInfoDTO in project nem2-sdk-java by nemtech.
the class TransactionMapperOkHttpTest method shouldCreateAccountOperationRestriction.
@Test
public void shouldCreateAccountOperationRestriction() throws Exception {
TransactionInfoDTO transactionInfoDTO = TestHelperOkHttp.loadTransactionInfoDTO("accountOperationRestrictionTransaction.json");
AccountOperationRestrictionTransaction transaction = (AccountOperationRestrictionTransaction) map(transactionInfoDTO);
validateStandaloneTransaction(transaction, transactionInfoDTO);
Assertions.assertEquals(AccountOperationRestrictionFlags.ALLOW_OUTGOING_TRANSACTION_TYPE, transaction.getRestrictionFlags());
Assertions.assertEquals(1, transaction.getRestrictionAdditions().size());
Assertions.assertEquals(TransactionType.MOSAIC_METADATA, transaction.getRestrictionAdditions().get(0));
}
use of io.nem.symbol.sdk.openapi.okhttp_gson.model.TransactionInfoDTO in project nem2-sdk-java by nemtech.
the class TransactionMapperOkHttpTest method shouldCreateAggregateSubNamespaceCreationTransaction.
@Test
void shouldCreateAggregateSubNamespaceCreationTransaction() {
TransactionInfoDTO aggregateNamespaceCreationTransactionDTO = TestHelperOkHttp.loadTransactionInfoDTO("aggregateSubNamespaceCreationTransaction.json");
Transaction aggregateNamespaceCreationTransaction = map(aggregateNamespaceCreationTransactionDTO);
validateAggregateTransaction((AggregateTransaction) aggregateNamespaceCreationTransaction, aggregateNamespaceCreationTransactionDTO);
}
use of io.nem.symbol.sdk.openapi.okhttp_gson.model.TransactionInfoDTO in project nem2-sdk-java by nemtech.
the class TransactionMapperOkHttpTest method shouldCreateAggregateRootNamespaceCreationTransaction.
@Test
void shouldCreateAggregateRootNamespaceCreationTransaction() {
TransactionInfoDTO aggregateNamespaceCreationTransactionDTO = TestHelperOkHttp.loadTransactionInfoDTO("aggregateRootNamespaceCreationTransaction.json");
Transaction aggregateNamespaceCreationTransaction = map(aggregateNamespaceCreationTransactionDTO);
validateAggregateTransaction((AggregateTransaction) aggregateNamespaceCreationTransaction, aggregateNamespaceCreationTransactionDTO);
}
use of io.nem.symbol.sdk.openapi.okhttp_gson.model.TransactionInfoDTO in project nem2-sdk-java by nemtech.
the class TransactionMapperOkHttpTest method shouldCreateAggregateMultisigModificationTransaction.
@Test
void shouldCreateAggregateMultisigModificationTransaction() {
TransactionInfoDTO aggregateMultisigModificationTransactionDTO = TestHelperOkHttp.loadTransactionInfoDTO("aggregateMultisigModificationTransaction.json");
Transaction aggregateMultisigModificationTransaction = map(aggregateMultisigModificationTransactionDTO);
validateAggregateTransaction((AggregateTransaction) aggregateMultisigModificationTransaction, aggregateMultisigModificationTransactionDTO);
}
Aggregations