use of javax.money.convert.ExchangeRateProvider in project jsr354-ri by JavaMoney.
the class ProviderTest method testAccess_HIST90.
@Test
public void testAccess_HIST90() throws InterruptedException {
final MonetaryAmount inEuro = Money.of(10, "EUR");
for (int i = 0; i < 100; i++) {
try {
final ExchangeRateProvider rateProvider = MonetaryConversions.getExchangeRateProvider("ECB-HIST90");
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-HIST90");
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));
}
}
use of javax.money.convert.ExchangeRateProvider in project jsr354-ri by JavaMoney.
the class ProviderTest method testAccess_IMF.
@Test
public void testAccess_IMF() throws InterruptedException {
final MonetaryAmount inEuro = Money.of(10, "EUR");
for (int i = 0; i < 100; i++) {
try {
final ExchangeRateProvider rateProvider = MonetaryConversions.getExchangeRateProvider("IMF");
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("IMF");
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));
}
}
use of javax.money.convert.ExchangeRateProvider in project jsr354-ri by JavaMoney.
the class CompoundRateProvider method createContext.
private static ProviderContext createContext(Iterable<ExchangeRateProvider> providers) {
Set<RateType> rateTypeSet = new HashSet<>();
StringBuilder providerName = new StringBuilder("Compound: ");
List<ProviderContext> childContextList = new ArrayList<>();
for (ExchangeRateProvider exchangeRateProvider : providers) {
childContextList.add(exchangeRateProvider.getContext());
providerName.append(exchangeRateProvider.getContext().getProviderName());
providerName.append(',');
rateTypeSet.addAll(exchangeRateProvider.getContext().getRateTypes());
}
providerName.setLength(providerName.length() - 1);
ProviderContextBuilder builder = ProviderContextBuilder.of(providerName.toString(), rateTypeSet);
builder.set(CHILD_PROVIDER_CONTEXTS_KEY, childContextList);
return builder.build();
}
use of javax.money.convert.ExchangeRateProvider in project jsr354-ri by JavaMoney.
the class MonetaryConversionTest method testGetExchangeRateProvider_Chained.
@Test
public void testGetExchangeRateProvider_Chained() throws InterruptedException {
ExchangeRateProvider prov = MonetaryConversions.getExchangeRateProvider("IMF");
assertTrue(Objects.nonNull(prov));
assertEquals(IMFRateProvider.class, prov.getClass());
// Test rate provided by IMF (derived)
// wait for provider to load...
Thread.sleep(5000L);
ExchangeRate exchangeRate = prov.getExchangeRate(Monetary.getCurrency("USD"), Monetary.getCurrency("INR"));
assertTrue(Objects.nonNull(exchangeRate));
assertTrue(exchangeRate.isDerived());
// Test rate provided by ECB
exchangeRate = prov.getExchangeRate(Monetary.getCurrency("EUR"), Monetary.getCurrency("CHF"));
assertTrue(Objects.nonNull(exchangeRate));
assertTrue(exchangeRate.isDerived());
}
use of javax.money.convert.ExchangeRateProvider in project jsr354-ri by JavaMoney.
the class MonetaryConversionTest method testGetExchangeRateDefault.
@Test
public void testGetExchangeRateDefault() {
ExchangeRateProvider prov = MonetaryConversions.getExchangeRateProvider();
assertTrue(Objects.nonNull(prov));
ExchangeRate rate = prov.getExchangeRate("CHF", "EUR");
assertNotNull(rate);
}
Aggregations