Search in sources :

Example 6 with MosaicRestrictionSearchCriteria

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

the class MosaicRestrictionTransactionServiceTest method setup.

@BeforeEach
void setup() {
    RepositoryFactory factory = mock(RepositoryFactory.class);
    restrictionMosaicRepository = mock(RestrictionMosaicRepository.class);
    when(factory.createRestrictionMosaicRepository()).thenReturn(restrictionMosaicRepository);
    namespaceRepository = mock(NamespaceRepository.class);
    when(factory.createNamespaceRepository()).thenReturn(namespaceRepository);
    when(factory.getNetworkType()).thenReturn(Observable.just(networkType));
    when(factory.getEpochAdjustment()).thenReturn(Observable.just(Duration.ofSeconds(10)));
    service = new MosaicRestrictionTransactionServiceImpl(factory);
    when(restrictionMosaicRepository.search(eq(new MosaicRestrictionSearchCriteria().pageNumber(1).mosaicId(mosaicId1).entryType(MosaicRestrictionEntryType.GLOBAL)))).thenReturn(Observable.just(toPage(mockGlobalRestriction())));
    when(restrictionMosaicRepository.search(eq(new MosaicRestrictionSearchCriteria().pageNumber(1).mosaicId(mosaicId2).entryType(MosaicRestrictionEntryType.GLOBAL)))).thenReturn(Observable.just(toPage(mockGlobalRestriction())));
    when(restrictionMosaicRepository.search(eq(new MosaicRestrictionSearchCriteria().pageNumber(1).mosaicId(mosaicIdWrongKey).entryType(MosaicRestrictionEntryType.GLOBAL)))).thenReturn(Observable.error(() -> new IllegalStateException("Not a nice mosaic id")));
    when(restrictionMosaicRepository.search(eq(new MosaicRestrictionSearchCriteria().pageNumber(1).mosaicId(mosaicIdNotFound).entryType(MosaicRestrictionEntryType.GLOBAL)))).thenReturn(Observable.just(toPage()));
    when(restrictionMosaicRepository.search(eq(new MosaicRestrictionSearchCriteria().pageNumber(1).mosaicId(mosaicId1).targetAddress(account1.getAddress()).entryType(MosaicRestrictionEntryType.ADDRESS)))).thenReturn(Observable.just(toPage(mockAddressRestriction())));
    when(restrictionMosaicRepository.search(eq(new MosaicRestrictionSearchCriteria().pageNumber(1).mosaicId(mosaicId2).targetAddress(account1.getAddress()).entryType(MosaicRestrictionEntryType.ADDRESS)))).thenReturn(Observable.just(toPage()));
    when(restrictionMosaicRepository.search(eq(new MosaicRestrictionSearchCriteria().pageNumber(1).mosaicId(mosaicIdWrongKey).targetAddress(account1.getAddress()).entryType(MosaicRestrictionEntryType.ADDRESS)))).thenReturn(Observable.error(() -> new IllegalStateException("Not a nice mosaic id")));
    when(restrictionMosaicRepository.search(eq(new MosaicRestrictionSearchCriteria().pageNumber(1).mosaicId(mosaicIdNotFound).targetAddress(account1.getAddress()).entryType(MosaicRestrictionEntryType.ADDRESS)))).thenReturn(Observable.just(toPage()));
    when(namespaceRepository.getNamespace(Mockito.any())).thenReturn(Observable.error(new IllegalStateException("Alias does not exist")));
    when(namespaceRepository.getNamespace(accountAlias1)).thenReturn(Observable.just(createAlias(account1.getAddress())));
    when(namespaceRepository.getNamespace(accountAlias2)).thenReturn(Observable.just(createAlias(account2.getAddress())));
    when(namespaceRepository.getNamespace(mosaicAlias1)).thenReturn(Observable.just(createAlias(mosaicId1)));
    when(namespaceRepository.getNamespace(mosaicAlias2)).thenReturn(Observable.just(createAlias(mosaicId2)));
}
Also used : NamespaceRepository(io.nem.symbol.sdk.api.NamespaceRepository) RestrictionMosaicRepository(io.nem.symbol.sdk.api.RestrictionMosaicRepository) RepositoryFactory(io.nem.symbol.sdk.api.RepositoryFactory) MosaicRestrictionSearchCriteria(io.nem.symbol.sdk.api.MosaicRestrictionSearchCriteria) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 7 with MosaicRestrictionSearchCriteria

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

