Search in sources :

Example 6 with NamespaceInfo

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

the class NamespaceRegistrationIntegrationTest method standaloneRootRegisterNamespaceTransaction.

@ParameterizedTest
@EnumSource(RepositoryType.class)
void standaloneRootRegisterNamespaceTransaction(RepositoryType type) {
    String namespaceName = "test-root-namespace-" + Double.valueOf(Math.floor(Math.random() * 10000)).intValue();
    NamespaceRegistrationTransaction namespaceRegistrationTransaction = NamespaceRegistrationTransactionFactory.createRootNamespace(getNetworkType(), getDeadline(), namespaceName, helper().getDuration()).maxFee(maxFee).build();
    announceAndValidate(type, this.account, namespaceRegistrationTransaction);
    rootNamespaceId = namespaceRegistrationTransaction.getNamespaceId();
    sleep(1000);
    NamespaceInfo namespaceInfo = get(getRepositoryFactory(type).createNamespaceRepository().getNamespace(namespaceRegistrationTransaction.getNamespaceId()));
    Assertions.assertEquals(this.account.getAddress(), namespaceInfo.getOwnerAddress());
    Assertions.assertEquals(namespaceRegistrationTransaction.getNamespaceId(), namespaceInfo.getId());
}
Also used : NamespaceInfo(io.nem.symbol.sdk.model.namespace.NamespaceInfo) NamespaceRegistrationTransaction(io.nem.symbol.sdk.model.transaction.NamespaceRegistrationTransaction) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 7 with NamespaceInfo

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

the class StateProofServiceTest method namespace.

@Test
void namespace() throws Exception {
    NamespaceRepository repository = mock(NamespaceRepository.class);
    when(factory.createNamespaceRepository()).thenReturn(repository);
    NamespaceId id = NamespaceId.createFromId(BigInteger.ONE);
    NamespaceInfo state = Mockito.mock(NamespaceInfo.class);
    when(state.getId()).thenReturn(id);
    when(state.serialize(any())).thenReturn(ConvertUtils.fromHexToBytes(serialized));
    when(repository.streamer()).thenReturn(new PaginationStreamer<>(repository));
    when(repository.search(any())).thenReturn(Observable.just(new Page<>(new ArrayList<>())));
    when(repository.getNamespace(eq(id))).thenReturn(Observable.just(state));
    when(repository.getNamespaceMerkle(eq(id))).thenReturn(Observable.just(tree));
    StateMerkleProof<NamespaceInfo> proof = service.namespace(id).toFuture().get();
    Assertions.assertTrue(proof.isValid());
    Assertions.assertEquals(state, proof.getState());
}
Also used : NamespaceRepository(io.nem.symbol.sdk.api.NamespaceRepository) Page(io.nem.symbol.sdk.api.Page) NamespaceId(io.nem.symbol.sdk.model.namespace.NamespaceId) NamespaceInfo(io.nem.symbol.sdk.model.namespace.NamespaceInfo) Test(org.junit.jupiter.api.Test)

Example 8 with NamespaceInfo

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

the class NamespaceRepositoryOkHttpImpl method search.

