diff --git a/src/main/java/org/prebid/server/bidder/yieldmo/YieldmoBidder.java b/src/main/java/org/prebid/server/bidder/yieldmo/YieldmoBidder.java index 09245179540..15ba2c4f812 100644 --- a/src/main/java/org/prebid/server/bidder/yieldmo/YieldmoBidder.java +++ b/src/main/java/org/prebid/server/bidder/yieldmo/YieldmoBidder.java @@ -1,7 +1,9 @@ package org.prebid.server.bidder.yieldmo; +import com.fasterxml.jackson.databind.JsonNode; import com.iab.openrtb.request.Imp; import com.iab.openrtb.response.Bid; +import org.apache.commons.lang3.StringUtils; import org.prebid.server.bidder.Bidder; import org.prebid.server.bidder.OpenrtbBidder; import org.prebid.server.bidder.yieldmo.proto.YieldmoImpExt; @@ -25,8 +27,13 @@ public YieldmoBidder(String endpointUrl, JacksonMapper mapper) { protected Imp modifyImp(Imp imp, ExtImpYieldmo impExt) throws PreBidException { final Imp.ImpBuilder modifiedImp = imp.toBuilder(); + final JsonNode pbadslotNode = imp.getExt().at("/data/pbadslot"); + final String pbadslot = !pbadslotNode.isMissingNode() + ? StringUtils.defaultIfEmpty(pbadslotNode.asText(), null) + : null; + try { - modifiedImp.ext(mapper.mapper().valueToTree(YieldmoImpExt.of(impExt.getPlacementId()))); + modifiedImp.ext(mapper.mapper().valueToTree(YieldmoImpExt.of(impExt.getPlacementId(), pbadslot))); } catch (IllegalArgumentException e) { throw new PreBidException(e.getMessage(), e); } diff --git a/src/main/java/org/prebid/server/bidder/yieldmo/proto/YieldmoImpExt.java b/src/main/java/org/prebid/server/bidder/yieldmo/proto/YieldmoImpExt.java index dd5656660b8..ee48883c5ea 100644 --- a/src/main/java/org/prebid/server/bidder/yieldmo/proto/YieldmoImpExt.java +++ b/src/main/java/org/prebid/server/bidder/yieldmo/proto/YieldmoImpExt.java @@ -8,4 +8,6 @@ public class YieldmoImpExt { String placementId; + + String pbadslot; } diff --git a/src/test/java/org/prebid/server/bidder/yieldmo/YieldmoBidderTest.java b/src/test/java/org/prebid/server/bidder/yieldmo/YieldmoBidderTest.java index 48695b219dc..c181ac8bcec 100644 --- a/src/test/java/org/prebid/server/bidder/yieldmo/YieldmoBidderTest.java +++ b/src/test/java/org/prebid/server/bidder/yieldmo/YieldmoBidderTest.java @@ -1,6 +1,8 @@ package org.prebid.server.bidder.yieldmo; import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.node.ObjectNode; +import com.fasterxml.jackson.databind.node.TextNode; import com.iab.openrtb.request.Banner; import com.iab.openrtb.request.BidRequest; import com.iab.openrtb.request.Imp; @@ -75,14 +77,70 @@ public void makeHttpRequestsShouldReturnExtPlacementFromYieldmoPlacement() { final Result>> result = yieldmoBidder.makeHttpRequests(bidRequest); // then - assertThat(result.getErrors()).hasSize(0); + assertThat(result.getErrors()).isEmpty(); + assertThat(result.getValue()) + .extracting(httpRequest -> mapper.readValue(httpRequest.getBody(), BidRequest.class)) + .flatExtracting(BidRequest::getImp) + .extracting(Imp::getExt) + .containsExactly(mapper.valueToTree(YieldmoImpExt.of(PLACEMENT_VALUE, null))); + } + + @Test + public void makeHttpRequestsShouldAddPbadslotToImpExtIfPresentAndNotEmpty() { + // given + final ObjectNode impExt = mapper.valueToTree(ExtPrebid.of(null, ExtImpYieldmo.of(null))); + impExt.set("data", mapper.createObjectNode().set("pbadslot", TextNode.valueOf("pbadslot"))); + + final BidRequest bidRequest = givenBidRequest(impBuilder -> impBuilder.ext(impExt)); + + // when + final Result>> result = yieldmoBidder.makeHttpRequests(bidRequest); - final YieldmoImpExt expectedExt = YieldmoImpExt.of(PLACEMENT_VALUE); - assertThat(result.getValue()).hasSize(1) + // then + assertThat(result.getErrors()).isEmpty(); + assertThat(result.getValue()) .extracting(httpRequest -> mapper.readValue(httpRequest.getBody(), BidRequest.class)) .flatExtracting(BidRequest::getImp) .extracting(Imp::getExt) - .containsOnly(mapper.valueToTree(expectedExt)); + .containsExactly(mapper.valueToTree(YieldmoImpExt.of(null, "pbadslot"))); + } + + @Test + public void makeHttpRequestsShouldNotAddPbadslotToImpExtIfEmpty() { + // given + final ObjectNode impExt = mapper.valueToTree(ExtPrebid.of(null, ExtImpYieldmo.of(null))); + impExt.set("data", mapper.createObjectNode().set("pbadslot", TextNode.valueOf(""))); + + final BidRequest bidRequest = givenBidRequest(impBuilder -> impBuilder.ext(impExt)); + + // when + final Result>> result = yieldmoBidder.makeHttpRequests(bidRequest); + + // then + assertThat(result.getErrors()).isEmpty(); + assertThat(result.getValue()) + .extracting(httpRequest -> mapper.readValue(httpRequest.getBody(), BidRequest.class)) + .flatExtracting(BidRequest::getImp) + .extracting(Imp::getExt) + .containsExactly(mapper.valueToTree(YieldmoImpExt.of(null, null))); + } + + @Test + public void makeHttpRequestsShouldNotAddPbadslotToImpExtIfNull() { + // given + final BidRequest bidRequest = givenBidRequest(impBuilder -> + impBuilder.ext(mapper.valueToTree(ExtPrebid.of(null, ExtImpYieldmo.of(null))))); + + // when + final Result>> result = yieldmoBidder.makeHttpRequests(bidRequest); + + // then + assertThat(result.getErrors()).isEmpty(); + assertThat(result.getValue()) + .extracting(httpRequest -> mapper.readValue(httpRequest.getBody(), BidRequest.class)) + .flatExtracting(BidRequest::getImp) + .extracting(Imp::getExt) + .containsExactly(mapper.valueToTree(YieldmoImpExt.of(null, null))); } @Test @@ -94,10 +152,10 @@ public void makeHttpRequestShouldReturnCorrectHeaders() { final Result>> result = yieldmoBidder.makeHttpRequests(bidRequest); // then - assertThat(result.getErrors()).hasSize(0); + assertThat(result.getErrors()).isEmpty(); assertThat(result.getValue()).flatExtracting(httpRequest -> httpRequest.getHeaders().entries()) .extracting(Map.Entry::getKey, Map.Entry::getValue) - .containsOnly( + .containsExactly( tuple(HttpUtil.CONTENT_TYPE_HEADER.toString(), HttpUtil.APPLICATION_JSON_CONTENT_TYPE), tuple(HttpUtil.ACCEPT_HEADER.toString(), HttpHeaderValues.APPLICATION_JSON.toString())); } @@ -161,7 +219,7 @@ public void makeBidsShouldReturnVideoBidByDefault() throws JsonProcessingExcepti // then assertThat(result.getErrors()).isEmpty(); assertThat(result.getValue()) - .containsOnly(BidderBid.of(Bid.builder().impid("123").build(), video, "USD")); + .containsExactly(BidderBid.of(Bid.builder().impid("123").build(), video, "USD")); } @Test @@ -180,7 +238,7 @@ public void makeBidsShouldReturnBannerBidIfBannerIsPresentInRequestImp() throws // then assertThat(result.getErrors()).isEmpty(); assertThat(result.getValue()) - .containsOnly(BidderBid.of(Bid.builder().impid("123").build(), banner, "USD")); + .containsExactly(BidderBid.of(Bid.builder().impid("123").build(), banner, "USD")); } @Test @@ -199,7 +257,7 @@ public void makeBidsShouldReturnVideoBidIfVideoIsPresentInRequestImp() throws Js // then assertThat(result.getErrors()).isEmpty(); assertThat(result.getValue()) - .containsOnly(BidderBid.of(Bid.builder().impid("123").build(), video, "USD")); + .containsExactly(BidderBid.of(Bid.builder().impid("123").build(), video, "USD")); } private static BidRequest givenBidRequest( @@ -207,7 +265,7 @@ private static BidRequest givenBidRequest( Function impCustomizer) { return bidRequestCustomizer.apply(BidRequest.builder() - .imp(singletonList(givenImp(impCustomizer)))) + .imp(singletonList(givenImp(impCustomizer)))) .build(); } @@ -217,9 +275,9 @@ private static BidRequest givenBidRequest(Function impCustomizer) { return impCustomizer.apply(Imp.builder() - .id("123") - .banner(Banner.builder().build()) - .ext(mapper.valueToTree(ExtPrebid.of(null, ExtImpYieldmo.of(PLACEMENT_VALUE))))) + .id("123") + .banner(Banner.builder().build()) + .ext(mapper.valueToTree(ExtPrebid.of(null, ExtImpYieldmo.of(PLACEMENT_VALUE))))) .build(); }