use of io.nem.symbol.sdk.model.mosaic.MosaicNames in project nem2-sdk-java by nemtech.
the class CurrencyServiceTest method getNetworkCurrencyFromMosaicIdWhenEmptyNames.
@Test
void getNetworkCurrencyFromMosaicIdWhenEmptyNames() 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.just(Collections.singletonList(new MosaicNames(mosaicId, 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());
}
use of io.nem.symbol.sdk.model.mosaic.MosaicNames in project nem2-sdk-java by nemtech.
the class CurrencyServiceTest method getNetworkCurrencyFromMosaicIdWhenNamespaceIsPresent.
@Test
void getNetworkCurrencyFromMosaicIdWhenNamespaceIsPresent() 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)));
String name = "some.alias";
NamespaceId namespaceId = NamespaceId.createFromName(name);
MosaicNames mosaicNames = new MosaicNames(mosaicId, Arrays.asList(new NamespaceName(name), new NamespaceName("some.alias2")));
MosaicNames mosaicNames2 = new MosaicNames(mosaicId, Arrays.asList(new NamespaceName("some.alias2"), new NamespaceName("some.alias3")));
Mockito.when(namespaceRepository.getMosaicsNames(Mockito.eq(Collections.singletonList(mosaicId)))).thenReturn(Observable.just(Arrays.asList(mosaicNames, mosaicNames2)));
Currency currency = service.getCurrency(mosaicId).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());
}
use of io.nem.symbol.sdk.model.mosaic.MosaicNames in project nem2-sdk-java by nemtech.
the class NamespaceRepositoryVertxImplTest method shouldGetMosaicsNamesFromPublicKeys.
@Test
public void shouldGetMosaicsNamesFromPublicKeys() throws Exception {
MosaicId mosaicId = MapperUtils.toMosaicId("99262122238339734");
MosaicNamesDTO dto = new MosaicNamesDTO();
dto.setMosaicId("99262122238339734");
dto.setNames(Collections.singletonList("accountalias"));
MosaicsNamesDTO accountsNamesDTO = new MosaicsNamesDTO();
accountsNamesDTO.setMosaicNames(Collections.singletonList(dto));
mockRemoteCall(accountsNamesDTO);
List<MosaicNames> resolvedList = repository.getMosaicsNames(Collections.singletonList(mosaicId)).toFuture().get();
Assertions.assertEquals(1, resolvedList.size());
MosaicNames accountNames = resolvedList.get(0);
Assertions.assertEquals(mosaicId, accountNames.getMosaicId());
Assertions.assertEquals("accountalias", accountNames.getNames().get(0).getName());
}
use of io.nem.symbol.sdk.model.mosaic.MosaicNames in project nem2-sdk-java by nemtech.
the class NamespaceRepositoryOkHttpImplTest method shouldGetMosaicsNamesFromPublicKeys.
@Test
public void shouldGetMosaicsNamesFromPublicKeys() throws Exception {
MosaicId mosaicId = MapperUtils.toMosaicId("99262122238339734");
MosaicNamesDTO dto = new MosaicNamesDTO();
dto.setMosaicId("99262122238339734");
dto.setNames(Collections.singletonList("accountalias"));
MosaicsNamesDTO accountsNamesDTO = new MosaicsNamesDTO();
accountsNamesDTO.setMosaicNames(Collections.singletonList(dto));
mockRemoteCall(accountsNamesDTO);
List<MosaicNames> resolvedList = repository.getMosaicsNames(Collections.singletonList(mosaicId)).toFuture().get();
Assertions.assertEquals(1, resolvedList.size());
MosaicNames accountNames = resolvedList.get(0);
Assertions.assertEquals(mosaicId, accountNames.getMosaicId());
Assertions.assertEquals("accountalias", accountNames.getNames().get(0).getName());
}
use of io.nem.symbol.sdk.model.mosaic.MosaicNames in project nem2-sdk-java by nemtech.
the class NamespaceRepositoryVertxImpl method getMosaicsNames.
@Override
public Observable<List<MosaicNames>> getMosaicsNames(List<MosaicId> ids) {
MosaicIds mosaicIds = new MosaicIds();
mosaicIds.mosaicIds(ids.stream().map(MosaicId::getIdAsHex).collect(Collectors.toList()));
Consumer<Handler<AsyncResult<MosaicsNamesDTO>>> callback = handler -> getClient().getMosaicsNames(mosaicIds, handler);
return exceptionHandling(call(callback).map(MosaicsNamesDTO::getMosaicNames).flatMapIterable(item -> item).map(this::toMosaicNames).toList().toObservable());
}
Aggregations