use of io.nem.symbol.sdk.model.restriction.MosaicRestriction 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.model.restriction.MosaicRestriction in project nem2-sdk-java by nemtech.
the class MosaicAddressRestrictionIntegrationTest method assertMosaicAddressRestriction.
private void assertMosaicAddressRestriction(RestrictionMosaicRepository restrictionRepository, Address address, MosaicAddressRestrictionTransaction transaction, Address targetAddress, MosaicId mosaicId) {
Page<MosaicRestriction<?>> page = get(restrictionRepository.search(new MosaicRestrictionSearchCriteria().entryType(MosaicRestrictionEntryType.ADDRESS).targetAddress(targetAddress).mosaicId(mosaicId)));
Assertions.assertEquals(1, page.getData().size(), "Cannot find restriction target address " + targetAddress.plain() + " encoded: " + targetAddress.encoded() + " mosaicId " + mosaicId.getIdAsHex());
MosaicAddressRestriction restriction = (MosaicAddressRestriction) page.getData().get(0);
BigInteger restrictionKey = transaction.getRestrictionKey();
BigInteger newRestrictionValue = transaction.getNewRestrictionValue();
Assertions.assertEquals(Collections.singleton(restrictionKey), restriction.getRestrictions().keySet());
Assertions.assertEquals(address, restriction.getTargetAddress());
Assertions.assertEquals(1, restriction.getRestrictions().size());
Assertions.assertEquals(newRestrictionValue, restriction.getRestrictions().get(restrictionKey));
Assertions.assertEquals(transaction.getNewRestrictionValue(), restriction.getRestrictions().get(restrictionKey));
}
use of io.nem.symbol.sdk.model.restriction.MosaicRestriction in project nem2-sdk-java by nemtech.
the class MosaicAddressRestrictionIntegrationTest method getMosaicAddressRestrictionWhenMosaicDoesNotExist.
@ParameterizedTest
@EnumSource(RepositoryType.class)
void getMosaicAddressRestrictionWhenMosaicDoesNotExist(RepositoryType type) {
RestrictionMosaicRepository repository = getRepositoryFactory(type).createRestrictionMosaicRepository();
Address address = Address.createFromPublicKey("67F69FA4BFCD158F6E1AF1ABC82F725F5C5C4710D6E29217B12BE66397435DFB", getNetworkType());
Page<MosaicRestriction<?>> page = get(repository.search(new MosaicRestrictionSearchCriteria().mosaicId(new MosaicId(BigInteger.valueOf(888888))).targetAddress(address).entryType(MosaicRestrictionEntryType.ADDRESS)));
Assertions.assertTrue(page.getData().isEmpty());
}
use of io.nem.symbol.sdk.model.restriction.MosaicRestriction in project nem2-sdk-java by nemtech.
the class RestrictionMosaicRepositoryVertxImplTest method shouldGetMosaicAddressRestrictions.
@Test
public void shouldGetMosaicAddressRestrictions() 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.setVersion(1);
wrapperDTO.setTargetAddress(address.encoded());
mockRemoteCall(toPage(dto));
List<MosaicRestriction<?>> mosaicAddressRestrictions = repository.search(new MosaicRestrictionSearchCriteria()).toFuture().get().getData();
Assertions.assertEquals(1, mosaicAddressRestrictions.size());
MosaicAddressRestriction mosaicAddressRestriction = (MosaicAddressRestriction) mosaicAddressRestrictions.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.model.restriction.MosaicRestriction in project nem2-sdk-java by nemtech.
the class MosaicRestrictionServiceIntegrationTest method getMosaicGlobalRestrictionWhenMosaicDoesNotExist.
@ParameterizedTest
@EnumSource(RepositoryType.class)
void getMosaicGlobalRestrictionWhenMosaicDoesNotExist(RepositoryType type) {
RestrictionMosaicRepository repository = getRepositoryFactory(type).createRestrictionMosaicRepository();
Address address = Address.createFromPublicKey("67F69FA4BFCD158F6E1AF1ABC82F725F5C5C4710D6E29217B12BE66397435DFB", getNetworkType());
Page<MosaicRestriction<?>> page = get(repository.search(new MosaicRestrictionSearchCriteria().mosaicId(new MosaicId(BigInteger.valueOf(888888))).targetAddress(address).entryType(MosaicRestrictionEntryType.GLOBAL)));
Assertions.assertTrue(page.getData().isEmpty());
}
Aggregations