Search in sources :

Example 6 with RepositoryFactory

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

the class RepositoryFactoryConfigurationExamplesIntegrationTest method bootAppUsingLegacyHardcodedCurrencies.

@Test
void bootAppUsingLegacyHardcodedCurrencies() throws ExecutionException, InterruptedException {
    // Option 3) Client app boot time relaying on some of the rest configuration.
    // User uses the
    // legacy hardcoded sdk currencies
    RepositoryFactoryConfiguration configuration = new RepositoryFactoryConfiguration("http://localhost:3000");
    configuration.withNetworkCurrencies(new NetworkCurrencies(Currency.CAT_CURRENCY, Currency.CAT_HARVEST));
    try (RepositoryFactory repositoryFactory = new RepositoryFactoryVertxImpl(configuration)) {
        appDoSomeStuff(repositoryFactory);
    }
}
Also used : NetworkCurrencies(io.nem.symbol.sdk.model.mosaic.NetworkCurrencies) RepositoryFactory(io.nem.symbol.sdk.api.RepositoryFactory) RepositoryFactoryConfiguration(io.nem.symbol.sdk.api.RepositoryFactoryConfiguration) RepositoryFactoryVertxImpl(io.nem.symbol.sdk.infrastructure.vertx.RepositoryFactoryVertxImpl) Test(org.junit.jupiter.api.Test)

Example 7 with RepositoryFactory

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

the class RepositoryFactoryConfigurationExamplesIntegrationTest method bootAppFullyOffline.

@Test
void bootAppFullyOffline() throws ExecutionException, InterruptedException {
    // Option 1) Client app boot time. The clients defines the configuration to work
    // offline.
    RepositoryFactoryConfiguration configuration = new RepositoryFactoryConfiguration("http://localhost:3000");
    configuration.withNetworkType(NetworkType.MAIN_NET);
    configuration.withGenerationHash("abc");
    Currency currency = new CurrencyBuilder(NamespaceId.createFromName("my.custom.currency"), 6).build();
    Currency harvest = new CurrencyBuilder(NamespaceId.createFromName("my.custom.harvest"), 3).build();
    configuration.withNetworkCurrencies(new NetworkCurrencies(currency, harvest));
    try (RepositoryFactory repositoryFactory = new RepositoryFactoryVertxImpl(configuration)) {
        appDoSomeStuff(repositoryFactory);
    }
}
Also used : CurrencyBuilder(io.nem.symbol.sdk.model.mosaic.CurrencyBuilder) Currency(io.nem.symbol.sdk.model.mosaic.Currency) NetworkCurrencies(io.nem.symbol.sdk.model.mosaic.NetworkCurrencies) RepositoryFactory(io.nem.symbol.sdk.api.RepositoryFactory) RepositoryFactoryConfiguration(io.nem.symbol.sdk.api.RepositoryFactoryConfiguration) RepositoryFactoryVertxImpl(io.nem.symbol.sdk.infrastructure.vertx.RepositoryFactoryVertxImpl) Test(org.junit.jupiter.api.Test)

Example 8 with RepositoryFactory

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

the class RestrictionMosaicRepositoryIntegrationTest method searchAddressRestriction.

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

Example 9 with RepositoryFactory

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

the class RepositoryFactoryOkHttpImplTest method getRestProvidedNetworkCurrencies.

@Test
public void getRestProvidedNetworkCurrencies() throws Exception {
    String baseUrl = "https://localhost:1934/path";
    RepositoryFactoryConfiguration configuration = new RepositoryFactoryConfiguration(baseUrl);
    configuration.withGenerationHash("abc");
    configuration.withNetworkType(NetworkType.MAIN_NET);
    RepositoryFactory factory = new RepositoryFactoryOkHttpImpl(configuration) {

        @Override
        protected Observable<NetworkCurrencies> loadNetworkCurrencies() {
            return Observable.just(new NetworkCurrencies(Currency.CAT_CURRENCY, Currency.CAT_HARVEST));
        }
    };
    Assertions.assertEquals(configuration.getNetworkType(), factory.getNetworkType().toFuture().get());
    Assertions.assertEquals(configuration.getGenerationHash(), factory.getGenerationHash().toFuture().get());
    Assertions.assertEquals(Currency.CAT_HARVEST, factory.getHarvestCurrency().toFuture().get());
    Assertions.assertEquals(Currency.CAT_CURRENCY, factory.getNetworkCurrency().toFuture().get());
}
Also used : NetworkCurrencies(io.nem.symbol.sdk.model.mosaic.NetworkCurrencies) RepositoryFactory(io.nem.symbol.sdk.api.RepositoryFactory) RepositoryFactoryConfiguration(io.nem.symbol.sdk.api.RepositoryFactoryConfiguration) Test(org.junit.jupiter.api.Test)

Example 10 with RepositoryFactory

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

the class RepositoryFactoryOkHttpImplTest method shouldCreateRepositories.

@Test
public void shouldCreateRepositories() {
    String baseUrl = "https://nem.com:3000/path";
    RepositoryFactory factory = new RepositoryFactoryOkHttpImpl(baseUrl);
    Assertions.assertNotNull(factory.createAccountRepository());
    Assertions.assertNotNull(factory.createBlockRepository());
    Assertions.assertNotNull(factory.createReceiptRepository());
    Assertions.assertNotNull(factory.createChainRepository());
    Assertions.assertNotNull(factory.createListener());
    Assertions.assertNotNull(factory.createMosaicRepository());
    Assertions.assertNotNull(factory.createNamespaceRepository());
    Assertions.assertNotNull(factory.createNetworkRepository());
    Assertions.assertNotNull(factory.createNodeRepository());
    Assertions.assertNotNull(factory.createTransactionRepository());
    Assertions.assertNotNull(factory.createTransactionStatusRepository());
    Assertions.assertNotNull(factory.createMetadataRepository());
    Assertions.assertNotNull(factory.createRestrictionAccountRepository());
    Assertions.assertNotNull(factory.createRestrictionMosaicRepository());
    Assertions.assertNotNull(factory.createHashLockRepository());
    Assertions.assertNotNull(factory.createSecretLockRepository());
    Assertions.assertNotNull(factory.createMultisigRepository());
    Assertions.assertNotNull(factory.createFinalizationRepository());
    Assertions.assertNotNull(factory.createJsonSerialization());
    factory.close();
    factory.close();
    factory.close();
}
Also used : RepositoryFactory(io.nem.symbol.sdk.api.RepositoryFactory) Test(org.junit.jupiter.api.Test)

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