From eba48dc7e1f88c76ef78319c3b3918387b676be7 Mon Sep 17 00:00:00 2001 From: Serhii Nahornyi Date: Tue, 3 Nov 2020 15:57:25 +0200 Subject: [PATCH 1/2] Fix null parameter in conversion error message. --- .../server/auction/ExchangeService.java | 4 +--- .../currency/CurrencyConversionService.java | 3 ++- .../CurrencyConversionServiceTest.java | 10 ++++----- .../server/auction/ExchangeServiceTest.java | 21 +++++++++++-------- 4 files changed, 20 insertions(+), 18 deletions(-) diff --git a/src/main/java/org/prebid/server/auction/ExchangeService.java b/src/main/java/org/prebid/server/auction/ExchangeService.java index 4b8a66b6058..bb6dfb17646 100644 --- a/src/main/java/org/prebid/server/auction/ExchangeService.java +++ b/src/main/java/org/prebid/server/auction/ExchangeService.java @@ -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())); } } diff --git a/src/main/java/org/prebid/server/currency/CurrencyConversionService.java b/src/main/java/org/prebid/server/currency/CurrencyConversionService.java index 34912e03d19..a2d66ad8c4a 100644 --- a/src/main/java/org/prebid/server/currency/CurrencyConversionService.java +++ b/src/main/java/org/prebid/server/currency/CurrencyConversionService.java @@ -172,7 +172,8 @@ public BigDecimal convertCurrency(BigDecimal price, Map currencyConversionService.convertCurrency(BigDecimal.ONE, null, EUR, GBP, false)) - .withMessage("no currency conversion available"); + .withMessage("Unable to covert bid currency GBP to desired ad server currency EUR"); } @Test @@ -239,7 +239,7 @@ public void convertCurrencyShouldThrowPrebidExceptionIfServerAndRequestRatesAreN // when and then assertThatExceptionOfType(PreBidException.class) .isThrownBy(() -> currencyService.convertCurrency(BigDecimal.ONE, null, USD, EUR, false)) - .withMessage("no currency conversion available"); + .withMessage("Unable to covert bid currency EUR to desired ad server currency USD"); } @Test @@ -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 covert bid currency AUD to desired ad server currency EUR"); } @Test @@ -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 covert bid currency AUD to desired ad server currency UAH"); } @Test @@ -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 covert bid currency AUD to desired ad server currency UAH"); } @SuppressWarnings("unchecked") diff --git a/src/test/java/org/prebid/server/auction/ExchangeServiceTest.java b/src/test/java/org/prebid/server/auction/ExchangeServiceTest.java index 10898988e58..af2baa8f1c5 100644 --- a/src/test/java/org/prebid/server/auction/ExchangeServiceTest.java +++ b/src/test/java/org/prebid/server/auction/ExchangeServiceTest.java @@ -129,6 +129,12 @@ public class ExchangeServiceTest extends VertxTest { + private static final String CUR2_CONVERSION_ERROR = + "Unable to covert bid currency CUR2 to desired ad server currency USD"; + private static final String CURRENCY_CONVERSION_ERROR = + "Unable to covert bid currency CUR to desired ad server currency USD"; + private static final String CURRENCY_CONVERSION_TO_BAD_ERROR = + "Unable to covert bid currency CUR to desired ad server currency BAD"; @Rule public final MockitoRule mockitoRule = MockitoJUnit.rule(); @@ -1879,7 +1885,7 @@ public void shouldDropBidIfPrebidExceptionWasThrownDuringCurrencyConversion() { identity()); given(currencyService.convertCurrency(any(), any(), any(), any(), any())) - .willThrow(new PreBidException("no currency conversion available")); + .willThrow(new PreBidException(CURRENCY_CONVERSION_ERROR)); // when exchangeService.holdAuction(givenRequestContext(bidRequest)).result(); @@ -1890,8 +1896,7 @@ 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(CURRENCY_CONVERSION_ERROR); final BidderSeatBid firstSeatBid = argumentCaptor.getValue().get(0).getSeatBid(); assertThat(firstSeatBid.getBids()).isEmpty(); assertThat(firstSeatBid.getErrors()).containsOnly(expectedError); @@ -1948,7 +1953,7 @@ 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(CUR2_CONVERSION_ERROR)); // when exchangeService.holdAuction(givenRequestContext(bidRequest)).result(); @@ -1963,8 +1968,7 @@ 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(CUR2_CONVERSION_ERROR); final BidderSeatBid firstSeatBid = argumentCaptor.getValue().get(0).getSeatBid(); assertThat(firstSeatBid.getBids()).containsOnly(expectedBidderBid); @@ -1989,7 +1993,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(CURRENCY_CONVERSION_TO_BAD_ERROR)); // when exchangeService.holdAuction(givenRequestContext(bidRequest)).result(); @@ -2009,8 +2013,7 @@ 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(CURRENCY_CONVERSION_TO_BAD_ERROR); assertThat(argumentCaptor.getValue()) .extracting(BidderResponse::getSeatBid) .flatExtracting(BidderSeatBid::getErrors) From 2beed48672e5f91fcd6be6354f35e5accff9e97b Mon Sep 17 00:00:00 2001 From: Serhii Nahornyi Date: Tue, 3 Nov 2020 16:09:03 +0200 Subject: [PATCH 2/2] Fixes after review. --- .../currency/CurrencyConversionService.java | 5 +++-- .../CurrencyConversionServiceTest.java | 10 ++++----- .../server/auction/ExchangeServiceTest.java | 22 +++++++++---------- 3 files changed, 18 insertions(+), 19 deletions(-) diff --git a/src/main/java/org/prebid/server/currency/CurrencyConversionService.java b/src/main/java/org/prebid/server/currency/CurrencyConversionService.java index a2d66ad8c4a..8645c86d458 100644 --- a/src/main/java/org/prebid/server/currency/CurrencyConversionService.java +++ b/src/main/java/org/prebid/server/currency/CurrencyConversionService.java @@ -172,8 +172,9 @@ public BigDecimal convertCurrency(BigDecimal price, Map currencyConversionService.convertCurrency(BigDecimal.ONE, null, EUR, GBP, false)) - .withMessage("Unable to covert bid currency GBP to desired ad server currency EUR"); + .withMessage("Unable to convert bid currency GBP to desired ad server currency EUR"); } @Test @@ -239,7 +239,7 @@ public void convertCurrencyShouldThrowPrebidExceptionIfServerAndRequestRatesAreN // when and then assertThatExceptionOfType(PreBidException.class) .isThrownBy(() -> currencyService.convertCurrency(BigDecimal.ONE, null, USD, EUR, false)) - .withMessage("Unable to covert bid currency EUR to desired ad server currency USD"); + .withMessage("Unable to convert bid currency EUR to desired ad server currency USD"); } @Test @@ -257,7 +257,7 @@ public void convertCurrencyShouldThrowPrebidExceptionIfMultiplierWasNotFoundFrom assertThatExceptionOfType(PreBidException.class) .isThrownBy(() -> currencyService.convertCurrency(BigDecimal.ONE, requestConversionRates, EUR, AUD, false)) - .withMessage("Unable to covert bid currency AUD to desired ad server currency EUR"); + .withMessage("Unable to convert bid currency AUD to desired ad server currency EUR"); } @Test @@ -271,7 +271,7 @@ public void convertCurrencyShouldThrowExceptionWhenCurrencyServerResponseStatusN // then assertThatExceptionOfType(PreBidException.class) .isThrownBy(() -> currencyService.convertCurrency(BigDecimal.ONE, null, UAH, AUD, false)) - .withMessage("Unable to covert bid currency AUD to desired ad server currency UAH"); + .withMessage("Unable to convert bid currency AUD to desired ad server currency UAH"); } @Test @@ -285,7 +285,7 @@ public void convertCurrencyShouldThrowExceptionWhenCurrencyServerResponseContain // then assertThatExceptionOfType(PreBidException.class) .isThrownBy(() -> currencyService.convertCurrency(BigDecimal.ONE, null, UAH, AUD, false)) - .withMessage("Unable to covert bid currency AUD to desired ad server currency UAH"); + .withMessage("Unable to convert bid currency AUD to desired ad server currency UAH"); } @SuppressWarnings("unchecked") diff --git a/src/test/java/org/prebid/server/auction/ExchangeServiceTest.java b/src/test/java/org/prebid/server/auction/ExchangeServiceTest.java index af2baa8f1c5..47aa5684387 100644 --- a/src/test/java/org/prebid/server/auction/ExchangeServiceTest.java +++ b/src/test/java/org/prebid/server/auction/ExchangeServiceTest.java @@ -129,12 +129,6 @@ public class ExchangeServiceTest extends VertxTest { - private static final String CUR2_CONVERSION_ERROR = - "Unable to covert bid currency CUR2 to desired ad server currency USD"; - private static final String CURRENCY_CONVERSION_ERROR = - "Unable to covert bid currency CUR to desired ad server currency USD"; - private static final String CURRENCY_CONVERSION_TO_BAD_ERROR = - "Unable to covert bid currency CUR to desired ad server currency BAD"; @Rule public final MockitoRule mockitoRule = MockitoJUnit.rule(); @@ -1885,7 +1879,7 @@ public void shouldDropBidIfPrebidExceptionWasThrownDuringCurrencyConversion() { identity()); given(currencyService.convertCurrency(any(), any(), any(), any(), any())) - .willThrow(new PreBidException(CURRENCY_CONVERSION_ERROR)); + .willThrow(new PreBidException("Unable to convert bid currency CUR to desired ad server currency USD")); // when exchangeService.holdAuction(givenRequestContext(bidRequest)).result(); @@ -1896,7 +1890,8 @@ public void shouldDropBidIfPrebidExceptionWasThrownDuringCurrencyConversion() { assertThat(argumentCaptor.getValue()).hasSize(1); - final BidderError expectedError = BidderError.generic(CURRENCY_CONVERSION_ERROR); + 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); @@ -1953,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(CUR2_CONVERSION_ERROR)); + .willThrow( + new PreBidException("Unable to convert bid currency CUR2 to desired ad server currency USD")); // when exchangeService.holdAuction(givenRequestContext(bidRequest)).result(); @@ -1968,7 +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(CUR2_CONVERSION_ERROR); + 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); @@ -1993,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(CURRENCY_CONVERSION_TO_BAD_ERROR)); + .willThrow(new PreBidException("Unable to convert bid currency CUR to desired ad server currency BAD")); // when exchangeService.holdAuction(givenRequestContext(bidRequest)).result(); @@ -2013,7 +2010,8 @@ public void shouldRespondWithOneBidAndErrorWhenBidResponseContainsOneUnsupported .flatExtracting(BidderSeatBid::getBids) .containsOnly(expectedBidderBid); - final BidderError expectedError = BidderError.generic(CURRENCY_CONVERSION_TO_BAD_ERROR); + 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)