Skip to content

Commit

Permalink
Merge pull request #24 from Q1nt/change-exchange-rates-service
Browse files Browse the repository at this point in the history
Switch exchange-rates provider
  • Loading branch information
sqshq authored Jul 10, 2018
2 parents 4935509 + 54c0efd commit 50504c0
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 4 deletions.
2 changes: 1 addition & 1 deletion config/src/main/resources/shared/statistics-service.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ server:
port: 7000

rates:
url: http://api.fixer.io
url: https://exchangeratesapi.io/api
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,19 @@
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.Arrays;
import java.util.Collection;

@FeignClient(url = "${rates.url}", name = "rates-client", fallback = ExchangeRatesClientFallback.class)
public interface ExchangeRatesClient {

default ExchangeRatesContainer getRates(Currency base) {
return getRates(base, Arrays.asList(Currency.values()));
}

@RequestMapping(method = RequestMethod.GET, value = "/latest")
ExchangeRatesContainer getRates(@RequestParam("base") Currency base);
ExchangeRatesContainer getRates(
@RequestParam("base") Currency base,
@RequestParam("symbols") Collection<Currency> currencies);

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@
import com.piggymetrics.statistics.domain.ExchangeRatesContainer;
import org.springframework.stereotype.Component;

import java.util.Collection;
import java.util.Collections;

@Component
public class ExchangeRatesClientFallback implements ExchangeRatesClient {

@Override
public ExchangeRatesContainer getRates(Currency base) {
public ExchangeRatesContainer getRates(Currency base, Collection<Currency> currencies) {
ExchangeRatesContainer container = new ExchangeRatesContainer();
container.setBase(Currency.getBase());
container.setRates(Collections.emptyMap());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import java.time.LocalDate;
import java.util.Collections;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
Expand All @@ -30,6 +31,24 @@ public void shouldRetrieveExchangeRates() {
assertEquals(container.getBase(), Currency.getBase());

assertNotNull(container.getRates());
assertEquals(Currency.values().length, container.getRates().size());
assertNotNull(container.getRates().get(Currency.USD.name()));
assertNotNull(container.getRates().get(Currency.EUR.name()));
assertNotNull(container.getRates().get(Currency.RUB.name()));
}

@Test
public void shouldRetrieveExchangeRatesForSpecifiedCurrency() {

Currency requestedCurrency = Currency.EUR;
ExchangeRatesContainer container = client.getRates(Currency.getBase(), Collections.singleton(requestedCurrency));

assertEquals(container.getDate(), LocalDate.now());
assertEquals(container.getBase(), Currency.getBase());

assertNotNull(container.getRates());
assertEquals(1, container.getRates().size());
assertNotNull(container.getRates().get(requestedCurrency.name()));
}

}
2 changes: 1 addition & 1 deletion statistics-service/src/test/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ spring:
port: 0

rates:
url: http://api.fixer.io
url: https://exchangeratesapi.io/api

0 comments on commit 50504c0

Please sign in to comment.