Skip to content

Commit 1cf8c18

Browse files
committed
Apply CR suggestions
1 parent 36d996c commit 1cf8c18

3 files changed

Lines changed: 117 additions & 75 deletions

File tree

src/main/java/org/prebid/server/bidder/openx/OpenxBidder.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -291,16 +291,15 @@ private List<BidderBid> bidsFromResponse(BidRequest bidRequest, OpenxBidResponse
291291
.map(SeatBid::getBid)
292292
.filter(Objects::nonNull)
293293
.flatMap(Collection::stream)
294-
.map(bid -> bid.toBuilder().ext(getBidExt(bid)).build())
295294
.map(bid -> toBidderBid(bid, impIdToBidType, bidCurrency))
296295
.toList();
297296
}
298297

299-
private static BidderBid toBidderBid(Bid bid, Map<String, BidType> impIdToBidType, String bidCurrency) {
298+
private BidderBid toBidderBid(Bid bid, Map<String, BidType> impIdToBidType, String bidCurrency) {
300299
final BidType bidType = getBidType(bid, impIdToBidType);
301300
final ExtBidPrebidVideo videoInfo = bidType == BidType.video ? getVideoInfo(bid) : null;
302301
return BidderBid.builder()
303-
.bid(bid)
302+
.bid(bid.toBuilder().ext(getBidExt(bid)).build())
304303
.type(bidType)
305304
.bidCurrency(bidCurrency)
306305
.videoInfo(videoInfo)
@@ -371,7 +370,7 @@ private OpenxBidExt parseOpenxBidExt(ObjectNode ext) {
371370
try {
372371
return mapper.mapper().convertValue(ext, OpenxBidExt.class);
373372
} catch (IllegalArgumentException e) {
374-
return new OpenxBidExt();
373+
return OpenxBidExt.builder().build();
375374
}
376375
}
377376

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,13 @@
11
package org.prebid.server.bidder.openx.proto;
22

3-
import com.fasterxml.jackson.annotation.JsonProperty;
4-
import lombok.AllArgsConstructor;
53
import lombok.Builder;
6-
import lombok.Getter;
7-
import lombok.NoArgsConstructor;
4+
import lombok.Value;
85

9-
@Getter
106
@Builder
11-
@NoArgsConstructor
12-
@AllArgsConstructor
7+
@Value
138
public class OpenxBidExt {
149

15-
@JsonProperty("dsp_id")
1610
String dspId;
17-
@JsonProperty("buyer_id")
1811
String buyerId;
19-
@JsonProperty("brand_id")
2012
String brandId;
2113
}

src/test/java/org/prebid/server/bidder/openx/OpenxBidderTest.java

Lines changed: 112 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import com.fasterxml.jackson.core.JsonProcessingException;
44
import com.fasterxml.jackson.databind.JsonNode;
5+
import com.fasterxml.jackson.databind.node.JsonNodeFactory;
56
import com.fasterxml.jackson.databind.node.ObjectNode;
67
import com.iab.openrtb.request.Audio;
78
import com.iab.openrtb.request.Banner;
@@ -15,9 +16,6 @@
1516
import com.iab.openrtb.response.BidResponse;
1617
import com.iab.openrtb.response.SeatBid;
1718
import org.junit.jupiter.api.Test;
18-
import org.junit.jupiter.params.ParameterizedTest;
19-
import org.junit.jupiter.params.provider.Arguments;
20-
import org.junit.jupiter.params.provider.MethodSource;
2119
import org.prebid.server.VertxTest;
2220
import org.prebid.server.bidder.model.BidderBid;
2321
import org.prebid.server.bidder.model.BidderCall;
@@ -46,7 +44,6 @@
4644
import java.util.Collections;
4745
import java.util.List;
4846
import java.util.Map;
49-
import java.util.stream.Stream;
5047

5148
import static java.util.Arrays.asList;
5249
import static java.util.Collections.emptyList;
@@ -988,73 +985,115 @@ public void makeBidsShouldReturnResultContainingEmptyValueAndErrorsWhenSeatBidEm
988985
.containsOnly(Collections.emptyList(), Collections.emptyList());
989986
}
990987

991-
private static Map<String, JsonNode> givenCustomParams(String key, Object values) {
992-
return singletonMap(key, mapper.valueToTree(values));
993-
}
994-
995-
private static BidderCall<BidRequest> givenHttpCall(String body) {
996-
return BidderCall.succeededHttp(null, HttpResponse.of(200, null, body), null);
997-
}
998-
999-
private static Stream<Arguments> bidWithExtTestCases() throws JsonProcessingException {
1000-
final ObjectNode allBuyerExt = mapper.valueToTree(OpenxBidExt.builder()
988+
@Test
989+
public void makeBidShouldReturnBidWithExtPrebidMetaContainingAllFieldsFromBidExt() throws JsonProcessingException {
990+
// given
991+
final ObjectNode bidExt = mapper.valueToTree(OpenxBidExt.builder()
1001992
.dspId("1")
1002993
.buyerId("2")
1003994
.brandId("3")
1004995
.build());
1005-
final ObjectNode onlyBrandExt = mapper.valueToTree(OpenxBidExt.builder()
996+
final BidderCall<BidRequest> httpCall = givenHttpCall(mapper.writeValueAsString(
997+
BidResponse.builder()
998+
.seatbid(singletonList(SeatBid.builder()
999+
.bid(List.of(
1000+
Bid.builder()
1001+
.w(200)
1002+
.h(150)
1003+
.price(BigDecimal.ONE)
1004+
.impid("impId1")
1005+
.dealid("dealid")
1006+
.adm("<div>This is an Ad</div>")
1007+
.ext(bidExt)
1008+
.build()))
1009+
.build()))
1010+
.build()));
1011+
1012+
final BidRequest bidRequest = BidRequest.builder()
1013+
.id("bidRequestId")
1014+
.imp(List.of(
1015+
Imp.builder()
1016+
.id("impId1")
1017+
.banner(Banner.builder().build())
1018+
.build()))
1019+
.build();
1020+
1021+
// when
1022+
final CompositeBidderResponse result = target.makeBidderResponse(httpCall, bidRequest);
1023+
1024+
// then
1025+
final ObjectNode expectedExtWithBidMeta = JsonNodeFactory.instance.objectNode()
1026+
.put("dsp_id", "1")
1027+
.put("buyer_id", "2")
1028+
.put("brand_id", "3")
1029+
.set("prebid", JsonNodeFactory.instance.objectNode()
1030+
.set("meta", JsonNodeFactory.instance.objectNode()
1031+
.put("advertiserId", 2)
1032+
.put("brandId", 3)
1033+
.put("networkId", 1)));
1034+
assertThat(result.getErrors()).isEmpty();
1035+
assertThat(result.getBids()).hasSize(1)
1036+
.extracting(BidderBid::getBid)
1037+
.extracting(Bid::getExt)
1038+
.containsExactly(expectedExtWithBidMeta);
1039+
}
1040+
1041+
@Test
1042+
public void makeBidShouldReturnBidWithExtPrebidMetaContainingBrandIdFieldOnly() throws JsonProcessingException {
1043+
// given
1044+
final ObjectNode bidExt = mapper.valueToTree(OpenxBidExt.builder()
10061045
.brandId("4")
10071046
.build());
1008-
final ObjectNode badExt = mapper.valueToTree(OpenxBidExt.builder()
1009-
.dspId("abc")
1010-
.brandId("cba")
1011-
.build());
1047+
final BidderCall<BidRequest> httpCall = givenHttpCall(mapper.writeValueAsString(
1048+
BidResponse.builder()
1049+
.seatbid(singletonList(SeatBid.builder()
1050+
.bid(List.of(
1051+
Bid.builder()
1052+
.w(200)
1053+
.h(150)
1054+
.price(BigDecimal.ONE)
1055+
.impid("impId1")
1056+
.dealid("dealid")
1057+
.adm("<div>This is an Ad</div>")
1058+
.ext(bidExt)
1059+
.build()))
1060+
.build()))
1061+
.build()));
1062+
1063+
final BidRequest bidRequest = BidRequest.builder()
1064+
.id("bidRequestId")
1065+
.imp(List.of(
1066+
Imp.builder()
1067+
.id("impId1")
1068+
.banner(Banner.builder().build())
1069+
.build()))
1070+
.build();
1071+
1072+
// when
1073+
final CompositeBidderResponse result = target.makeBidderResponse(httpCall, bidRequest);
10121074

1013-
final ObjectNode allBuyerExpectedExt = (ObjectNode) mapper.readTree("""
1014-
{
1015-
"dsp_id": "1",
1016-
"buyer_id": "2",
1017-
"brand_id": "3",
1018-
"prebid": {
1019-
"meta": {
1020-
"advertiserId":2,
1021-
"brandId":3,
1022-
"networkId":1
1023-
}
1024-
}
1025-
}
1026-
""");
1027-
final ObjectNode onlyBrandExpectedExt = (ObjectNode) mapper.readTree("""
1028-
{
1029-
"brand_id": "4",
1030-
"prebid": {
1031-
"meta": {
1032-
"brandId":4
1033-
}
1034-
}
1035-
}
1036-
""");
1037-
final ObjectNode badExpectedExt = (ObjectNode) mapper.readTree("""
1038-
{
1039-
"dsp_id": "abc",
1040-
"brand_id": "cba"
1041-
}
1042-
""");
1043-
1044-
return Stream.of(
1045-
Arguments.of(allBuyerExt, allBuyerExpectedExt),
1046-
Arguments.of(onlyBrandExt, onlyBrandExpectedExt),
1047-
Arguments.of(badExt, badExpectedExt),
1048-
Arguments.of(null, null)
1049-
);
1075+
// then
1076+
final ObjectNode expectedExtWithBidMeta = JsonNodeFactory.instance.objectNode()
1077+
.put("brand_id", "4")
1078+
.set("prebid", JsonNodeFactory.instance.objectNode()
1079+
.set("meta", JsonNodeFactory.instance.objectNode()
1080+
.put("brandId", 4)));
1081+
assertThat(result.getErrors()).isEmpty();
1082+
assertThat(result.getBids()).hasSize(1)
1083+
.extracting(BidderBid::getBid)
1084+
.extracting(Bid::getExt)
1085+
.containsExactly(expectedExtWithBidMeta);
10501086
}
10511087

1052-
@ParameterizedTest
1053-
@MethodSource("bidWithExtTestCases")
1054-
public void makeBidsShouldReturnBidWithExt(
1055-
ObjectNode bidExt,
1056-
ObjectNode expectedExtWithBidMeta) throws JsonProcessingException {
1088+
@Test
1089+
public void makeBidShouldReturnBidWithExtPrebidMetaNotContainingFieldsWithInvalidValues()
1090+
throws JsonProcessingException {
10571091
// given
1092+
final ObjectNode bidExt = mapper.valueToTree(OpenxBidExt.builder()
1093+
.dspId("abc")
1094+
.buyerId("xyz")
1095+
.brandId("cba")
1096+
.build());
10581097
final BidderCall<BidRequest> httpCall = givenHttpCall(mapper.writeValueAsString(
10591098
BidResponse.builder()
10601099
.seatbid(singletonList(SeatBid.builder()
@@ -1084,10 +1123,22 @@ public void makeBidsShouldReturnBidWithExt(
10841123
final CompositeBidderResponse result = target.makeBidderResponse(httpCall, bidRequest);
10851124

10861125
// then
1126+
final ObjectNode expectedExtWithBidMeta = JsonNodeFactory.instance.objectNode()
1127+
.put("dsp_id", "abc")
1128+
.put("buyer_id", "xyz")
1129+
.put("brand_id", "cba");
10871130
assertThat(result.getErrors()).isEmpty();
10881131
assertThat(result.getBids()).hasSize(1)
10891132
.extracting(BidderBid::getBid)
10901133
.extracting(Bid::getExt)
10911134
.containsExactly(expectedExtWithBidMeta);
10921135
}
1136+
1137+
private static Map<String, JsonNode> givenCustomParams(String key, Object values) {
1138+
return singletonMap(key, mapper.valueToTree(values));
1139+
}
1140+
1141+
private static BidderCall<BidRequest> givenHttpCall(String body) {
1142+
return BidderCall.succeededHttp(null, HttpResponse.of(200, null, body), null);
1143+
}
10931144
}

0 commit comments

Comments
 (0)