Search in sources :

Example 1 with ExchangeRateProvider

use of javax.money.convert.ExchangeRateProvider in project jsr354-ri by JavaMoney.

the class ExchangeRateTypeTest method shouldReturnsECBCurrentRateProvider.

@Test
public void shouldReturnsECBCurrentRateProvider() {
    ExchangeRateProvider prov = MonetaryConversions.getExchangeRateProvider(ExchangeRateType.ECB);
    assertTrue(Objects.nonNull(prov));
    assertEquals(ECBCurrentRateProvider.class, prov.getClass());
}
Also used : ExchangeRateProvider(javax.money.convert.ExchangeRateProvider) Test(org.testng.annotations.Test)

Example 2 with ExchangeRateProvider

use of javax.money.convert.ExchangeRateProvider in project jsr354-ri by JavaMoney.

the class ProviderTest method testAccess_ECB.

@Test
public void testAccess_ECB() throws InterruptedException {
    final MonetaryAmount inEuro = Money.of(10, "EUR");
    for (int i = 0; i < 100; i++) {
        try {
            final ExchangeRateProvider rateProvider = MonetaryConversions.getExchangeRateProvider("ECB");
            final CurrencyConversion dollarConversion = rateProvider.getCurrencyConversion("USD");
            final MonetaryAmount inDollar = inEuro.with(dollarConversion);
            System.out.println(String.format("RUN: %n - %s: %s ≙ %s", i, rateProvider, inEuro, inDollar));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    for (int i = 0; i < 100; i++) {
        final ExchangeRateProvider rateProvider = MonetaryConversions.getExchangeRateProvider("ECB");
        final CurrencyConversion dollarConversion = rateProvider.getCurrencyConversion("USD");
        Thread.sleep(100L);
        final MonetaryAmount inDollar = inEuro.with(dollarConversion);
        System.out.println(String.format("RUN: %n - %s: %s ≙ %s", i, rateProvider, inEuro, inDollar));
    }
}
Also used : ExchangeRateProvider(javax.money.convert.ExchangeRateProvider) MonetaryAmount(javax.money.MonetaryAmount) CurrencyConversion(javax.money.convert.CurrencyConversion) Test(org.testng.annotations.Test)

Example 3 with ExchangeRateProvider

use of javax.money.convert.ExchangeRateProvider in project jsr354-ri by JavaMoney.

the class ProviderTest method testAccess_HIST.

@Test
public void testAccess_HIST() throws InterruptedException {
    final MonetaryAmount inEuro = Money.of(10, "EUR");
    for (int i = 0; i < 100; i++) {
        try {
            final ExchangeRateProvider rateProvider = MonetaryConversions.getExchangeRateProvider("ECB-HIST");
            final CurrencyConversion dollarConversion = rateProvider.getCurrencyConversion("USD");
            final MonetaryAmount inDollar = inEuro.with(dollarConversion);
            System.out.println(String.format("RUN: %n - %s: %s ≙ %s", i, rateProvider, inEuro, inDollar));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    for (int i = 0; i < 100; i++) {
        final ExchangeRateProvider rateProvider = MonetaryConversions.getExchangeRateProvider("ECB-HIST");
        final CurrencyConversion dollarConversion = rateProvider.getCurrencyConversion("USD");
        Thread.sleep(100L);
        final MonetaryAmount inDollar = inEuro.with(dollarConversion);
        System.out.println(String.format("RUN: %n - %s: %s ≙ %s", i, rateProvider, inEuro, inDollar));
    }
}
Also used : ExchangeRateProvider(javax.money.convert.ExchangeRateProvider) MonetaryAmount(javax.money.MonetaryAmount) CurrencyConversion(javax.money.convert.CurrencyConversion) Test(org.testng.annotations.Test)

Example 4 with ExchangeRateProvider

use of javax.money.convert.ExchangeRateProvider in project jsr354-ri by JavaMoney.

the class ExchangeRateTypeTest method shouldReturnsIMFHistoricRateProvider.

@Test
public void shouldReturnsIMFHistoricRateProvider() {
    ExchangeRateProvider prov = MonetaryConversions.getExchangeRateProvider(ExchangeRateType.IMF_HIST);
    assertTrue(Objects.nonNull(prov));
    assertEquals(IMFHistoricRateProvider.class, prov.getClass());
}
Also used : ExchangeRateProvider(javax.money.convert.ExchangeRateProvider) Test(org.testng.annotations.Test)

Example 5 with ExchangeRateProvider

use of javax.money.convert.ExchangeRateProvider in project jsr354-ri by JavaMoney.

the class ExchangeRateTypeTest method shouldReturnsIMFRateProvider.

@Test
public void shouldReturnsIMFRateProvider() {
    ExchangeRateProvider prov = MonetaryConversions.getExchangeRateProvider(ExchangeRateType.IMF);
    assertTrue(Objects.nonNull(prov));
    assertEquals(IMFRateProvider.class, prov.getClass());
}
Also used : ExchangeRateProvider(javax.money.convert.ExchangeRateProvider) Test(org.testng.annotations.Test)

Aggregations

ExchangeRateProvider (javax.money.convert.ExchangeRateProvider)35 Test (org.testng.annotations.Test)23 CurrencyConversion (javax.money.convert.CurrencyConversion)10 ArrayList (java.util.ArrayList)9 MonetaryAmount (javax.money.MonetaryAmount)9 MonetaryException (javax.money.MonetaryException)7 CompoundRateProvider (org.javamoney.moneta.spi.CompoundRateProvider)4 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 ExchangeRate (javax.money.convert.ExchangeRate)2 ProviderContext (javax.money.convert.ProviderContext)2 ProviderContextBuilder (javax.money.convert.ProviderContextBuilder)2 RateType (javax.money.convert.RateType)2 HashSet (java.util.HashSet)1 Money (org.javamoney.moneta.Money)1