Search in sources :

Example 6 with MosaicGlobalRestriction

use of io.nem.symbol.sdk.model.restriction.MosaicGlobalRestriction in project nem2-sdk-java by nemtech.

the class RestrictionMosaicRepositoryVertxImplTest 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.setVersion(1);
    wrapperDTO.setCompositeHash("compositeHash");
    wrapperDTO.setMosaicId(mosaicId.getIdAsHex());
    wrapperDTO.setRestrictions(restrictions);
    wrapperDTO.setEntryType(MosaicRestrictionEntryTypeEnum.NUMBER_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());
}
Also used : MosaicGlobalRestrictionEntryDTO(io.nem.symbol.sdk.openapi.vertx.model.MosaicGlobalRestrictionEntryDTO) MosaicGlobalRestrictionEntryRestrictionDTO(io.nem.symbol.sdk.openapi.vertx.model.MosaicGlobalRestrictionEntryRestrictionDTO) MosaicGlobalRestrictionDTO(io.nem.symbol.sdk.openapi.vertx.model.MosaicGlobalRestrictionDTO) MosaicId(io.nem.symbol.sdk.model.mosaic.MosaicId) ArrayList(java.util.ArrayList) MosaicRestrictionSearchCriteria(io.nem.symbol.sdk.api.MosaicRestrictionSearchCriteria) MosaicGlobalRestrictionEntryWrapperDTO(io.nem.symbol.sdk.openapi.vertx.model.MosaicGlobalRestrictionEntryWrapperDTO) MosaicGlobalRestriction(io.nem.symbol.sdk.model.restriction.MosaicGlobalRestriction) Test(org.junit.jupiter.api.Test)

Example 7 with MosaicGlobalRestriction

use of io.nem.symbol.sdk.model.restriction.MosaicGlobalRestriction in project nem2-sdk-java by nemtech.

the class RestrictionMosaicRepositoryIntegrationTest method searchGlobalRestriction.

@ParameterizedTest
@EnumSource(RepositoryType.class)
void searchGlobalRestriction(RepositoryType type) {
    RepositoryFactory repositoryFactory = getRepositoryFactory(type);
    RestrictionMosaicRepository repository = repositoryFactory.createRestrictionMosaicRepository();
    MosaicRestrictionEntryType entryType = MosaicRestrictionEntryType.GLOBAL;
    Page<MosaicRestriction<?>> page = get(repository.search(new MosaicRestrictionSearchCriteria().entryType(entryType)));
    System.out.println(page.getData().size());
    page.getData().forEach(restriction -> {
        Assertions.assertTrue(restriction instanceof MosaicGlobalRestriction);
        Assertions.assertEquals(entryType, restriction.getEntryType());
        Assertions.assertNotNull(restriction.getMosaicId());
        Assertions.assertNotNull(restriction.getCompositeHash());
        Assertions.assertFalse(restriction.getRestrictions().isEmpty());
    });
}
Also used : MosaicRestrictionEntryType(io.nem.symbol.sdk.model.restriction.MosaicRestrictionEntryType) RestrictionMosaicRepository(io.nem.symbol.sdk.api.RestrictionMosaicRepository) RepositoryFactory(io.nem.symbol.sdk.api.RepositoryFactory) MosaicRestriction(io.nem.symbol.sdk.model.restriction.MosaicRestriction) MosaicRestrictionSearchCriteria(io.nem.symbol.sdk.api.MosaicRestrictionSearchCriteria) MosaicGlobalRestriction(io.nem.symbol.sdk.model.restriction.MosaicGlobalRestriction) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

MosaicRestrictionSearchCriteria (io.nem.symbol.sdk.api.MosaicRestrictionSearchCriteria)7 MosaicGlobalRestriction (io.nem.symbol.sdk.model.restriction.MosaicGlobalRestriction)7 MosaicRestriction (io.nem.symbol.sdk.model.restriction.MosaicRestriction)5 MosaicId (io.nem.symbol.sdk.model.mosaic.MosaicId)4 ArrayList (java.util.ArrayList)4 Test (org.junit.jupiter.api.Test)4 RestrictionMosaicRepository (io.nem.symbol.sdk.api.RestrictionMosaicRepository)3 MosaicRestrictionEntryType (io.nem.symbol.sdk.model.restriction.MosaicRestrictionEntryType)3 MosaicGlobalRestrictionDTO (io.nem.symbol.sdk.openapi.okhttp_gson.model.MosaicGlobalRestrictionDTO)3 MosaicGlobalRestrictionEntryRestrictionDTO (io.nem.symbol.sdk.openapi.okhttp_gson.model.MosaicGlobalRestrictionEntryRestrictionDTO)3 MosaicGlobalRestrictionEntryWrapperDTO (io.nem.symbol.sdk.openapi.okhttp_gson.model.MosaicGlobalRestrictionEntryWrapperDTO)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 MapperUtils (io.nem.symbol.core.utils.MapperUtils)2 Page (io.nem.symbol.sdk.api.Page)2 MerkleStateInfo (io.nem.symbol.sdk.model.blockchain.MerkleStateInfo)2 MosaicAddressRestriction (io.nem.symbol.sdk.model.restriction.MosaicAddressRestriction)2 MosaicGlobalRestrictionItem (io.nem.symbol.sdk.model.restriction.MosaicGlobalRestrictionItem)2 MosaicRestrictionType (io.nem.symbol.sdk.model.transaction.MosaicRestrictionType)2