Search in sources :

Example 11 with RepositoryCallException

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

the class MetadataTransactionServiceTest method shouldNotCreateMosaicMetadataTransactionFactoryWhenAnyOtherRemoteException.

@Test
void shouldNotCreateMosaicMetadataTransactionFactoryWhenAnyOtherRemoteException() {
    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(mosaicId).metadataType(MetadataType.MOSAIC);
    Mockito.when(metadataRepositoryMock.search(Mockito.eq(criteria))).thenReturn(Observable.error(expectedException));
    RepositoryCallException exception = Assertions.assertThrows(RepositoryCallException.class, () -> ExceptionUtils.propagate(() -> service.createMosaicMetadataTransactionFactory(targetAccount.getAddress(), metadataKey, newValue, sourceAddress, mosaicId).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 12 with RepositoryCallException

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

the class RepositoryFactoryOkHttpImplTest method getGenerationHashFailWhenInvalidServer.

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

Example 13 with RepositoryCallException

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

the class RepositoryFactoryOkHttpImplTest method getNetworkTypeFailWhenInvalidServer.

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

Example 14 with RepositoryCallException

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

the class CurrencyServiceIntegrationTest method testNetworkCurrencyInvalidNamespaceId.

@ParameterizedTest
@EnumSource(RepositoryType.class)
void testNetworkCurrencyInvalidNamespaceId(RepositoryType type) {
    RepositoryFactory repositoryFactory = getRepositoryFactory(type);
    CurrencyService service = new CurrencyServiceImpl(repositoryFactory);
    RepositoryCallException exception = Assertions.assertThrows(RepositoryCallException.class, () -> {
        get(service.getCurrencyFromNamespaceId(NamespaceId.createFromName("invalid.currency")));
    });
    Assertions.assertEquals("ApiException: Not Found - 404 - ResourceNotFound - no resource exists with id 'C1DF8A076D934A50'", exception.getMessage());
}
Also used : RepositoryCallException(io.nem.symbol.sdk.api.RepositoryCallException) RepositoryFactory(io.nem.symbol.sdk.api.RepositoryFactory) CurrencyService(io.nem.symbol.sdk.api.CurrencyService) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 15 with RepositoryCallException

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

the class CurrencyServiceIntegrationTest method testNetworkCurrencyInvaliMosaicId.

@ParameterizedTest
@EnumSource(RepositoryType.class)
void testNetworkCurrencyInvaliMosaicId(RepositoryType type) {
    RepositoryFactory repositoryFactory = getRepositoryFactory(type);
    CurrencyService service = new CurrencyServiceImpl(repositoryFactory);
    RepositoryCallException exception = Assertions.assertThrows(RepositoryCallException.class, () -> {
        get(service.getCurrency(new MosaicId(BigInteger.TEN)));
    });
    Assertions.assertEquals("ApiException: Not Found - 404 - ResourceNotFound - no resource exists with id '000000000000000A'", exception.getMessage());
}
Also used : RepositoryCallException(io.nem.symbol.sdk.api.RepositoryCallException) MosaicId(io.nem.symbol.sdk.model.mosaic.MosaicId) RepositoryFactory(io.nem.symbol.sdk.api.RepositoryFactory) CurrencyService(io.nem.symbol.sdk.api.CurrencyService) 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