Skip to content

Commit 2d26693

Browse files
Silvermob: Use mtype and add global host #3602 (#3664)
1 parent 9739aeb commit 2d26693

File tree

6 files changed

+60
-31
lines changed

6 files changed

+60
-31
lines changed

src/main/java/org/prebid/server/bidder/silvermob/SilvermobBidder.java

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import com.iab.openrtb.request.BidRequest;
55
import com.iab.openrtb.request.Device;
66
import com.iab.openrtb.request.Imp;
7+
import com.iab.openrtb.response.Bid;
78
import com.iab.openrtb.response.BidResponse;
89
import com.iab.openrtb.response.SeatBid;
910
import io.vertx.core.MultiMap;
@@ -98,7 +99,7 @@ private ExtImpSilvermob parseImpExt(Imp imp) {
9899
}
99100

100101
private static Boolean isInvalidHost(String host) {
101-
return !StringUtils.equalsAny(host, "eu", "us", "apac");
102+
return !StringUtils.equalsAny(host, "eu", "us", "apac", "global");
102103
}
103104

104105
private String resolveEndpoint(ExtImpSilvermob extImp) {
@@ -142,30 +143,31 @@ private List<BidderBid> extractBids(BidderCall<BidRequest> httpCall) {
142143
if (CollectionUtils.isEmpty(bidResponse.getSeatbid())) {
143144
throw new PreBidException("Empty SeatBid array");
144145
}
145-
return bidsFromResponse(bidResponse, httpCall.getRequest().getPayload());
146+
return bidsFromResponse(bidResponse);
146147
}
147148

148-
private static List<BidderBid> bidsFromResponse(BidResponse bidResponse, BidRequest bidRequest) {
149+
private static List<BidderBid> bidsFromResponse(BidResponse bidResponse) {
149150
return bidResponse.getSeatbid().stream()
150151
.filter(Objects::nonNull)
151152
.map(SeatBid::getBid)
152153
.filter(Objects::nonNull)
153154
.flatMap(Collection::stream)
154-
.map(bid -> BidderBid.of(bid, getBidType(bid.getImpid(), bidRequest.getImp()), bidResponse.getCur()))
155+
.map(bid -> BidderBid.of(bid, getBidType(bid), bidResponse.getCur()))
155156
.toList();
156157
}
157158

158-
private static BidType getBidType(String impId, List<Imp> imps) {
159-
for (Imp imp : imps) {
160-
if (imp.getId().equals(impId)) {
161-
if (imp.getVideo() != null) {
162-
return BidType.video;
163-
}
164-
if (imp.getXNative() != null) {
165-
return BidType.xNative;
166-
}
167-
}
159+
private static BidType getBidType(Bid bid) {
160+
final Integer markupType = bid.getMtype();
161+
if (markupType == null) {
162+
throw new PreBidException("Missing MType for bid: " + bid.getId());
168163
}
169-
return BidType.banner;
164+
165+
return switch (markupType) {
166+
case 1 -> BidType.banner;
167+
case 2 -> BidType.video;
168+
case 4 -> BidType.xNative;
169+
default -> throw new PreBidException("Unable to fetch mediaType in multi-format: %s"
170+
.formatted(bid.getImpid()));
171+
};
170172
}
171173
}

src/test/java/org/prebid/server/bidder/silvermob/SilvermobBidderTest.java

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -192,40 +192,40 @@ public void makeBidsShouldReturnErrorIfBidResponseSeatBidIsNullOrEmpty() throws
192192
}
193193

194194
@Test
195-
public void makeBidsShouldReturnBannerBidIfBannerIsPresentInRequestImp() throws JsonProcessingException {
195+
public void makeBidsShouldReturnBannerBidIfMTypeIsBanner() throws JsonProcessingException {
196196
// given
197197
final BidderCall<BidRequest> httpCall = givenHttpCall(
198198
BidRequest.builder()
199199
.imp(singletonList(Imp.builder().id("123").banner(Banner.builder().build()).build()))
200200
.build(),
201201
mapper.writeValueAsString(
202-
givenBidResponse(bidBuilder -> bidBuilder.impid("123"))));
202+
givenBidResponse(bidBuilder -> bidBuilder.impid("123").mtype(1))));
203203

204204
// when
205205
final Result<List<BidderBid>> result = target.makeBids(httpCall, null);
206206

207207
// then
208208
assertThat(result.getErrors()).isEmpty();
209209
assertThat(result.getValue())
210-
.containsOnly(BidderBid.of(Bid.builder().impid("123").build(), banner, "USD"));
210+
.containsOnly(BidderBid.of(Bid.builder().impid("123").mtype(1).build(), banner, "USD"));
211211
}
212212

213213
@Test
214-
public void makeBidsShouldReturnVideoBidIfVideoIsPresentInRequestImp() throws JsonProcessingException {
214+
public void makeBidsShouldReturnVideoBidIfMTypeIsVideo() throws JsonProcessingException {
215215
// given
216216
final BidderCall<BidRequest> httpCall = givenHttpCall(BidRequest.builder()
217217
.imp(singletonList(Imp.builder().id("123").video(Video.builder().build()).build()))
218218
.build(),
219219
mapper.writeValueAsString(
220-
givenBidResponse(bidBuilder -> bidBuilder.impid("123"))));
220+
givenBidResponse(bidBuilder -> bidBuilder.impid("123").mtype(2))));
221221

222222
// when
223223
final Result<List<BidderBid>> result = target.makeBids(httpCall, null);
224224

225225
// then
226226
assertThat(result.getErrors()).isEmpty();
227227
assertThat(result.getValue())
228-
.containsOnly(BidderBid.of(Bid.builder().impid("123").build(), video, "USD"));
228+
.containsOnly(BidderBid.of(Bid.builder().impid("123").mtype(2).build(), video, "USD"));
229229
}
230230

