Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix null parameter in conversion error message. #993

Merged
merged 2 commits into from
Nov 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions src/main/java/org/prebid/server/auction/ExchangeService.java
Original file line number Diff line number Diff line change
Expand Up @@ -903,9 +903,7 @@ price, currencyRates(bidRequest), adServerCurrency,
}
updatedBidderBids.add(bidderBid);
} catch (PreBidException e) {
errors.add(BidderError.generic(
String.format("Unable to covert bid currency %s to desired ad server currency %s. %s",
bidCurrency, adServerCurrency, e.getMessage())));
errors.add(BidderError.generic(e.getMessage()));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,9 @@ public BigDecimal convertCurrency(BigDecimal price, Map<String, Map<String, BigD
adServerCurrency, effectiveBidCurrency);

if (conversionRate == null) {
throw new PreBidException("no currency conversion available");
throw new PreBidException(
String.format("Unable to convert bid currency %s to desired ad server currency %s",
effectiveBidCurrency, adServerCurrency));
}

return price.divide(conversionRate, DEFAULT_PRICE_PRECISION, RoundingMode.HALF_EVEN);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,15 +231,15 @@ public void convertCurrencyShouldFailWhenRequestRatesIsNullAndNoExternalRatesPro
assertThatExceptionOfType(PreBidException.class)
.isThrownBy(() -> currencyConversionService.convertCurrency(BigDecimal.ONE, null, EUR, GBP,
false))
.withMessage("no currency conversion available");
.withMessage("Unable to convert bid currency GBP to desired ad server currency EUR");
}

@Test
public void convertCurrencyShouldThrowPrebidExceptionIfServerAndRequestRatesAreNull() {
// when and then
assertThatExceptionOfType(PreBidException.class)
.isThrownBy(() -> currencyService.convertCurrency(BigDecimal.ONE, null, USD, EUR, false))
.withMessage("no currency conversion available");
.withMessage("Unable to convert bid currency EUR to desired ad server currency USD");
}

@Test
Expand All @@ -257,7 +257,7 @@ public void convertCurrencyShouldThrowPrebidExceptionIfMultiplierWasNotFoundFrom
assertThatExceptionOfType(PreBidException.class)
.isThrownBy(() -> currencyService.convertCurrency(BigDecimal.ONE, requestConversionRates, EUR, AUD,
false))
.withMessage("no currency conversion available");
.withMessage("Unable to convert bid currency AUD to desired ad server currency EUR");
}

@Test
Expand All @@ -271,7 +271,7 @@ public void convertCurrencyShouldThrowExceptionWhenCurrencyServerResponseStatusN
// then
assertThatExceptionOfType(PreBidException.class)
.isThrownBy(() -> currencyService.convertCurrency(BigDecimal.ONE, null, UAH, AUD, false))
.withMessage("no currency conversion available");
.withMessage("Unable to convert bid currency AUD to desired ad server currency UAH");
}

@Test
Expand All @@ -285,7 +285,7 @@ public void convertCurrencyShouldThrowExceptionWhenCurrencyServerResponseContain
// then
assertThatExceptionOfType(PreBidException.class)
.isThrownBy(() -> currencyService.convertCurrency(BigDecimal.ONE, null, UAH, AUD, false))
.withMessage("no currency conversion available");
.withMessage("Unable to convert bid currency AUD to desired ad server currency UAH");
}

@SuppressWarnings("unchecked")
Expand Down
19 changes: 10 additions & 9 deletions src/test/java/org/prebid/server/auction/ExchangeServiceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -1879,7 +1879,7 @@ public void shouldDropBidIfPrebidExceptionWasThrownDuringCurrencyConversion() {
identity());

given(currencyService.convertCurrency(any(), any(), any(), any(), any()))
.willThrow(new PreBidException("no currency conversion available"));
.willThrow(new PreBidException("Unable to convert bid currency CUR to desired ad server currency USD"));

// when
exchangeService.holdAuction(givenRequestContext(bidRequest)).result();
Expand All @@ -1890,8 +1890,8 @@ public void shouldDropBidIfPrebidExceptionWasThrownDuringCurrencyConversion() {

assertThat(argumentCaptor.getValue()).hasSize(1);

final BidderError expectedError = BidderError.generic("Unable to covert bid currency CUR to desired ad"
+ " server currency USD. no currency conversion available");
final BidderError expectedError =
BidderError.generic("Unable to convert bid currency CUR to desired ad server currency USD");
final BidderSeatBid firstSeatBid = argumentCaptor.getValue().get(0).getSeatBid();
assertThat(firstSeatBid.getBids()).isEmpty();
assertThat(firstSeatBid.getErrors()).containsOnly(expectedError);
Expand Down Expand Up @@ -1948,7 +1948,8 @@ public void shouldUpdatePriceForOneBidAndDropAnotherIfPrebidExceptionHappensForS

final BigDecimal updatedPrice = BigDecimal.valueOf(10.0);
given(currencyService.convertCurrency(any(), any(), any(), any(), any())).willReturn(updatedPrice)
.willThrow(new PreBidException("no currency conversion available"));
.willThrow(
new PreBidException("Unable to convert bid currency CUR2 to desired ad server currency USD"));

// when
exchangeService.holdAuction(givenRequestContext(bidRequest)).result();
Expand All @@ -1963,8 +1964,8 @@ public void shouldUpdatePriceForOneBidAndDropAnotherIfPrebidExceptionHappensForS

final Bid expectedBid = Bid.builder().price(updatedPrice).build();
final BidderBid expectedBidderBid = BidderBid.of(expectedBid, banner, "CUR1");
final BidderError expectedError = BidderError.generic("Unable to covert bid currency CUR2 to desired ad"
+ " server currency USD. no currency conversion available");
final BidderError expectedError =
BidderError.generic("Unable to convert bid currency CUR2 to desired ad server currency USD");

final BidderSeatBid firstSeatBid = argumentCaptor.getValue().get(0).getSeatBid();
assertThat(firstSeatBid.getBids()).containsOnly(expectedBidderBid);
Expand All @@ -1989,7 +1990,7 @@ public void shouldRespondWithOneBidAndErrorWhenBidResponseContainsOneUnsupported
final BigDecimal updatedPrice = BigDecimal.valueOf(20);
given(currencyService.convertCurrency(any(), any(), any(), any(), any())).willReturn(updatedPrice);
given(currencyService.convertCurrency(any(), any(), eq("BAD"), eq("CUR"), any()))
.willThrow(new PreBidException("no currency conversion available"));
.willThrow(new PreBidException("Unable to convert bid currency CUR to desired ad server currency BAD"));

// when
exchangeService.holdAuction(givenRequestContext(bidRequest)).result();
Expand All @@ -2009,8 +2010,8 @@ public void shouldRespondWithOneBidAndErrorWhenBidResponseContainsOneUnsupported
.flatExtracting(BidderSeatBid::getBids)
.containsOnly(expectedBidderBid);

final BidderError expectedError = BidderError.generic("Unable to covert bid currency CUR to desired ad"
+ " server currency BAD. no currency conversion available");
final BidderError expectedError =
BidderError.generic("Unable to convert bid currency CUR to desired ad server currency BAD");
assertThat(argumentCaptor.getValue())
.extracting(BidderResponse::getSeatBid)
.flatExtracting(BidderSeatBid::getErrors)
Expand Down