66import com .iab .openrtb .request .BidRequest ;
77import com .iab .openrtb .request .Imp ;
88import com .iab .openrtb .request .Site ;
9- import com .iab .openrtb .request .Video ;
109import com .iab .openrtb .request .Source ;
1110import com .iab .openrtb .response .Bid ;
1211import com .iab .openrtb .response .BidResponse ;
@@ -204,7 +203,7 @@ public void makeHttpRequestsShouldNotConvertCurrencyEur() {
204203 public void makeHttpRequestsShouldCreateSingleRequestForAllImps () {
205204 // given
206205 final BidRequest bidRequest = BidRequest .builder ()
207- .site (Site .builder ().page ("https://example.com" ).build ())
206+ .site (Site .builder ().page ("https://test- example.com" ).build ())
208207 .imp (List .of (
209208 givenImp (impBuilder -> impBuilder .id ("imp1" )),
210209 givenImp (impBuilder -> impBuilder .id ("imp2" ))))
@@ -241,24 +240,10 @@ public void makeHttpRequestsShouldSetCorrectHeaders() {
241240 .containsEntry ("Accept" , "application/json" );
242241 }
243242
244- @ Test
245- public void makeBidsShouldReturnErrorIfResponseBodyCouldNotBeParsed () {
246- // given
247- final BidderCall <BidRequest > httpCall = givenHttpCall (null , "invalid" );
248-
249- // when
250- final Result <List <BidderBid >> result = target .makeBids (httpCall , null );
251-
252- // then
253- assertThat (result .getErrors ()).hasSize (1 );
254- assertThat (result .getErrors ().get (0 ).getMessage ()).startsWith ("Failed to decode: Unrecognized token" );
255- assertThat (result .getValue ()).isEmpty ();
256- }
257-
258243 @ Test
259244 public void makeBidsShouldReturnEmptyListIfBidResponseIsNull () throws JsonProcessingException {
260245 // given
261- final BidderCall <BidRequest > httpCall = givenHttpCall (null , mapper . writeValueAsString ( null ) );
246+ final BidderCall <BidRequest > httpCall = givenHttpCall (null );
262247
263248 // when
264249 final Result <List <BidderBid >> result = target .makeBids (httpCall , null );
@@ -271,8 +256,7 @@ public void makeBidsShouldReturnEmptyListIfBidResponseIsNull() throws JsonProces
271256 @ Test
272257 public void makeBidsShouldReturnEmptyListIfBidResponseSeatBidIsNull () throws JsonProcessingException {
273258 // given
274- final BidderCall <BidRequest > httpCall = givenHttpCall (null ,
275- mapper .writeValueAsString (BidResponse .builder ().build ()));
259+ final BidderCall <BidRequest > httpCall = givenHttpCall (BidResponse .builder ().build ());
276260
277261 // when
278262 final Result <List <BidderBid >> result = target .makeBids (httpCall , null );
@@ -285,8 +269,7 @@ public void makeBidsShouldReturnEmptyListIfBidResponseSeatBidIsNull() throws Jso
285269 @ Test
286270 public void makeBidsShouldReturnEmptyListIfBidResponseSeatBidIsEmpty () throws JsonProcessingException {
287271 // given
288- final BidderCall <BidRequest > httpCall = givenHttpCall (null ,
289- mapper .writeValueAsString (BidResponse .builder ().seatbid (List .of ()).build ()));
272+ final BidderCall <BidRequest > httpCall = givenHttpCall (BidResponse .builder ().seatbid (List .of ()).build ());
290273
291274 // when
292275 final Result <List <BidderBid >> result = target .makeBids (httpCall , null );
@@ -300,83 +283,55 @@ public void makeBidsShouldReturnEmptyListIfBidResponseSeatBidIsEmpty() throws Js
300283 public void makeBidsShouldReturnBannerBidIfBannerIsPresentInImp () throws JsonProcessingException {
301284 // given
302285 final BidderCall <BidRequest > httpCall = givenHttpCall (
303- BidRequest .builder ()
304- .imp (singletonList (Imp .builder ()
305- .id ("123" )
306- .banner (Banner .builder ().build ())
307- .build ()))
308- .build (),
309- mapper .writeValueAsString (
310- givenBidResponse (bidBuilder -> bidBuilder .impid ("123" ).mtype (1 ))));
286+ givenBidResponse (bidBuilder -> bidBuilder .impid ("123" ).mtype (1 )));
311287
312288 // when
313289 final Result <List <BidderBid >> result = target .makeBids (httpCall , null );
314290
315291 // then
316292 assertThat (result .getErrors ()).isEmpty ();
317293 assertThat (result .getValue ())
318- .extracting (BidderBid ::getType )
319- .containsExactly (banner );
294+ .extracting (BidderBid ::getBid , BidderBid :: getType )
295+ .containsExactly (tuple ( Bid . builder (). impid ( "123" ). mtype ( 1 ). build (), banner ) );
320296 }
321297
322298 @ Test
323299 public void makeBidsShouldReturnVideoBidIfVideoIsPresentInImp () throws JsonProcessingException {
324300 // given
325301 final BidderCall <BidRequest > httpCall = givenHttpCall (
326- BidRequest .builder ()
327- .imp (singletonList (Imp .builder ()
328- .id ("123" )
329- .video (Video .builder ().build ())
330- .build ()))
331- .build (),
332- mapper .writeValueAsString (
333- givenBidResponse (bidBuilder -> bidBuilder .impid ("123" ).mtype (2 ))));
302+ givenBidResponse (bidBuilder -> bidBuilder .impid ("123" ).mtype (2 )));
334303
335304 // when
336305 final Result <List <BidderBid >> result = target .makeBids (httpCall , null );
337306
338307 // then
339308 assertThat (result .getErrors ()).isEmpty ();
340309 assertThat (result .getValue ())
341- .extracting (BidderBid ::getType )
342- .containsExactly (video );
310+ .extracting (BidderBid ::getBid , BidderBid :: getType )
311+ .containsExactly (tuple ( Bid . builder (). impid ( "123" ). mtype ( 2 ). build (), video ) );
343312 }
344313
345314 @ Test
346315 public void makeBidsShouldReturnVideoBidByDefaultWhenMtypeIsUnknown () throws JsonProcessingException {
347316 // given
348317 final BidderCall <BidRequest > httpCall = givenHttpCall (
349- BidRequest .builder ()
350- .imp (singletonList (Imp .builder ()
351- .id ("123" )
352- .video (Video .builder ().build ())
353- .build ()))
354- .build (),
355- mapper .writeValueAsString (
356- givenBidResponse (bidBuilder -> bidBuilder .impid ("123" ).mtype (99 ))));
318+ givenBidResponse (bidBuilder -> bidBuilder .impid ("123" ).mtype (99 )));
357319
358320 // when
359321 final Result <List <BidderBid >> result = target .makeBids (httpCall , null );
360322
361323 // then
362324 assertThat (result .getErrors ()).isEmpty ();
363325 assertThat (result .getValue ())
364- .extracting (BidderBid ::getType )
365- .containsExactly (video );
326+ .extracting (BidderBid ::getBid , BidderBid :: getType )
327+ .containsExactly (tuple ( Bid . builder (). impid ( "123" ). mtype ( 99 ). build (), video ) );
366328 }
367329
368330 @ Test
369331 public void makeBidsShouldReturnCorrectBidderBid () throws JsonProcessingException {
370332 // given
371333 final BidderCall <BidRequest > httpCall = givenHttpCall (
372- BidRequest .builder ()
373- .imp (singletonList (Imp .builder ()
374- .id ("123" )
375- .banner (Banner .builder ().build ())
376- .build ()))
377- .build (),
378- mapper .writeValueAsString (
379- givenBidResponse (bidBuilder -> bidBuilder .impid ("123" ).price (BigDecimal .ONE ))));
334+ givenBidResponse (bidBuilder -> bidBuilder .impid ("123" ).price (BigDecimal .ONE )));
380335
381336 // when
382337 final Result <List <BidderBid >> result = target .makeBids (httpCall , null );
@@ -393,18 +348,13 @@ public void makeBidsShouldReturnCorrectBidderBid() throws JsonProcessingExceptio
393348 public void makeBidsShouldReturnMultipleBids () throws JsonProcessingException {
394349 // given
395350 final BidderCall <BidRequest > httpCall = givenHttpCall (
396- BidRequest .builder ()
397- .imp (List .of (
398- Imp .builder ().id ("123" ).banner (Banner .builder ().build ()).build (),
399- Imp .builder ().id ("456" ).video (Video .builder ().build ()).build ()))
400- .build (),
401- mapper .writeValueAsString (BidResponse .builder ()
351+ BidResponse .builder ()
402352 .seatbid (singletonList (SeatBid .builder ()
403353 .bid (List .of (
404354 Bid .builder ().impid ("123" ).mtype (1 ).price (BigDecimal .ONE ).build (),
405355 Bid .builder ().impid ("456" ).mtype (2 ).price (BigDecimal .TEN ).build ()))
406356 .build ()))
407- .build ())) ;
357+ .build ());
408358
409359 // when
410360 final Result <List <BidderBid >> result = target .makeBids (httpCall , null );
@@ -420,7 +370,7 @@ public void makeBidsShouldReturnMultipleBids() throws JsonProcessingException {
420370
421371 private static BidRequest givenBidRequest (Function <Imp .ImpBuilder , Imp .ImpBuilder > impCustomizer ) {
422372 return BidRequest .builder ()
423- .site (Site .builder ().page ("https://example.com" ).build ())
373+ .site (Site .builder ().page ("https://test- example.com" ).build ())
424374 .imp (singletonList (givenImp (impCustomizer )))
425375 .build ();
426376 }
@@ -441,10 +391,12 @@ private static BidResponse givenBidResponse(Function<Bid.BidBuilder, Bid.BidBuil
441391 .build ();
442392 }
443393
444- private static BidderCall <BidRequest > givenHttpCall (BidRequest bidRequest , String body ) {
394+ private static BidderCall <BidRequest > givenHttpCall (BidResponse bidResponse )
395+ throws JsonProcessingException {
396+
445397 return BidderCall .succeededHttp (
446- HttpRequest .< BidRequest > builder (). payload ( bidRequest ). build () ,
447- HttpResponse .of (200 , null , body ),
398+ null ,
399+ HttpResponse .of (200 , null , mapper . writeValueAsString ( bidResponse ) ),
448400 null );
449401 }
450402}
0 commit comments