Skip to content

Commit

Permalink
Sovrn: Change Imp.bidfloor if invalid (#1331)
Browse files Browse the repository at this point in the history
  • Loading branch information
SerhiiNahornyi authored and nickluck8 committed Aug 10, 2021
1 parent 2b5af07 commit 6c123aa
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/main/java/org/prebid/server/bidder/sovrn/SovrnBidder.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.prebid.server.proto.openrtb.ext.response.BidType;
import org.prebid.server.util.HttpUtil;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
Expand Down Expand Up @@ -103,7 +104,7 @@ private Imp makeImp(Imp imp) {

final ExtImpSovrn sovrnExt = parseExtImpSovrn(imp);
return imp.toBuilder()
.bidfloor(sovrnExt.getBidfloor())
.bidfloor(resolveBidFloor(imp.getBidfloor(), sovrnExt.getBidfloor()))
.tagid(ObjectUtils.defaultIfNull(sovrnExt.getTagid(), sovrnExt.getLegacyTagId()))
.build();
}
Expand All @@ -120,6 +121,14 @@ private ExtImpSovrn parseExtImpSovrn(Imp imp) {
}
}

private static BigDecimal resolveBidFloor(BigDecimal impBidFloor, BigDecimal extBidFloor) {
return !isValidBidFloor(impBidFloor) && isValidBidFloor(extBidFloor) ? extBidFloor : impBidFloor;
}

private static boolean isValidBidFloor(BigDecimal bidFloor) {
return bidFloor != null && bidFloor.compareTo(BigDecimal.ZERO) > 0;
}

private static MultiMap headers(BidRequest bidRequest) {
final MultiMap headers = HttpUtil.headers();

Expand Down
69 changes: 69 additions & 0 deletions src/test/java/org/prebid/server/bidder/sovrn/SovrnBidderTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,75 @@ public void makeHttpRequestsShouldReturnResultWithHttpRequestContainingExpectedF
.build());
}

@Test
public void makeHttpRequestsShouldSetBidFloorFromExtIfImpBidFloorIsZero() {
// given
final BidRequest bidRequest = BidRequest.builder()
.imp(Collections.singletonList(
Imp.builder().id("impId")
.bidfloor(BigDecimal.ZERO)
.ext(mapper.valueToTree(ExtPrebid.of(null, ExtImpSovrn.of(null, null, BigDecimal.TEN))))
.build()))
.build();

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

// then
assertThat(result.getValue()).hasSize(1)
.extracting(HttpRequest::getBody)
.extracting(body -> mapper.readValue(body, BidRequest.class))
.flatExtracting(BidRequest::getImp)
.extracting(Imp::getBidfloor)
.containsExactly(BigDecimal.TEN);
}

@Test
public void makeHttpRequestsShouldSetBidFloorFromExtIfImpBidFloorIsMissed() {
// given
final BidRequest bidRequest = BidRequest.builder()
.imp(Collections.singletonList(
Imp.builder().id("impId")
.bidfloor(null)
.ext(mapper.valueToTree(ExtPrebid.of(null, ExtImpSovrn.of(null, null, BigDecimal.TEN))))
.build()))
.build();

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

// then
assertThat(result.getValue()).hasSize(1)
.extracting(HttpRequest::getBody)
.extracting(body -> mapper.readValue(body, BidRequest.class))
.flatExtracting(BidRequest::getImp)
.extracting(Imp::getBidfloor)
.containsExactly(BigDecimal.TEN);
}

@Test
public void makeHttpRequestsShouldNotSetBidFloorFromExtIfImpBidFloorIsValid() {
// given
final BidRequest bidRequest = BidRequest.builder()
.imp(Collections.singletonList(
Imp.builder().id("impId")
.bidfloor(BigDecimal.ONE)
.ext(mapper.valueToTree(ExtPrebid.of(null, ExtImpSovrn.of(null, null, BigDecimal.TEN))))
.build()))
.build();

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

// then
assertThat(result.getValue()).hasSize(1)
.extracting(HttpRequest::getBody)
.extracting(body -> mapper.readValue(body, BidRequest.class))
.flatExtracting(BidRequest::getImp)
.extracting(Imp::getBidfloor)
.containsExactly(BigDecimal.ONE);
}

@Test
public void makeHttpRequestsShouldReturnResultWithHttpRequestsContainingExpectedHeaders() {
// given
Expand Down

0 comments on commit 6c123aa

Please sign in to comment.