Search in sources :

Example 16 with RepositoryFactory

use of io.nem.symbol.sdk.api.RepositoryFactory 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 17 with RepositoryFactory

use of io.nem.symbol.sdk.api.RepositoryFactory 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)));
}
Also used : NamespaceRepository(io.nem.symbol.sdk.api.NamespaceRepository) RestrictionMosaicRepository(io.nem.symbol.sdk.api.RestrictionMosaicRepository) RepositoryFactory(io.nem.symbol.sdk.api.RepositoryFactory) MosaicRestrictionSearchCriteria(io.nem.symbol.sdk.api.MosaicRestrictionSearchCriteria) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 18 with RepositoryFactory

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

the class RepositoryFactoryOkHttpImplTest method getUserProvidedConfiguration.

@Test
public void getUserProvidedConfiguration() throws Exception {
    String baseUrl = "https://localhost:1934/path";
    RepositoryFactoryConfiguration configuration = new RepositoryFactoryConfiguration(baseUrl);
    configuration.withGenerationHash("abc");
    configuration.withNetworkType(NetworkType.MAIN_NET);
    configuration.withNetworkCurrencies(NetworkCurrencies.PUBLIC);
    RepositoryFactory factory = new RepositoryFactoryOkHttpImpl(configuration);
    Assertions.assertEquals(configuration.getNetworkType(), factory.getNetworkType().toFuture().get());
    Assertions.assertEquals(configuration.getGenerationHash(), factory.getGenerationHash().toFuture().get());
    Assertions.assertEquals(configuration.getNetworkCurrencies().getHarvest(), factory.getHarvestCurrency().toFuture().get());
    Assertions.assertEquals(configuration.getNetworkCurrencies().getCurrency(), factory.getNetworkCurrency().toFuture().get());
}
Also used : RepositoryFactory(io.nem.symbol.sdk.api.RepositoryFactory) RepositoryFactoryConfiguration(io.nem.symbol.sdk.api.RepositoryFactoryConfiguration) Test(org.junit.jupiter.api.Test)

Example 19 with RepositoryFactory

use of io.nem.symbol.sdk.api.RepositoryFactory 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));
}
Also used : NamespaceRepository(io.nem.symbol.sdk.api.NamespaceRepository) RepositoryFactory(io.nem.symbol.sdk.api.RepositoryFactory) NamespaceSearchCriteria(io.nem.symbol.sdk.api.NamespaceSearchCriteria)

Example 20 with RepositoryFactory

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

the class MerkleLoaderIntegrationTest method hashLocks.

public List<Arguments> hashLocks() {
    RepositoryFactory repositoryFactory = getRepositoryFactory(DEFAULT_REPOSITORY_TYPE);
    HashLockRepository repository = repositoryFactory.createHashLockRepository();
    return getArguments(repository, new HashLockSearchCriteria());
}
Also used : HashLockSearchCriteria(io.nem.symbol.sdk.api.HashLockSearchCriteria) RepositoryFactory(io.nem.symbol.sdk.api.RepositoryFactory) HashLockRepository(io.nem.symbol.sdk.api.HashLockRepository)

Aggregations

RepositoryFactory (io.nem.symbol.sdk.api.RepositoryFactory)44 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)19 EnumSource (org.junit.jupiter.params.provider.EnumSource)16 Test (org.junit.jupiter.api.Test)11 BeforeEach (org.junit.jupiter.api.BeforeEach)7 RepositoryFactoryConfiguration (io.nem.symbol.sdk.api.RepositoryFactoryConfiguration)6 Account (io.nem.symbol.sdk.model.account.Account)6 BigInteger (java.math.BigInteger)6 Listener (io.nem.symbol.sdk.api.Listener)5 MetadataRepository (io.nem.symbol.sdk.api.MetadataRepository)5 NamespaceRepository (io.nem.symbol.sdk.api.NamespaceRepository)5 RestrictionMosaicRepository (io.nem.symbol.sdk.api.RestrictionMosaicRepository)5 NetworkCurrencies (io.nem.symbol.sdk.model.mosaic.NetworkCurrencies)5 MosaicRestrictionSearchCriteria (io.nem.symbol.sdk.api.MosaicRestrictionSearchCriteria)4 CosignatureSignedTransaction (io.nem.symbol.sdk.model.transaction.CosignatureSignedTransaction)4 SignedTransaction (io.nem.symbol.sdk.model.transaction.SignedTransaction)4 CurrencyService (io.nem.symbol.sdk.api.CurrencyService)3 MetadataTransactionService (io.nem.symbol.sdk.api.MetadataTransactionService)3 TransactionRepository (io.nem.symbol.sdk.api.TransactionRepository)3 TransactionService (io.nem.symbol.sdk.api.TransactionService)3