1
1
package org .prebid .server .bidder .oms ;
2
2
3
3
import com .fasterxml .jackson .core .JsonProcessingException ;
4
+ import com .fasterxml .jackson .databind .node .ObjectNode ;
4
5
import com .iab .openrtb .request .Banner ;
5
6
import com .iab .openrtb .request .BidRequest ;
6
7
import com .iab .openrtb .request .Imp ;
15
16
import org .prebid .server .bidder .model .HttpRequest ;
16
17
import org .prebid .server .bidder .model .HttpResponse ;
17
18
import org .prebid .server .bidder .model .Result ;
19
+ import org .prebid .server .proto .openrtb .ext .ExtPrebid ;
20
+ import org .prebid .server .proto .openrtb .ext .request .omx .ExtImpOms ;
21
+ import org .prebid .server .proto .openrtb .ext .response .BidType ;
18
22
23
+ import java .util .Arrays ;
24
+ import java .util .Collections ;
19
25
import java .util .List ;
20
26
import java .util .function .Function ;
21
27
import java .util .function .UnaryOperator ;
24
30
import static java .util .function .UnaryOperator .identity ;
25
31
import static org .assertj .core .api .Assertions .assertThat ;
26
32
import static org .assertj .core .api .Assertions .assertThatIllegalArgumentException ;
27
- import static org .prebid .server .proto . openrtb . ext . response . BidType . banner ;
33
+ import static org .prebid .server .bidder . model . BidderError . badInput ;
28
34
29
35
public class OmsBidderTest extends VertxTest {
30
36
@@ -37,10 +43,40 @@ public void creationShouldFailOnInvalidEndpointUrl() {
37
43
assertThatIllegalArgumentException ().isThrownBy (() -> new OmsBidder ("invalid_url" , jacksonMapper ));
38
44
}
39
45
46
+ @ Test
47
+ public void makeHttpRequestsShouldReturnErrorWhenRequestHasInvalidImpression () {
48
+ // given
49
+ final ObjectNode invalidExt = mapper .valueToTree (ExtPrebid .of (null , mapper .createArrayNode ()));
50
+ final BidRequest bidRequest = givenBidRequest (impBuilder -> impBuilder .ext (invalidExt ));
51
+
52
+ // when
53
+ final Result <List <HttpRequest <BidRequest >>> result = target .makeHttpRequests (bidRequest );
54
+
55
+ // then
56
+ assertThat (result .getErrors ()).hasSize (1 ).first ().isEqualTo (badInput ("Invalid ext. Imp.Id: 123" ));
57
+ }
58
+
40
59
@ Test
41
60
public void makeHttpRequestsShouldCreateExpectedUrl () {
42
61
// given
43
- final BidRequest bidRequest = givenBidRequest (identity ());
62
+ final ExtImpOms impExt = ExtImpOms .of ("otherTagId" , 12345 );
63
+ final BidRequest bidRequest = givenBidRequest (impCustomizer -> impCustomizer .ext (givenImpExt (impExt )));
64
+
65
+ // when
66
+ final Result <List <HttpRequest <BidRequest >>> result = target .makeHttpRequests (bidRequest );
67
+
68
+ // then
69
+ assertThat (result .getErrors ()).isEmpty ();
70
+ assertThat (result .getValue ()).hasSize (1 )
71
+ .extracting (HttpRequest ::getUri )
72
+ .containsExactly ("https://randomurl.com?publisherId=otherTagId" );
73
+ }
74
+
75
+ @ Test
76
+ public void makeHttpRequestsShouldCreateExpectedUrlWithPublisherId () {
77
+ // given
78
+ final ExtImpOms impExt = ExtImpOms .of (null , 12345 );
79
+ final BidRequest bidRequest = givenBidRequest (impCustomizer -> impCustomizer .ext (givenImpExt (impExt )));
44
80
45
81
// when
46
82
final Result <List <HttpRequest <BidRequest >>> result = target .makeHttpRequests (bidRequest );
@@ -49,7 +85,43 @@ public void makeHttpRequestsShouldCreateExpectedUrl() {
49
85
assertThat (result .getErrors ()).isEmpty ();
50
86
assertThat (result .getValue ()).hasSize (1 )
51
87
.extracting (HttpRequest ::getUri )
52
- .containsExactly ("https://randomurl.com" );
88
+ .containsExactly ("https://randomurl.com?publisherId=12345" );
89
+ }
90
+
91
+ @ Test
92
+ public void makeHttpRequestsShouldIncludePidInRequestWhenPresent () {
93
+ // given
94
+ final ObjectNode impExt = mapper .createObjectNode ().put ("pid" , "examplePid" );
95
+ final BidRequest bidRequest = givenBidRequest (impBuilder -> impBuilder .ext (impExt ));
96
+
97
+ // when
98
+ final Result <List <HttpRequest <BidRequest >>> result = target .makeHttpRequests (bidRequest );
99
+
100
+ // then
101
+ assertThat (result .getErrors ()).isEmpty ();
102
+ assertThat (result .getValue ())
103
+ .extracting (HttpRequest ::getPayload )
104
+ .flatExtracting (BidRequest ::getImp )
105
+ .extracting (Imp ::getExt )
106
+ .containsExactly (impExt );
107
+ }
108
+
109
+ @ Test
110
+ public void makeHttpRequestsShouldIncludePublisherIdInRequestWhenPresent () {
111
+ // given
112
+ final ObjectNode impExt = mapper .createObjectNode ().put ("publisherId" , 12345 );
113
+ final BidRequest bidRequest = givenBidRequest (impBuilder -> impBuilder .ext (impExt ));
114
+
115
+ // when
116
+ final Result <List <HttpRequest <BidRequest >>> result = target .makeHttpRequests (bidRequest );
117
+
118
+ // then
119
+ assertThat (result .getErrors ()).isEmpty ();
120
+ assertThat (result .getValue ())
121
+ .extracting (HttpRequest ::getPayload )
122
+ .flatExtracting (BidRequest ::getImp )
123
+ .extracting (Imp ::getExt )
124
+ .containsExactly (impExt );
53
125
}
54
126
55
127
@ Test
@@ -101,32 +173,75 @@ public void makeBidsShouldReturnBannerBid() throws JsonProcessingException {
101
173
// given
102
174
final BidderCall <BidRequest > httpCall = givenHttpCall (
103
175
givenBidRequest (impBuilder -> impBuilder .banner (Banner .builder ().build ())),
104
- mapper .writeValueAsString (givenBidResponse (impBuilder -> impBuilder .impid ("123" ))));
176
+ mapper .writeValueAsString (givenBidResponse (impBuilder -> impBuilder .impid ("123" ). mtype ( 1 ) )));
105
177
106
178
// when
107
179
final Result <List <BidderBid >> result = target .makeBids (httpCall , null );
108
180
109
181
// then
110
182
assertThat (result .getErrors ()).isEmpty ();
111
- assertThat (result .getValue ())
112
- .containsExactly (BidderBid .of (givenBid (), banner , null ));
183
+ assertThat (result .getValue ()).extracting (BidderBid ::getType ).containsExactly (BidType .banner );
113
184
}
114
185
115
186
@ Test
116
- public void makeBidsShouldReturnBannerBidIfBannerAndVideoAndAudioAndNativeIsAbsentInRequestImp ()
117
- throws JsonProcessingException {
187
+ public void makeBidsShouldReturnVideoBid () throws JsonProcessingException {
118
188
// given
119
189
final BidderCall <BidRequest > httpCall = givenHttpCall (
120
- givenBidRequest (identity ( )),
121
- mapper .writeValueAsString (givenBidResponse (impBuilder -> impBuilder .impid ("123" ))));
190
+ givenBidRequest (impBuilder -> impBuilder . banner ( Banner . builder (). build () )),
191
+ mapper .writeValueAsString (givenBidResponse (impBuilder -> impBuilder .impid ("123" ). mtype ( 2 ) )));
122
192
123
193
// when
124
194
final Result <List <BidderBid >> result = target .makeBids (httpCall , null );
125
195
126
196
// then
127
197
assertThat (result .getErrors ()).isEmpty ();
128
- assertThat (result .getValue ())
129
- .containsExactly (BidderBid .of (givenBid (), banner , null ));
198
+ assertThat (result .getValue ()).extracting (BidderBid ::getType ).containsExactly (BidType .video );
199
+ }
200
+
201
+ @ Test
202
+ public void makeBidsShouldReturnErrorWhenMTypeIsUnsupported () throws JsonProcessingException {
203
+ // given
204
+ final BidderCall <BidRequest > httpCall = givenHttpCall (
205
+ givenBidRequest (impBuilder -> impBuilder .banner (Banner .builder ().build ())),
206
+ mapper .writeValueAsString (givenBidResponse (impBuilder -> impBuilder .impid ("123" ).mtype (99 ))));
207
+
208
+ // when
209
+ final Result <List <BidderBid >> result = target .makeBids (httpCall , null );
210
+
211
+ // then
212
+ assertThat (result .getErrors ()).hasSize (1 );
213
+ assertThat (result .getErrors ().get (0 ).getMessage ()).contains ("Unsupported mType 99" );
214
+ assertThat (result .getValue ()).isEmpty ();
215
+ }
216
+
217
+ @ Test
218
+ public void makeBidsShouldExtractAllBidsFromMultipleSeatBids () throws JsonProcessingException {
219
+ // given
220
+ final Bid bid1 = Bid .builder ().impid ("bid1" ).mtype (1 ).build ();
221
+ final Bid bid2 = Bid .builder ().impid ("bid2" ).mtype (1 ).build ();
222
+ final Bid bid3 = Bid .builder ().impid ("bid3" ).mtype (2 ).build ();
223
+
224
+ final SeatBid seatBid1 = SeatBid .builder ().bid (Arrays .asList (bid1 , bid2 )).build ();
225
+ final SeatBid seatBid2 = SeatBid .builder ().bid (Collections .singletonList (bid3 )).build ();
226
+
227
+ final BidResponse bidResponse = BidResponse .builder ()
228
+ .seatbid (Arrays .asList (seatBid1 , seatBid2 ))
229
+ .cur ("USD" )
230
+ .build ();
231
+ final String bidResponseJson = mapper .writeValueAsString (bidResponse );
232
+
233
+ final BidRequest bidRequest = givenBidRequest (impBuilder -> impBuilder .banner (Banner .builder ().build ()));
234
+ final BidderCall <BidRequest > httpCall = givenHttpCall (bidRequest , bidResponseJson );
235
+
236
+ // when
237
+ final Result <List <BidderBid >> result = target .makeBids (httpCall , bidRequest );
238
+
239
+ // then
240
+ assertThat (result .getErrors ()).isEmpty ();
241
+ assertThat (result .getValue ()).hasSize (3 )
242
+ .extracting (BidderBid ::getType )
243
+ .containsExactly (BidType .banner , BidType .banner , BidType .video );
244
+ assertThat (result .getValue ()).extracting (BidderBid ::getBidCurrency ).containsOnly ("USD" );
130
245
}
131
246
132
247
private static BidRequest givenBidRequest (UnaryOperator <Imp .ImpBuilder > impCustomizer ) {
@@ -148,14 +263,14 @@ private static BidResponse givenBidResponse(Function<Bid.BidBuilder, Bid.BidBuil
148
263
.build ();
149
264
}
150
265
151
- private static Bid givenBid () {
152
- return Bid .builder ().impid ("123" ).build ();
153
- }
154
-
155
266
private static BidderCall <BidRequest > givenHttpCall (BidRequest bidRequest , String body ) {
156
267
return BidderCall .succeededHttp (
157
268
HttpRequest .<BidRequest >builder ().payload (bidRequest ).build (),
158
269
HttpResponse .of (200 , null , body ),
159
270
null );
160
271
}
272
+
273
+ private ObjectNode givenImpExt (ExtImpOms impExt ) {
274
+ return mapper .valueToTree (ExtPrebid .of (null , impExt ));
275
+ }
161
276
}
0 commit comments