Search in sources :

Example 6 with RepositoryCallException

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

the class BlockRepositoryIntegrationTest method throwExceptionWhenBlockDoesNotExists.

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

Example 7 with RepositoryCallException

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

the class AccountRestrictionIntegrationTest method getAccountRestrictionsWhenAccountDoesNotExist.

@ParameterizedTest
@EnumSource(RepositoryType.class)
void getAccountRestrictionsWhenAccountDoesNotExist(RepositoryType type) {
    RestrictionAccountRepository repository = getRepositoryFactory(type).createRestrictionAccountRepository();
    Address address = Address.createFromPublicKey("67F69FA4BFCD158F6E1AF1ABC82F725F5C5C4710D6E29217B12BE66397435DFB", getNetworkType());
    RepositoryCallException exception = Assertions.assertThrows(RepositoryCallException.class, () -> get(repository.getAccountRestrictions(address)));
    Assertions.assertTrue(exception.getMessage().contains("ApiException: Not Found - 404 - ResourceNotFound - no resource exists with id"));
}
Also used : UnresolvedAddress(io.nem.symbol.sdk.model.account.UnresolvedAddress) Address(io.nem.symbol.sdk.model.account.Address) RepositoryCallException(io.nem.symbol.sdk.api.RepositoryCallException) RestrictionAccountRepository(io.nem.symbol.sdk.api.RestrictionAccountRepository) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 8 with RepositoryCallException

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

the class RepositoryFactoryVertxImplTest method getNetworkTypeFailWhenInvalidServer.

@Test
public void getNetworkTypeFailWhenInvalidServer() {
    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 9 with RepositoryCallException

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

the class MetadataTransactionServiceTest method shouldNotCreateNamespaceMetadataTransactionFactoryWhenAnyOtherRemoteException.

@Test
void shouldNotCreateNamespaceMetadataTransactionFactoryWhenAnyOtherRemoteException() {
    BigInteger metadataKey = BigInteger.valueOf(10);
    String newValue = "the new Message";
    RepositoryCallException expectedException = new RepositoryCallException("Some other problem.", 500, null);
    MetadataSearchCriteria criteria = new MetadataSearchCriteria().sourceAddress(sourceAddress).scopedMetadataKey(metadataKey).targetId(namespaceId).metadataType(MetadataType.NAMESPACE);
    Mockito.when(metadataRepositoryMock.search(Mockito.eq(criteria))).thenReturn(Observable.error(expectedException));
    RepositoryCallException exception = Assertions.assertThrows(RepositoryCallException.class, () -> ExceptionUtils.propagate(() -> service.createNamespaceMetadataTransactionFactory(targetAccount.getAddress(), metadataKey, newValue, sourceAddress, namespaceId).toFuture().get()));
    Assertions.assertEquals(expectedException, exception);
    Mockito.verify(metadataRepositoryMock).search(criteria);
}
Also used : MetadataSearchCriteria(io.nem.symbol.sdk.api.MetadataSearchCriteria) RepositoryCallException(io.nem.symbol.sdk.api.RepositoryCallException) BigInteger(java.math.BigInteger) Test(org.junit.jupiter.api.Test)

Example 10 with RepositoryCallException

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

the class MetadataTransactionServiceTest method shouldNotCreateAccountMetadataTransactionFactoryWhenAnyOtherRemoteException.

@Test
void shouldNotCreateAccountMetadataTransactionFactoryWhenAnyOtherRemoteException() {
    BigInteger metadataKey = BigInteger.valueOf(10);
    String newValue = "the new Message";
    RepositoryCallException expectedException = new RepositoryCallException("Some other problem.", 500, null);
    MetadataSearchCriteria criteria = new MetadataSearchCriteria().sourceAddress(sourceAddress).scopedMetadataKey(metadataKey).targetAddress(targetAccount.getAddress()).metadataType(MetadataType.ACCOUNT);
    Mockito.when(metadataRepositoryMock.search(Mockito.eq(criteria))).thenReturn(Observable.error(expectedException));
    RepositoryCallException exception = Assertions.assertThrows(RepositoryCallException.class, () -> ExceptionUtils.propagate(() -> service.createAccountMetadataTransactionFactory(targetAccount.getAddress(), metadataKey, newValue, sourceAddress).toFuture().get()));
    Assertions.assertEquals(expectedException, exception);
    Mockito.verify(metadataRepositoryMock).search(Mockito.eq(criteria));
}
Also used : MetadataSearchCriteria(io.nem.symbol.sdk.api.MetadataSearchCriteria) RepositoryCallException(io.nem.symbol.sdk.api.RepositoryCallException) BigInteger(java.math.BigInteger) Test(org.junit.jupiter.api.Test)

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