/** Access the conversion using the default conversion chain. */ @Test(description = "4.3.1 Access and test conversion using the default provider chain.") @SpecAssertion(id = "431-A5", section = "4.3.1") public void testDefaultConversion() { ConversionQuery query = ConversionQueryBuilder.of().setTermCurrency(Monetary.getCurrency("USD")).build(); CurrencyConversion conv = MonetaryConversions.getConversion(query); AssertJUnit.assertNotNull("No default CurrencyConversion returned for USD.", conv); query = ConversionQueryBuilder.of().setTermCurrency(Monetary.getCurrency("EUR")).build(); conv = MonetaryConversions.getConversion(query); AssertJUnit.assertNotNull("No default CurrencyConversion returned for EUR.", conv); }
/** * Access and test different Currency Conversions for the provider in place. * * <p>Test TCK providers, but also test implementation providers. Doing the ladder it is not * possible to test the rates quality, just that rates are returned if necessary. */ @Test( description = "4.3.1 Access Conversion by query to term currency XXX for all providers that support according " + "conversion, if" + "available a non-null CurrencyConversion must be provided.") @SpecAssertion(id = "431-A2", section = "4.3.1") public void testConversionsAreAvailableWithQuery() { for (String providerName : MonetaryConversions.getConversionProviderNames()) { ConversionQuery query = ConversionQueryBuilder.of().setTermCurrency("XXX").setProviderNames(providerName).build(); try { if (MonetaryConversions.isConversionAvailable(query)) { CurrencyConversion conv = MonetaryConversions.getConversion(query); AssertJUnit.assertNotNull( "CurrencyConversion returned from MonetaryConversions.getConversion(ConversionQuery) must" + " " + "never be null: " + providerName, conv); AssertJUnit.assertTrue( "CurrencyConversion is not flagged as available though it was returned from " + "MonetaryConversions.getConversion(ConversionQuery): " + providerName, MonetaryConversions.isConversionAvailable(query)); } } catch (MonetaryException e) { // OK, possible! AssertJUnit.assertFalse( "CurrencyConversion is not flagged as not available, though it was not returned from " + "MonetaryConversions.getConversion(ConversionQuery): " + providerName, MonetaryConversions.isConversionAvailable(query)); } } }
/** * Test if all providers returns valid meta data. * * @see javax.money.convert.ProviderContext */ @Test( description = "4.3.1 Test if all CurrencyConversion instances returns valid ConversionContext, accessed by " + "ConversionQuery/CurrencyUnit.") @SpecAssertion(id = "431-A3", section = "4.3.1") public void testProviderMetadata3WithContext() { for (String providerName : MonetaryConversions.getConversionProviderNames()) { ConversionQuery query = ConversionQueryBuilder.of() .setTermCurrency(Monetary.getCurrency("XXX")) .setProviderName(providerName) .build(); if (MonetaryConversions.isConversionAvailable(query)) { CurrencyConversion conv = MonetaryConversions.getConversion(query); ConversionContext ctx = conv.getContext(); AssertJUnit.assertNotNull( "ExchangeProvider must return a valid ProviderContext, but returned null: " + providerName, ctx); AssertJUnit.assertEquals( "ExchangeProvider's ProviderContext returns invalid name: " + providerName, providerName, ctx.getProviderName()); AssertJUnit.assertNotNull( "ExchangeProvider's ProviderContext declares invalid RateTypes to be returned (null): " + providerName, ctx.getRateType()); } } }
/** * Access the default provider chain. Compare with entries from javamoney.properties. The chain * must not be empty! */ @Test( description = "4.3.1 Access and test the default conversion provider chain, by accessing a default" + "CurrencyConversion for ConversionQuery.") @SpecAssertion(id = "431-A4", section = "4.3.1") public void testDefaultProviderChainIsDefinedDefaultWithContext() { ConversionQuery query = ConversionQueryBuilder.of().setTermCurrency(Monetary.getCurrency("CHF")).build(); CurrencyConversion conv = MonetaryConversions.getConversion(query); AssertJUnit.assertNotNull("No default CurrencyConversion returned.", conv); // we cannot test more here... }