test: NbpServiceTest invocation fixed
This commit is contained in:
parent
4a2338d699
commit
157a1ebe68
2 changed files with 17 additions and 8 deletions
|
@ -0,0 +1,9 @@
|
||||||
|
package eu.ztsh.wymiana.exception;
|
||||||
|
|
||||||
|
public class NoDataException extends RuntimeException {
|
||||||
|
|
||||||
|
public NoDataException(String code, String date) {
|
||||||
|
super("No data for code %s and date %s".formatted(code, date));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -4,6 +4,7 @@ import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import eu.ztsh.wymiana.EntityCreator;
|
import eu.ztsh.wymiana.EntityCreator;
|
||||||
import eu.ztsh.wymiana.WireMockExtension;
|
import eu.ztsh.wymiana.WireMockExtension;
|
||||||
|
import eu.ztsh.wymiana.exception.NoDataException;
|
||||||
import org.junit.jupiter.api.BeforeAll;
|
import org.junit.jupiter.api.BeforeAll;
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.jupiter.api.DisplayName;
|
import org.junit.jupiter.api.DisplayName;
|
||||||
|
@ -23,6 +24,7 @@ import java.time.format.DateTimeFormatter;
|
||||||
import java.time.temporal.TemporalAdjusters;
|
import java.time.temporal.TemporalAdjusters;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
||||||
|
|
||||||
@ExtendWith(WireMockExtension.class)
|
@ExtendWith(WireMockExtension.class)
|
||||||
class NbpServiceTest {
|
class NbpServiceTest {
|
||||||
|
@ -76,28 +78,26 @@ class NbpServiceTest {
|
||||||
var date = dtf.format(updateClock(DayOfWeek.FRIDAY));
|
var date = dtf.format(updateClock(DayOfWeek.FRIDAY));
|
||||||
var url = "/api/exchangerates/rates/c/usd/%s/".formatted(date);
|
var url = "/api/exchangerates/rates/c/usd/%s/".formatted(date);
|
||||||
WireMockExtension.response(url, 200, new ObjectMapper().writeValueAsString(EntityCreator.rates(date)));
|
WireMockExtension.response(url, 200, new ObjectMapper().writeValueAsString(EntityCreator.rates(date)));
|
||||||
nbpService.fetchData(EntityCreator.Constants.USD_SYMBOL, date);
|
assertThat(nbpService.getSellRate(EntityCreator.Constants.USD_SYMBOL)).isEqualTo(EntityCreator.Constants.SELL_RATE);
|
||||||
WireMockExtension.verifyGet(1, url);
|
WireMockExtension.verifyGet(1, url);
|
||||||
}
|
}
|
||||||
|
|
||||||
@DisplayName("Fetch rates from cache")
|
@DisplayName("Fetch rates from cache")
|
||||||
@Test
|
@Test
|
||||||
void getWithCacheTest() throws JsonProcessingException {
|
void getWithCacheTest() {
|
||||||
var date = dtf.format(updateClock(DayOfWeek.FRIDAY));
|
var date = dtf.format(updateClock(DayOfWeek.FRIDAY));
|
||||||
var url = "/api/exchangerates/rates/c/usd/%s/".formatted(date);
|
var url = "/api/exchangerates/rates/c/usd/%s/".formatted(date);
|
||||||
WireMockExtension.response(url, 200, new ObjectMapper().writeValueAsString(EntityCreator.rates(date)));
|
assertThat(nbpService.getSellRate(EntityCreator.Constants.USD_SYMBOL)).isEqualTo(EntityCreator.Constants.SELL_RATE);
|
||||||
nbpService.fetchData(EntityCreator.Constants.USD_SYMBOL, date);
|
WireMockExtension.verifyGet(0, url);
|
||||||
nbpService.fetchData(EntityCreator.Constants.USD_SYMBOL, date);
|
|
||||||
WireMockExtension.verifyGet(1, url);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@DisplayName("Support 404")
|
@DisplayName("Support 404: invalid currency or no data")
|
||||||
@Test
|
@Test
|
||||||
void getInvalidCurrencyTest() {
|
void getInvalidCurrencyTest() {
|
||||||
var date = dtf.format(updateClock(DayOfWeek.FRIDAY));
|
var date = dtf.format(updateClock(DayOfWeek.FRIDAY));
|
||||||
var url = "/api/exchangerates/rates/c/usb/%s/".formatted(date);
|
var url = "/api/exchangerates/rates/c/usb/%s/".formatted(date);
|
||||||
WireMockExtension.response(url, 404, "404 NotFound - Not Found - Brak danych");
|
WireMockExtension.response(url, 404, "404 NotFound - Not Found - Brak danych");
|
||||||
nbpService.fetchData("usb", date);
|
assertThatThrownBy(() -> nbpService.getSellRate("usb")).isInstanceOf(NoDataException.class);
|
||||||
WireMockExtension.verifyGet(1, url);
|
WireMockExtension.verifyGet(1, url);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue