javax.money.convert.ConversionQueryBuilder Java Examples
The following examples show how to use
javax.money.convert.ConversionQueryBuilder.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ECBHistoric90RateProviderTest.java From jsr354-ri with Apache License 2.0 | 6 votes |
@Test public void shouldSetTimeInLocalDateTime2() { LocalDate localDate = LocalDate.now().minusDays(90) .with(TemporalAdjusters.next(DayOfWeek.FRIDAY)); ConversionQuery conversionQuery = ConversionQueryBuilder.of() .setTermCurrency(EURO).set(localDate).build(); CurrencyConversion currencyConversion = provider .getCurrencyConversion(conversionQuery); assertNotNull(currencyConversion); MonetaryAmount money = Money.of(BigDecimal.TEN, DOLLAR); MonetaryAmount result = currencyConversion.apply(money); assertEquals(result.getCurrency(), EURO); assertTrue(result.getNumber().doubleValue() > 0); }
Example #2
Source File: ECBHistoric90RateProviderTest.java From jsr354-ri with Apache License 2.0 | 6 votes |
@Test(expectedExceptions = MonetaryException.class) public void shouldReturnErrorWhenFindFromHistoricalUsingPeriod() { LocalDate localDate = YearMonth.of(2011, Month.JANUARY).atDay(9); ConversionQuery conversionQuery = ConversionQueryBuilder.of() .setTermCurrency(EURO) .set(withDaysBetween(localDate.minusDays(1), localDate)) .build(); CurrencyConversion currencyConversion = provider .getCurrencyConversion(conversionQuery); assertNotNull(currencyConversion); MonetaryAmount money = Money.of(BigDecimal.TEN, DOLLAR); currencyConversion.apply(money); fail(); }
Example #3
Source File: ECBHistoric90RateProviderTest.java From jsr354-ri with Apache License 2.0 | 6 votes |
@Test(expectedExceptions = MonetaryException.class) public void shouldSetTimeInLocalDateTime() { LocalDate localDate = YearMonth.of(2014, Month.JANUARY).atDay(9); ConversionQuery conversionQuery = ConversionQueryBuilder.of() .setTermCurrency(EURO).set(localDate).build(); CurrencyConversion currencyConversion = provider .getCurrencyConversion(conversionQuery); assertNotNull(currencyConversion); MonetaryAmount money = Money.of(BigDecimal.TEN, DOLLAR); MonetaryAmount result = currencyConversion.apply(money); assertEquals(result.getCurrency(), EURO); assertTrue(result.getNumber().doubleValue() > 0); }
Example #4
Source File: IMFHistoricRateProviderTest.java From jsr354-ri with Apache License 2.0 | 6 votes |
@Test public void shouldSetTimeInLocalDateTime2() { LocalDate localDate = LocalDate.now().minusDays(90) .with(TemporalAdjusters.next(DayOfWeek.FRIDAY)); ConversionQuery conversionQuery = ConversionQueryBuilder.of() .setTermCurrency(EURO).set(localDate).build(); CurrencyConversion currencyConversion = provider .getCurrencyConversion(conversionQuery); assertNotNull(currencyConversion); MonetaryAmount money = Money.of(BigDecimal.TEN, DOLLAR); MonetaryAmount result = currencyConversion.apply(money); assertEquals(result.getCurrency(), EURO); assertTrue(result.getNumber().doubleValue() > 0); }
Example #5
Source File: IMFHistoricRateProviderTest.java From jsr354-ri with Apache License 2.0 | 6 votes |
@Test(expectedExceptions = MonetaryException.class) public void shouldReturnErrorWhenFindFromHistoricalUsingPeriod() { LocalDate localDate = YearMonth.of(2011, Month.JANUARY).atDay(9); ConversionQuery conversionQuery = ConversionQueryBuilder.of() .setTermCurrency(EURO) .set(withDaysBetween(localDate.minusDays(1), localDate)) .build(); CurrencyConversion currencyConversion = provider .getCurrencyConversion(conversionQuery); assertNotNull(currencyConversion); MonetaryAmount money = Money.of(BigDecimal.TEN, DOLLAR); currencyConversion.apply(money); fail(); }
Example #6
Source File: IMFHistoricRateProviderTest.java From jsr354-ri with Apache License 2.0 | 6 votes |
@Test public void shouldSetTimeInLocalDateTime() { LocalDate localDate = YearMonth.of(2014, Month.JANUARY).atDay(9); ConversionQuery conversionQuery = ConversionQueryBuilder.of() .setTermCurrency(EURO).set(localDate).build(); CurrencyConversion currencyConversion = provider .getCurrencyConversion(conversionQuery); assertNotNull(currencyConversion); MonetaryAmount money = Money.of(BigDecimal.TEN, DOLLAR); MonetaryAmount result = currencyConversion.apply(money); assertEquals(result.getCurrency(), EURO); assertTrue(result.getNumber().doubleValue() > 0); }
Example #7
Source File: ExchangeRateAccess.java From javamoney-examples with Apache License 2.0 | 6 votes |
public static void main(String... args){ System.out.println("Default conversion chain -> " + MonetaryConversions.getDefaultConversionProviderChain()); ExchangeRateProvider provider = MonetaryConversions.getExchangeRateProvider("IDENT"); System.out.println("IDENT provider -> " + provider); provider = MonetaryConversions.getExchangeRateProvider("IDENT", "ECB"); System.out.println("IDENT, ECB provider -> " + provider); System.out.println(provider.getExchangeRate("CHF", "EUR")); System.out.println(provider.getExchangeRate("CHF", "CHF")); provider = MonetaryConversions.getExchangeRateProvider("IDENT", "IMF"); System.out.println(provider.getExchangeRate("TND", "BRL")); provider = MonetaryConversions.getExchangeRateProvider("IDENT", "ECB", "ECB-HIST"); System.out.println("CHF -> EUR (today) -> " + provider.getExchangeRate(ConversionQueryBuilder.of() .setBaseCurrency("EUR").setTermCurrency("CHF") //.set(new Date() LocalDate.of(2008, 1, 8)) .build())); System.out.println("CHF -> EUR (1.8.2008) -> " + provider.getExchangeRate(ConversionQueryBuilder.of() .setBaseCurrency("EUR").setTermCurrency("CHF") //.set(LocalDate.of(2008, 1, 8)) .build())); }
Example #8
Source File: ConversionExample.java From javamoney-examples with Apache License 2.0 | 6 votes |
public static void main(String... args) { String termCurrencyCode = DEFAULT_TERM_CURRENCY_CODE; if (args.length > 0) { termCurrencyCode = args[0]; } final MonetaryAmount amt = Money.of(2000, "EUR"); CurrencyConversion conv= MonetaryConversions.getConversion(termCurrencyCode, "ECB"); System.out.println(MessageFormat.format("2000 EUR (ECB)-> {0} = {1}", termCurrencyCode, amt.with(conv))); conv= MonetaryConversions.getConversion(termCurrencyCode, "IMF"); System.out.println(MessageFormat.format("2000 EUR (IMF)-> {0} = {1}", termCurrencyCode, amt.with(conv))); System.out.println(MessageFormat.format( "2000 EUR (ECB, at 5th Jan 2015)-> {0} = {1}", termCurrencyCode, amt.with(MonetaryConversions .getConversion(ConversionQueryBuilder.of() .setTermCurrency(termCurrencyCode) //.set(LocalDate.of(2015, 01, 05)) .build())))); }
Example #9
Source File: ExchangeRateAccess.java From javamoney-examples with Apache License 2.0 | 6 votes |
public static void main(String... args){ System.out.println("Default conversion chain -> " + MonetaryConversions.getDefaultConversionProviderChain()); ExchangeRateProvider provider = MonetaryConversions.getExchangeRateProvider("IDENT"); System.out.println("IDENT provider -> " + provider); provider = MonetaryConversions.getExchangeRateProvider("IDENT", "ECB"); System.out.println("IDENT, ECB provider -> " + provider); System.out.println(provider.getExchangeRate("CHF", "EUR")); System.out.println(provider.getExchangeRate("CHF", "CHF")); provider = MonetaryConversions.getExchangeRateProvider("IDENT", "IMF"); System.out.println(provider.getExchangeRate("TND", "BRL")); provider = MonetaryConversions.getExchangeRateProvider("IDENT", "ECB", "ECB-HIST"); System.out.println("CHF -> EUR (today) -> " + provider.getExchangeRate(ConversionQueryBuilder.of() .setBaseCurrency("EUR").setTermCurrency("CHF") .set(LocalDate.of(2008, 1, 8)).build())); System.out.println("CHF -> EUR (1.8.2008) -> " + provider.getExchangeRate(ConversionQueryBuilder.of() .setBaseCurrency("EUR").setTermCurrency("CHF") .set(LocalDate.of(2008, 1, 8)).build())); }
Example #10
Source File: ConversionExample.java From javamoney-examples with Apache License 2.0 | 6 votes |
public static void main(String... args) { String termCurrencyCode = DEFAULT_TERM_CURRENCY_CODE; if (args.length > 0) { termCurrencyCode = args[0]; } final MonetaryAmount amt = Money.of(2000, "EUR"); CurrencyConversion conv= MonetaryConversions.getConversion(termCurrencyCode, "ECB"); System.out.println(MessageFormat.format("2000 EUR (ECB)-> {0} = {1}", termCurrencyCode, amt.with(conv))); conv= MonetaryConversions.getConversion(termCurrencyCode, "IMF"); System.out.println(MessageFormat.format("2000 EUR (IMF)-> {0} = {1}", termCurrencyCode, amt.with(conv))); System.out.println(MessageFormat.format( "2000 EUR (ECB, at 5th Jan 2015)-> {0} = {1}", termCurrencyCode, amt.with(MonetaryConversions .getConversion(ConversionQueryBuilder.of() .setTermCurrency(termCurrencyCode) .set(LocalDate.of(2015, 01, 05)).build())))); }
Example #11
Source File: LazyBoundCurrencyConversion.java From jsr354-ri with Apache License 2.0 | 5 votes |
/** * Get the exchange rate type that this provider instance is providing data * for. * * @return the exchange rate type if this instance. */ @Override public ExchangeRate getExchangeRate(MonetaryAmount amount) { return this.rateProvider.getExchangeRate(ConversionQueryBuilder .of(conversionQuery).setBaseCurrency(amount.getCurrency()) .build()); // return this.rateProvider.getExchangeRate(amount.getCurrency(), // getCurrency()); }
Example #12
Source File: ECBHistoric90RateProviderTest.java From jsr354-ri with Apache License 2.0 | 5 votes |
@Test(expectedExceptions = MonetaryException.class) public void shouldReturnErrorWhenDoesNotFindTheExchangeRate() { LocalDate localDate = YearMonth.of(2011, Month.JANUARY).atDay(9); ConversionQuery conversionQuery = ConversionQueryBuilder.of() .set(localDate).setTermCurrency(EURO).build(); CurrencyConversion currencyConversion = provider .getCurrencyConversion(conversionQuery); assertNotNull(currencyConversion); MonetaryAmount money = Money.of(BigDecimal.TEN, DOLLAR); currencyConversion.apply(money); fail(); }
Example #13
Source File: IMFHistoricRateProviderTest.java From jsr354-ri with Apache License 2.0 | 5 votes |
@Test(expectedExceptions = MonetaryException.class) public void shouldReturnErrorWhenDoesNotFindTheExchangeRate() { LocalDate localDate = YearMonth.of(2011, Month.JANUARY).atDay(9); ConversionQuery conversionQuery = ConversionQueryBuilder.of() .set(localDate).setTermCurrency(EURO).build(); CurrencyConversion currencyConversion = provider .getCurrencyConversion(conversionQuery); assertNotNull(currencyConversion); MonetaryAmount money = Money.of(BigDecimal.TEN, DOLLAR); currencyConversion.apply(money); fail(); }