Search in sources :

Example 16 with MosaicInfo

use of io.nem.symbol.sdk.model.mosaic.MosaicInfo in project nem2-sdk-java by nemtech.

the class MosaicRepositoryIntegrationTest method searchUsingOffset.

@ParameterizedTest
@EnumSource(RepositoryType.class)
void searchUsingOffset(RepositoryType type) {
    MosaicRepository mosaicRepository = getMosaicRepository(type);
    MosaicPaginationStreamer streamer = new MosaicPaginationStreamer(mosaicRepository);
    MosaicSearchCriteria criteria = new MosaicSearchCriteria();
    criteria.setPageSize(10);
    int offsetIndex = 2;
    List<MosaicInfo> mosaicsWithoutOffset = get(streamer.search(criteria).toList().toObservable());
    criteria.setOffset(mosaicsWithoutOffset.get(offsetIndex).getRecordId().get());
    List<MosaicInfo> mosaicFromOffsets = get(streamer.search(criteria).toList().toObservable());
    PaginationTester.sameEntities(mosaicsWithoutOffset.stream().skip(offsetIndex + 1).collect(Collectors.toList()), mosaicFromOffsets);
}
Also used : MosaicPaginationStreamer(io.nem.symbol.sdk.api.MosaicPaginationStreamer) MosaicInfo(io.nem.symbol.sdk.model.mosaic.MosaicInfo) MosaicRepository(io.nem.symbol.sdk.api.MosaicRepository) MosaicSearchCriteria(io.nem.symbol.sdk.api.MosaicSearchCriteria) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 17 with MosaicInfo

use of io.nem.symbol.sdk.model.mosaic.MosaicInfo in project nem2-sdk-java by nemtech.

the class CurrencyServiceTest method getNetworkCurrencyFromNamespaceId.

@Test
void getNetworkCurrencyFromNamespaceId() 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.getMosaic(Mockito.eq(mosaicId))).thenReturn(Observable.just(mosaicInfo));
    String name = "some.alias";
    NamespaceId namespaceId = NamespaceId.createFromName(name);
    MosaicNames mosaicNames = new MosaicNames(mosaicId, Arrays.asList(new NamespaceName(name), new NamespaceName("some.alias2")));
    Mockito.when(namespaceRepository.getLinkedMosaicId(Mockito.eq(namespaceId))).thenReturn(Observable.just(mosaicId));
    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.just(Collections.singletonList(mosaicNames)));
    Currency currency = service.getCurrencyFromNamespaceId(namespaceId).toFuture().get();
    Assertions.assertEquals(10, currency.getDivisibility());
    Assertions.assertEquals(mosaicId, currency.getUnresolvedMosaicId());
    Assertions.assertEquals(mosaicId, currency.getMosaicId().get());
    Assertions.assertEquals(namespaceId, currency.getNamespaceId().get());
    Assertions.assertEquals("some.alias", currency.getNamespaceId().get().getFullName().get());
    Assertions.assertTrue(currency.isTransferable());
    Assertions.assertTrue(currency.isSupplyMutable());
}
Also used : Account(io.nem.symbol.sdk.model.account.Account) MosaicInfo(io.nem.symbol.sdk.model.mosaic.MosaicInfo) NamespaceName(io.nem.symbol.sdk.model.namespace.NamespaceName) MosaicId(io.nem.symbol.sdk.model.mosaic.MosaicId) MosaicNames(io.nem.symbol.sdk.model.mosaic.MosaicNames) Currency(io.nem.symbol.sdk.model.mosaic.Currency) BigInteger(java.math.BigInteger) NamespaceId(io.nem.symbol.sdk.model.namespace.NamespaceId) Test(org.junit.jupiter.api.Test)

Example 18 with MosaicInfo

use of io.nem.symbol.sdk.model.mosaic.MosaicInfo 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());
}
Also used : Account(io.nem.symbol.sdk.model.account.Account) MosaicInfo(io.nem.symbol.sdk.model.mosaic.MosaicInfo) MosaicId(io.nem.symbol.sdk.model.mosaic.MosaicId) RepositoryCallException(io.nem.symbol.sdk.api.RepositoryCallException) Currency(io.nem.symbol.sdk.model.mosaic.Currency) BigInteger(java.math.BigInteger) Test(org.junit.jupiter.api.Test)

Example 19 with MosaicInfo

use of io.nem.symbol.sdk.model.mosaic.MosaicInfo in project nem2-sdk-java by nemtech.

the class CurrencyServiceTest method getNetworkCurrencyFromMosaicIdWhenNoNamespace.

@Test
void getNetworkCurrencyFromMosaicIdWhenNoNamespace() 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(Arrays.asList(mosaicId)))).thenReturn(Observable.just(Arrays.asList(mosaicInfo)));
    Mockito.when(namespaceRepository.getMosaicsNames(Mockito.eq(Collections.singletonList(mosaicId)))).thenReturn(Observable.just(Collections.emptyList()));
    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());
}
Also used : Account(io.nem.symbol.sdk.model.account.Account) MosaicInfo(io.nem.symbol.sdk.model.mosaic.MosaicInfo) MosaicId(io.nem.symbol.sdk.model.mosaic.MosaicId) Currency(io.nem.symbol.sdk.model.mosaic.Currency) BigInteger(java.math.BigInteger) Test(org.junit.jupiter.api.Test)

Aggregations

MosaicInfo (io.nem.symbol.sdk.model.mosaic.MosaicInfo)19 MosaicId (io.nem.symbol.sdk.model.mosaic.MosaicId)15 Test (org.junit.jupiter.api.Test)13 Address (io.nem.symbol.sdk.model.account.Address)9 MosaicSearchCriteria (io.nem.symbol.sdk.api.MosaicSearchCriteria)6 Account (io.nem.symbol.sdk.model.account.Account)5 Currency (io.nem.symbol.sdk.model.mosaic.Currency)5 BigInteger (java.math.BigInteger)5 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)5 EnumSource (org.junit.jupiter.params.provider.EnumSource)5 MosaicDTO (io.nem.symbol.sdk.openapi.vertx.model.MosaicDTO)4 MosaicInfoDTO (io.nem.symbol.sdk.openapi.vertx.model.MosaicInfoDTO)4 MosaicPaginationStreamer (io.nem.symbol.sdk.api.MosaicPaginationStreamer)3 MosaicRepository (io.nem.symbol.sdk.api.MosaicRepository)3 MosaicNames (io.nem.symbol.sdk.model.mosaic.MosaicNames)3 MosaicDTO (io.nem.symbol.sdk.openapi.okhttp_gson.model.MosaicDTO)3 MosaicInfoDTO (io.nem.symbol.sdk.openapi.okhttp_gson.model.MosaicInfoDTO)3 PublicAccount (io.nem.symbol.sdk.model.account.PublicAccount)2 NamespaceId (io.nem.symbol.sdk.model.namespace.NamespaceId)2 NamespaceName (io.nem.symbol.sdk.model.namespace.NamespaceName)2