Skip to content

Commit

Permalink
DMX Bidfloor fix (#1039)
Browse files Browse the repository at this point in the history
  • Loading branch information
SerhiiNahornyi authored Dec 2, 2020
1 parent 7c32a9d commit ea7c2d6
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 35 deletions.
8 changes: 2 additions & 6 deletions src/main/java/org/prebid/server/bidder/dmx/DmxBidder.java
Original file line number Diff line number Diff line change
Expand Up @@ -156,20 +156,16 @@ private static Imp fetchParams(Imp imp, ExtImpDmx extImp) {

final String tagId = extImp.getTagId();
if (StringUtils.isNotBlank(tagId)) {
updatedImp = Imp.builder()
.id(imp.getId())
updatedImp = imp.toBuilder()
.tagid(tagId)
.ext(imp.getExt())
.secure(SECURE)
.build();
}

final String dmxId = extImp.getDmxId();
if (StringUtils.isNotBlank(dmxId)) {
updatedImp = Imp.builder()
.id(imp.getId())
updatedImp = imp.toBuilder()
.tagid(dmxId)
.ext(imp.getExt())
.secure(SECURE)
.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@ public class ExtImpDmx {
@JsonProperty("memberid")
String memberId;

@JsonProperty("publisher_id")
String publisherId;

@JsonProperty("seller_id")
String sellerId;
}
81 changes: 54 additions & 27 deletions src/test/java/org/prebid/server/bidder/dmx/DmxBidderTest.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package org.prebid.server.bidder.dmx;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.iab.openrtb.request.Banner;
import com.iab.openrtb.request.BidRequest;
import com.iab.openrtb.request.Format;
Expand All @@ -24,6 +23,7 @@
import org.prebid.server.proto.openrtb.ext.request.dmx.ExtImpDmx;
import org.prebid.server.proto.openrtb.ext.response.BidType;

import java.math.BigDecimal;
import java.util.List;
import java.util.function.Function;

Expand All @@ -32,7 +32,6 @@
import static java.util.function.Function.identity;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
import static org.assertj.core.api.Assertions.tuple;
import static org.prebid.server.proto.openrtb.ext.response.BidType.banner;
import static org.prebid.server.proto.openrtb.ext.response.BidType.video;

Expand Down Expand Up @@ -96,22 +95,58 @@ public void makeHttpRequestsShouldReturnErrorIfUserIdIsEmpty() {
@Test
public void makeHttpRequestsShouldModifyImpIfBannerFormatIsNotEmpty() {
// given
final Imp givenImp = Imp.builder()
.id("id")
.bidfloor(BigDecimal.ONE)
.banner(Banner.builder()
.format(singletonList(Format.builder().w(300).h(500).build()))
.build())
.ext(mapper.valueToTree(ExtPrebid.of(null,
ExtImpDmx.builder()
.tagId("tagId")
.dmxId("dmxId")
.memberId("memberId")
.publisherId("publisherId")
.sellerId("sellerId")
.build())))
.build();
final BidRequest bidRequest = BidRequest.builder()
.imp(singletonList(
Imp.builder()
.id("id")
.banner(Banner.builder()
.format(singletonList(Format.builder().w(300).h(500).build()))
.build())
.ext(mapper.valueToTree(ExtPrebid.of(null,
ExtImpDmx.builder()
.tagId("tagId")
.dmxId("dmxId")
.memberId("memberId")
.publisherId("publisherId")
.sellerId("sellerId")
.build())))
.build()))
.imp(singletonList(givenImp))
.user(User.builder().id("userId").build())
.build();

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

// then
final Imp expectedImp = givenImp.toBuilder()
.tagid("dmxId")
.secure(1)
.build();
assertThat(result.getErrors()).isEmpty();
assertThat(result.getValue()).hasSize(1)
.extracting(httpRequest -> mapper.readValue(httpRequest.getBody(), BidRequest.class))
.flatExtracting(BidRequest::getImp)
.containsExactly(expectedImp);
}

@Test
public void makeHttpRequestsShouldWriteTagIdToImpIfItIsPresentAndDmxIsMissing() {
// given
final Imp givenImp = Imp.builder()
.banner(Banner.builder()
.format(singletonList(Format.builder().build()))
.build())
.ext(mapper.valueToTree(ExtPrebid.of(null,
ExtImpDmx.builder()
.tagId("tagId")
.dmxId("")
.memberId("memberId")
.publisherId("publisherId")
.build())))
.build();
final BidRequest bidRequest = BidRequest.builder()
.imp(singletonList(givenImp))
.user(User.builder().id("userId").build())
.build();

Expand All @@ -120,19 +155,11 @@ public void makeHttpRequestsShouldModifyImpIfBannerFormatIsNotEmpty() {

// then
assertThat(result.getErrors()).isEmpty();
final JsonNode expectedImpExt = mapper.valueToTree(ExtPrebid.of(null,
ExtImpDmx.builder()
.tagId("tagId")
.dmxId("dmxId")
.memberId("memberId")
.publisherId("publisherId")
.sellerId("sellerId")
.build()));
assertThat(result.getValue()).hasSize(1)
.extracting(httpRequest -> mapper.readValue(httpRequest.getBody(), BidRequest.class))
.flatExtracting(BidRequest::getImp)
.extracting(Imp::getId, Imp::getTagid, Imp::getExt, Imp::getSecure)
.containsOnly(tuple("id", "dmxId", expectedImpExt, 1));
.extracting(Imp::getTagid)
.containsExactly("tagId");
}

@Test
Expand Down

0 comments on commit ea7c2d6

Please sign in to comment.