the class RestrictionMosaicRepositoryOkHttpImplTest method shouldGetMosaicGlobalRestrictions.

@Test
public void shouldGetMosaicGlobalRestrictions() throws Exception {
    MosaicId mosaicId = MapperUtils.toMosaicId("123");
    MosaicGlobalRestrictionDTO dto = new MosaicGlobalRestrictionDTO();
    MosaicGlobalRestrictionEntryWrapperDTO wrapperDTO = new MosaicGlobalRestrictionEntryWrapperDTO();
    dto.setMosaicRestrictionEntry(wrapperDTO);
    MosaicGlobalRestrictionEntryDTO entryDTO = new MosaicGlobalRestrictionEntryDTO();
    entryDTO.setKey(ConvertUtils.toString(BigInteger.valueOf(1111)));
    MosaicGlobalRestrictionEntryRestrictionDTO entryRestrictionDto = new MosaicGlobalRestrictionEntryRestrictionDTO();
    entryRestrictionDto.setRestrictionType(MosaicRestrictionTypeEnum.NUMBER_5);
    entryRestrictionDto.setReferenceMosaicId("456");
    entryRestrictionDto.setRestrictionValue(BigInteger.valueOf(3333));
    entryDTO.setRestriction(entryRestrictionDto);
    List<MosaicGlobalRestrictionEntryDTO> restrictions = new ArrayList<>();
    restrictions.add(entryDTO);
    wrapperDTO.setCompositeHash("compositeHash");
    wrapperDTO.setMosaicId(mosaicId.getIdAsHex());
    wrapperDTO.setRestrictions(restrictions);
    wrapperDTO.setEntryType(MosaicRestrictionEntryTypeEnum.NUMBER_1);
    wrapperDTO.setVersion(1);
    mockRemoteCall(toPage(dto));
    List<MosaicRestriction<?>> mosaicGlobalRestrictions = repository.search(new MosaicRestrictionSearchCriteria()).toFuture().get().getData();
    Assertions.assertEquals(1, mosaicGlobalRestrictions.size());
    MosaicGlobalRestriction mosaicGlobalRestriction = (MosaicGlobalRestriction) mosaicGlobalRestrictions.get(0);
    Assertions.assertEquals(wrapperDTO.getCompositeHash(), mosaicGlobalRestriction.getCompositeHash());
    Assertions.assertEquals(MosaicRestrictionEntryType.GLOBAL, mosaicGlobalRestriction.getEntryType());
    Assertions.assertEquals(mosaicId, mosaicGlobalRestriction.getMosaicId());
    Assertions.assertEquals(1, mosaicGlobalRestriction.getRestrictions().size());
    Assertions.assertEquals(BigInteger.valueOf(3333), mosaicGlobalRestriction.getRestrictions().get(BigInteger.valueOf(1111)).getRestrictionValue());
    Assertions.assertEquals("0000000000000456", mosaicGlobalRestriction.getRestrictions().get(BigInteger.valueOf(1111)).getReferenceMosaicId().getIdAsHex());
    Assertions.assertEquals(MosaicRestrictionType.GT, mosaicGlobalRestriction.getRestrictions().get(BigInteger.valueOf(1111)).getRestrictionType());
}
Also used : MosaicGlobalRestrictionEntryDTO(io.nem.symbol.sdk.openapi.okhttp_gson.model.MosaicGlobalRestrictionEntryDTO) MosaicGlobalRestrictionEntryRestrictionDTO(io.nem.symbol.sdk.openapi.okhttp_gson.model.MosaicGlobalRestrictionEntryRestrictionDTO) MosaicGlobalRestrictionDTO(io.nem.symbol.sdk.openapi.okhttp_gson.model.MosaicGlobalRestrictionDTO) MosaicId(io.nem.symbol.sdk.model.mosaic.MosaicId) ArrayList(java.util.ArrayList) MosaicRestriction(io.nem.symbol.sdk.model.restriction.MosaicRestriction) MosaicRestrictionSearchCriteria(io.nem.symbol.sdk.api.MosaicRestrictionSearchCriteria) MosaicGlobalRestrictionEntryWrapperDTO(io.nem.symbol.sdk.openapi.okhttp_gson.model.MosaicGlobalRestrictionEntryWrapperDTO) MosaicGlobalRestriction(io.nem.symbol.sdk.model.restriction.MosaicGlobalRestriction) Test(org.junit.jupiter.api.Test)

