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)));
}
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());
}
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))));
}
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())));
}
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());
}
Aggregations