Skip to content

Commit

Permalink
StroeerCore: support DSA
Browse files Browse the repository at this point in the history
  • Loading branch information
philipwatson committed Feb 13, 2024
1 parent ed1baac commit 14a490e
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.prebid.server.bidder.stroeercore;

import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.iab.openrtb.request.BidRequest;
import com.iab.openrtb.request.Imp;
import com.iab.openrtb.response.Bid;
Expand Down Expand Up @@ -144,7 +145,7 @@ public Result<List<BidderBid>> makeBids(BidderCall<BidRequest> httpCall, BidRequ
}
}

private static List<BidderBid> extractBids(BidRequest bidRequest, StroeerCoreBidResponse bidResponse) {
private List<BidderBid> extractBids(BidRequest bidRequest, StroeerCoreBidResponse bidResponse) {
if (bidResponse == null || CollectionUtils.isEmpty(bidResponse.getBids())) {
return Collections.emptyList();
}
Expand All @@ -155,7 +156,11 @@ private static List<BidderBid> extractBids(BidRequest bidRequest, StroeerCoreBid
.toList();
}

private static BidderBid toBidderBid(BidRequest bidRequest, StroeerCoreBid stroeercoreBid) {
private BidderBid toBidderBid(BidRequest bidRequest, StroeerCoreBid stroeercoreBid) {
final ObjectNode bidExt = stroeercoreBid.getDsa() != null
? mapper.mapper().createObjectNode().set("dsa", stroeercoreBid.getDsa())
: null;

return BidderBid.of(
Bid.builder()
.id(stroeercoreBid.getId())
Expand All @@ -165,6 +170,7 @@ private static BidderBid toBidderBid(BidRequest bidRequest, StroeerCoreBid stroe
.price(stroeercoreBid.getCpm())
.adm(stroeercoreBid.getAdMarkup())
.crid(stroeercoreBid.getCreativeId())
.ext(bidExt)
.build(),
getBidType(stroeercoreBid.getImpId(), bidRequest.getImp()),
BIDDER_CURRENCY);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.prebid.server.bidder.stroeercore.model;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.node.ObjectNode;
import lombok.Builder;
import lombok.Value;

Expand All @@ -26,5 +27,7 @@ public class StroeerCoreBid {

@JsonProperty("crid")
String creativeId;

ObjectNode dsa;
}

Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.iab.openrtb.request.BidRequest;
import com.iab.openrtb.request.Imp;
import com.iab.openrtb.request.Imp.ImpBuilder;
import com.iab.openrtb.request.Regs;
import com.iab.openrtb.request.Video;
import com.iab.openrtb.response.Bid;
import io.vertx.core.http.HttpMethod;
Expand All @@ -28,11 +29,15 @@
import org.prebid.server.currency.CurrencyConversionService;
import org.prebid.server.exception.PreBidException;
import org.prebid.server.proto.openrtb.ext.ExtPrebid;
import org.prebid.server.proto.openrtb.ext.request.ExtRegs;
import org.prebid.server.proto.openrtb.ext.request.ExtRegsDsa;
import org.prebid.server.proto.openrtb.ext.request.ExtRegsDsaTransparency;
import org.prebid.server.proto.openrtb.ext.request.stroeercore.ExtImpStroeerCore;
import org.prebid.server.proto.openrtb.ext.response.BidType;
import org.prebid.server.util.HttpUtil;

import java.math.BigDecimal;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
Expand Down Expand Up @@ -125,6 +130,31 @@ public void makeHttpRequestsShouldReturnImpsWithExpectedTagIds() {
.containsExactly("827194", "abc");
}

@Test
public void makeHttpRequestsShouldReturnDSA() {
// given
final List<ExtRegsDsaTransparency> transparencies = Arrays.asList(
ExtRegsDsaTransparency.of("platform-example.com", List.of(1, 2)),
ExtRegsDsaTransparency.of("ssp-example.com", List.of(1))
);

final ExtRegsDsa dsa = ExtRegsDsa.of(3, 1, 2, transparencies);

final BidRequest bidRequest = createBidRequest(createBannerImp("1")).toBuilder()
.regs(Regs.builder().ext(ExtRegs.of(null, null, null, dsa)).build())
.build();

// when
final Result<List<HttpRequest<BidRequest>>> result = target.makeHttpRequests(bidRequest);

// then
assertThat(result.getErrors()).isEmpty();
assertThat(result.getValue())
.extracting(HttpRequest::getPayload)
.extracting(payload -> payload.getRegs().getExt().getDsa())
.allSatisfy(actualDsa -> assertThat(actualDsa).isSameAs(dsa));
}

@Test
public void makeHttpRequestsShouldReturnErrorIfImpExtCouldNotBeParsed() {
// given
Expand Down Expand Up @@ -251,12 +281,14 @@ public void makeHttpRequestsShouldIgnoreBidIfCurrencyServiceThrowsException() {
}

@Test
public void makeBidsShouldReturnExpectedBidderBidsWithProperBidType() throws JsonProcessingException {
public void makeBidsShouldReturnExpectedBidderBids() throws JsonProcessingException {
// given
final Imp bannerImp = createBannerImp("banner-slot-id", impBuilder -> impBuilder.id("banner-imp-id"));
final Imp videoImp = createVideoImp("video-slot-id", impBuilder -> impBuilder.id("video-imp-id"));
final BidRequest bidRequest = createBidRequest(bannerImp, videoImp);

final ObjectNode dsaResponse = createDsaResponse();

final StroeerCoreBid bannerBid = StroeerCoreBid.builder()
.id("1")
.impId("banner-imp-id")
Expand All @@ -265,6 +297,7 @@ public void makeBidsShouldReturnExpectedBidderBidsWithProperBidType() throws Jso
.creativeId("foo")
.width(300)
.height(600)
.dsa(dsaResponse.deepCopy())
.build();

final StroeerCoreBid videoBid = StroeerCoreBid.builder()
Expand All @@ -273,6 +306,7 @@ public void makeBidsShouldReturnExpectedBidderBidsWithProperBidType() throws Jso
.adMarkup("<vast><span></span></vast>")
.cpm(BigDecimal.valueOf(1.58))
.creativeId("vid")
.dsa(null)
.build();

final StroeerCoreBidResponse response = StroeerCoreBidResponse.of(List.of(bannerBid, videoBid));
Expand All @@ -290,6 +324,7 @@ public void makeBidsShouldReturnExpectedBidderBidsWithProperBidType() throws Jso
.crid("foo")
.w(300)
.h(600)
.ext(mapper.createObjectNode().set("dsa", dsaResponse))
.build();

final Bid expectedVideoBid = Bid.builder()
Expand All @@ -298,6 +333,7 @@ public void makeBidsShouldReturnExpectedBidderBidsWithProperBidType() throws Jso
.adm("<vast><span></span></vast>")
.price(BigDecimal.valueOf(1.58))
.crid("vid")
.ext(null)
.build();

assertThat(result.getErrors()).isEmpty();
Expand Down Expand Up @@ -392,4 +428,14 @@ private BidderCall<BidRequest> createHttpCallWithNonParsableResponse() {
return createHttpCall(HttpRequest.<BidRequest>builder().build(),
HttpResponse.of(200, null, "[]"));
}

private ObjectNode createDsaResponse() {
final ObjectNode dsaTransparency = mapper.createObjectNode()
.put("domain", "example.com")
.set("dsaparams", mapper.createArrayNode().add(1).add(2));
return mapper.createObjectNode()
.put("behalf", "advertiser-a")
.put("paid", "advertiser-b")
.set("transparency", mapper.createArrayNode().add(dsaTransparency));
}
}

0 comments on commit 14a490e

Please sign in to comment.