Skip to content

OpenX: Determine bid type based on mtype #3811

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

Merged
merged 3 commits into from
Mar 17, 2025
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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove all code related to the old logic.

Copy link
Contributor Author

@gmiedlar-ox gmiedlar-ox Mar 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@CTMBNara We would like to keep the old logic and fallback to it when there is no mtype in the bid response.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gmiedlar-ox You can revert the commit at any time later. We don't keep "dead" code in our repository.

Copy link
Contributor Author

@gmiedlar-ox gmiedlar-ox Mar 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@CTMBNara I don't think we have "dead" code here. In case bid.getMtype() is null or there is no case match, the "old" getBidType logic will be executed.

case null, default -> impIdToBidType.getOrDefault(bid.getImpid(), BidType.banner);

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gmiedlar-ox Yes, you're right. Sorry for that, missed this part

Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,12 @@ private static Map<String, BidType> impIdToBidType(BidRequest bidRequest) {
}

private static BidType getBidType(Bid bid, Map<String, BidType> impIdToBidType) {
return impIdToBidType.getOrDefault(bid.getImpid(), BidType.banner);
return switch (bid.getMtype()) {
case 1 -> BidType.banner;
case 2 -> BidType.video;
case 4 -> BidType.xNative;
case null, default -> impIdToBidType.getOrDefault(bid.getImpid(), BidType.banner);
};
}

private static List<ExtIgi> extractIgi(OpenxBidResponse bidResponse) {
Expand Down
159 changes: 156 additions & 3 deletions src/test/java/org/prebid/server/bidder/openx/OpenxBidderTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ public void makeHttpRequestsShouldReturnResultWithSingleBidRequestForMultiFormat
.banner(Banner.builder().w(300).h(150).build())
.xNative(Native.builder().request("{\"version\":1}").build())
.ext(mapper.valueToTree(ExtImpOpenx.builder().build()))
.build()))
.build()))
.ext(jacksonMapper.fillExtension(
ExtRequest.empty(),
OpenxRequestExt.of(null, null, "hb_pbs_1.0.0")))
Expand Down Expand Up @@ -608,7 +608,7 @@ public void makeBidsShouldReturnErrorIfResponseBodyCouldNotBeParsed() {
}

@Test
public void makeBidsShouldReturnResultWithExpectedFields() throws JsonProcessingException {
public void makeBidsShouldReturnResultForBannerBidsWithExpectedFields() throws JsonProcessingException {
// given
final BidderCall<BidRequest> httpCall = givenHttpCall(mapper.writeValueAsString(OpenxBidResponse.builder()
.seatbid(singletonList(SeatBid.builder()
Expand All @@ -619,6 +619,7 @@ public void makeBidsShouldReturnResultWithExpectedFields() throws JsonProcessing
.impid("impId1")
.dealid("dealid")
.adm("<div>This is an Ad</div>")
.mtype(1)
.build()))
.build()))
.cur("UAH")
Expand Down Expand Up @@ -654,6 +655,7 @@ public void makeBidsShouldReturnResultWithExpectedFields() throws JsonProcessing
.w(200)
.h(150)
.adm("<div>This is an Ad</div>")
.mtype(1)
.build(),
BidType.banner, "UAH"));
assertThat(result.getIgi()).containsExactly(igi);
Expand All @@ -670,6 +672,7 @@ public void makeBidsShouldReturnResultForNativeBidsWithExpectedFields() throws J
.price(BigDecimal.ONE)
.impid("impId1")
.adm("{\"ver\":\"1.2\"}")
.mtype(4)
.build()))
.build()))
.cur("UAH")
Expand Down Expand Up @@ -697,6 +700,7 @@ public void makeBidsShouldReturnResultForNativeBidsWithExpectedFields() throws J
.w(200)
.h(150)
.adm("{\"ver\":\"1.2\"}")
.mtype(4)
.build(),
BidType.xNative, "UAH"));
}
Expand All @@ -715,6 +719,7 @@ public void makeBidsShouldReturnVideoInfoWhenAvailable() throws JsonProcessingEx
.adm("<div>This is an Ad</div>")
.dur(30)
.cat(singletonList("category1"))
.mtype(2)
.build()))
.build()))
.build()));
Expand All @@ -737,6 +742,102 @@ public void makeBidsShouldReturnVideoInfoWhenAvailable() throws JsonProcessingEx
.containsExactly(ExtBidPrebidVideo.of(30, "category1"));
}