@Override
public Observable<Page<NamespaceInfo>> search(NamespaceSearchCriteria criteria) {
    String ownerAddress = toDto(criteria.getOwnerAddress());
    NamespaceRegistrationTypeEnum registrationType = criteria.getRegistrationType() == null ? null : NamespaceRegistrationTypeEnum.fromValue(criteria.getRegistrationType().getValue());
    String level0 = criteria.getLevel0();
    AliasTypeEnum aliasType = criteria.getAliasType() == null ? null : AliasTypeEnum.fromValue(criteria.getAliasType().getValue());
    Integer pageSize = criteria.getPageSize();
    Integer pageNumber = criteria.getPageNumber();
    String offset = criteria.getOffset();
    Order order = toDto(criteria.getOrder());
    Callable<NamespacePage> callback = () -> getClient().searchNamespaces(ownerAddress, registrationType, level0, aliasType, pageSize, pageNumber, offset, order);
    return exceptionHandling(call(callback).map(page -> this.toPage(page.getPagination(), page.getData().stream().map(this::toNamespaceInfo).collect(Collectors.toList()))));
}
Also used : Order(io.nem.symbol.sdk.openapi.okhttp_gson.model.Order) NamespacePage(io.nem.symbol.sdk.openapi.okhttp_gson.model.NamespacePage) NamespaceInfo(io.nem.symbol.sdk.model.namespace.NamespaceInfo) MosaicsNamesDTO(io.nem.symbol.sdk.openapi.okhttp_gson.model.MosaicsNamesDTO) NamespaceRepository(io.nem.symbol.sdk.api.NamespaceRepository) Callable(java.util.concurrent.Callable) MosaicIds(io.nem.symbol.sdk.openapi.okhttp_gson.model.MosaicIds) NamespaceNameDTO(io.nem.symbol.sdk.openapi.okhttp_gson.model.NamespaceNameDTO) ArrayList(java.util.ArrayList) AccountsNamesDTO(io.nem.symbol.sdk.openapi.okhttp_gson.model.AccountsNamesDTO) MapperUtils.toNamespaceId(io.nem.symbol.core.utils.MapperUtils.toNamespaceId) NamespaceSearchCriteria(io.nem.symbol.sdk.api.NamespaceSearchCriteria) MosaicNamesDTO(io.nem.symbol.sdk.openapi.okhttp_gson.model.MosaicNamesDTO) NamespaceDTO(io.nem.symbol.sdk.openapi.okhttp_gson.model.NamespaceDTO) NamespaceRegistrationTypeEnum(io.nem.symbol.sdk.openapi.okhttp_gson.model.NamespaceRegistrationTypeEnum) ObjectUtils(org.apache.commons.lang3.ObjectUtils) MerkleStateInfo(io.nem.symbol.sdk.model.blockchain.MerkleStateInfo) NamespaceInfoDTO(io.nem.symbol.sdk.openapi.okhttp_gson.model.NamespaceInfoDTO) MosaicAlias(io.nem.symbol.sdk.model.namespace.MosaicAlias) Observable(io.reactivex.Observable) NamespaceId(io.nem.symbol.sdk.model.namespace.NamespaceId) AliasTypeEnum(io.nem.symbol.sdk.openapi.okhttp_gson.model.AliasTypeEnum) MapperUtils(io.nem.symbol.core.utils.MapperUtils) Alias(io.nem.symbol.sdk.model.namespace.Alias) Addresses(io.nem.symbol.sdk.openapi.okhttp_gson.model.Addresses) NamespaceName(io.nem.symbol.sdk.model.namespace.NamespaceName) ApiClient(io.nem.symbol.sdk.openapi.okhttp_gson.invoker.ApiClient) MosaicNames(io.nem.symbol.sdk.model.mosaic.MosaicNames) MosaicId(io.nem.symbol.sdk.model.mosaic.MosaicId) EmptyAlias(io.nem.symbol.sdk.model.namespace.EmptyAlias) Collectors(java.util.stream.Collectors) Order(io.nem.symbol.sdk.openapi.okhttp_gson.model.Order) AccountNames(io.nem.symbol.sdk.model.account.AccountNames) NamespaceRegistrationType(io.nem.symbol.sdk.model.namespace.NamespaceRegistrationType) AccountNamesDTO(io.nem.symbol.sdk.openapi.okhttp_gson.model.AccountNamesDTO) List(java.util.List) NamespaceRoutesApi(io.nem.symbol.sdk.openapi.okhttp_gson.api.NamespaceRoutesApi) AliasType(io.nem.symbol.sdk.model.namespace.AliasType) Optional(java.util.Optional) Address(io.nem.symbol.sdk.model.account.Address) NamespaceIds(io.nem.symbol.sdk.openapi.okhttp_gson.model.NamespaceIds) Page(io.nem.symbol.sdk.api.Page) AddressAlias(io.nem.symbol.sdk.model.namespace.AddressAlias) AliasTypeEnum(io.nem.symbol.sdk.openapi.okhttp_gson.model.AliasTypeEnum) NamespacePage(io.nem.symbol.sdk.openapi.okhttp_gson.model.NamespacePage) NamespaceRegistrationTypeEnum(io.nem.symbol.sdk.openapi.okhttp_gson.model.NamespaceRegistrationTypeEnum)

