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

Yieldmo: Add gpid support #1452

Merged
merged 5 commits into from
Sep 24, 2021
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
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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");
rpanchyk marked this conversation as resolved.
Show resolved Hide resolved
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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,6 @@
public class YieldmoImpExt {

String placementId;

String pbadslot;
}
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -75,14 +77,70 @@ public void makeHttpRequestsShouldReturnExtPlacementFromYieldmoPlacement() {
final Result<List<HttpRequest<BidRequest>>> 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<List<HttpRequest<BidRequest>>> 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<List<HttpRequest<BidRequest>>> 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<List<HttpRequest<BidRequest>>> 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
Expand All @@ -94,10 +152,10 @@ public void makeHttpRequestShouldReturnCorrectHeaders() {
final Result<List<HttpRequest<BidRequest>>> 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()));
}
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -199,15 +257,15 @@ 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(
Function<BidRequest.BidRequestBuilder, BidRequest.BidRequestBuilder> bidRequestCustomizer,
Function<Imp.ImpBuilder, Imp.ImpBuilder> impCustomizer) {

return bidRequestCustomizer.apply(BidRequest.builder()
.imp(singletonList(givenImp(impCustomizer))))
.imp(singletonList(givenImp(impCustomizer))))
.build();
}

Expand All @@ -217,9 +275,9 @@ private static BidRequest givenBidRequest(Function<Imp.ImpBuilder, Imp.ImpBuilde

private static Imp givenImp(Function<Imp.ImpBuilder, Imp.ImpBuilder> 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();
}

Expand Down