Search in sources :

Example 1 with MosaicRepository

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

the class CurrencyServiceTest method setup.

@BeforeEach
void setup() {
    RepositoryFactory factory = mock(RepositoryFactory.class);
    namespaceRepository = mock(NamespaceRepository.class);
    when(factory.createNamespaceRepository()).thenReturn(namespaceRepository);
    mosaicRepository = mock(MosaicRepository.class);
    when(factory.createMosaicRepository()).thenReturn(mosaicRepository);
    networkRepository = mock(NetworkRepository.class);
    when(factory.createNetworkRepository()).thenReturn(networkRepository);
    service = new CurrencyServiceImpl(factory);
}
Also used : NamespaceRepository(io.nem.symbol.sdk.api.NamespaceRepository) MosaicRepository(io.nem.symbol.sdk.api.MosaicRepository) NetworkRepository(io.nem.symbol.sdk.api.NetworkRepository) RepositoryFactory(io.nem.symbol.sdk.api.RepositoryFactory) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 2 with MosaicRepository

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

the class StateProofServiceTest method mosaic.

@Test
void mosaic() throws Exception {
    MosaicRepository repository = mock(MosaicRepository.class);
    when(factory.createMosaicRepository()).thenReturn(repository);
    MosaicId id = new MosaicId(BigInteger.ONE);
    MosaicInfo state = Mockito.mock(MosaicInfo.class);
    when(state.getMosaicId()).thenReturn(id);
    when(state.serialize()).thenReturn(ConvertUtils.fromHexToBytes(serialized));
    when(repository.getMosaic(eq(id))).thenReturn(Observable.just(state));
    when(repository.getMosaicMerkle(eq(id))).thenReturn(Observable.just(tree));
    StateMerkleProof<MosaicInfo> proof = service.mosaic(id).toFuture().get();
    Assertions.assertTrue(proof.isValid());
    Assertions.assertEquals(state, proof.getState());
}
Also used : MosaicInfo(io.nem.symbol.sdk.model.mosaic.MosaicInfo) RestrictionMosaicRepository(io.nem.symbol.sdk.api.RestrictionMosaicRepository) MosaicRepository(io.nem.symbol.sdk.api.MosaicRepository) MosaicId(io.nem.symbol.sdk.model.mosaic.MosaicId) Test(org.junit.jupiter.api.Test)

Example 3 with MosaicRepository

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

the class MerkleLoaderIntegrationTest method mosaics.

public List<Arguments> mosaics() {
    RepositoryFactory repositoryFactory = getRepositoryFactory(DEFAULT_REPOSITORY_TYPE);
    MosaicRepository repository = repositoryFactory.createMosaicRepository();
    return getArguments(repository, new MosaicSearchCriteria().order(ORDER_BY));
}
Also used : RestrictionMosaicRepository(io.nem.symbol.sdk.api.RestrictionMosaicRepository) MosaicRepository(io.nem.symbol.sdk.api.MosaicRepository) RepositoryFactory(io.nem.symbol.sdk.api.RepositoryFactory) MosaicSearchCriteria(io.nem.symbol.sdk.api.MosaicSearchCriteria)

Example 4 with MosaicRepository

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

the class MosaicRepositoryIntegrationTest method searchUsingOffset.

@ParameterizedTest
@EnumSource(RepositoryType.class)
void searchUsingOffset(RepositoryType type) {
    MosaicRepository mosaicRepository = getMosaicRepository(type);
    MosaicPaginationStreamer streamer = new MosaicPaginationStreamer(mosaicRepository);
    MosaicSearchCriteria criteria = new MosaicSearchCriteria();
    criteria.setPageSize(10);
    int offsetIndex = 2;
    List<MosaicInfo> mosaicsWithoutOffset = get(streamer.search(criteria).toList().toObservable());
    criteria.setOffset(mosaicsWithoutOffset.get(offsetIndex).getRecordId().get());
    List<MosaicInfo> mosaicFromOffsets = get(streamer.search(criteria).toList().toObservable());
    PaginationTester.sameEntities(mosaicsWithoutOffset.stream().skip(offsetIndex + 1).collect(Collectors.toList()), mosaicFromOffsets);
}
Also used : MosaicPaginationStreamer(io.nem.symbol.sdk.api.MosaicPaginationStreamer) MosaicInfo(io.nem.symbol.sdk.model.mosaic.MosaicInfo) MosaicRepository(io.nem.symbol.sdk.api.MosaicRepository) MosaicSearchCriteria(io.nem.symbol.sdk.api.MosaicSearchCriteria) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

MosaicRepository (io.nem.symbol.sdk.api.MosaicRepository)4 MosaicSearchCriteria (io.nem.symbol.sdk.api.MosaicSearchCriteria)2 RepositoryFactory (io.nem.symbol.sdk.api.RepositoryFactory)2 RestrictionMosaicRepository (io.nem.symbol.sdk.api.RestrictionMosaicRepository)2 MosaicInfo (io.nem.symbol.sdk.model.mosaic.MosaicInfo)2 MosaicPaginationStreamer (io.nem.symbol.sdk.api.MosaicPaginationStreamer)1 NamespaceRepository (io.nem.symbol.sdk.api.NamespaceRepository)1 NetworkRepository (io.nem.symbol.sdk.api.NetworkRepository)1 MosaicId (io.nem.symbol.sdk.model.mosaic.MosaicId)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1 Test (org.junit.jupiter.api.Test)1 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)1 EnumSource (org.junit.jupiter.params.provider.EnumSource)1