Example 8 with MosaicRestrictionSearchCriteria

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

the class RestrictionMosaicRepositoryOkHttpImplTest method shouldGetMosaicAddressRestriction.

@Test
public void shouldGetMosaicAddressRestriction() throws Exception {
    Address address = Address.generateRandom(this.networkType);
    MosaicId mosaicId = MapperUtils.toMosaicId("123");
    MosaicAddressRestrictionDTO dto = new MosaicAddressRestrictionDTO();
    MosaicAddressRestrictionEntryWrapperDTO wrapperDTO = new MosaicAddressRestrictionEntryWrapperDTO();
    dto.setMosaicRestrictionEntry(wrapperDTO);
    MosaicAddressRestrictionEntryDTO entryDTO = new MosaicAddressRestrictionEntryDTO();
    entryDTO.setKey(ConvertUtils.toString(BigInteger.valueOf(1111)));
    entryDTO.setValue("2222");
    List<MosaicAddressRestrictionEntryDTO> restrictions = new ArrayList<>();
    restrictions.add(entryDTO);
    wrapperDTO.setCompositeHash("compositeHash");
    wrapperDTO.setMosaicId(mosaicId.getIdAsHex());
    wrapperDTO.setRestrictions(restrictions);
    wrapperDTO.setEntryType(MosaicRestrictionEntryTypeEnum.NUMBER_0);
    wrapperDTO.setTargetAddress(address.encoded());
    wrapperDTO.setVersion(1);
    mockRemoteCall(toPage(dto));
    MosaicAddressRestriction mosaicAddressRestriction = (MosaicAddressRestriction) repository.search(new MosaicRestrictionSearchCriteria().targetAddress(address).mosaicId(mosaicId).entryType(MosaicRestrictionEntryType.ADDRESS)).toFuture().get().getData().get(0);
    Assertions.assertEquals(wrapperDTO.getCompositeHash(), mosaicAddressRestriction.getCompositeHash());
    Assertions.assertEquals(MosaicRestrictionEntryType.ADDRESS, mosaicAddressRestriction.getEntryType());
    Assertions.assertEquals(mosaicId, mosaicAddressRestriction.getMosaicId());
    Assertions.assertEquals(address, mosaicAddressRestriction.getTargetAddress());
    Assertions.assertEquals(1, mosaicAddressRestriction.getRestrictions().size());
    Assertions.assertEquals(BigInteger.valueOf(2222), mosaicAddressRestriction.getRestrictions().get((BigInteger.valueOf(1111))));
}
Also used : MosaicAddressRestriction(io.nem.symbol.sdk.model.restriction.MosaicAddressRestriction) Address(io.nem.symbol.sdk.model.account.Address) MosaicAddressRestrictionDTO(io.nem.symbol.sdk.openapi.okhttp_gson.model.MosaicAddressRestrictionDTO) MosaicId(io.nem.symbol.sdk.model.mosaic.MosaicId) ArrayList(java.util.ArrayList) MosaicAddressRestrictionEntryDTO(io.nem.symbol.sdk.openapi.okhttp_gson.model.MosaicAddressRestrictionEntryDTO) MosaicRestrictionSearchCriteria(io.nem.symbol.sdk.api.MosaicRestrictionSearchCriteria) MosaicAddressRestrictionEntryWrapperDTO(io.nem.symbol.sdk.openapi.okhttp_gson.model.MosaicAddressRestrictionEntryWrapperDTO) Test(org.junit.jupiter.api.Test)

