From 055a80d28987da29429e5a56fa2e0a9ffb8307b9 Mon Sep 17 00:00:00 2001 From: SerhiiNahornyi Date: Tue, 22 Mar 2022 12:46:57 +0200 Subject: [PATCH] Fix asset missing id resolving (#1777) --- .../server/auction/BidResponseCreator.java | 9 +- .../auction/BidResponseCreatorTest.java | 120 ++++++++++++++++++ 2 files changed, 125 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/prebid/server/auction/BidResponseCreator.java b/src/main/java/org/prebid/server/auction/BidResponseCreator.java index 782af8e9283..0612238febf 100644 --- a/src/main/java/org/prebid/server/auction/BidResponseCreator.java +++ b/src/main/java/org/prebid/server/auction/BidResponseCreator.java @@ -1335,8 +1335,9 @@ private static void setAssetTypes(Asset responseAsset, List requestAssets) { return requestAssets.stream() - .filter(asset -> asset.getId() == assetId) + .filter(asset -> Objects.equals(assetId, asset.getId())) .findFirst() .orElse(com.iab.openrtb.request.Asset.EMPTY); } diff --git a/src/test/java/org/prebid/server/auction/BidResponseCreatorTest.java b/src/test/java/org/prebid/server/auction/BidResponseCreatorTest.java index 6c4d30ff1dd..e9b6c978391 100644 --- a/src/test/java/org/prebid/server/auction/BidResponseCreatorTest.java +++ b/src/test/java/org/prebid/server/auction/BidResponseCreatorTest.java @@ -1139,6 +1139,126 @@ public void shouldReturnEmptyAssetIfImageTypeIsEmpty() throws JsonProcessingExce .isEmpty(); } + @Test + public void shouldReturnEmptyAssetIfNoRelatedNativeAssetFound() throws JsonProcessingException { + // given + final Request nativeRequest = Request.builder() + .assets(singletonList(Asset.builder() + .id(null) + .img(ImageObject.builder().type(null).build()) + .data(DataObject.builder().type(2).build()) + .build())) + .build(); + + final BidRequest bidRequest = BidRequest.builder() + .cur(singletonList("USD")) + .tmax(1000L) + .app(App.builder().build()) + .imp(singletonList(Imp.builder() + .id(IMP_ID) + .xNative(Native.builder().request(mapper.writeValueAsString(nativeRequest)).build()) + .build())) + .build(); + + final AuctionContext auctionContext = givenAuctionContext(bidRequest); + + final Response responseAdm = Response.builder() + .assets(singletonList(com.iab.openrtb.response.Asset.builder() + .id(123) + .img(com.iab.openrtb.response.ImageObject.builder().type(null).build()) + .data(com.iab.openrtb.response.DataObject.builder().build()) + .build())) + .build(); + + final Bid bid = Bid.builder() + .id("bidId") + .price(BigDecimal.ONE) + .impid(IMP_ID) + .adm(mapper.writeValueAsString(responseAdm)) + .ext(mapper.valueToTree(singletonMap("bidExt", 1))) + .build(); + final List bidderResponses = singletonList(BidderResponse.of("bidder1", + givenSeatBid(BidderBid.of(bid, xNative, "USD")), 100)); + + // when + final BidResponse bidResponse = + bidResponseCreator.create(toAuctionParticipant(bidderResponses), auctionContext, CACHE_INFO, MULTI_BIDS) + .result(); + + // then + + assertThat(bidResponse.getSeatbid()).hasSize(1) + .flatExtracting(SeatBid::getBid) + .extracting(Bid::getAdm) + .extracting(adm -> mapper.readValue(adm, Response.class)) + .flatExtracting(Response::getAssets) + .isEmpty(); + assertThat(bidResponse.getExt()) + .extracting(ExtBidResponse::getErrors) + .isEqualTo(Map.of("bidder1", singletonList(ExtBidderError.of(3, + "Response has an Image asset with ID:'123' present that doesn't exist in the request")))); + } + + @Test + public void shouldReturnEmptyAssetIfIdIsNotPresentRelatedNativeAssetFound() throws JsonProcessingException { + // given + final Request nativeRequest = Request.builder() + .assets(singletonList(Asset.builder() + .id(123) + .img(ImageObject.builder().type(null).build()) + .data(DataObject.builder().type(2).build()) + .build())) + .build(); + + final BidRequest bidRequest = BidRequest.builder() + .cur(singletonList("USD")) + .tmax(1000L) + .app(App.builder().build()) + .imp(singletonList(Imp.builder() + .id(IMP_ID) + .xNative(Native.builder().request(mapper.writeValueAsString(nativeRequest)).build()) + .build())) + .build(); + + final AuctionContext auctionContext = givenAuctionContext(bidRequest); + + final Response responseAdm = Response.builder() + .assets(singletonList(com.iab.openrtb.response.Asset.builder() + .id(null) + .img(com.iab.openrtb.response.ImageObject.builder().type(null).build()) + .data(com.iab.openrtb.response.DataObject.builder().build()) + .build())) + .build(); + + final Bid bid = Bid.builder() + .id("bidId") + .price(BigDecimal.ONE) + .impid(IMP_ID) + .adm(mapper.writeValueAsString(responseAdm)) + .ext(mapper.valueToTree(singletonMap("bidExt", 1))) + .build(); + final List bidderResponses = singletonList(BidderResponse.of("bidder1", + givenSeatBid(BidderBid.of(bid, xNative, "USD")), 100)); + + // when + final BidResponse bidResponse = + bidResponseCreator.create(toAuctionParticipant(bidderResponses), auctionContext, CACHE_INFO, MULTI_BIDS) + .result(); + + // then + + assertThat(bidResponse.getSeatbid()).hasSize(1) + .flatExtracting(SeatBid::getBid) + .extracting(Bid::getAdm) + .extracting(adm -> mapper.readValue(adm, Response.class)) + .flatExtracting(Response::getAssets) + .isEmpty(); + assertThat(bidResponse.getExt()) + .extracting(ExtBidResponse::getErrors) + .isEqualTo(Map.of("bidder1", singletonList(ExtBidderError.of(3, + "Response has an Image asset with ID:'' present that doesn't exist in the request")))); + } + @Test public void shouldReturnEmptyAssetIfDataTypeIsEmpty() throws JsonProcessingException { // given