diff --git a/src/main/java/org/prebid/server/bidder/adnuntius/AdnuntiusBidder.java b/src/main/java/org/prebid/server/bidder/adnuntius/AdnuntiusBidder.java index 3399e575653..e97db214f3c 100644 --- a/src/main/java/org/prebid/server/bidder/adnuntius/AdnuntiusBidder.java +++ b/src/main/java/org/prebid/server/bidder/adnuntius/AdnuntiusBidder.java @@ -137,7 +137,7 @@ private static String resolveNetwork(ExtImpAdnuntius extImpAdnuntius) { } private static AdnuntiusAdUnit makeAdUnit(Imp imp, ExtImpAdnuntius extImpAdnuntius) { - final String auId = StringUtils.defaultString(extImpAdnuntius.getAuId()); + final String auId = extImpAdnuntius.getAuId(); return AdnuntiusAdUnit.builder() .auId(auId) .targetId(targetId(auId, imp.getId())) @@ -334,14 +334,17 @@ private List extractBids(BidRequest bidRequest, AdnuntiusResponse adn final Map targetIdToAdsUnit = adnuntiusResponse.getAdsUnits().stream() .filter(AdnuntiusBidder::validateAdsUnit) - .collect(Collectors.toMap(AdnuntiusAdsUnit::getTargetId, Function.identity())); + .collect(Collectors.toMap( + AdnuntiusAdsUnit::getTargetId, + Function.identity(), + (first, second) -> second)); String currency = null; final List bids = new ArrayList<>(); for (Imp imp : bidRequest.getImp()) { final ExtImpAdnuntius extImpAdnuntius = parseImpExt(imp); - final String targetId = targetId(StringUtils.defaultString(extImpAdnuntius.getAuId()), imp.getId()); + final String targetId = targetId(extImpAdnuntius.getAuId(), imp.getId()); final AdnuntiusAdsUnit adsUnit = targetIdToAdsUnit.get(targetId); if (adsUnit == null) { diff --git a/src/main/java/org/prebid/server/bidder/adnuntius/model/request/AdnuntiusRequest.java b/src/main/java/org/prebid/server/bidder/adnuntius/model/request/AdnuntiusRequest.java index 483b17993e8..eafd24facbf 100644 --- a/src/main/java/org/prebid/server/bidder/adnuntius/model/request/AdnuntiusRequest.java +++ b/src/main/java/org/prebid/server/bidder/adnuntius/model/request/AdnuntiusRequest.java @@ -4,12 +4,12 @@ import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.databind.node.ObjectNode; import lombok.Builder; -import lombok.Getter; +import lombok.Value; import java.util.List; @Builder(toBuilder = true) -@Getter +@Value public class AdnuntiusRequest { @JsonProperty("adUnits") diff --git a/src/test/java/org/prebid/server/bidder/adnuntius/AdnuntiusBidderTest.java b/src/test/java/org/prebid/server/bidder/adnuntius/AdnuntiusBidderTest.java index 19a2f6c76b4..a2a0cbffb1c 100644 --- a/src/test/java/org/prebid/server/bidder/adnuntius/AdnuntiusBidderTest.java +++ b/src/test/java/org/prebid/server/bidder/adnuntius/AdnuntiusBidderTest.java @@ -47,11 +47,11 @@ import java.math.BigDecimal; import java.time.Clock; import java.time.ZoneId; -import java.util.Collections; import java.util.List; import java.util.Map; import java.util.function.UnaryOperator; +import static java.util.Arrays.asList; import static java.util.function.UnaryOperator.identity; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException; @@ -84,7 +84,7 @@ public void makeHttpRequestsShouldReturnErrorWhenSomeImpBannerIsAbsent() { // then assertThat(result.getValue()).isEmpty(); assertThat(result.getErrors()).extracting(BidderError::getMessage) - .containsExactly("Fail on Imp.Id=test: Adnuntius supports only Banner"); + .containsExactly("Fail on Imp.Id=impId: Adnuntius supports only Banner"); } @Test @@ -160,8 +160,13 @@ public void makeHttpRequestsShouldReturnRequestsWithDimensionsIfBannerHighAndWid public void makeHttpRequestsShouldReturnRequestsWithDimensionsIfBannerFormatHighAndWidthArePresent() { // given final BidRequest bidRequest = givenBidRequest( - givenImp(imp -> imp.banner(Banner.builder().format( - List.of(Format.builder().w(150).h(200).build())).build()))); + givenImp(imp -> imp.banner(Banner.builder() + .format(List.of( + Format.builder().w(150).h(200).build(), + Format.builder().w(100).h(300).build())) + .w(50) + .h(350) + .build()))); // when final Result>> result = target.makeHttpRequests(bidRequest); @@ -172,15 +177,13 @@ public void makeHttpRequestsShouldReturnRequestsWithDimensionsIfBannerFormatHigh .extracting(HttpRequest::getPayload) .flatExtracting(AdnuntiusRequest::getAdUnits) .extracting(AdnuntiusAdUnit::getDimensions) - .containsExactly(List.of(List.of(150, 200))); + .containsExactly(List.of(List.of(150, 200), List.of(100, 300))); } @Test - public void makeHttpRequestsShouldReturnRequestsWithEmptyDimensionsIfBannerFormatHighAndWidthAreAbsent() { + public void makeHttpRequestsShouldReturnRequestsWithoutDimensionsIfBannerFormatHighAndWidthAreAbsent() { // given - final BidRequest bidRequest = givenBidRequest( - givenImp(imp -> imp.banner(Banner.builder().format( - List.of(Format.builder().build())).build()))); + final BidRequest bidRequest = givenBidRequest(givenImp(identity())); // when final Result>> result = target.makeHttpRequests(bidRequest); @@ -191,7 +194,7 @@ public void makeHttpRequestsShouldReturnRequestsWithEmptyDimensionsIfBannerForma .extracting(HttpRequest::getPayload) .flatExtracting(AdnuntiusRequest::getAdUnits) .extracting(AdnuntiusAdUnit::getDimensions) - .containsExactly(Collections.emptyList()); + .containsOnlyNulls(); } @Test @@ -210,7 +213,8 @@ public void makeHttpRequestsShouldReturnRequestsWithAdUnitsSeparatedByImpExtNetw assertThat(result.getValue()).hasSize(2) .extracting(HttpRequest::getPayload) .extracting(AdnuntiusRequest::getAdUnits) - .allSatisfy(adUnits -> assertThat(adUnits).extracting(AdnuntiusAdUnit::getAuId) + .allSatisfy(adUnits -> assertThat(adUnits) + .extracting(AdnuntiusAdUnit::getAuId) .containsExactly("auId1", "auId2")); assertThat(result.getErrors()).isEmpty(); } @@ -238,9 +242,10 @@ public void makeHttpRequestsShouldReturnRequestsWithCorrectAdUnits() { @Test public void makeHttpRequestsShouldReturnRequestsWithMetaDataIfUserIdIsPresent() { // given - final BidRequest bidRequest = givenBidRequest(request -> request.user(User.builder().id("userId") - .ext(ExtUser.builder().build()).build()), - givenImp(ExtImpAdnuntius.builder().network("network").build(), identity()), givenImp(identity())); + final BidRequest bidRequest = givenBidRequest( + request -> request.user(User.builder().id("userId").build()), + givenImp(ExtImpAdnuntius.builder().network("network").build(), identity()), + givenImp(identity())); // when final Result>> result = target.makeHttpRequests(bidRequest); @@ -254,52 +259,19 @@ public void makeHttpRequestsShouldReturnRequestsWithMetaDataIfUserIdIsPresent() assertThat(result.getErrors()).isEmpty(); } - @Test - public void makeHttpRequestsShouldReturnThrowErrorWhenUserExtIsNull() { - // given - final BidRequest bidRequest = givenBidRequest(request -> request.user(User.builder().id("userId") - .ext(null).build()), - givenImp(ExtImpAdnuntius.builder().network("network").build(), identity()), givenImp(identity())); - - // when - final Result>> result = target.makeHttpRequests(bidRequest); - - // then - assertThat(result.getValue()).isEmpty(); - assertThat(result.getErrors()) - .extracting(BidderError::getMessage) - .allMatch(errorMessage -> errorMessage.startsWith("Failed to parse user.ext")); - } - - @Test - public void makeHttpRequestsShouldReturnThrowErrorWhenSiteExtDataIsNull() { - // given - final BidRequest bidRequest = givenBidRequest(request -> - request.user(User.builder().id("userId").ext(ExtUser.builder().build()).build()) - .site(Site.builder().ext(ExtSite.of(null, null)).build()), - givenImp(ExtImpAdnuntius.builder().network("network").build(), identity()), givenImp(identity())); - - // when - final Result>> result = target.makeHttpRequests(bidRequest); - - // then - assertThat(result.getValue()).isEmpty(); - assertThat(result.getErrors()) - .extracting(BidderError::getMessage) - .allMatch(errorMessage -> errorMessage.startsWith("Failed to parse site.ext.data")); - } - @Test public void makeHttpRequestsShouldPopulateMetaDataUsiFromUserIdWhenBothUidIdAndUserIdPresentInRequest() { // given - final BidRequest bidRequest = givenBidRequest(request -> - request.user(User.builder().id("userId").ext(ExtUser.builder() - .eids(List.of(Eid.of(null, - List.of(Uid.of("eidsId", null, null)), null))) - .build()) - .build()) - .site(Site.builder().ext(ExtSite.of(null, mapper.createObjectNode())).build()), - givenImp(ExtImpAdnuntius.builder().network("network").build(), identity()), givenImp(identity())); + final BidRequest bidRequest = givenBidRequest( + request -> request.user(User.builder() + .id("userId") + .ext(ExtUser.builder() + .eids(List.of(Eid.of(null, + List.of(Uid.of("eidsId", null, null)), null))) + .build()) + .build()), + givenImp(ExtImpAdnuntius.builder().network("network").build(), identity()), + givenImp(identity())); // when final Result>> result = target.makeHttpRequests(bidRequest); @@ -316,14 +288,16 @@ public void makeHttpRequestsShouldPopulateMetaDataUsiFromUserIdWhenBothUidIdAndU @Test public void makeHttpRequestsShouldPopulateMetaDataUsiWhenUserExtEidsUidIdPresent() { // given - final BidRequest bidRequest = givenBidRequest(request -> - request.user(User.builder().id(null).ext(ExtUser.builder() - .eids(List.of(Eid.of(null, - List.of(Uid.of("eidsId", null, null)), null))) - .build()) - .build()) - .site(Site.builder().ext(ExtSite.of(null, mapper.createObjectNode())).build()), - givenImp(ExtImpAdnuntius.builder().network("network").build(), identity()), givenImp(identity())); + final BidRequest bidRequest = givenBidRequest( + request -> request.user(User.builder() + .id(null) + .ext(ExtUser.builder() + .eids(List.of(Eid.of(null, + List.of(Uid.of("eidsId", null, null)), null))) + .build()) + .build()), + givenImp(ExtImpAdnuntius.builder().network("network").build(), identity()), + givenImp(identity())); // when final Result>> result = target.makeHttpRequests(bidRequest); @@ -340,10 +314,12 @@ public void makeHttpRequestsShouldPopulateMetaDataUsiWhenUserExtEidsUidIdPresent @Test public void makeHttpRequestsShouldPopulateHttpRequestKeyValueFieldFromSiteExtDataWhenDataIsPresentInRequest() { // given - final BidRequest bidRequest = givenBidRequest(request -> - request.site(Site.builder().ext(ExtSite.of(null, - mapper.createObjectNode().put("ANY", "ANY"))).build()), - givenImp(ExtImpAdnuntius.builder().network("network").build(), identity()), givenImp(identity())); + final BidRequest bidRequest = givenBidRequest( + request -> request.site(Site.builder() + .ext(ExtSite.of(null, mapper.createObjectNode().put("ANY", "ANY"))) + .build()), + givenImp(ExtImpAdnuntius.builder().network("network").build(), identity()), + givenImp(identity())); // when final Result>> result = target.makeHttpRequests(bidRequest); @@ -361,8 +337,8 @@ public void makeHttpRequestsShouldPopulateHttpRequestKeyValueFieldFromSiteExtDat @Test public void makeHttpRequestsShouldReturnRequestsWithHeadersIfDeviceIsPresent() { // given - final BidRequest bidRequest = givenBidRequest(request -> request - .device(Device.builder().ip("ip").ua("ua").build()), + final BidRequest bidRequest = givenBidRequest( + request -> request.device(Device.builder().ip("ip").ua("ua").build()), givenImp(identity())); // when @@ -384,9 +360,10 @@ public void makeHttpRequestsShouldReturnRequestsWithHeadersIfDeviceIsPresent() { @Test public void makeHttpRequestsShouldReturnRequestsWithContextIfSitePageIsPresent() { // given - final BidRequest bidRequest = givenBidRequest(request -> request.site(Site.builder().page("page") - .ext(ExtSite.of(null, mapper.createObjectNode())).build()), - givenImp(ExtImpAdnuntius.builder().network("network").build(), identity()), givenImp(identity())); + final BidRequest bidRequest = givenBidRequest( + request -> request.site(Site.builder().page("page").build()), + givenImp(ExtImpAdnuntius.builder().network("network").build(), identity()), + givenImp(identity())); // when final Result>> result = target.makeHttpRequests(bidRequest); @@ -401,10 +378,12 @@ public void makeHttpRequestsShouldReturnRequestsWithContextIfSitePageIsPresent() @Test public void makeHttpRequestsShouldReturnRequestsWithCorrectUriIfGdprAndConsentAreAbsent() { // given - final BidRequest bidRequest = givenBidRequest(request -> request + final BidRequest bidRequest = givenBidRequest( + request -> request .regs(Regs.builder().ext(ExtRegs.of(null, null, null, null)).build()) .user(User.builder().ext(ExtUser.builder().consent(null).build()).build()), - givenImp(identity()), givenImp(ExtImpAdnuntius.builder().network("network").build(), identity())); + givenImp(identity()), + givenImp(ExtImpAdnuntius.builder().network("network").build(), identity())); // when final Result>> result = target.makeHttpRequests(bidRequest); @@ -412,7 +391,8 @@ public void makeHttpRequestsShouldReturnRequestsWithCorrectUriIfGdprAndConsentAr // then final String expectedUrl = givenExpectedUrl(null, null); - assertThat(result.getValue()).extracting(HttpRequest::getUri) + assertThat(result.getValue()) + .extracting(HttpRequest::getUri) .containsExactly(expectedUrl, expectedUrl); assertThat(result.getErrors()).isEmpty(); } @@ -420,10 +400,12 @@ public void makeHttpRequestsShouldReturnRequestsWithCorrectUriIfGdprAndConsentAr @Test public void makeHttpRequestsShouldReturnRequestsWithCorrectUriIfGdprIsAbsent() { // given - final BidRequest bidRequest = givenBidRequest(request -> request + final BidRequest bidRequest = givenBidRequest( + request -> request .regs(Regs.builder().ext(ExtRegs.of(null, null, null, null)).build()) .user(User.builder().ext(ExtUser.builder().consent("consent").build()).build()), - givenImp(identity()), givenImp(ExtImpAdnuntius.builder().network("network").build(), identity())); + givenImp(identity()), + givenImp(ExtImpAdnuntius.builder().network("network").build(), identity())); // when final Result>> result = target.makeHttpRequests(bidRequest); @@ -431,7 +413,8 @@ public void makeHttpRequestsShouldReturnRequestsWithCorrectUriIfGdprIsAbsent() { // then final String expectedUrl = givenExpectedUrl(null, "consent"); - assertThat(result.getValue()).extracting(HttpRequest::getUri) + assertThat(result.getValue()) + .extracting(HttpRequest::getUri) .containsExactly(expectedUrl, expectedUrl); assertThat(result.getErrors()).isEmpty(); } @@ -439,10 +422,12 @@ public void makeHttpRequestsShouldReturnRequestsWithCorrectUriIfGdprIsAbsent() { @Test public void makeHttpRequestsShouldReturnRequestsWithCorrectUriIfConsentIsAbsent() { // given - final BidRequest bidRequest = givenBidRequest(request -> request + final BidRequest bidRequest = givenBidRequest( + request -> request .regs(Regs.builder().ext(ExtRegs.of(1, null, null, null)).build()) .user(User.builder().ext(ExtUser.builder().consent(null).build()).build()), - givenImp(identity()), givenImp(ExtImpAdnuntius.builder().network("network").build(), identity())); + givenImp(identity()), + givenImp(ExtImpAdnuntius.builder().network("network").build(), identity())); // when final Result>> result = target.makeHttpRequests(bidRequest); @@ -450,7 +435,8 @@ public void makeHttpRequestsShouldReturnRequestsWithCorrectUriIfConsentIsAbsent( // then final String expectedUrl = givenExpectedUrl(1, null); - assertThat(result.getValue()).extracting(HttpRequest::getUri) + assertThat(result.getValue()) + .extracting(HttpRequest::getUri) .containsExactly(expectedUrl, expectedUrl); assertThat(result.getErrors()).isEmpty(); } @@ -460,10 +446,12 @@ public void makeHttpRequestsShouldReturnRequestsWithCorrectUri() { // given final Integer gdpr = 1; final String consent = "con sent"; - final BidRequest bidRequest = givenBidRequest(request -> request + final BidRequest bidRequest = givenBidRequest( + request -> request .regs(Regs.builder().ext(ExtRegs.of(gdpr, null, null, null)).build()) .user(User.builder().ext(ExtUser.builder().consent(consent).build()).build()), - givenImp(identity()), givenImp(ExtImpAdnuntius.builder().network("network").build(), identity())); + givenImp(identity()), + givenImp(ExtImpAdnuntius.builder().network("network").build(), identity())); // when final Result>> result = target.makeHttpRequests(bidRequest); @@ -471,7 +459,8 @@ public void makeHttpRequestsShouldReturnRequestsWithCorrectUri() { // then final String expectedUrl = givenExpectedUrl(gdpr, consent); - assertThat(result.getValue()).extracting(HttpRequest::getUri) + assertThat(result.getValue()) + .extracting(HttpRequest::getUri) .containsExactly(expectedUrl, expectedUrl); assertThat(result.getErrors()).isEmpty(); } @@ -480,8 +469,8 @@ public void makeHttpRequestsShouldReturnRequestsWithCorrectUri() { public void makeHttpRequestsShouldReturnRequestsWithCorrectUriIfExtImpNoCookiesIsNull() { // given final BidRequest bidRequest = givenBidRequest(identity(), - givenImp(identity()), - givenImp(ExtImpAdnuntius.builder().network("network").build(), identity())); + givenImp(ExtImpAdnuntius.builder().network("network").build(), identity()), + givenImp(identity())); // when final Result>> result = target.makeHttpRequests(bidRequest); @@ -489,7 +478,8 @@ public void makeHttpRequestsShouldReturnRequestsWithCorrectUriIfExtImpNoCookiesI // then final String expectedUrl = givenExpectedUrl(null); - assertThat(result.getValue()).extracting(HttpRequest::getUri) + assertThat(result.getValue()) + .extracting(HttpRequest::getUri) .containsExactly(expectedUrl, expectedUrl); assertThat(result.getErrors()).isEmpty(); } @@ -498,9 +488,10 @@ public void makeHttpRequestsShouldReturnRequestsWithCorrectUriIfExtImpNoCookiesI public void makeHttpRequestsShouldReturnRequestsWithCorrectUriIfExtImpNoCookiesIsFalse() { // given final Boolean noCookies = false; - final BidRequest bidRequest = givenBidRequest(identity(), - givenImp(identity()), - givenImp(ExtImpAdnuntius.builder().network("network").noCookies(noCookies).build(), identity())); + final BidRequest bidRequest = givenBidRequest( + identity(), + givenImp(ExtImpAdnuntius.builder().network("network").noCookies(noCookies).build(), identity()), + givenImp(identity())); // when final Result>> result = target.makeHttpRequests(bidRequest); @@ -508,7 +499,8 @@ public void makeHttpRequestsShouldReturnRequestsWithCorrectUriIfExtImpNoCookiesI // then final String expectedUrl = givenExpectedUrl(noCookies); - assertThat(result.getValue()).extracting(HttpRequest::getUri) + assertThat(result.getValue()) + .extracting(HttpRequest::getUri) .containsExactly(expectedUrl, expectedUrl); assertThat(result.getErrors()).isEmpty(); } @@ -517,9 +509,10 @@ public void makeHttpRequestsShouldReturnRequestsWithCorrectUriIfExtImpNoCookiesI public void makeHttpRequestsShouldReturnRequestsWithCorrectUriIfExtImpNoCookiesIsTrue() { // given final Boolean noCookies = true; - final BidRequest bidRequest = givenBidRequest(identity(), - givenImp(identity()), - givenImp(ExtImpAdnuntius.builder().network("network").noCookies(noCookies).build(), identity())); + final BidRequest bidRequest = givenBidRequest( + identity(), + givenImp(ExtImpAdnuntius.builder().network("network").noCookies(noCookies).build(), identity()), + givenImp(ExtImpAdnuntius.builder().noCookies(!noCookies).build(), identity())); // when final Result>> result = target.makeHttpRequests(bidRequest); @@ -527,7 +520,8 @@ public void makeHttpRequestsShouldReturnRequestsWithCorrectUriIfExtImpNoCookiesI // then final String expectedUrl = givenExpectedUrl(noCookies); - assertThat(result.getValue()).extracting(HttpRequest::getUri) + assertThat(result.getValue()) + .extracting(HttpRequest::getUri) .containsExactly(expectedUrl, expectedUrl); assertThat(result.getErrors()).isEmpty(); } @@ -535,8 +529,8 @@ public void makeHttpRequestsShouldReturnRequestsWithCorrectUriIfExtImpNoCookiesI @Test public void makeHttpRequestsShouldReturnRequestsWithCorrectUriAndPopulateExtDeviceWithNoCookies() { // given - final BidRequest bidRequest = givenBidRequest(request -> request - .device(Device.builder().ext(givenExtDeviceNoCookies(null)).build()), + final BidRequest bidRequest = givenBidRequest( + request -> request.device(Device.builder().ext(givenExtDeviceNoCookies(null)).build()), givenImp(identity()), givenImp(ExtImpAdnuntius.builder().network("network").build(), identity())); @@ -546,7 +540,8 @@ public void makeHttpRequestsShouldReturnRequestsWithCorrectUriAndPopulateExtDevi // then final String expectedUrl = givenExpectedUrl(null); - assertThat(result.getValue()).extracting(HttpRequest::getUri) + assertThat(result.getValue()) + .extracting(HttpRequest::getUri) .containsExactly(expectedUrl, expectedUrl); assertThat(result.getErrors()).isEmpty(); } @@ -555,8 +550,8 @@ public void makeHttpRequestsShouldReturnRequestsWithCorrectUriAndPopulateExtDevi public void makeHttpRequestsShouldReturnRequestsWithCorrectUriIfExtDeviceImpNoCookiesIsFalse() { // given final Boolean noCookies = false; - final BidRequest bidRequest = givenBidRequest(request -> request - .device(Device.builder().ext(givenExtDeviceNoCookies(noCookies)).build()), + final BidRequest bidRequest = givenBidRequest( + request -> request.device(Device.builder().ext(givenExtDeviceNoCookies(noCookies)).build()), givenImp(identity()), givenImp(ExtImpAdnuntius.builder().network("network").build(), identity())); @@ -566,7 +561,8 @@ public void makeHttpRequestsShouldReturnRequestsWithCorrectUriIfExtDeviceImpNoCo // then final String expectedUrl = givenExpectedUrl(noCookies); - assertThat(result.getValue()).extracting(HttpRequest::getUri) + assertThat(result.getValue()) + .extracting(HttpRequest::getUri) .containsExactly(expectedUrl, expectedUrl); assertThat(result.getErrors()).isEmpty(); } @@ -575,8 +571,8 @@ public void makeHttpRequestsShouldReturnRequestsWithCorrectUriIfExtDeviceImpNoCo public void makeHttpRequestsShouldReturnRequestsWithCorrectUriIfExtDeviceImpNoCookiesIsTrue() { // given final Boolean noCookies = true; - final BidRequest bidRequest = givenBidRequest(request -> request - .device(Device.builder().ext(givenExtDeviceNoCookies(noCookies)).build()), + final BidRequest bidRequest = givenBidRequest( + request -> request.device(Device.builder().ext(givenExtDeviceNoCookies(noCookies)).build()), givenImp(identity()), givenImp(ExtImpAdnuntius.builder().network("network").build(), identity())); @@ -586,7 +582,8 @@ public void makeHttpRequestsShouldReturnRequestsWithCorrectUriIfExtDeviceImpNoCo // then final String expectedUrl = givenExpectedUrl(noCookies); - assertThat(result.getValue()).extracting(HttpRequest::getUri) + assertThat(result.getValue()) + .extracting(HttpRequest::getUri) .containsExactly(expectedUrl, expectedUrl); assertThat(result.getErrors()).isEmpty(); } @@ -650,7 +647,7 @@ public void makeBidsShouldReturnEmptyListIfResponseAdsUnitsIsEmpty() throws Json @Test public void makeBidsShouldSkipInvalidAdsUnits() throws JsonProcessingException { // given - final BidderCall httpCall = givenHttpCall(givenAdsUnitWithAds()); + final BidderCall httpCall = givenHttpCall(givenAdsUnitWithAds("auId")); final BidRequest bidRequest = givenBidRequest(givenImp(identity())); // when @@ -662,32 +659,39 @@ public void makeBidsShouldSkipInvalidAdsUnits() throws JsonProcessingException { } @Test - public void makeBidsShouldUseCurrencyOfFirstBidOfLastAdsUnit() throws JsonProcessingException { + public void makeBidsShouldUseCurrencyOfFirstBidOfLastRelatedImp() throws JsonProcessingException { // given final BidderCall httpCall = givenHttpCall( - givenAdsUnitWithAds(givenAd(ad -> ad.bid(AdnuntiusBid.of(null, "1.1"))), + givenAdsUnitWithAds( + "au1", + givenAd(ad -> ad.bid(AdnuntiusBid.of(null, "1.1"))), givenAd(ad -> ad.bid(AdnuntiusBid.of(null, "1.2")))), - givenAdsUnitWithAds(givenAd(ad -> ad.bid(AdnuntiusBid.of(null, "2.1"))), + givenAdsUnitWithAds( + "au2", + givenAd(ad -> ad.bid(AdnuntiusBid.of(null, "2.1"))), givenAd(ad -> ad.bid(AdnuntiusBid.of(null, "2.2"))))); - final BidRequest bidRequest = givenBidRequest(givenImp(identity()), givenImp(identity())); + final BidRequest bidRequest = givenBidRequest( + givenImp(ExtImpAdnuntius.builder().auId("au2").build(), identity()), + givenImp(ExtImpAdnuntius.builder().auId("au1").build(), identity())); // when final Result> result = target.makeBids(httpCall, bidRequest); // then - assertThat(result.getValue()).extracting(BidderBid::getBidCurrency) - .containsExactly("2.1", "2.1"); + assertThat(result.getValue()) + .extracting(BidderBid::getBidCurrency) + .containsExactly("1.1", "1.1"); assertThat(result.getErrors()).isEmpty(); } @Test public void makeBidsShouldPopulateGrossBidPriceWhenGrossBidSpecified() throws JsonProcessingException { // given - final BidderCall httpCall = givenHttpCall(givenAdsUnitWithAds( - givenAd(ad -> ad.grossBid(AdnuntiusGrossBid.of(BigDecimal.ONE))))); + final BidderCall httpCall = givenHttpCall( + givenAdsUnitWithAds("auId", givenAd(ad -> ad.grossBid(AdnuntiusGrossBid.of(BigDecimal.ONE))))); final BidRequest bidRequest = givenBidRequest( - givenImp(ExtImpAdnuntius.builder().bidType("gross").build(), identity())); + givenImp(ExtImpAdnuntius.builder().auId("auId").bidType("gross").build(), identity())); // when final Result> result = target.makeBids(httpCall, bidRequest); @@ -703,10 +707,10 @@ public void makeBidsShouldPopulateGrossBidPriceWhenGrossBidSpecified() throws Js @Test public void makeBidsShouldPopulateNetBidPriceWhenGrossBidSpecified() throws JsonProcessingException { // given - final BidderCall httpCall = givenHttpCall(givenAdsUnitWithAds( - givenAd(ad -> ad.netBid(AdnuntiusNetBid.of(BigDecimal.ONE))))); + final BidderCall httpCall = givenHttpCall( + givenAdsUnitWithAds("auId", givenAd(ad -> ad.netBid(AdnuntiusNetBid.of(BigDecimal.ONE))))); final BidRequest bidRequest = givenBidRequest( - givenImp(ExtImpAdnuntius.builder().bidType("net").build(), identity())); + givenImp(ExtImpAdnuntius.builder().auId("auId").bidType("net").build(), identity())); // when final Result> result = target.makeBids(httpCall, bidRequest); @@ -722,9 +726,10 @@ public void makeBidsShouldPopulateNetBidPriceWhenGrossBidSpecified() throws Json @Test public void makeBidsShouldNotReturnBidFromDealsWhenAdsIsAbsentAndDealsIsSpecified() throws JsonProcessingException { // given - final BidderCall httpCall = givenHttpCall(givenAdsUnitWithDeals(givenAd(identity()))); + final BidderCall httpCall = givenHttpCall(givenAdsUnitWithDeals("auId", givenAd(identity()))); - final BidRequest bidRequest = givenBidRequest(givenImp(identity())); + final BidRequest bidRequest = givenBidRequest( + givenImp(ExtImpAdnuntius.builder().auId("auId").build(), identity())); // when final Result> result = target.makeBids(httpCall, bidRequest); @@ -738,13 +743,15 @@ public void makeBidsShouldNotReturnBidFromDealsWhenAdsIsAbsentAndDealsIsSpecifie public void makeBidsShouldReturnTwoBidFromDealsAndAdsWhenAdsAndDealsIsSpecified() throws JsonProcessingException { // given final BidderCall httpCall = givenHttpCall(givenAdsUnitWithDealsAndAds( + "auId", List.of(givenAd(ad -> ad .bid(AdnuntiusBid.of(BigDecimal.ONE, "USD")) .adId("adId") .creativeId("creativeId") .lineItemId("lineItemId") .dealId("dealId") - .destinationUrls(Map.of("key1", "https://www.domain1.com/uri", + .destinationUrls(Map.of( + "key1", "https://www.domain1.com/uri", "key2", "http://www.domain2.dt/uri")))), List.of(givenAd(ad -> ad .bid(AdnuntiusBid.of(BigDecimal.ONE, "USD")) @@ -752,23 +759,26 @@ public void makeBidsShouldReturnTwoBidFromDealsAndAdsWhenAdsAndDealsIsSpecified( .creativeId("creativeId") .lineItemId("lineItemId") .dealId("dealId") - .destinationUrls(Map.of("key1", "https://www.domain1.com/uri", + .html("dealHtml") + .destinationUrls(Map.of( + "key1", "https://www.domain1.com/uri", "key2", "http://www.domain2.dt/uri")))))); - final BidRequest bidRequest = givenBidRequest(givenImp(identity())); + final BidRequest bidRequest = givenBidRequest(givenImp( + ExtImpAdnuntius.builder().auId("auId").build(), identity())); // when final Result> result = target.makeBids(httpCall, bidRequest); // then - assertThat(result.getValue()).hasSize(2).allSatisfy(bidderBid -> { + assertThat(result.getValue()).hasSize(2).zipSatisfy(asList("html", "dealHtml"), (bidderBid, html) -> { assertThat(bidderBid).extracting(BidderBid::getBid).satisfies(bid -> { assertThat(bid).extracting(Bid::getId).isEqualTo("adId"); - assertThat(bid).extracting(Bid::getImpid).isEqualTo("test"); + assertThat(bid).extracting(Bid::getImpid).isEqualTo("impId"); assertThat(bid).extracting(Bid::getW).isEqualTo(21); assertThat(bid).extracting(Bid::getH).isEqualTo(9); assertThat(bid).extracting(Bid::getAdid).isEqualTo("adId"); - assertThat(bid).extracting(Bid::getAdm).isEqualTo("html"); + assertThat(bid).extracting(Bid::getAdm).isEqualTo(html); assertThat(bid).extracting(Bid::getCid).isEqualTo("lineItemId"); assertThat(bid).extracting(Bid::getDealid).isEqualTo("dealId"); assertThat(bid).extracting(Bid::getCrid).isEqualTo("creativeId"); @@ -786,10 +796,12 @@ public void makeBidsShouldReturnTwoBidFromDealsAndAdsWhenAdsAndDealsIsSpecified( public void makeBidsShouldReturnErrorIfCreativeHeightOfSomeAdIsAbsent() throws JsonProcessingException { // given final BidderCall httpCall = givenHttpCall( - givenAdsUnitWithAds(givenAd(ad -> ad.bid(AdnuntiusBid.of(null, "CUR")))), - givenAdsUnitWithAds(givenAd(ad -> ad.creativeHeight(null)))); + givenAdsUnitWithAds("au1", givenAd(ad -> ad.bid(AdnuntiusBid.of(null, "CUR")))), + givenAdsUnitWithAds("au2", givenAd(ad -> ad.creativeHeight(null)))); - final BidRequest bidRequest = givenBidRequest(givenImp(identity()), givenImp(identity())); + final BidRequest bidRequest = givenBidRequest( + givenImp(ExtImpAdnuntius.builder().auId("au1").build(), identity()), + givenImp(ExtImpAdnuntius.builder().auId("au2").build(), identity())); // when final Result> result = target.makeBids(httpCall, bidRequest); @@ -804,10 +816,12 @@ public void makeBidsShouldReturnErrorIfCreativeHeightOfSomeAdIsAbsent() throws J public void makeBidsShouldReturnErrorIfCreativeWidthtOfSomeAdIsAbsent() throws JsonProcessingException { // given final BidderCall httpCall = givenHttpCall( - givenAdsUnitWithAds(givenAd(ad -> ad.bid(AdnuntiusBid.of(null, "CUR")))), - givenAdsUnitWithAds(givenAd(ad -> ad.creativeWidth(null)))); + givenAdsUnitWithAds("au1", givenAd(ad -> ad.bid(AdnuntiusBid.of(null, "CUR")))), + givenAdsUnitWithAds("au2", givenAd(ad -> ad.creativeWidth(null)))); - final BidRequest bidRequest = givenBidRequest(givenImp(identity()), givenImp(identity())); + final BidRequest bidRequest = givenBidRequest( + givenImp(ExtImpAdnuntius.builder().auId("au1").build(), identity()), + givenImp(ExtImpAdnuntius.builder().auId("au2").build(), identity())); // when final Result> result = target.makeBids(httpCall, bidRequest); @@ -821,16 +835,20 @@ public void makeBidsShouldReturnErrorIfCreativeWidthtOfSomeAdIsAbsent() throws J @Test public void makeBidsShouldReturnCorrectSeatBids() throws JsonProcessingException { // given - final BidderCall httpCall = givenHttpCall(givenAdsUnitWithAds(givenAd(ad -> ad - .bid(AdnuntiusBid.of(BigDecimal.ONE, "CUR")) - .adId("adId") - .creativeId("creativeId") - .lineItemId("lineItemId") - .dealId("dealId") - .destinationUrls(Map.of("key1", "https://www.domain1.com/uri", - "key2", "http://www.domain2.dt/uri"))))); + final BidderCall httpCall = givenHttpCall(givenAdsUnitWithAds( + "auId", + givenAd(ad -> ad + .bid(AdnuntiusBid.of(BigDecimal.ONE, "CUR")) + .adId("adId") + .creativeId("creativeId") + .lineItemId("lineItemId") + .dealId("dealId") + .destinationUrls(Map.of( + "key1", "https://www.domain1.com/uri", + "key2", "http://www.domain2.dt/uri"))))); - final BidRequest bidRequest = givenBidRequest(givenImp(imp -> imp.id("impId"))); + final BidRequest bidRequest = givenBidRequest( + givenImp(ExtImpAdnuntius.builder().auId("auId").build(), identity())); // when final Result> result = target.makeBids(httpCall, bidRequest); @@ -857,29 +875,8 @@ public void makeBidsShouldReturnCorrectSeatBids() throws JsonProcessingException assertThat(result.getErrors()).isEmpty(); } - @Test - public void makeBidsShouldReturnErrorWhenAdsUnitsCountGreaterThanImpsCount() throws JsonProcessingException { - // given - final BidderCall httpCall = givenHttpCall( - givenAdsUnitWithAds(givenAd(identity())), - givenAdsUnitWithAds(givenAd(identity()))); - - final BidRequest bidRequest = givenBidRequest(givenImp(identity())); - - // when - final Result> result = target.makeBids(httpCall, bidRequest); - - // then - assertThat(result.getValue()).isEmpty(); - assertThat(result.getErrors()).extracting(BidderError::getMessage) - .containsExactly("Impressions count is less then ads units count."); - } - private BidRequest givenBidRequest(UnaryOperator bidRequestCustomizer, Imp... imps) { - return bidRequestCustomizer.apply(BidRequest.builder() - .user(User.builder().ext(ExtUser.builder().build()).build()) - .site(Site.builder().ext(ExtSite.of(null, mapper.createObjectNode())).build())) - .imp(List.of(imps)).build(); + return bidRequestCustomizer.apply(BidRequest.builder()).imp(List.of(imps)).build(); } private BidRequest givenBidRequest(Imp... imps) { @@ -889,7 +886,7 @@ private BidRequest givenBidRequest(Imp... imps) { private Imp givenImp(ExtImpAdnuntius extImpAdnuntius, UnaryOperator impCustomizer) { final Banner banner = Banner.builder().build(); final ObjectNode ext = mapper.valueToTree(ExtPrebid.of(null, extImpAdnuntius)); - return impCustomizer.apply(Imp.builder().id("test").banner(banner).ext(ext)).build(); + return impCustomizer.apply(Imp.builder().id("impId").banner(banner).ext(ext)).build(); } private Imp givenImp(UnaryOperator impCustomizer) { @@ -907,22 +904,22 @@ private BidderCall givenHttpCall(AdnuntiusAdsUnit... adsUnits) return givenHttpCall(mapper.writeValueAsString(AdnuntiusResponse.of(List.of(adsUnits)))); } - private AdnuntiusAdsUnit givenAdsUnitWithAds(AdnuntiusAd... ads) { - return givenAdsUnit(List.of(ads), null); + private AdnuntiusAdsUnit givenAdsUnitWithAds(String auId, AdnuntiusAd... ads) { + return givenAdsUnit(auId, List.of(ads), null); } - private AdnuntiusAdsUnit givenAdsUnitWithDeals(AdnuntiusAd... deals) { - return givenAdsUnit(null, List.of(deals)); + private AdnuntiusAdsUnit givenAdsUnitWithDeals(String auId, AdnuntiusAd... deals) { + return givenAdsUnit(auId, null, List.of(deals)); } - private AdnuntiusAdsUnit givenAdsUnitWithDealsAndAds(List ads, List deals) { - return givenAdsUnit(ads, deals); + private AdnuntiusAdsUnit givenAdsUnitWithDealsAndAds(String auId, List ads, List deals) { + return givenAdsUnit(auId, ads, deals); } - private AdnuntiusAdsUnit givenAdsUnit(List ads, List deals) { + private AdnuntiusAdsUnit givenAdsUnit(String auId, List ads, List deals) { return AdnuntiusAdsUnit.builder() - .auId("auId") - .targetId("auId-impId") + .auId(auId) + .targetId(auId + "-impId") .html("html") .ads(ads) .deals(deals) @@ -951,8 +948,10 @@ private static String givenExpectedUrl(Boolean noCookies) { private static String buildExpectedUrl(Integer gdpr, String consent, Boolean noCookies) { final StringBuilder expectedUri = new StringBuilder("https://test.domain.dm/uri?format=json&tzo=-300"); - if (gdpr != null && consent != null) { + if (gdpr != null) { expectedUri.append("&gdpr=").append(HttpUtil.encodeUrl(gdpr.toString())); + } + if (consent != null) { expectedUri.append("&consentString=").append(HttpUtil.encodeUrl(consent)); } if (BooleanUtils.isTrue(noCookies)) {