From 5c2880d4a3905399a74b778db4d46f22c4401385 Mon Sep 17 00:00:00 2001 From: sqshq Date: Sun, 26 Aug 2018 16:29:39 -0400 Subject: [PATCH] #34 fixed exchange rates client in order to support API changes in exchangeratesapi.io --- .../account/AccountServiceApplicationTests.java | 4 ++-- .../account/controller/AccountControllerTest.java | 4 ++-- .../account/repository/AccountRepositoryTest.java | 4 ++-- .../auth/AuthServiceApplicationTests.java | 4 ++-- .../auth/controller/UserControllerTest.java | 4 ++-- .../auth/repository/UserRepositoryTest.java | 4 ++-- .../main/resources/shared/statistics-service.yml | 2 +- gateway/src/main/resources/static/js/launch.js | 2 +- .../gateway/GatewayApplicationTests.java | 4 ++-- .../monitoring/MonitoringApplicationTests.java | 4 ++-- .../NotificationServiceApplicationTests.java | 4 ++-- .../controller/RecipientControllerTest.java | 4 ++-- .../repository/RecipientRepositoryTest.java | 4 ++-- .../statistics/client/ExchangeRatesClient.java | 13 ++----------- .../client/ExchangeRatesClientFallback.java | 3 +-- .../StatisticsServiceApplicationTests.java | 4 ++-- .../statistics/client/ExchangeRatesClientTest.java | 13 +++++-------- .../controller/StatisticsControllerTest.java | 4 ++-- .../repository/DataPointRepositoryTest.java | 4 ++-- .../src/test/resources/application.yml | 2 +- 20 files changed, 39 insertions(+), 52 deletions(-) diff --git a/account-service/src/test/java/com/piggymetrics/account/AccountServiceApplicationTests.java b/account-service/src/test/java/com/piggymetrics/account/AccountServiceApplicationTests.java index 9cc5451f36..393183b14c 100644 --- a/account-service/src/test/java/com/piggymetrics/account/AccountServiceApplicationTests.java +++ b/account-service/src/test/java/com/piggymetrics/account/AccountServiceApplicationTests.java @@ -3,9 +3,9 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit4.SpringRunner; -@RunWith(SpringJUnit4ClassRunner.class) +@RunWith(SpringRunner.class) @SpringBootTest public class AccountServiceApplicationTests { diff --git a/account-service/src/test/java/com/piggymetrics/account/controller/AccountControllerTest.java b/account-service/src/test/java/com/piggymetrics/account/controller/AccountControllerTest.java index caf5d088e0..b078ea6fac 100644 --- a/account-service/src/test/java/com/piggymetrics/account/controller/AccountControllerTest.java +++ b/account-service/src/test/java/com/piggymetrics/account/controller/AccountControllerTest.java @@ -12,7 +12,7 @@ import org.mockito.Mock; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.http.MediaType; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit4.SpringRunner; import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.setup.MockMvcBuilders; @@ -25,7 +25,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; -@RunWith(SpringJUnit4ClassRunner.class) +@RunWith(SpringRunner.class) @SpringBootTest public class AccountControllerTest { diff --git a/account-service/src/test/java/com/piggymetrics/account/repository/AccountRepositoryTest.java b/account-service/src/test/java/com/piggymetrics/account/repository/AccountRepositoryTest.java index aead8cffa9..a28ec2bf98 100644 --- a/account-service/src/test/java/com/piggymetrics/account/repository/AccountRepositoryTest.java +++ b/account-service/src/test/java/com/piggymetrics/account/repository/AccountRepositoryTest.java @@ -9,7 +9,7 @@ import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.data.mongo.DataMongoTest; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit4.SpringRunner; import java.math.BigDecimal; import java.util.Arrays; @@ -17,7 +17,7 @@ import static org.junit.Assert.assertEquals; -@RunWith(SpringJUnit4ClassRunner.class) +@RunWith(SpringRunner.class) @DataMongoTest public class AccountRepositoryTest { diff --git a/auth-service/src/test/java/com/piggymetrics/auth/AuthServiceApplicationTests.java b/auth-service/src/test/java/com/piggymetrics/auth/AuthServiceApplicationTests.java index 4f597906a8..9189fa4381 100644 --- a/auth-service/src/test/java/com/piggymetrics/auth/AuthServiceApplicationTests.java +++ b/auth-service/src/test/java/com/piggymetrics/auth/AuthServiceApplicationTests.java @@ -3,9 +3,9 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit4.SpringRunner; -@RunWith(SpringJUnit4ClassRunner.class) +@RunWith(SpringRunner.class) @SpringBootTest public class AuthServiceApplicationTests { diff --git a/auth-service/src/test/java/com/piggymetrics/auth/controller/UserControllerTest.java b/auth-service/src/test/java/com/piggymetrics/auth/controller/UserControllerTest.java index 7117e60c42..bbff0c1be9 100644 --- a/auth-service/src/test/java/com/piggymetrics/auth/controller/UserControllerTest.java +++ b/auth-service/src/test/java/com/piggymetrics/auth/controller/UserControllerTest.java @@ -11,7 +11,7 @@ import org.mockito.Mock; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.http.MediaType; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit4.SpringRunner; import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.setup.MockMvcBuilders; @@ -21,7 +21,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; -@RunWith(SpringJUnit4ClassRunner.class) +@RunWith(SpringRunner.class) @SpringBootTest public class UserControllerTest { diff --git a/auth-service/src/test/java/com/piggymetrics/auth/repository/UserRepositoryTest.java b/auth-service/src/test/java/com/piggymetrics/auth/repository/UserRepositoryTest.java index 0c6a369ee6..a9c93838cf 100644 --- a/auth-service/src/test/java/com/piggymetrics/auth/repository/UserRepositoryTest.java +++ b/auth-service/src/test/java/com/piggymetrics/auth/repository/UserRepositoryTest.java @@ -8,14 +8,14 @@ import org.springframework.boot.autoconfigure.mongo.embedded.EmbeddedMongoAutoConfiguration; import org.springframework.boot.test.autoconfigure.data.mongo.DataMongoTest; import org.springframework.boot.test.mock.mockito.MockBean; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit4.SpringRunner; import java.util.Optional; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; -@RunWith(SpringJUnit4ClassRunner.class) +@RunWith(SpringRunner.class) @DataMongoTest public class UserRepositoryTest { diff --git a/config/src/main/resources/shared/statistics-service.yml b/config/src/main/resources/shared/statistics-service.yml index 37eac2d77b..a460f902e3 100644 --- a/config/src/main/resources/shared/statistics-service.yml +++ b/config/src/main/resources/shared/statistics-service.yml @@ -22,4 +22,4 @@ server: port: 7000 rates: - url: https://exchangeratesapi.io/api \ No newline at end of file + url: https://api.exchangeratesapi.io \ No newline at end of file diff --git a/gateway/src/main/resources/static/js/launch.js b/gateway/src/main/resources/static/js/launch.js index 52b32fae37..cbc78d4366 100644 --- a/gateway/src/main/resources/static/js/launch.js +++ b/gateway/src/main/resources/static/js/launch.js @@ -80,7 +80,7 @@ $(window).load(function(){ global.mobileClient = true; } - $.getJSON("https://exchangeratesapi.io/api/latest?base=RUB", function( data ) { + $.getJSON("https://api.exchangeratesapi.io/latest?base=RUB&symbols=EUR,USD", function( data ) { global.eur = 1 / data.rates.EUR; global.usd = 1 / data.rates.USD; }); diff --git a/gateway/src/test/java/com/piggymetrics/gateway/GatewayApplicationTests.java b/gateway/src/test/java/com/piggymetrics/gateway/GatewayApplicationTests.java index d11042b297..13d17592dd 100644 --- a/gateway/src/test/java/com/piggymetrics/gateway/GatewayApplicationTests.java +++ b/gateway/src/test/java/com/piggymetrics/gateway/GatewayApplicationTests.java @@ -3,9 +3,9 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit4.SpringRunner; -@RunWith(SpringJUnit4ClassRunner.class) +@RunWith(SpringRunner.class) @SpringBootTest public class GatewayApplicationTests { diff --git a/monitoring/src/test/java/com/piggymetrics/monitoring/MonitoringApplicationTests.java b/monitoring/src/test/java/com/piggymetrics/monitoring/MonitoringApplicationTests.java index 1f8dd34f32..b71493e765 100644 --- a/monitoring/src/test/java/com/piggymetrics/monitoring/MonitoringApplicationTests.java +++ b/monitoring/src/test/java/com/piggymetrics/monitoring/MonitoringApplicationTests.java @@ -3,9 +3,9 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit4.SpringRunner; -@RunWith(SpringJUnit4ClassRunner.class) +@RunWith(SpringRunner.class) @SpringBootTest public class MonitoringApplicationTests { diff --git a/notification-service/src/test/java/com/piggymetrics/notification/NotificationServiceApplicationTests.java b/notification-service/src/test/java/com/piggymetrics/notification/NotificationServiceApplicationTests.java index 5f97b2f01d..ab77ed0fcc 100644 --- a/notification-service/src/test/java/com/piggymetrics/notification/NotificationServiceApplicationTests.java +++ b/notification-service/src/test/java/com/piggymetrics/notification/NotificationServiceApplicationTests.java @@ -3,9 +3,9 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit4.SpringRunner; -@RunWith(SpringJUnit4ClassRunner.class) +@RunWith(SpringRunner.class) @SpringBootTest public class NotificationServiceApplicationTests { diff --git a/notification-service/src/test/java/com/piggymetrics/notification/controller/RecipientControllerTest.java b/notification-service/src/test/java/com/piggymetrics/notification/controller/RecipientControllerTest.java index 36726c9666..c1433ca3ba 100644 --- a/notification-service/src/test/java/com/piggymetrics/notification/controller/RecipientControllerTest.java +++ b/notification-service/src/test/java/com/piggymetrics/notification/controller/RecipientControllerTest.java @@ -15,7 +15,7 @@ import org.mockito.Mock; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.http.MediaType; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit4.SpringRunner; import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.setup.MockMvcBuilders; @@ -26,7 +26,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; -@RunWith(SpringJUnit4ClassRunner.class) +@RunWith(SpringRunner.class) @SpringBootTest public class RecipientControllerTest { diff --git a/notification-service/src/test/java/com/piggymetrics/notification/repository/RecipientRepositoryTest.java b/notification-service/src/test/java/com/piggymetrics/notification/repository/RecipientRepositoryTest.java index 747c7b7505..0293fa6c56 100644 --- a/notification-service/src/test/java/com/piggymetrics/notification/repository/RecipientRepositoryTest.java +++ b/notification-service/src/test/java/com/piggymetrics/notification/repository/RecipientRepositoryTest.java @@ -10,7 +10,7 @@ import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.data.mongo.DataMongoTest; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit4.SpringRunner; import java.util.Date; import java.util.List; @@ -19,7 +19,7 @@ import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; -@RunWith(SpringJUnit4ClassRunner.class) +@RunWith(SpringRunner.class) @DataMongoTest public class RecipientRepositoryTest { diff --git a/statistics-service/src/main/java/com/piggymetrics/statistics/client/ExchangeRatesClient.java b/statistics-service/src/main/java/com/piggymetrics/statistics/client/ExchangeRatesClient.java index 8b18607d9c..9bd6563cd9 100644 --- a/statistics-service/src/main/java/com/piggymetrics/statistics/client/ExchangeRatesClient.java +++ b/statistics-service/src/main/java/com/piggymetrics/statistics/client/ExchangeRatesClient.java @@ -7,19 +7,10 @@ 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, - @RequestParam("symbols") Collection currencies); + @RequestMapping(method = RequestMethod.GET, value = "/latest") + ExchangeRatesContainer getRates(@RequestParam("base") Currency base); } diff --git a/statistics-service/src/main/java/com/piggymetrics/statistics/client/ExchangeRatesClientFallback.java b/statistics-service/src/main/java/com/piggymetrics/statistics/client/ExchangeRatesClientFallback.java index 13caa1d3d3..dbc61a1396 100644 --- a/statistics-service/src/main/java/com/piggymetrics/statistics/client/ExchangeRatesClientFallback.java +++ b/statistics-service/src/main/java/com/piggymetrics/statistics/client/ExchangeRatesClientFallback.java @@ -4,14 +4,13 @@ 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, Collection currencies) { + public ExchangeRatesContainer getRates(Currency base) { ExchangeRatesContainer container = new ExchangeRatesContainer(); container.setBase(Currency.getBase()); container.setRates(Collections.emptyMap()); diff --git a/statistics-service/src/test/java/com/piggymetrics/statistics/StatisticsServiceApplicationTests.java b/statistics-service/src/test/java/com/piggymetrics/statistics/StatisticsServiceApplicationTests.java index 1c5b2a6e06..d3c52e0df5 100644 --- a/statistics-service/src/test/java/com/piggymetrics/statistics/StatisticsServiceApplicationTests.java +++ b/statistics-service/src/test/java/com/piggymetrics/statistics/StatisticsServiceApplicationTests.java @@ -3,9 +3,9 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit4.SpringRunner; -@RunWith(SpringJUnit4ClassRunner.class) +@RunWith(SpringRunner.class) @SpringBootTest public class StatisticsServiceApplicationTests { diff --git a/statistics-service/src/test/java/com/piggymetrics/statistics/client/ExchangeRatesClientTest.java b/statistics-service/src/test/java/com/piggymetrics/statistics/client/ExchangeRatesClientTest.java index 729b6574cd..e149af6dee 100644 --- a/statistics-service/src/test/java/com/piggymetrics/statistics/client/ExchangeRatesClientTest.java +++ b/statistics-service/src/test/java/com/piggymetrics/statistics/client/ExchangeRatesClientTest.java @@ -6,15 +6,15 @@ import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit4.SpringRunner; import java.time.LocalDate; -import java.util.Collections; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; -@RunWith(SpringJUnit4ClassRunner.class) +@RunWith(SpringRunner.class) @SpringBootTest public class ExchangeRatesClientTest { @@ -30,8 +30,7 @@ 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())); + assertNull(container.getRates().get(Currency.USD.name())); assertNotNull(container.getRates().get(Currency.EUR.name())); assertNotNull(container.getRates().get(Currency.RUB.name())); } @@ -40,14 +39,12 @@ public void shouldRetrieveExchangeRates() { public void shouldRetrieveExchangeRatesForSpecifiedCurrency() { Currency requestedCurrency = Currency.EUR; - ExchangeRatesContainer container = client.getRates(Currency.getBase(), Collections.singleton(requestedCurrency)); + ExchangeRatesContainer container = client.getRates(Currency.getBase()); assertEquals(container.getDate(), LocalDate.now()); assertEquals(container.getBase(), Currency.getBase()); assertNotNull(container.getRates()); - assertEquals(1, container.getRates().size()); assertNotNull(container.getRates().get(requestedCurrency.name())); } - } \ No newline at end of file diff --git a/statistics-service/src/test/java/com/piggymetrics/statistics/controller/StatisticsControllerTest.java b/statistics-service/src/test/java/com/piggymetrics/statistics/controller/StatisticsControllerTest.java index e20b252474..6040a21735 100644 --- a/statistics-service/src/test/java/com/piggymetrics/statistics/controller/StatisticsControllerTest.java +++ b/statistics-service/src/test/java/com/piggymetrics/statistics/controller/StatisticsControllerTest.java @@ -18,7 +18,7 @@ import org.mockito.Mock; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.http.MediaType; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit4.SpringRunner; import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.setup.MockMvcBuilders; @@ -36,7 +36,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; -@RunWith(SpringJUnit4ClassRunner.class) +@RunWith(SpringRunner.class) @SpringBootTest public class StatisticsControllerTest { diff --git a/statistics-service/src/test/java/com/piggymetrics/statistics/repository/DataPointRepositoryTest.java b/statistics-service/src/test/java/com/piggymetrics/statistics/repository/DataPointRepositoryTest.java index 9c680ddab7..fcf525742e 100644 --- a/statistics-service/src/test/java/com/piggymetrics/statistics/repository/DataPointRepositoryTest.java +++ b/statistics-service/src/test/java/com/piggymetrics/statistics/repository/DataPointRepositoryTest.java @@ -10,7 +10,7 @@ import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.data.mongo.DataMongoTest; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit4.SpringRunner; import java.math.BigDecimal; import java.util.Date; @@ -18,7 +18,7 @@ import static org.junit.Assert.assertEquals; -@RunWith(SpringJUnit4ClassRunner.class) +@RunWith(SpringRunner.class) @DataMongoTest public class DataPointRepositoryTest { diff --git a/statistics-service/src/test/resources/application.yml b/statistics-service/src/test/resources/application.yml index 424a56e455..2f962f7af5 100644 --- a/statistics-service/src/test/resources/application.yml +++ b/statistics-service/src/test/resources/application.yml @@ -13,4 +13,4 @@ spring: port: 0 rates: - url: https://exchangeratesapi.io/api \ No newline at end of file + url: https://api.exchangeratesapi.io \ No newline at end of file