Skip to content

Commit

Permalink
Merge pull request #23 from Q1nt/add-exchange-rates-fallback
Browse files Browse the repository at this point in the history
Add exchange-rates-client fallback implementation
  • Loading branch information
sqshq committed Jul 8, 2018
2 parents eaec3c0 + 5763e90 commit 4935509
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

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

@RequestMapping(method = RequestMethod.GET, value = "/latest")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.piggymetrics.statistics.client;

import com.piggymetrics.statistics.domain.Currency;
import com.piggymetrics.statistics.domain.ExchangeRatesContainer;
import org.springframework.stereotype.Component;

import java.util.Collections;

@Component
public class ExchangeRatesClientFallback implements ExchangeRatesClient {

@Override
public ExchangeRatesContainer getRates(Currency base) {
ExchangeRatesContainer container = new ExchangeRatesContainer();
container.setBase(Currency.getBase());
container.setRates(Collections.emptyMap());
return container;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ public void shouldRetrieveExchangeRates() {
assertEquals(container.getDate(), LocalDate.now());
assertEquals(container.getBase(), Currency.getBase());

assertNotNull(container.getRates().get(Currency.EUR.name()));
assertNotNull(container.getRates().get(Currency.RUB.name()));
assertNotNull(container.getRates());
}

}

0 comments on commit 4935509

Please sign in to comment.