diff --git a/src/main/java/org/prebid/server/bidder/boldwin/BoldwinBidder.java b/src/main/java/org/prebid/server/bidder/boldwin/BoldwinBidder.java index f89aae35222..d0c702d42bf 100644 --- a/src/main/java/org/prebid/server/bidder/boldwin/BoldwinBidder.java +++ b/src/main/java/org/prebid/server/bidder/boldwin/BoldwinBidder.java @@ -4,6 +4,7 @@ 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; import com.iab.openrtb.response.BidResponse; import com.iab.openrtb.response.SeatBid; import org.apache.commons.collections4.CollectionUtils; @@ -106,13 +107,13 @@ private HttpRequest createSingleRequest(Imp imp, BidRequest request) public Result> makeBids(BidderCall httpCall, BidRequest bidRequest) { try { final BidResponse bidResponse = mapper.decodeValue(httpCall.getResponse().getBody(), BidResponse.class); - return Result.withValues(extractBids(httpCall.getRequest().getPayload(), bidResponse)); + return Result.withValues(extractBids(bidResponse)); } catch (DecodeException | PreBidException e) { return Result.withError(BidderError.badServerResponse(e.getMessage())); } } - private static List extractBids(BidRequest bidRequest, BidResponse bidResponse) { + private static List extractBids(BidResponse bidResponse) { if (bidResponse == null || CollectionUtils.isEmpty(bidResponse.getSeatbid())) { return Collections.emptyList(); } @@ -123,23 +124,19 @@ private static List extractBids(BidRequest bidRequest, BidResponse bi .filter(Objects::nonNull) .flatMap(Collection::stream) .filter(Objects::nonNull) - .map(bid -> BidderBid.of(bid, getBidType(bid.getImpid(), bidRequest.getImp()), bidResponse.getCur())) + .map(bid -> BidderBid.of(bid, getBidType(bid), bidResponse.getCur())) .toList(); } - private static BidType getBidType(String impId, List imps) { - for (Imp imp : imps) { - if (imp.getId().equals(impId)) { - if (imp.getBanner() != null) { - return BidType.banner; - } else if (imp.getVideo() != null) { - return BidType.video; - } else if (imp.getXNative() != null) { - return BidType.xNative; - } - } - } - - throw new PreBidException("Failed to find impression for ID: '%s'".formatted(impId)); + private static BidType getBidType(Bid bid) { + final Integer mType = bid.getMtype() != null ? bid.getMtype() : 999; + return switch (mType) { + case 1 -> BidType.banner; + case 2 -> BidType.video; + case 4 -> BidType.xNative; + default -> throw new PreBidException( + "Unable to fetch mediaType in multi-format: %s".formatted(bid.getImpid()) + ); + }; } } diff --git a/src/test/java/org/prebid/server/bidder/boldwin/BoldwinBidderTest.java b/src/test/java/org/prebid/server/bidder/boldwin/BoldwinBidderTest.java index 6e9b1748cf2..7a02369a396 100644 --- a/src/test/java/org/prebid/server/bidder/boldwin/BoldwinBidderTest.java +++ b/src/test/java/org/prebid/server/bidder/boldwin/BoldwinBidderTest.java @@ -157,7 +157,7 @@ public void makeBidsShouldReturnxNativeBid() throws JsonProcessingException { .imp(singletonList(Imp.builder().id("123").xNative(Native.builder().build()).build())) .build(), mapper.writeValueAsString( - givenBidResponse(bidBuilder -> bidBuilder.impid("123")))); + givenBidResponse(bidBuilder -> bidBuilder.mtype(4).impid("123")))); // when final Result> result = target.makeBids(httpCall, null); @@ -165,7 +165,7 @@ public void makeBidsShouldReturnxNativeBid() throws JsonProcessingException { // then assertThat(result.getErrors()).isEmpty(); assertThat(result.getValue()) - .containsExactly(BidderBid.of(Bid.builder().impid("123").build(), xNative, "USD")); + .containsExactly(BidderBid.of(Bid.builder().impid("123").mtype(4).build(), xNative, "USD")); } @Test @@ -176,7 +176,7 @@ public void makeBidsShouldReturnBannerBid() throws JsonProcessingException { .imp(singletonList(Imp.builder().id("123").banner(Banner.builder().build()).build())) .build(), mapper.writeValueAsString( - givenBidResponse(bidBuilder -> bidBuilder.impid("123")))); + givenBidResponse(bidBuilder -> bidBuilder.mtype(1).impid("123")))); // when final Result> result = target.makeBids(httpCall, null); @@ -184,7 +184,7 @@ public void makeBidsShouldReturnBannerBid() throws JsonProcessingException { // then assertThat(result.getErrors()).isEmpty(); assertThat(result.getValue()) - .containsExactly(BidderBid.of(Bid.builder().impid("123").build(), banner, "USD")); + .containsExactly(BidderBid.of(Bid.builder().mtype(1).impid("123").build(), banner, "USD")); } @Test @@ -195,7 +195,7 @@ public void makeBidsShouldReturnVideoBid() throws JsonProcessingException { .imp(singletonList(Imp.builder().id("123").video(Video.builder().build()).build())) .build(), mapper.writeValueAsString( - givenBidResponse(bidBuilder -> bidBuilder.impid("123")))); + givenBidResponse(bidBuilder -> bidBuilder.mtype(2).impid("123")))); // when final Result> result = target.makeBids(httpCall, null); @@ -203,11 +203,11 @@ public void makeBidsShouldReturnVideoBid() throws JsonProcessingException { // then assertThat(result.getErrors()).isEmpty(); assertThat(result.getValue()) - .containsExactly(BidderBid.of(Bid.builder().impid("123").build(), video, "USD")); + .containsExactly(BidderBid.of(Bid.builder().mtype(2).impid("123").build(), video, "USD")); } @Test - public void makeBidsShouldThrowErrorFailedToFindImpression() throws JsonProcessingException { + public void makeBidsShouldThrowErrorUnableToFetchMediaType() throws JsonProcessingException { // given final BidderCall httpCall = givenHttpCall( BidRequest.builder() @@ -223,7 +223,7 @@ public void makeBidsShouldThrowErrorFailedToFindImpression() throws JsonProcessi assertThat(result.getValue()).isEmpty(); assertThat(result.getErrors()).hasSize(1) .allSatisfy(error -> { - assertThat(error.getMessage()).startsWith("Failed to find impression for ID: '123'"); + assertThat(error.getMessage()).startsWith("Unable to fetch mediaType in multi-format: 123"); assertThat(error.getType()).isEqualTo(BidderError.Type.bad_server_response); }); } diff --git a/src/test/resources/org/prebid/server/it/openrtb2/boldwin/test-auction-boldwin-response.json b/src/test/resources/org/prebid/server/it/openrtb2/boldwin/test-auction-boldwin-response.json index 709556a1d6e..e9242e76699 100644 --- a/src/test/resources/org/prebid/server/it/openrtb2/boldwin/test-auction-boldwin-response.json +++ b/src/test/resources/org/prebid/server/it/openrtb2/boldwin/test-auction-boldwin-response.json @@ -16,7 +16,8 @@ "type": "video" }, "origbidcpm": 1.25 - } + }, + "mtype": 2 } ], "seat": "boldwin", diff --git a/src/test/resources/org/prebid/server/it/openrtb2/boldwin/test-boldwin-bid-response.json b/src/test/resources/org/prebid/server/it/openrtb2/boldwin/test-boldwin-bid-response.json index e5865de2093..b00165a1652 100644 --- a/src/test/resources/org/prebid/server/it/openrtb2/boldwin/test-boldwin-bid-response.json +++ b/src/test/resources/org/prebid/server/it/openrtb2/boldwin/test-boldwin-bid-response.json @@ -10,7 +10,8 @@ "crid": "crid", "adm": "adm001", "h": 600, - "w": 800 + "w": 800, + "mtype": 2 } ] }