Search in sources :

Example 1 with HashLockSearchCriteria

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

the class HashLockRepositoryOkHttpImplTest method shouldSearch.

@Test
public void shouldSearch() throws Exception {
    Address address = Address.generateRandom(this.networkType);
    MosaicId mosaicId = MosaicId.createFromNonce(MosaicNonce.createRandom(), address);
    HashLockEntryDTO lockHashDto = new HashLockEntryDTO();
    lockHashDto.setOwnerAddress(encodeAddress(address));
    lockHashDto.setAmount(BigInteger.ONE);
    lockHashDto.setEndHeight(BigInteger.TEN);
    lockHashDto.setVersion(1);
    lockHashDto.setHash("ABC");
    lockHashDto.setMosaicId(mosaicId.getIdAsHex());
    lockHashDto.setStatus(LockStatus.NUMBER_1);
    HashLockInfoDTO hashLockInfoDTO = new HashLockInfoDTO();
    hashLockInfoDTO.setLock(lockHashDto);
    hashLockInfoDTO.setId("123");
    mockRemoteCall(toPage(hashLockInfoDTO));
    List<HashLockInfo> list = repository.search(new HashLockSearchCriteria().address(address)).toFuture().get().getData();
    Assertions.assertEquals(1, list.size());
    HashLockInfo resolvedHashLockInfo = list.get(0);
    Assertions.assertEquals(address, resolvedHashLockInfo.getOwnerAddress());
    Assertions.assertEquals(hashLockInfoDTO.getId(), resolvedHashLockInfo.getRecordId().get());
    Assertions.assertEquals(address, resolvedHashLockInfo.getOwnerAddress());
    Assertions.assertEquals(lockHashDto.getHash(), resolvedHashLockInfo.getHash());
    Assertions.assertEquals(io.nem.symbol.sdk.model.transaction.LockStatus.USED, resolvedHashLockInfo.getStatus());
    Assertions.assertEquals(mosaicId, resolvedHashLockInfo.getMosaicId());
    Assertions.assertEquals(lockHashDto.getAmount(), resolvedHashLockInfo.getAmount());
    Assertions.assertEquals(lockHashDto.getEndHeight(), resolvedHashLockInfo.getEndHeight());
}
Also used : Address(io.nem.symbol.sdk.model.account.Address) MosaicId(io.nem.symbol.sdk.model.mosaic.MosaicId) HashLockEntryDTO(io.nem.symbol.sdk.openapi.okhttp_gson.model.HashLockEntryDTO) HashLockSearchCriteria(io.nem.symbol.sdk.api.HashLockSearchCriteria) HashLockInfo(io.nem.symbol.sdk.model.transaction.HashLockInfo) HashLockInfoDTO(io.nem.symbol.sdk.openapi.okhttp_gson.model.HashLockInfoDTO) Test(org.junit.jupiter.api.Test)

Example 2 with HashLockSearchCriteria

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

the class HashLockRepositoryVertxImpl method search.

@Override
public Observable<Page<HashLockInfo>> search(HashLockSearchCriteria criteria) {
    String address = toDto(criteria.getAddress());
    Integer pageSize = criteria.getPageSize();
    Integer pageNumber = criteria.getPageNumber();
    String offset = criteria.getOffset();
    Order order = toDto(criteria.getOrder());
    Consumer<Handler<AsyncResult<HashLockPage>>> handlerConsumer = (h) -> getClient().searchHashLock(address, pageSize, pageNumber, offset, order, h);
    return this.call(handlerConsumer, this::toPage);
}
Also used : Order(io.nem.symbol.sdk.openapi.vertx.model.Order) MapperUtils(io.nem.symbol.core.utils.MapperUtils) ApiClient(io.nem.symbol.sdk.openapi.vertx.invoker.ApiClient) HashLockPage(io.nem.symbol.sdk.openapi.vertx.model.HashLockPage) HashLockRepository(io.nem.symbol.sdk.api.HashLockRepository) HashLockRoutesApi(io.nem.symbol.sdk.openapi.vertx.api.HashLockRoutesApi) LockStatus(io.nem.symbol.sdk.model.transaction.LockStatus) HashLockSearchCriteria(io.nem.symbol.sdk.api.HashLockSearchCriteria) HashLockRoutesApiImpl(io.nem.symbol.sdk.openapi.vertx.api.HashLockRoutesApiImpl) Collectors(java.util.stream.Collectors) HashLockInfoDTO(io.nem.symbol.sdk.openapi.vertx.model.HashLockInfoDTO) HashLockEntryDTO(io.nem.symbol.sdk.openapi.vertx.model.HashLockEntryDTO) Consumer(java.util.function.Consumer) Order(io.nem.symbol.sdk.openapi.vertx.model.Order) ObjectUtils(org.apache.commons.lang3.ObjectUtils) MerkleStateInfo(io.nem.symbol.sdk.model.blockchain.MerkleStateInfo) HashLockInfo(io.nem.symbol.sdk.model.transaction.HashLockInfo) Observable(io.reactivex.Observable) AsyncResult(io.vertx.core.AsyncResult) Handler(io.vertx.core.Handler) Page(io.nem.symbol.sdk.api.Page) HashLockPage(io.nem.symbol.sdk.openapi.vertx.model.HashLockPage) Handler(io.vertx.core.Handler)

Example 3 with HashLockSearchCriteria

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

the class MerkleLoaderIntegrationTest method hashLocks.