Example 9 with MosaicRestrictionSearchCriteria

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

the class RestrictionMosaicRepositoryVertxImpl method search.

@Override
public Observable<Page<MosaicRestriction<?>>> search(MosaicRestrictionSearchCriteria criteria) {
    String mosaicId = criteria.getMosaicId() == null ? null : criteria.getMosaicId().getIdAsHex();
    MosaicRestrictionEntryTypeEnum entryType = criteria.getEntryType() == null ? null : MosaicRestrictionEntryTypeEnum.fromValue(criteria.getEntryType().getValue());
    String targetAddress = toDto(criteria.getTargetAddress());
    Integer pageSize = criteria.getPageSize();
    Integer pageNumber = criteria.getPageNumber();
    String offset = criteria.getOffset();
    Order order = toDto(criteria.getOrder());
    Consumer<Handler<AsyncResult<MosaicRestrictionsPage>>> callback = (h) -> getClient().searchMosaicRestrictions(mosaicId, entryType, targetAddress, pageSize, pageNumber, offset, order, h);
    return call(callback, page -> toPage(page.getPagination(), page.getData().stream().map(this::toMosaicRestriction).collect(Collectors.toList())));
}
Also used : BigInteger(java.math.BigInteger) Order(io.nem.symbol.sdk.openapi.vertx.model.Order) MosaicAddressRestrictionEntryWrapperDTO(io.nem.symbol.sdk.openapi.vertx.model.MosaicAddressRestrictionEntryWrapperDTO) RestrictionMosaicRepository(io.nem.symbol.sdk.api.RestrictionMosaicRepository) RestrictionMosaicRoutesApi(io.nem.symbol.sdk.openapi.vertx.api.RestrictionMosaicRoutesApi) MosaicRestrictionEntryTypeEnum(io.nem.symbol.sdk.openapi.vertx.model.MosaicRestrictionEntryTypeEnum) MosaicRestrictionsPage(io.nem.symbol.sdk.openapi.vertx.model.MosaicRestrictionsPage) LinkedHashMap(java.util.LinkedHashMap) MosaicGlobalRestrictionEntryWrapperDTO(io.nem.symbol.sdk.openapi.vertx.model.MosaicGlobalRestrictionEntryWrapperDTO) MosaicRestrictionSearchCriteria(io.nem.symbol.sdk.api.MosaicRestrictionSearchCriteria) MosaicRestriction(io.nem.symbol.sdk.model.restriction.MosaicRestriction) Order(io.nem.symbol.sdk.openapi.vertx.model.Order) MosaicRestrictionType(io.nem.symbol.sdk.model.transaction.MosaicRestrictionType) ObjectUtils(org.apache.commons.lang3.ObjectUtils) Map(java.util.Map) MerkleStateInfo(io.nem.symbol.sdk.model.blockchain.MerkleStateInfo) MosaicGlobalRestrictionEntryRestrictionDTO(io.nem.symbol.sdk.openapi.vertx.model.MosaicGlobalRestrictionEntryRestrictionDTO) Observable(io.reactivex.Observable) BigInteger(java.math.BigInteger) AsyncResult(io.vertx.core.AsyncResult) MosaicGlobalRestrictionDTO(io.nem.symbol.sdk.openapi.vertx.model.MosaicGlobalRestrictionDTO) MapperUtils(io.nem.symbol.core.utils.MapperUtils) ApiClient(io.nem.symbol.sdk.openapi.vertx.invoker.ApiClient) MosaicAddressRestrictionDTO(io.nem.symbol.sdk.openapi.vertx.model.MosaicAddressRestrictionDTO) RestrictionMosaicRoutesApiImpl(io.nem.symbol.sdk.openapi.vertx.api.RestrictionMosaicRoutesApiImpl) MosaicGlobalRestriction(io.nem.symbol.sdk.model.restriction.MosaicGlobalRestriction) MosaicRestrictionEntryType(io.nem.symbol.sdk.model.restriction.MosaicRestrictionEntryType) Collectors(java.util.stream.Collectors) Consumer(java.util.function.Consumer) MosaicGlobalRestrictionItem(io.nem.symbol.sdk.model.restriction.MosaicGlobalRestrictionItem) Handler(io.vertx.core.Handler) Page(io.nem.symbol.sdk.api.Page) MosaicAddressRestriction(io.nem.symbol.sdk.model.restriction.MosaicAddressRestriction) Handler(io.vertx.core.Handler) MosaicRestrictionEntryTypeEnum(io.nem.symbol.sdk.openapi.vertx.model.MosaicRestrictionEntryTypeEnum) MosaicRestrictionsPage(io.nem.symbol.sdk.openapi.vertx.model.MosaicRestrictionsPage)

