Search in sources :

Example 16 with RepositoryCallException

use of io.nem.symbol.sdk.api.RepositoryCallException in project nem2-sdk-java by nemtech.

the class AccountRepositoryIntegrationTest method throwExceptionWhenAddressDoesNotExist.

@ParameterizedTest
@EnumSource(RepositoryType.class)
void throwExceptionWhenAddressDoesNotExist(RepositoryType type) {
    Address address = Address.generateRandom(getNetworkType());
    RepositoryCallException exception = Assertions.assertThrows(RepositoryCallException.class, () -> get(this.getAccountRepository(type).getAccountInfo(address)));
    Assertions.assertEquals("ApiException: Not Found - 404 - ResourceNotFound - no resource exists with id '" + address.plain() + "'", exception.getMessage());
}
Also used : Address(io.nem.symbol.sdk.model.account.Address) RepositoryCallException(io.nem.symbol.sdk.api.RepositoryCallException) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 17 with RepositoryCallException

use of io.nem.symbol.sdk.api.RepositoryCallException in project nem2-sdk-java by nemtech.

the class RepositoryFactoryVertxImplTest method getGenerationHashFailWhenInvalidServer.

@Test
public void getGenerationHashFailWhenInvalidServer() {
    String baseUrl = "https://localhost:1934/path";
    RepositoryCallException e = Assertions.assertThrows(RepositoryCallException.class, () -> GeneratorUtils.propagate(() -> new RepositoryFactoryVertxImpl(baseUrl).getNetworkType().toFuture().get()));
    Assertions.assertTrue(e.getMessage().contains("ApiException: Connection refused"));
}
Also used : RepositoryCallException(io.nem.symbol.sdk.api.RepositoryCallException) Test(org.junit.jupiter.api.Test)

Example 18 with RepositoryCallException

use of io.nem.symbol.sdk.api.RepositoryCallException in project nem2-sdk-java by nemtech.

the class TransactionRepositoryVertxImplTest method exceptionWhenRestCallFails.

@Test
public void exceptionWhenRestCallFails() {
    TransactionInfoDTO transactionInfoDTO = new TransactionInfoDTO();
    TransactionMetaDTO meta = new TransactionMetaDTO();
    meta.setHash("ABC");
    transactionInfoDTO.setMeta(meta);
    mockErrorCode(400, "The error message");
    RepositoryCallException exception = Assertions.assertThrows(RepositoryCallException.class, () -> {
        ExceptionUtils.propagateVoid(() -> {
            repository.getTransaction(TransactionGroup.CONFIRMED, meta.getHash()).toFuture().get();
        });
    });
    Assertions.assertTrue(exception.getMessage().contains("The error message"));
}
Also used : RepositoryCallException(io.nem.symbol.sdk.api.RepositoryCallException) 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) TransactionMetaDTO(io.nem.symbol.sdk.openapi.vertx.model.TransactionMetaDTO) Test(org.junit.jupiter.api.Test)

Example 19 with RepositoryCallException

use of io.nem.symbol.sdk.api.RepositoryCallException in project nem2-sdk-java by nemtech.

the class TransactionRepositoryVertxImplTest method exceptionWhenMapperFails.

@Test
public void exceptionWhenMapperFails() {
    TransactionInfoDTO transactionInfoDTO = new TransactionInfoDTO();
    TransactionMetaDTO meta = new TransactionMetaDTO();
    String hash = "ABC";
    meta.setHash(hash);
    transactionInfoDTO.setMeta(meta);
    mockRemoteCall(transactionInfoDTO);
    RepositoryCallException exception = Assertions.assertThrows(RepositoryCallException.class, () -> {
        ExceptionUtils.propagateVoid(() -> {
            repository.getTransaction(TransactionGroup.CONFIRMED, hash).toFuture().get();
        });
    });
    Assertions.assertTrue(exception.getMessage().contains("Transaction cannot be mapped, object does not not have transaction type."));
}
Also used : RepositoryCallException(io.nem.symbol.sdk.api.RepositoryCallException) 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) TransactionMetaDTO(io.nem.symbol.sdk.openapi.vertx.model.TransactionMetaDTO) Test(org.junit.jupiter.api.Test)

Example 20 with RepositoryCallException

use of io.nem.symbol.sdk.api.RepositoryCallException in project nem2-sdk-java by nemtech.

the class TransactionRepositoryIntegrationTest method throwExceptionWhenTransactionStatusOfATransactionDoesNotExists.

@ParameterizedTest
@EnumSource(RepositoryType.class)
public void throwExceptionWhenTransactionStatusOfATransactionDoesNotExists(RepositoryType type) {
    RepositoryCallException exception = Assertions.assertThrows(RepositoryCallException.class, () -> get(getTransactionStatusRepository(type).getTransactionStatus(invalidTransactionHash)));
    Assertions.assertEquals("ApiException: Not Found - 404 - ResourceNotFound - no resource exists with id '" + invalidTransactionHash + "'", exception.getMessage());
}
Also used : RepositoryCallException(io.nem.symbol.sdk.api.RepositoryCallException) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

RepositoryCallException (io.nem.symbol.sdk.api.RepositoryCallException)25 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)13 EnumSource (org.junit.jupiter.params.provider.EnumSource)13 Test (org.junit.jupiter.api.Test)10 BigInteger (java.math.BigInteger)4 MetadataSearchCriteria (io.nem.symbol.sdk.api.MetadataSearchCriteria)3 Address (io.nem.symbol.sdk.model.account.Address)3 MosaicId (io.nem.symbol.sdk.model.mosaic.MosaicId)3 AccountRepository (io.nem.symbol.sdk.api.AccountRepository)2 CurrencyService (io.nem.symbol.sdk.api.CurrencyService)2 HashLockRepository (io.nem.symbol.sdk.api.HashLockRepository)2 MultisigRepository (io.nem.symbol.sdk.api.MultisigRepository)2 RepositoryFactory (io.nem.symbol.sdk.api.RepositoryFactory)2 TestHelperVertx.loadTransactionInfoDTO (io.nem.symbol.sdk.infrastructure.vertx.TestHelperVertx.loadTransactionInfoDTO)2 MultisigAccountInfo (io.nem.symbol.sdk.model.account.MultisigAccountInfo)2 UnresolvedAddress (io.nem.symbol.sdk.model.account.UnresolvedAddress)2 AnnounceTransactionInfoDTO (io.nem.symbol.sdk.openapi.vertx.model.AnnounceTransactionInfoDTO)2 TransactionInfoDTO (io.nem.symbol.sdk.openapi.vertx.model.TransactionInfoDTO)2 TransactionMetaDTO (io.nem.symbol.sdk.openapi.vertx.model.TransactionMetaDTO)2 AccountSearchCriteria (io.nem.symbol.sdk.api.AccountSearchCriteria)1