public List<Arguments> hashLocks() {
    RepositoryFactory repositoryFactory = getRepositoryFactory(DEFAULT_REPOSITORY_TYPE);
    HashLockRepository repository = repositoryFactory.createHashLockRepository();
    return getArguments(repository, new HashLockSearchCriteria());
}
Also used : HashLockSearchCriteria(io.nem.symbol.sdk.api.HashLockSearchCriteria) RepositoryFactory(io.nem.symbol.sdk.api.RepositoryFactory) HashLockRepository(io.nem.symbol.sdk.api.HashLockRepository)

Example 4 with HashLockSearchCriteria

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

the class HashLockRepositoryIntegrationTest method searchWhenInvalidAddress.

@ParameterizedTest
@EnumSource(RepositoryType.class)
void searchWhenInvalidAddress(RepositoryType type) {
    HashLockRepository repository = getRepositoryFactory(type).createHashLockRepository();
    Address address = Address.generateRandom(getNetworkType());
    Page<HashLockInfo> page = get(repository.search(new HashLockSearchCriteria().address(address)));
    Assertions.assertTrue(page.isLast());
    Assertions.assertTrue(page.getData().isEmpty());
    Assertions.assertEquals(20, page.getPageSize());
}
Also used : Address(io.nem.symbol.sdk.model.account.Address) HashLockSearchCriteria(io.nem.symbol.sdk.api.HashLockSearchCriteria) HashLockRepository(io.nem.symbol.sdk.api.HashLockRepository) HashLockInfo(io.nem.symbol.sdk.model.transaction.HashLockInfo) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 5 with HashLockSearchCriteria

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

the class HashLockRepositoryVertxImplTest method shouldSearch.

@Test
public void shouldSearch() throws Exception {
    Address address = Address.generateRandom(this.networkType);
    MosaicId mosaicId = MosaicId.createFromNonce(MosaicNonce.createRandom(), address);
    HashLockEntryDTO lockHashDto = new HashLockEntryDTO();
    lockHashDto.setOwnerAddress(encodeAddress(address));
    lockHashDto.setAmount(BigInteger.ONE);
    lockHashDto.setEndHeight(BigInteger.TEN);
    lockHashDto.setVersion(1);
    lockHashDto.setHash("ABC");
    lockHashDto.setMosaicId(mosaicId.getIdAsHex());
    lockHashDto.setStatus(LockStatus.NUMBER_1);
    HashLockInfoDTO hashLockInfoDTO = new HashLockInfoDTO();
    hashLockInfoDTO.setLock(lockHashDto);
    hashLockInfoDTO.setId("123");
    mockRemoteCall(toPage(hashLockInfoDTO));
    List<HashLockInfo> list = repository.search(new HashLockSearchCriteria().address(address)).toFuture().get().getData();
    Assertions.assertEquals(1, list.size());
    HashLockInfo resolvedHashLockInfo = list.get(0);
    Assertions.assertEquals(address, resolvedHashLockInfo.getOwnerAddress());
    Assertions.assertEquals(hashLockInfoDTO.getId(), resolvedHashLockInfo.getRecordId().get());
    Assertions.assertEquals(address, resolvedHashLockInfo.getOwnerAddress());
    Assertions.assertEquals(lockHashDto.getHash(), resolvedHashLockInfo.getHash());
    Assertions.assertEquals(io.nem.symbol.sdk.model.transaction.LockStatus.USED, resolvedHashLockInfo.getStatus());
    Assertions.assertEquals(mosaicId, resolvedHashLockInfo.getMosaicId());
    Assertions.assertEquals(lockHashDto.getAmount(), resolvedHashLockInfo.getAmount());
    Assertions.assertEquals(lockHashDto.getEndHeight(), resolvedHashLockInfo.getEndHeight());
}
Also used : Address(io.nem.symbol.sdk.model.account.Address) MosaicId(io.nem.symbol.sdk.model.mosaic.MosaicId) HashLockEntryDTO(io.nem.symbol.sdk.openapi.vertx.model.HashLockEntryDTO) HashLockSearchCriteria(io.nem.symbol.sdk.api.HashLockSearchCriteria) HashLockInfo(io.nem.symbol.sdk.model.transaction.HashLockInfo) HashLockInfoDTO(io.nem.symbol.sdk.openapi.vertx.model.HashLockInfoDTO) Test(org.junit.jupiter.api.Test)

Aggregations

HashLockSearchCriteria (io.nem.symbol.sdk.api.HashLockSearchCriteria)6 HashLockInfo (io.nem.symbol.sdk.model.transaction.HashLockInfo)5 HashLockRepository (io.nem.symbol.sdk.api.HashLockRepository)4 Address (io.nem.symbol.sdk.model.account.Address)4 MosaicId (io.nem.symbol.sdk.model.mosaic.MosaicId)3 Page (io.nem.symbol.sdk.api.Page)2 RepositoryFactory (io.nem.symbol.sdk.api.RepositoryFactory)2 LockStatus (io.nem.symbol.sdk.model.transaction.LockStatus)2 HashLockEntryDTO (io.nem.symbol.sdk.openapi.vertx.model.HashLockEntryDTO)2 HashLockInfoDTO (io.nem.symbol.sdk.openapi.vertx.model.HashLockInfoDTO)2 Observable (io.reactivex.Observable)2 Collectors (java.util.stream.Collectors)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ExceptionUtils (io.nem.symbol.core.utils.ExceptionUtils)1 MapperUtils (io.nem.symbol.core.utils.MapperUtils)1 AccountRepository (io.nem.symbol.sdk.api.AccountRepository)1 Listener (io.nem.symbol.sdk.api.Listener)1 MultisigRepository (io.nem.symbol.sdk.api.MultisigRepository)1 RepositoryCallException (io.nem.symbol.sdk.api.RepositoryCallException)1 TransactionRepository (io.nem.symbol.sdk.api.TransactionRepository)1