17
17
import org .prebid .server .bidder .model .HttpRequest ;
18
18
import org .prebid .server .bidder .model .HttpResponse ;
19
19
import org .prebid .server .bidder .model .Result ;
20
+ import org .prebid .server .proto .openrtb .ext .ExtPrebid ;
21
+ import org .prebid .server .proto .openrtb .ext .request .smilewanted .ExtImpSmilewanted ;
20
22
import org .prebid .server .util .HttpUtil ;
21
23
24
+ import java .math .BigDecimal ;
25
+ import java .util .Arrays ;
22
26
import java .util .List ;
23
27
import java .util .Map ;
24
28
import java .util .function .Function ;
32
36
33
37
public class SmileWantedBidderTest extends VertxTest {
34
38
35
- private static final String ENDPOINT_URL = "https://{{Host}}/test?param={{PublisherId }}" ;
39
+ private static final String ENDPOINT_URL = "https://prebid-server.smilewanted.com/java/{{ZoneId }}" ;
36
40
37
41
private final SmileWantedBidder target = new SmileWantedBidder (ENDPOINT_URL , jacksonMapper );
38
42
@@ -41,10 +45,76 @@ public void creationShouldFailOnInvalidEndpointUrl() {
41
45
assertThatIllegalArgumentException ().isThrownBy (() -> new SmileWantedBidder ("invalid_url" , jacksonMapper ));
42
46
}
43
47
48
+ @ Test
49
+ public void makeHttpRequestsShouldReturnErrorIfImpExtCouldNotBeParsed () {
50
+ // given
51
+ final BidRequest bidRequest = BidRequest .builder ()
52
+ .imp (singletonList (Imp .builder ()
53
+ .id ("123" )
54
+ .ext (mapper .valueToTree (ExtPrebid .of (null , mapper .createArrayNode ())))
55
+ .build ()))
56
+ .build ();
57
+
58
+ // when
59
+ final Result <List <HttpRequest <BidRequest >>> result = target .makeHttpRequests (bidRequest );
60
+
61
+ // then
62
+ assertThat (result .getValue ()).isEmpty ();
63
+ assertThat (result .getErrors ()).hasSize (1 )
64
+ .allSatisfy (error -> {
65
+ assertThat (error .getType ()).isEqualTo (BidderError .Type .bad_input );
66
+ assertThat (error .getMessage ()).startsWith ("Missing bidder ext in impression with id: 123" );
67
+ });
68
+ }
69
+
70
+ @ Test
71
+ public void makeHttpRequestsShouldReturnSingleRequest () {
72
+ // given
73
+ final BidRequest bidRequest = BidRequest .builder ()
74
+ .imp (List .of (
75
+ givenImp ("zone123" ),
76
+ Imp .builder ()
77
+ .id ("456" )
78
+ .ext (mapper .valueToTree (ExtPrebid .of (null , ExtImpSmilewanted .of ("zone123" ))))
79
+ .build ()))
80
+ .build ();
81
+
82
+ // when
83
+ final Result <List <HttpRequest <BidRequest >>> result = target .makeHttpRequests (bidRequest );
84
+
85
+ // then
86
+ assertThat (result .getErrors ()).isEmpty ();
87
+ assertThat (result .getValue ()).hasSize (1 );
88
+ final HttpRequest <BidRequest > httpRequest = result .getValue ().get (0 );
89
+ assertThat (httpRequest .getPayload ()).isNotNull ();
90
+ assertThat (httpRequest .getPayload ().getImp ()).hasSize (2 );
91
+ assertThat (httpRequest .getPayload ().getAt ()).isEqualTo (1 );
92
+ assertThat (httpRequest .getImpIds ()).containsExactlyInAnyOrder ("123" , "456" );
93
+ }
94
+
95
+ @ Test
96
+ public void makeHttpRequestsShouldBuildCorrectEndpointUrlWithZoneId () {
97
+ // given
98
+ final BidRequest bidRequest = BidRequest .builder ()
99
+ .imp (singletonList (givenImp ("zone456" )))
100
+ .build ();
101
+
102
+ // when
103
+ final Result <List <HttpRequest <BidRequest >>> result = target .makeHttpRequests (bidRequest );
104
+
105
+ // then
106
+ assertThat (result .getErrors ()).isEmpty ();
107
+ assertThat (result .getValue ())
108
+ .extracting (HttpRequest ::getUri )
109
+ .containsExactly ("https://prebid-server.smilewanted.com/java/zone456" );
110
+ }
111
+
44
112
@ Test
45
113
public void makeHttpRequestsShouldCorrectlyAddHeaders () {
46
114
// given
47
- final BidRequest bidRequest = BidRequest .builder ().build ();
115
+ final BidRequest bidRequest = BidRequest .builder ()
116
+ .imp (singletonList (givenImp ("zone123" )))
117
+ .build ();
48
118
49
119
// when
50
120
final Result <List <HttpRequest <BidRequest >>> result = target .makeHttpRequests (bidRequest );
@@ -65,7 +135,9 @@ public void makeHttpRequestsShouldCorrectlyAddHeaders() {
65
135
@ Test
66
136
public void makeHttpRequestsShouldSetAtToOne () {
67
137
// given
68
- final BidRequest bidRequest = BidRequest .builder ().build ();
138
+ final BidRequest bidRequest = BidRequest .builder ()
139
+ .imp (singletonList (givenImp ("zone123" )))
140
+ .build ();
69
141
70
142
// when
71
143
final Result <List <HttpRequest <BidRequest >>> result = target .makeHttpRequests (bidRequest );
@@ -160,6 +232,105 @@ public void makeBidsShouldReturnBannerBidIfVideoIsAbsentInRequestImp() throws Js
160
232
.containsOnly (BidderBid .of (Bid .builder ().impid ("123" ).build (), banner , null ));
161
233
}
162
234
235
+ @ Test
236
+ public void makeBidsShouldReturnMultipleBidsFromSingleSeatBid () throws JsonProcessingException {
237
+ // given
238
+ final BidderCall <BidRequest > httpCall = givenHttpCall (
239
+ BidRequest .builder ()
240
+ .imp (List .of (
241
+ Imp .builder ().id ("123" ).build (),
242
+ Imp .builder ().id ("456" ).video (Video .builder ().build ()).build ()))
243
+ .build (),
244
+ mapper .writeValueAsString (
245
+ BidResponse .builder ()
246
+ .cur ("USD" )
247
+ .seatbid (singletonList (SeatBid .builder ()
248
+ .bid (List .of (
249
+ Bid .builder ().impid ("123" ).price (BigDecimal .valueOf (1.0 )).build (),
250
+ Bid .builder ().impid ("456" ).price (BigDecimal .valueOf (2.0 )).build ()))
251
+ .build ()))
252
+ .build ()));
253
+
254
+ // when
255
+ final Result <List <BidderBid >> result = target .makeBids (httpCall , null );
256
+
257
+ // then
258
+ assertThat (result .getErrors ()).isEmpty ();
259
+ assertThat (result .getValue ()).hasSize (2 )
260
+ .containsExactlyInAnyOrder (
261
+ BidderBid .of (Bid .builder ().impid ("123" ).price (BigDecimal .valueOf (1.0 )).build (), banner , "USD" ),
262
+ BidderBid .of (Bid .builder ().impid ("456" ).price (BigDecimal .valueOf (2.0 )).build (), video , "USD" ));
263
+ }
264
+
265
+ @ Test
266
+ public void makeBidsShouldFilterNullBids () throws JsonProcessingException {
267
+ // given
268
+ final BidderCall <BidRequest > httpCall = givenHttpCall (
269
+ BidRequest .builder ()
270
+ .imp (singletonList (Imp .builder ().id ("123" ).build ()))
271
+ .build (),
272
+ mapper .writeValueAsString (
273
+ BidResponse .builder ()
274
+ .seatbid (singletonList (SeatBid .builder ()
275
+ .bid (Arrays .asList (
276
+ Bid .builder ().impid ("123" ).build (),
277
+ null ,
278
+ Bid .builder ().impid ("456" ).build ()))
279
+ .build ()))
280
+ .build ()));
281
+
282
+ // when
283
+ final Result <List <BidderBid >> result = target .makeBids (httpCall , null );
284
+
285
+ // then
286
+ assertThat (result .getErrors ()).isEmpty ();
287
+ assertThat (result .getValue ()).hasSize (2 )
288
+ .extracting (BidderBid ::getBid )
289
+ .extracting (Bid ::getImpid )
290
+ .containsExactlyInAnyOrder ("123" , "456" );
291
+ }
292
+
293
+ @ Test
294
+ public void makeBidsShouldReturnBidWithCurrency () throws JsonProcessingException {
295
+ // given
296
+ final BidderCall <BidRequest > httpCall = givenHttpCall (
297
+ BidRequest .builder ()
298
+ .imp (singletonList (Imp .builder ().id ("123" ).build ()))
299
+ .build (),
300
+ mapper .writeValueAsString (
301
+ BidResponse .builder ()
302
+ .cur ("EUR" )
303
+ .seatbid (singletonList (SeatBid .builder ()
304
+ .bid (singletonList (Bid .builder ().impid ("123" ).build ()))
305
+ .build ()))
306
+ .build ()));
307
+
308
+ // when
309
+ final Result <List <BidderBid >> result = target .makeBids (httpCall , null );
310
+
311
+ // then
312
+ assertThat (result .getErrors ()).isEmpty ();
313
+ assertThat (result .getValue ())
314
+ .extracting (BidderBid ::getBidCurrency )
315
+ .containsExactly ("EUR" );
316
+ }
317
+
318
+ @ Test
319
+ public void makeBidsShouldReturnEmptyListIfSeatBidIsEmpty () throws JsonProcessingException {
320
+ // given
321
+ final BidderCall <BidRequest > httpCall = givenHttpCall (null ,
322
+ mapper .writeValueAsString (BidResponse .builder ()
323
+ .seatbid (singletonList (SeatBid .builder ().build ()))
324
+ .build ()));
325
+
326
+ // when
327
+ final Result <List <BidderBid >> result = target .makeBids (httpCall , null );
328
+
329
+ // then
330
+ assertThat (result .getErrors ()).isEmpty ();
331
+ assertThat (result .getValue ()).isEmpty ();
332
+ }
333
+
163
334
private static BidResponse givenBidResponse (Function <Bid .BidBuilder , Bid .BidBuilder > bidCustomizer ) {
164
335
return BidResponse .builder ()
165
336
.seatbid (singletonList (SeatBid .builder ().bid (singletonList (bidCustomizer .apply (Bid .builder ()).build ()))
@@ -173,4 +344,11 @@ private static BidderCall<BidRequest> givenHttpCall(BidRequest bidRequest, Strin
173
344
HttpResponse .of (200 , null , body ),
174
345
null );
175
346
}
347
+
348
+ private static Imp givenImp (String zoneId ) {
349
+ return Imp .builder ()
350
+ .id ("123" )
351
+ .ext (mapper .valueToTree (ExtPrebid .of (null , ExtImpSmilewanted .of (zoneId ))))
352
+ .build ();
353
+ }
176
354
}
0 commit comments