/** * 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)); } } }
/** * 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 to term currency code 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 testConversionsAreAvailable() { for (String providerName : MonetaryConversions.getConversionProviderNames()) { try { if (MonetaryConversions.isConversionAvailable("XXX", providerName)) { CurrencyConversion conv = MonetaryConversions.getConversion("XXX", providerName); AssertJUnit.assertNotNull( "CurrencyConversion returned from MonetaryConversions.getConversion(String, " + "String...) should never be null: " + providerName, conv); AssertJUnit.assertTrue( "CurrencyConversion is not flagged as available, " + "though it was returned from MonetaryConversions.getConversion" + "(String," + " String...): " + providerName, MonetaryConversions.isConversionAvailable("XXX", providerName)); } } catch (MonetaryException e) { AssertJUnit.assertFalse( "CurrencyConversion is not flagged as NOT available, though it is not accessible from " + "MonetaryConversions.getConversion(String, String...): " + providerName, MonetaryConversions.isConversionAvailable("XXX", providerName)); } } }
/** * 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()); } } }
/** * 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 " + "currency code.") @SpecAssertion(id = "431-A3", section = "4.3.1") public void testProviderMetadata2() { for (String providerName : MonetaryConversions.getConversionProviderNames()) { if (MonetaryConversions.isConversionAvailable("XXX", providerName)) { CurrencyConversion conv = MonetaryConversions.getConversion("XXX", providerName); 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()); } } }
/** * Test if all providers returns valid meta data. * * @see javax.money.convert.ProviderContext */ @Test( description = "4.3.1 Test if all ExchangeRateProvider instances returns valid ProviderContext.") @SpecAssertion(id = "431-A3", section = "4.3.1") public void testProviderMetadata() { for (String providerName : MonetaryConversions.getConversionProviderNames()) { ExchangeRateProvider prov = MonetaryConversions.getExchangeRateProvider(providerName); AssertJUnit.assertNotNull("Provider mot accessible: " + providerName, prov); ProviderContext ctx = prov.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.getRateTypes()); AssertJUnit.assertFalse( "ExchangeProvider's ProviderContext declares empty RateTypes to be returned: " + providerName, ctx.getRateTypes().isEmpty()); } }
/** * Ensure at least one conversion provider is available. * * <p>Hint: ignore all TCK test providers, only count up productive providers. */ @Test( description = "4.3.1 Ensure at least one conversion provider is available, TestRateProvider must be present.") @SpecAssertion(id = "431-A1", section = "4.3.1") public void testProvidersAvailable() { int providerCount = 0; for (String providername : MonetaryConversions.getConversionProviderNames()) { if (!"TestRateProvider".equals(providername)) { providerCount++; } } AssertJUnit.assertTrue( "At least one conversion provider must be available/registered.", providerCount > 0); }