@Test
public void makeBidsShouldReturnBidsWithTypeFromImpWhenNoMtype() throws JsonProcessingException {
// given
final BidderCall<BidRequest> httpCall = givenHttpCall(mapper.writeValueAsString(OpenxBidResponse.builder()
.seatbid(List.of(
SeatBid.builder()
.bid(singletonList(Bid.builder()
.w(200)
.h(150)
.price(BigDecimal.ONE)
.impid("impId1-banner")
.adm("<div>This is an Ad</div>")
.build()))
.build(),
SeatBid.builder()
.bid(singletonList(Bid.builder()
.w(300)
.h(150)
.price(BigDecimal.TWO)
.impid("impId2-video")
.adm("<div>This is an Ad</div>")
.dur(15)
.build()))
.build(),
SeatBid.builder()
.bid(singletonList(Bid.builder()
.w(150)
.h(150)
.price(BigDecimal.TEN)
.impid("impId3-native")
.adm("{\"ver\":\"1.2\"}")
.build()))
.build()))
.cur("UAH")
.build()));

final BidRequest bidRequest = BidRequest.builder()
.id("bidRequestId")
.imp(List.of(
Imp.builder()
.id("impId1-banner")
.banner(Banner.builder().build())
.build(),
Imp.builder()
.id("impId2-video")
.video(Video.builder().build())
.build(),
Imp.builder()
.id("impId3-native")
.xNative(Native.builder().build())
.build()))
.build();

// when
final CompositeBidderResponse result = target.makeBidderResponse(httpCall, bidRequest);

// then
assertThat(result.getErrors()).isEmpty();
assertThat(result.getBids()).hasSize(3)
.contains(BidderBid.builder()
.bid(Bid.builder()
.impid("impId1-banner")
.price(BigDecimal.ONE)
.w(200)
.h(150)
.adm("<div>This is an Ad</div>")
.build())
.type(BidType.banner)
.bidCurrency("UAH")
.build())
.contains(BidderBid.builder()
.bid(Bid.builder()
.impid("impId2-video")
.price(BigDecimal.TWO)
.w(300)
.h(150)
.adm("<div>This is an Ad</div>")
.dur(15)
.build())
.videoInfo(ExtBidPrebidVideo.of(15, null))
.type(BidType.video)
.bidCurrency("UAH")
.build())
.contains(BidderBid.builder()
.bid(Bid.builder()
.impid("impId3-native")
.price(BigDecimal.TEN)
.w(150)
.h(150)
.adm("{\"ver\":\"1.2\"}")
.build())
.type(BidType.xNative)
.bidCurrency("UAH")
.build());
}

@Test
public void makeBidsShouldReturnFledgeConfigEvenIfNoBids() throws JsonProcessingException {
// given
Expand Down Expand Up @@ -770,7 +871,59 @@ public void makeBidsShouldReturnFledgeConfigEvenIfNoBids() throws JsonProcessing
}

@Test
public void makeBidsShouldReturnRespectBannerImpWhenBothBannerAndVideoImpWithSameIdExist()
public void makeBidsShouldRespectMtypeWhenBothBannerAndVideoImpWithSameIdExist() throws JsonProcessingException {
// given
final BidderCall<BidRequest> httpCall = givenHttpCall(mapper.writeValueAsString(BidResponse.builder()
.seatbid(singletonList(SeatBid.builder()
.bid(singletonList(Bid.builder()
.w(200)
.h(150)
.price(BigDecimal.ONE)
.impid("impId1")
.dealid("dealid")
.adm("<div>This is an Ad</div>")
.dur(30)
.cat(singletonList("category1"))
.mtype(2)
.build()))
.build()))
.build()));

final BidRequest bidRequest = BidRequest.builder()
.id("bidRequestId")
.imp(singletonList(Imp.builder()
.id("impId1")
.video(Video.builder().build())
.banner(Banner.builder().build())
.build()))
.build();

// when
final CompositeBidderResponse result = target.makeBidderResponse(httpCall, bidRequest);

// then
assertThat(result.getErrors()).isEmpty();
assertThat(result.getBids()).hasSize(1)
.containsOnly(
BidderBid.builder()
.bid(Bid.builder()
.impid("impId1")
.price(BigDecimal.ONE)
.dealid("dealid")
.w(200)
.h(150)
.adm("<div>This is an Ad</div>")
.dur(30)
.cat(singletonList("category1"))
.mtype(2)
.build())
.videoInfo(ExtBidPrebidVideo.of(30, "category1"))
.type(BidType.video)
.bidCurrency("USD").build());
}

@Test
public void makeBidsShouldRespectBannerImpWhenBothBannerAndVideoImpWithSameIdExistAndNoMtype()
throws JsonProcessingException {
// given
final BidderCall<BidRequest> httpCall = givenHttpCall(mapper.writeValueAsString(BidResponse.builder()
Expand Down
Loading