use of io.nem.symbol.sdk.api.RepositoryCallException in project nem2-sdk-java by nemtech.
the class TransactionRepositoryIntegrationTest method throwExceptionWhenTransactionDoesNotExists.
@ParameterizedTest
@EnumSource(RepositoryType.class)
public void throwExceptionWhenTransactionDoesNotExists(RepositoryType type) {
RepositoryCallException exception = Assertions.assertThrows(RepositoryCallException.class, () -> get(getTransactionRepository(type).getTransaction(TransactionGroup.CONFIRMED, invalidTransactionHash)));
Assertions.assertEquals("ApiException: Not Found - 404 - ResourceNotFound - no resource exists with id '" + invalidTransactionHash + "'", exception.getMessage());
}
use of io.nem.symbol.sdk.api.RepositoryCallException in project nem2-sdk-java by nemtech.
the class TestHelper method isMultisig.
public boolean isMultisig(RepositoryType type, Account multisigAccount) {
try {
MultisigRepository multisigRepository = getRepositoryFactory(type).createMultisigRepository();
MultisigAccountInfo multisigAccountInfo = get(multisigRepository.getMultisigAccountInfo(multisigAccount.getAddress()));
return multisigAccountInfo != null;
} catch (RepositoryCallException e) {
Assertions.assertEquals(404, e.getStatusCode());
return false;
}
}
use of io.nem.symbol.sdk.api.RepositoryCallException in project nem2-sdk-java by nemtech.
the class TestHelper method createMultisigAccountComplete.
public MultisigAccountInfo createMultisigAccountComplete(RepositoryType type, Account multisigAccount, Account... accounts) {
AccountRepository accountRepository = getRepositoryFactory(type).createAccountRepository();
MultisigRepository multisigRepository = getRepositoryFactory(type).createMultisigRepository();
AccountInfo accountInfo = get(accountRepository.getAccountInfo(multisigAccount.getAddress()));
System.out.println(getJsonHelper().print(accountInfo));
try {
MultisigAccountInfo multisigAccountInfo = get(multisigRepository.getMultisigAccountInfo(multisigAccount.getAddress()));
System.out.println("Multisig account with address " + multisigAccount.getAddress().plain() + " already exist");
System.out.println(getJsonHelper().print(multisigAccountInfo));
return multisigAccountInfo;
} catch (RepositoryCallException e) {
System.out.println("Multisig account with address " + multisigAccount.getAddress().plain() + " does not exist. Creating");
}
System.out.println("Creating multisg account " + multisigAccount.getAddress().plain());
List<UnresolvedAddress> additions = Arrays.stream(accounts).map(Account::getAddress).collect(Collectors.toList());
MultisigAccountModificationTransaction convertIntoMultisigTransaction = MultisigAccountModificationTransactionFactory.create(getNetworkType(), getDeadline(), (byte) 1, (byte) 1, additions, Collections.emptyList()).maxFee(maxFee).build();
AggregateTransaction aggregateTransaction = AggregateTransactionFactory.createComplete(getNetworkType(), getDeadline(), Collections.singletonList(convertIntoMultisigTransaction.toAggregate(multisigAccount.getPublicAccount()))).maxFee(maxFee).build();
SignedTransaction signedAggregateTransaction = aggregateTransaction.signTransactionWithCosigners(multisigAccount, Arrays.asList(accounts), getGenerationHash());
Transaction aggregateTransaciton = get(getTransactionService(type).announce(getListener(type), signedAggregateTransaction));
sleep(1000);
Assertions.assertEquals(aggregateTransaciton.getTransactionInfo().get().getHash().get(), signedAggregateTransaction.getHash());
return get(multisigRepository.getMultisigAccountInfo(multisigAccount.getAddress()));
}
use of io.nem.symbol.sdk.api.RepositoryCallException in project nem2-sdk-java by nemtech.
the class NamespaceRepositoryIntegrationTest method throwExceptionWhenNamespaceDoesNotExists.
@ParameterizedTest
@EnumSource(RepositoryType.class)
void throwExceptionWhenNamespaceDoesNotExists(RepositoryType type) {
RepositoryCallException exception = Assertions.assertThrows(RepositoryCallException.class, () -> get(getNamespaceRepository(type).getNamespace(NamespaceId.createFromName("nonregisterednamespace"))));
Assertions.assertEquals("ApiException: Not Found - 404 - ResourceNotFound - no resource exists with id 'F75CF605C224A9E7'", exception.getMessage());
}
use of io.nem.symbol.sdk.api.RepositoryCallException in project nem2-sdk-java by nemtech.
the class CurrencyServiceTest method getNetworkCurrencyFromMosaicIdWhenNoNamespaceError.
@Test
void getNetworkCurrencyFromMosaicIdWhenNoNamespaceError() throws Exception {
MosaicId mosaicId = new MosaicId(BigInteger.TEN);
Account account = Account.generateNewAccount(NetworkType.MAIN_NET);
BigInteger supply = BigInteger.valueOf(12);
MosaicInfo mosaicInfo = new MosaicInfo("abc", 1, mosaicId, supply, BigInteger.ONE, account.getAddress(), 4L, MosaicFlags.create(true, true, true), 10, BigInteger.TEN);
Mockito.when(mosaicRepository.getMosaics(Mockito.eq(Collections.singletonList(mosaicId)))).thenReturn(Observable.just(Collections.singletonList(mosaicInfo)));
Mockito.when(namespaceRepository.getMosaicsNames(Mockito.eq(Collections.singletonList(mosaicId)))).thenReturn(Observable.error(new RepositoryCallException("Not found", 404, null)));
Currency currency = service.getCurrency(mosaicId).toFuture().get();
Assertions.assertEquals(10, currency.getDivisibility());
Assertions.assertEquals(mosaicId, currency.getUnresolvedMosaicId());
Assertions.assertEquals(mosaicId, currency.getMosaicId().get());
Assertions.assertFalse(currency.getNamespaceId().isPresent());
Assertions.assertTrue(currency.isTransferable());
Assertions.assertTrue(currency.isSupplyMutable());
}
Aggregations