use of io.nem.symbol.sdk.api.NamespaceRepository 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);
}
use of io.nem.symbol.sdk.api.NamespaceRepository 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.NamespaceRepository in project nem2-sdk-java by nemtech.
the class StateProofServiceTest method namespace.
@Test
void namespace() throws Exception {
NamespaceRepository repository = mock(NamespaceRepository.class);
when(factory.createNamespaceRepository()).thenReturn(repository);
NamespaceId id = NamespaceId.createFromId(BigInteger.ONE);
NamespaceInfo state = Mockito.mock(NamespaceInfo.class);
when(state.getId()).thenReturn(id);
when(state.serialize(any())).thenReturn(ConvertUtils.fromHexToBytes(serialized));
when(repository.streamer()).thenReturn(new PaginationStreamer<>(repository));
when(repository.search(any())).thenReturn(Observable.just(new Page<>(new ArrayList<>())));
when(repository.getNamespace(eq(id))).thenReturn(Observable.just(state));
when(repository.getNamespaceMerkle(eq(id))).thenReturn(Observable.just(tree));
StateMerkleProof<NamespaceInfo> proof = service.namespace(id).toFuture().get();
Assertions.assertTrue(proof.isValid());
Assertions.assertEquals(state, proof.getState());
}
use of io.nem.symbol.sdk.api.NamespaceRepository in project nem2-sdk-java by nemtech.
the class StateProofServiceImpl method namespace.
@Override
public Observable<StateMerkleProof<NamespaceInfo>> namespace(NamespaceInfo state) {
NamespaceId id = state.getId();
NamespaceRepository namespaceRepository = this.repositoryFactory.createNamespaceRepository();
PaginationStreamer<NamespaceInfo, NamespaceSearchCriteria> streamer = namespaceRepository.streamer();
return namespaceRepository.getNamespaceMerkle(id).flatMap(merkle -> streamer.search(new NamespaceSearchCriteria().level0(state.getId().getIdAsHex()).registrationType(NamespaceRegistrationType.SUB_NAMESPACE)).toList().toObservable().map(state::serialize).map(s -> toStateMerkleProof(state, merkle, s)));
}
use of io.nem.symbol.sdk.api.NamespaceRepository in project nem2-sdk-java by nemtech.
the class MerkleLoaderIntegrationTest method namespaces.
public List<Arguments> namespaces() {
RepositoryFactory repositoryFactory = getRepositoryFactory(DEFAULT_REPOSITORY_TYPE);
NamespaceRepository repository = repositoryFactory.createNamespaceRepository();
return getArguments(repository, new NamespaceSearchCriteria().order(ORDER_BY).registrationType(NamespaceRegistrationType.ROOT_NAMESPACE));
}
Aggregations