231231
@Test
@@ -254,22 +254,43 @@ public void makeHttpRequestsShouldSetAdditionalHeadersIfDeviceFieldsAreNotEmpty(
254254
}
255255

256256
@Test
257-
public void makeBidsShouldReturnNativeBidIfNativeIsPresentInRequestImp() throws JsonProcessingException {
257+
public void makeBidsShouldReturnNativeBidIfMTypeIsNative() throws JsonProcessingException {
258258
// given
259259
final BidderCall<BidRequest> httpCall = givenHttpCall(
260260
BidRequest.builder()
261261
.imp(singletonList(Imp.builder().id("123").xNative(Native.builder().build()).build()))
262262
.build(),
263263
mapper.writeValueAsString(
264-
givenBidResponse(bidBuilder -> bidBuilder.impid("123"))));
264+
givenBidResponse(bidBuilder -> bidBuilder.impid("123").mtype(4))));
265265

266266
// when
267267
final Result<List<BidderBid>> result = target.makeBids(httpCall, null);
268268

269269
// then
270270
assertThat(result.getErrors()).isEmpty();
271271
assertThat(result.getValue())
272-
.containsOnly(BidderBid.of(Bid.builder().impid("123").build(), xNative, "USD"));
272+
.containsOnly(BidderBid.of(Bid.builder().impid("123").mtype(4).build(), xNative, "USD"));
273+
}
274+
275+
@Test
276+
public void makeBidsShouldThrowErrorWhenMediaTypeIsMissing() throws JsonProcessingException {
277+
// given
278+
final BidderCall<BidRequest> httpCall = givenHttpCall(BidRequest.builder()
279+
.imp(singletonList(Imp.builder().id("123").build()))
280+
.build(),
281+
mapper.writeValueAsString(
282+
givenBidResponse(bidBuilder -> bidBuilder.impid("123"))));
283+
284+
// when
285+
final Result<List<BidderBid>> result = target.makeBids(httpCall, null);
286+
287+
// then
288+
assertThat(result.getValue()).isEmpty();
289+
assertThat(result.getErrors()).hasSize(1)
290+
.allSatisfy(error -> {
291+
assertThat(error.getMessage()).startsWith("Missing MType for bid: null");
292+
assertThat(error.getType()).isEqualTo(BidderError.Type.bad_server_response);
293+
});
273294
}
274295

275296
private static BidRequest givenBidRequest(

src/test/resources/org/prebid/server/it/openrtb2/silvermob/test-auction-silvermob-request.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
"silvermob": {
1212
"zoneid": "testZoneId",
1313
"host": "eu"
14-
}
14+
},
15+
"mtype": 1
1516
},
1617
"tagid": "tag_id"
1718
}

src/test/resources/org/prebid/server/it/openrtb2/silvermob/test-auction-silvermob-response.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,10 @@
1515
"prebid": {
1616
"type": "banner"
1717
},
18-
"origbidcpm": 0.01
19-
}
18+
"origbidcpm": 0.01,
19+
"origbidcur": "USD"
20+
},
21+
"mtype": 1
2022
}
2123
],
2224
"seat": "silvermob",

src/test/resources/org/prebid/server/it/openrtb2/silvermob/test-silvermob-bid-request.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
"bidder": {
1515
"zoneid": "testZoneId",
1616
"host": "eu"
17-
}
17+
},
18+
"mtype": 1
1819
}
1920
}
2021
],

src/test/resources/org/prebid/server/it/openrtb2/silvermob/test-silvermob-bid-response.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,12 @@
99
"price": 0.01,
1010
"id": "bid_id",
1111
"impid": "imp_id",
12-
"cid": "cid"
12+
"cid": "cid",
13+
"mtype": 1
1314
}
1415
],
15-
"type": "banner"
16+
"seat": "silvermob"
1617
}
17-
]
18+
],
19+
"cur": "USD"
1820
}

0 commit comments

Comments
 (0)