Search in sources :

Example 6 with NamespaceName

use of io.nem.symbol.sdk.model.namespace.NamespaceName in project nem2-sdk-java by nemtech.

the class NamespaceRepositoryOkHttpImplTest method shouldGetNamespaceNames.

@Test
public void shouldGetNamespaceNames() throws Exception {
    NamespaceId namespaceId = NamespaceId.createFromName("accountalias");
    NamespaceNameDTO dto1 = new NamespaceNameDTO();
    dto1.setName("someName1");
    dto1.setId("1");
    dto1.setParentId("2");
    NamespaceNameDTO dto2 = new NamespaceNameDTO();
    dto2.setName("someName2");
    dto2.setId("3");
    mockRemoteCall(Arrays.asList(dto1, dto2));
    List<NamespaceName> names = repository.getNamespaceNames(Arrays.asList(namespaceId)).toFuture().get();
    Assertions.assertNotNull(names);
    Assertions.assertEquals(2, names.size());
    Assertions.assertEquals("someName1", names.get(0).getName());
    Assertions.assertEquals(BigInteger.valueOf(1L), names.get(0).getNamespaceId().getId());
    Assertions.assertEquals(BigInteger.valueOf(2L), names.get(0).getParentId().orElseThrow(() -> new IllegalStateException("No parent id")).getId());
    Assertions.assertEquals("someName2", names.get(1).getName());
    Assertions.assertEquals(BigInteger.valueOf(3L), names.get(1).getNamespaceId().getId());
    Assertions.assertFalse(names.get(1).getParentId().isPresent());
}
Also used : NamespaceName(io.nem.symbol.sdk.model.namespace.NamespaceName) NamespaceNameDTO(io.nem.symbol.sdk.openapi.okhttp_gson.model.NamespaceNameDTO) NamespaceId(io.nem.symbol.sdk.model.namespace.NamespaceId) Test(org.junit.jupiter.api.Test)

Example 7 with NamespaceName

use of io.nem.symbol.sdk.model.namespace.NamespaceName 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 8 with NamespaceName

use of io.nem.symbol.sdk.model.namespace.NamespaceName in project nem2-sdk-java by nemtech.

the class MosaicNamesTest method createMosaicNames.

@Test
void createMosaicNames() {
    MosaicId mosaicId = new MosaicId(new BigInteger("-3087871471161192663"));
    List<NamespaceName> namespaceNames = Arrays.asList(new NamespaceName("xem"), new NamespaceName("anotheralias"));
    MosaicNames names = new MosaicNames(mosaicId, namespaceNames);
    assertEquals(mosaicId, names.getMosaicId());
    assertEquals(namespaceNames, names.getNames());
}
Also used : NamespaceName(io.nem.symbol.sdk.model.namespace.NamespaceName) BigInteger(java.math.BigInteger) Test(org.junit.jupiter.api.Test)

Aggregations

NamespaceName (io.nem.symbol.sdk.model.namespace.NamespaceName)8 NamespaceId (io.nem.symbol.sdk.model.namespace.NamespaceId)6 Test (org.junit.jupiter.api.Test)6 BigInteger (java.math.BigInteger)4 Account (io.nem.symbol.sdk.model.account.Account)3 MosaicId (io.nem.symbol.sdk.model.mosaic.MosaicId)3 MosaicNames (io.nem.symbol.sdk.model.mosaic.MosaicNames)3 Address (io.nem.symbol.sdk.model.account.Address)2 Currency (io.nem.symbol.sdk.model.mosaic.Currency)2 MosaicInfo (io.nem.symbol.sdk.model.mosaic.MosaicInfo)2 NamespaceNameDTO (io.nem.symbol.sdk.openapi.vertx.model.NamespaceNameDTO)2 Observable (io.reactivex.Observable)2 List (java.util.List)2 Collectors (java.util.stream.Collectors)2 MapperUtils (io.nem.symbol.core.utils.MapperUtils)1 MapperUtils.toNamespaceId (io.nem.symbol.core.utils.MapperUtils.toNamespaceId)1 Listener (io.nem.symbol.sdk.api.Listener)1 NamespaceRepository (io.nem.symbol.sdk.api.NamespaceRepository)1 NamespaceSearchCriteria (io.nem.symbol.sdk.api.NamespaceSearchCriteria)1 Page (io.nem.symbol.sdk.api.Page)1