Example 10 with MosaicRestrictionSearchCriteria

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

the class MerkleLoaderIntegrationTest method mosaicRestriction.

public List<Arguments> mosaicRestriction() {
    RepositoryFactory repositoryFactory = getRepositoryFactory(DEFAULT_REPOSITORY_TYPE);
    RestrictionMosaicRepository repository = repositoryFactory.createRestrictionMosaicRepository();
    return getArguments(repository, new MosaicRestrictionSearchCriteria());
}
Also used : RestrictionMosaicRepository(io.nem.symbol.sdk.api.RestrictionMosaicRepository) RepositoryFactory(io.nem.symbol.sdk.api.RepositoryFactory) MosaicRestrictionSearchCriteria(io.nem.symbol.sdk.api.MosaicRestrictionSearchCriteria)

Aggregations

MosaicRestrictionSearchCriteria (io.nem.symbol.sdk.api.MosaicRestrictionSearchCriteria)17 MosaicId (io.nem.symbol.sdk.model.mosaic.MosaicId)11 MosaicRestriction (io.nem.symbol.sdk.model.restriction.MosaicRestriction)11 RestrictionMosaicRepository (io.nem.symbol.sdk.api.RestrictionMosaicRepository)8 ArrayList (java.util.ArrayList)8 Test (org.junit.jupiter.api.Test)8 MosaicAddressRestriction (io.nem.symbol.sdk.model.restriction.MosaicAddressRestriction)7 Address (io.nem.symbol.sdk.model.account.Address)6 MosaicGlobalRestriction (io.nem.symbol.sdk.model.restriction.MosaicGlobalRestriction)6 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)5 EnumSource (org.junit.jupiter.params.provider.EnumSource)5 RepositoryFactory (io.nem.symbol.sdk.api.RepositoryFactory)4 MosaicRestrictionEntryType (io.nem.symbol.sdk.model.restriction.MosaicRestrictionEntryType)3 MosaicAddressRestrictionDTO (io.nem.symbol.sdk.openapi.vertx.model.MosaicAddressRestrictionDTO)3 MosaicAddressRestrictionEntryWrapperDTO (io.nem.symbol.sdk.openapi.vertx.model.MosaicAddressRestrictionEntryWrapperDTO)3 MosaicGlobalRestrictionDTO (io.nem.symbol.sdk.openapi.vertx.model.MosaicGlobalRestrictionDTO)3 MosaicGlobalRestrictionEntryRestrictionDTO (io.nem.symbol.sdk.openapi.vertx.model.MosaicGlobalRestrictionEntryRestrictionDTO)3 MosaicGlobalRestrictionEntryWrapperDTO (io.nem.symbol.sdk.openapi.vertx.model.MosaicGlobalRestrictionEntryWrapperDTO)3 BigInteger (java.math.BigInteger)3 MosaicAddressRestrictionDTO (io.nem.symbol.sdk.openapi.okhttp_gson.model.MosaicAddressRestrictionDTO)2