Example 9 with NamespaceInfo

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

the class NamespaceRepositoryVertxImplTest method search.

@Test
public void search() throws Exception {
    Address address = Address.generateRandom(networkType);
    Address ownerAccount = Account.generateNewAccount(NetworkType.MIJIN_TEST).getAddress();
    NamespaceInfoDTO dto = new NamespaceInfoDTO();
    NamespaceMetaDTO meta = new NamespaceMetaDTO();
    meta.setActive(true);
    dto.setId("SomeId");
    meta.setIndex(123);
    dto.setMeta(meta);
    NamespaceDTO namespace = new NamespaceDTO();
    namespace.setDepth(111);
    namespace.setVersion(1);
    namespace.setStartHeight(BigInteger.valueOf(4));
    namespace.setEndHeight(BigInteger.valueOf(5));
    namespace.setRegistrationType(NamespaceRegistrationTypeEnum.NUMBER_1);
    namespace.setOwnerAddress(ownerAccount.encoded());
    AliasDTO alias = new AliasDTO();
    alias.setType(AliasTypeEnum.NUMBER_2);
    alias.setAddress(address.encoded());
    namespace.setAlias(alias);
    dto.setNamespace(namespace);
    mockRemoteCall(toPage(dto));
    NamespaceInfo info = repository.search(new NamespaceSearchCriteria().ownerAddress(address)).toFuture().get().getData().get(0);
    Assertions.assertNotNull(info);
    Assertions.assertEquals(NamespaceRegistrationType.SUB_NAMESPACE, info.getRegistrationType());
    Assertions.assertEquals(dto.getId(), info.getRecordId().get());
    Assertions.assertEquals(meta.getIndex(), info.getIndex());
    Assertions.assertEquals(meta.getActive(), info.isActive());
    Assertions.assertEquals(BigInteger.valueOf(4), info.getStartHeight());
    Assertions.assertEquals(BigInteger.valueOf(5), info.getEndHeight());
}
Also used : NamespaceDTO(io.nem.symbol.sdk.openapi.vertx.model.NamespaceDTO) Address(io.nem.symbol.sdk.model.account.Address) NamespaceMetaDTO(io.nem.symbol.sdk.openapi.vertx.model.NamespaceMetaDTO) NamespaceInfoDTO(io.nem.symbol.sdk.openapi.vertx.model.NamespaceInfoDTO) AliasDTO(io.nem.symbol.sdk.openapi.vertx.model.AliasDTO) NamespaceInfo(io.nem.symbol.sdk.model.namespace.NamespaceInfo) NamespaceSearchCriteria(io.nem.symbol.sdk.api.NamespaceSearchCriteria) Test(org.junit.jupiter.api.Test)

Example 10 with NamespaceInfo

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

the class NamespaceRepositoryVertxImplTest method shouldGetNamespace.

