use of io.nem.symbol.sdk.openapi.okhttp_gson.model.MosaicGlobalRestrictionDTO in project nem2-sdk-java by nemtech.
the class RestrictionMosaicRepositoryOkHttpImpl method toMosaicGlobalRestriction.
private MosaicGlobalRestriction toMosaicGlobalRestriction(MosaicGlobalRestrictionDTO mosaicGlobalRestrictionDTO) {
MosaicGlobalRestrictionEntryWrapperDTO dto = mosaicGlobalRestrictionDTO.getMosaicRestrictionEntry();
Map<BigInteger, MosaicGlobalRestrictionItem> restrictions = dto.getRestrictions().stream().collect(Collectors.toMap(e -> new BigInteger(e.getKey()), e -> toMosaicGlobalRestrictionItem(e.getRestriction()), (x, y) -> y, LinkedHashMap::new));
return new MosaicGlobalRestriction(mosaicGlobalRestrictionDTO.getId(), ObjectUtils.defaultIfNull(mosaicGlobalRestrictionDTO.getMosaicRestrictionEntry().getVersion(), 1), dto.getCompositeHash(), MosaicRestrictionEntryType.rawValueOf(dto.getEntryType().getValue()), MapperUtils.toMosaicId(dto.getMosaicId()), restrictions);
}
use of io.nem.symbol.sdk.openapi.okhttp_gson.model.MosaicGlobalRestrictionDTO in project nem2-sdk-java by nemtech.
the class RestrictionMosaicRepositoryOkHttpImplTest method shouldMosaicGlobalRestriction.
@Test
public void shouldMosaicGlobalRestriction() 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));
MosaicGlobalRestriction mosaicGlobalRestriction = (MosaicGlobalRestriction) repository.search(new MosaicRestrictionSearchCriteria()).toFuture().get().getData().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.openapi.okhttp_gson.model.MosaicGlobalRestrictionDTO 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());
}
Aggregations