11package org .prebid .server .bidder .seedtag ;
22
33import com .fasterxml .jackson .core .JsonProcessingException ;
4- import com .iab .openrtb .request .Banner ;
54import com .iab .openrtb .request .BidRequest ;
65import com .iab .openrtb .request .Imp ;
76import com .iab .openrtb .response .Bid ;
2120import org .prebid .server .bidder .model .Result ;
2221import org .prebid .server .currency .CurrencyConversionService ;
2322import org .prebid .server .exception .PreBidException ;
24- import org .prebid .server .proto .openrtb .ext .ExtPrebid ;
25- import org .prebid .server .proto .openrtb .ext .request .seedtag .ExtImpSeedtag ;
2623
2724import java .math .BigDecimal ;
28- import java .util .Arrays ;
2925import java .util .List ;
30- import java .util .function .Function ;
26+ import java .util .function .UnaryOperator ;
3127
3228import static java .util .Arrays .asList ;
3329import static java .util .Collections .singletonList ;
34- import static java .util .function .Function .identity ;
30+ import static java .util .function .UnaryOperator .identity ;
3531import static org .assertj .core .api .Assertions .assertThat ;
3632import static org .assertj .core .api .Assertions .assertThatIllegalArgumentException ;
3733import static org .assertj .core .api .Assertions .tuple ;
@@ -58,17 +54,19 @@ public void setUp() {
5854
5955 @ Test
6056 public void creationShouldFailOnInvalidEndpointUrl () {
61- assertThatIllegalArgumentException ().isThrownBy (() -> new SeedtagBidder ("invalid_url" ,
62- currencyConversionService ,
63- jacksonMapper ));
57+ assertThatIllegalArgumentException ()
58+ .isThrownBy (() -> new SeedtagBidder (
59+ "invalid_url" ,
60+ currencyConversionService ,
61+ jacksonMapper ));
6462 }
6563
6664 @ Test
6765 public void makeHttpRequestsShouldMakeOneRequestWithAllImps () {
6866 // given
6967 final BidRequest bidRequest = givenBidRequest (
7068 identity (),
71- requestBuilder -> requestBuilder .imp (Arrays . asList (
69+ requestBuilder -> requestBuilder .imp (asList (
7270 givenImp (identity ()),
7371 givenImp (identity ()))));
7472
@@ -90,7 +88,7 @@ public void makeHttpRequestsShouldConvertCurrency() {
9088 .willReturn (BigDecimal .TEN );
9189
9290 final BidRequest bidRequest = givenBidRequest (imp -> imp
93- .bidfloor (BigDecimal .TEN )
91+ .bidfloor (BigDecimal .TWO )
9492 .bidfloorcur ("EUR" ));
9593
9694 // when
@@ -106,98 +104,35 @@ public void makeHttpRequestsShouldConvertCurrency() {
106104 }
107105
108106 @ Test
109- public void makeHttpRequestsShouldMakeOneRequesWithAllCurrencyConvertedImps () {
107+ public void makeHttpRequestsShouldSkipImpsWithCurrencyThatCanNotBeConverted () {
110108 // given
111109 given (currencyConversionService .convertCurrency (any (), any (), anyString (), anyString ()))
112110 .willThrow (PreBidException .class );
113111
114112 final BidRequest bidRequest = givenBidRequest (
115113 identity (),
116- requestBuilder -> requestBuilder .imp (Arrays . asList (
114+ requestBuilder -> requestBuilder .imp (asList (
117115 givenImp (identity ()),
118116 givenImp (impBuilder -> impBuilder
119117 .bidfloor (BigDecimal .TEN )
120- .bidfloorcur ("EUR" )
121- )))) ;
118+ .bidfloorcur ("EUR" ))
119+ )));
122120
123121 // when
124122 final Result <List <HttpRequest <BidRequest >>> result = target .makeHttpRequests (bidRequest );
125123
126124 // then
127- assertThat (result .getErrors ()).isEmpty ( );
125+ assertThat (result .getErrors ()).hasSize ( 1 );
128126 assertThat (result .getValue ()).hasSize (1 )
129127 .extracting (HttpRequest ::getPayload )
130128 .flatExtracting (BidRequest ::getImp )
131129 .hasSize (1 );
132130 }
133131
134- @ Test
135- public void makeHttpRequestsShouldReturnErrorMessageOnFailedConvertCurrencyForAllImps () {
136- // given
137- given (currencyConversionService .convertCurrency (any (), any (), anyString (), anyString ()))
138- .willThrow (PreBidException .class );
139-
140- final BidRequest bidRequest = givenBidRequest (impBuilder -> impBuilder
141- .bidfloor (BigDecimal .TEN )
142- .bidfloorcur ("EUR" ));
143-
144- // when
145- final Result <List <HttpRequest <BidRequest >>> result = target .makeHttpRequests (bidRequest );
146-
147- // then
148- assertThat (result .getErrors ()).allSatisfy (bidderError -> {
149- assertThat (bidderError .getType ())
150- .isEqualTo (BidderError .Type .bad_input );
151- assertThat (bidderError .getMessage ())
152- .isEqualTo ("Unable to convert provided bid floor currency from EUR to USD for imp `123`" );
153- });
154- }
155-
156- @ Test
157- public void makeHttpRequestsShouldReturnErrorIfImpExtCanNotBeParsed () {
158- // given
159- final BidRequest bidRequest = BidRequest .builder ()
160- .imp (asList (Imp .builder ()
161- .ext (mapper .valueToTree (ExtPrebid .of (null , mapper .createArrayNode ())))
162- .build ()))
163- .build ();
164-
165- // when
166- final Result <List <HttpRequest <BidRequest >>> result = target .makeHttpRequests (bidRequest );
167-
168- // then
169- assertThat (result .getErrors ()).hasSize (1 )
170- .allSatisfy (error -> {
171- assertThat (error .getType ()).isEqualTo (BidderError .Type .bad_input );
172- assertThat (error .getMessage ()).startsWith ("Cannot deserialize value" );
173- });
174- assertThat (result .getValue ()).isEmpty ();
175- }
176-
177- @ Test
178- public void makeHttpRequestsShouldReturnEveryOccurredErrorWithNoValue () {
179- // given
180- final BidRequest bidRequest = BidRequest .builder ()
181- .imp (asList (Imp .builder ()
182- .ext (mapper .valueToTree (ExtPrebid .of (null , mapper .createArrayNode ())))
183- .build (),
184- Imp .builder ()
185- .ext (mapper .valueToTree (ExtPrebid .of (null , mapper .createArrayNode ())))
186- .build ()))
187- .build ();
188-
189- // when
190- final Result <List <HttpRequest <BidRequest >>> result = target .makeHttpRequests (bidRequest );
191-
192- // then
193- assertThat (result .getErrors ()).hasSize (2 );
194- assertThat (result .getValue ()).isEmpty ();
195- }
196-
197132 @ Test
198133 public void makeBidsShouldReturnEmptyListIfBidResponseIsNull () throws JsonProcessingException {
199134 // given
200- final BidderCall <BidRequest > httpCall = givenHttpCall (null , mapper .writeValueAsString (null ));
135+ final BidderCall <BidRequest > httpCall = givenHttpCall (mapper .writeValueAsString (null ));
201136
202137 // when
203138 final Result <List <BidderBid >> result = target .makeBids (httpCall , null );
@@ -210,8 +145,7 @@ public void makeBidsShouldReturnEmptyListIfBidResponseIsNull() throws JsonProces
210145 @ Test
211146 public void makeBidsShouldReturnEmptyListIfBidResponseSeatBidIsNull () throws JsonProcessingException {
212147 // given
213- final BidderCall <BidRequest > httpCall = givenHttpCall (null ,
214- mapper .writeValueAsString (BidResponse .builder ().build ()));
148+ final BidderCall <BidRequest > httpCall = givenHttpCall (mapper .writeValueAsString (BidResponse .builder ().build ()));
215149
216150 // when
217151 final Result <List <BidderBid >> result = target .makeBids (httpCall , null );
@@ -224,7 +158,7 @@ public void makeBidsShouldReturnEmptyListIfBidResponseSeatBidIsNull() throws Jso
224158 @ Test
225159 public void makeBidsShouldReturnErrorIfResponseBodyCouldNotBeParsed () {
226160 // given
227- final BidderCall <BidRequest > httpCall = givenHttpCall (null , "invalid" );
161+ final BidderCall <BidRequest > httpCall = givenHttpCall ("invalid" );
228162
229163 // when
230164 final Result <List <BidderBid >> result = target .makeBids (httpCall , null );
@@ -242,9 +176,6 @@ public void makeBidsShouldReturnErrorIfResponseBodyCouldNotBeParsed() {
242176 public void makeBidsShouldReturnBannerBidIfMediaTypeBanner () throws JsonProcessingException {
243177 // given
244178 final BidderCall <BidRequest > httpCall = givenHttpCall (
245- BidRequest .builder ()
246- .imp (singletonList (Imp .builder ().id ("123" ).build ()))
247- .build (),
248179 mapper .writeValueAsString (givenBidResponse (bidBuilder -> bidBuilder .impid ("123" ).mtype (1 ))));
249180
250181 // when
@@ -260,9 +191,6 @@ public void makeBidsShouldReturnBannerBidIfMediaTypeBanner() throws JsonProcessi
260191 public void makeBidsShouldReturnVideoBidIfMediaTypeVideo () throws JsonProcessingException {
261192 // given
262193 final BidderCall <BidRequest > httpCall = givenHttpCall (
263- BidRequest .builder ()
264- .imp (singletonList (Imp .builder ().id ("123" ).build ()))
265- .build (),
266194 mapper .writeValueAsString (givenBidResponse (bidBuilder -> bidBuilder .impid ("123" ).mtype (2 ))));
267195
268196 // when
@@ -278,9 +206,6 @@ public void makeBidsShouldReturnVideoBidIfMediaTypeVideo() throws JsonProcessing
278206 public void makeBidsShouldReturnErrorIfMediaTypeInvalid () throws JsonProcessingException {
279207 // given
280208 final BidderCall <BidRequest > httpCall = givenHttpCall (
281- BidRequest .builder ()
282- .imp (singletonList (Imp .builder ().id ("123" ).build ()))
283- .build (),
284209 mapper .writeValueAsString (givenBidResponse (bidBuilder -> bidBuilder .impid ("123" ).mtype (4 ).id ("456" ))));
285210
286211 // when
@@ -296,28 +221,22 @@ public void makeBidsShouldReturnErrorIfMediaTypeInvalid() throws JsonProcessingE
296221 }
297222
298223 private static BidRequest givenBidRequest (
299- Function < Imp . ImpBuilder , Imp .ImpBuilder > impCustomizer ,
300- Function < BidRequest . BidRequestBuilder , BidRequest .BidRequestBuilder > requestCustomizer ) {
224+ UnaryOperator < Imp .ImpBuilder > impCustomizer ,
225+ UnaryOperator < BidRequest .BidRequestBuilder > requestCustomizer ) {
301226 return requestCustomizer .apply (BidRequest .builder ()
302227 .imp (singletonList (givenImp (impCustomizer ))))
303228 .build ();
304229 }
305230
306- private static BidRequest givenBidRequest (
307- Function <Imp .ImpBuilder , Imp .ImpBuilder > impCustomizer ) {
231+ private static BidRequest givenBidRequest (UnaryOperator <Imp .ImpBuilder > impCustomizer ) {
308232 return givenBidRequest (impCustomizer , identity ());
309233 }
310234
311- private static Imp givenImp (Function <Imp .ImpBuilder , Imp .ImpBuilder > impCustomizer ) {
312- return impCustomizer .apply (Imp .builder ()
313- .id ("123" ))
314- .banner (Banner .builder ().build ())
315- .ext (mapper .valueToTree (ExtPrebid .of (null ,
316- ExtImpSeedtag .of ("adUnitId" ))))
317- .build ();
235+ private static Imp givenImp (UnaryOperator <Imp .ImpBuilder > impCustomizer ) {
236+ return impCustomizer .apply (Imp .builder ().id ("123" )).build ();
318237 }
319238
320- private static BidResponse givenBidResponse (Function < Bid . BidBuilder , Bid .BidBuilder > bidCustomizer ) {
239+ private static BidResponse givenBidResponse (UnaryOperator < Bid .BidBuilder > bidCustomizer ) {
321240 return BidResponse .builder ()
322241 .cur ("USD" )
323242 .seatbid (singletonList (SeatBid .builder ()
@@ -326,8 +245,7 @@ private static BidResponse givenBidResponse(Function<Bid.BidBuilder, Bid.BidBuil
326245 .build ();
327246 }
328247
329- private static BidderCall <BidRequest > givenHttpCall (BidRequest bidRequest , String body ) {
330- return BidderCall .succeededHttp (HttpRequest .<BidRequest >builder ().payload (bidRequest ).build (),
331- HttpResponse .of (200 , null , body ), null );
248+ private static BidderCall <BidRequest > givenHttpCall (String responseBody ) {
249+ return BidderCall .succeededHttp (null , HttpResponse .of (200 , null , responseBody ), null );
332250 }
333251}
0 commit comments