@Test
public void shouldGetNamespace() throws Exception {
    Address ownerAddress = Account.generateNewAccount(networkType).getAddress();
    NamespaceId namespaceId = NamespaceId.createFromName("accountalias");
    NamespaceInfoDTO dto = new NamespaceInfoDTO();
    dto.setId("SomeId");
    NamespaceMetaDTO meta = new NamespaceMetaDTO();
    meta.setActive(true);
    meta.setIndex(123);
    dto.setMeta(meta);
    NamespaceDTO namespace = new NamespaceDTO();
    namespace.setDepth(111);
    namespace.setVersion(1);
    namespace.setStartHeight(BigInteger.valueOf(4));
    namespace.setEndHeight(BigInteger.valueOf(5));
    namespace.setRegistrationType(NamespaceRegistrationTypeEnum.NUMBER_1);
    namespace.setOwnerAddress(ownerAddress.encoded());
    AliasDTO alias = new AliasDTO();
    alias.setType(AliasTypeEnum.NUMBER_1);
    alias.setMosaicId("123");
    namespace.setAlias(alias);
    dto.setNamespace(namespace);
    mockRemoteCall(dto);
    NamespaceInfo info = repository.getNamespace(namespaceId).toFuture().get();
    Assertions.assertNotNull(info);
    Assertions.assertEquals(NamespaceRegistrationType.SUB_NAMESPACE, info.getRegistrationType());
    Assertions.assertEquals(dto.getId(), info.getRecordId().get());
    Assertions.assertEquals(meta.getIndex(), info.getIndex());
    Assertions.assertEquals(meta.getActive(), info.isActive());
    Assertions.assertEquals(BigInteger.valueOf(4), info.getStartHeight());
    Assertions.assertEquals(BigInteger.valueOf(5), info.getEndHeight());
}
Also used : NamespaceDTO(io.nem.symbol.sdk.openapi.vertx.model.NamespaceDTO) Address(io.nem.symbol.sdk.model.account.Address) NamespaceMetaDTO(io.nem.symbol.sdk.openapi.vertx.model.NamespaceMetaDTO) NamespaceInfoDTO(io.nem.symbol.sdk.openapi.vertx.model.NamespaceInfoDTO) AliasDTO(io.nem.symbol.sdk.openapi.vertx.model.AliasDTO) NamespaceId(io.nem.symbol.sdk.model.namespace.NamespaceId) NamespaceInfo(io.nem.symbol.sdk.model.namespace.NamespaceInfo) Test(org.junit.jupiter.api.Test)

Aggregations

NamespaceInfo (io.nem.symbol.sdk.model.namespace.NamespaceInfo)15 Address (io.nem.symbol.sdk.model.account.Address)7 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)7 NamespaceSearchCriteria (io.nem.symbol.sdk.api.NamespaceSearchCriteria)6 NamespaceId (io.nem.symbol.sdk.model.namespace.NamespaceId)6 EnumSource (org.junit.jupiter.params.provider.EnumSource)6 Test (org.junit.jupiter.api.Test)5 NamespaceRepository (io.nem.symbol.sdk.api.NamespaceRepository)4 NamespaceRegistrationTransaction (io.nem.symbol.sdk.model.transaction.NamespaceRegistrationTransaction)4 Page (io.nem.symbol.sdk.api.Page)3 MerkleStateInfo (io.nem.symbol.sdk.model.blockchain.MerkleStateInfo)3 MosaicId (io.nem.symbol.sdk.model.mosaic.MosaicId)3 NamespaceRegistrationType (io.nem.symbol.sdk.model.namespace.NamespaceRegistrationType)3 NamespaceDTO (io.nem.symbol.sdk.openapi.okhttp_gson.model.NamespaceDTO)3 NamespaceInfoDTO (io.nem.symbol.sdk.openapi.okhttp_gson.model.NamespaceInfoDTO)3 NamespaceDTO (io.nem.symbol.sdk.openapi.vertx.model.NamespaceDTO)3 NamespaceInfoDTO (io.nem.symbol.sdk.openapi.vertx.model.NamespaceInfoDTO)3 Observable (io.reactivex.Observable)3 MapperUtils (io.nem.symbol.core.utils.MapperUtils)2 MapperUtils.toNamespaceId (io.nem.symbol.core.utils.MapperUtils.toNamespaceId)2