11package org .prebid .server .bidder .nextmillennium ;
22
33import com .fasterxml .jackson .core .JsonProcessingException ;
4- import com .fasterxml .jackson .databind .node .ObjectNode ;
54import com .iab .openrtb .request .App ;
65import com .iab .openrtb .request .Banner ;
76import com .iab .openrtb .request .BidRequest ;
2423import org .prebid .server .bidder .model .HttpRequest ;
2524import org .prebid .server .bidder .model .HttpResponse ;
2625import org .prebid .server .bidder .model .Result ;
26+ import org .prebid .server .bidder .nextmillennium .proto .NextMillenniumExt ;
27+ import org .prebid .server .bidder .nextmillennium .proto .NextMillenniumExtBidder ;
2728import org .prebid .server .proto .openrtb .ext .ExtPrebid ;
2829import org .prebid .server .proto .openrtb .ext .request .ExtRequest ;
2930import org .prebid .server .proto .openrtb .ext .request .ExtRequestPrebid ;
@@ -117,8 +118,8 @@ public void makeHttpRequestsShouldUseImpExtBidderPlacementIdForStoredRequestId()
117118 // given
118119 final BidRequest bidRequest = givenBidRequest (
119120 identity (),
120- givenImpWithExt (identity (), ExtImpNextMillennium . of ("placement1" , null , null , null )),
121- givenImpWithExt (identity (), ExtImpNextMillennium . of ("placement2" , null , null , null )));
121+ givenImpWithExt (identity (), givenExtImpWithPlacementId ("placement1" )),
122+ givenImpWithExt (identity (), givenExtImpWithPlacementId ("placement2" )));
122123
123124 // when
124125 final Result <List <HttpRequest <BidRequest >>> result = target .makeHttpRequests (bidRequest );
@@ -139,8 +140,8 @@ public void makeHttpRequestsShouldUseImpExtBidderGroupIdForStoredRequestId() {
139140 // given
140141 final BidRequest bidRequest = givenBidRequest (
141142 identity (),
142- givenImpWithExt (identity (), ExtImpNextMillennium . of ( null , "group1" , null , null )),
143- givenImpWithExt (identity (), ExtImpNextMillennium . of ( null , "group2" , null , null )));
143+ givenImpWithExt (identity (), givenExtImpWithGroupId ( "group1" )),
144+ givenImpWithExt (identity (), givenExtImpWithGroupId ( "group2" )));
144145
145146 // when
146147 final Result <List <HttpRequest <BidRequest >>> result = target .makeHttpRequests (bidRequest );
@@ -169,10 +170,10 @@ public void makeHttpRequestsShouldUseFirstImpBannerFirstFormatForStoredRequestId
169170 .w (5 )
170171 .h (6 )
171172 .build ()),
172- ExtImpNextMillennium . of ( null , "group1" , null , null )),
173+ givenExtImpWithGroupId ( "group1" )),
173174 givenImpWithExt (
174175 imp -> imp .banner (Banner .builder ().w (7 ).h (8 ).build ()),
175- ExtImpNextMillennium . of ( null , "group2" , null , null )));
176+ givenExtImpWithGroupId ( "group2" )));
176177
177178 // when
178179 final Result <List <HttpRequest <BidRequest >>> result = target .makeHttpRequests (bidRequest );
@@ -209,17 +210,23 @@ public void makeHttpRequestsShouldIncludeAdSlotsAndAllowedAdsInRequestAndImpExt(
209210
210211 final BidRequest actualRequest = result .getValue ().getFirst ().getPayload ();
211212
212- final ObjectNode requestExtNode = mapper .valueToTree (actualRequest .getExt ());
213- assertThat (requestExtNode .at ("/nextMillennium/adSlots/0" ).asText ()).isEqualTo ("slot1" );
214- assertThat (requestExtNode .at ("/nextMillennium/adSlots/1" ).asText ()).isEqualTo ("slot2" );
215- assertThat (requestExtNode .at ("/nextMillennium/allowedAds/0" ).asText ()).isEqualTo ("ad1" );
216- assertThat (requestExtNode .at ("/nextMillennium/allowedAds/1" ).asText ()).isEqualTo ("ad2" );
217-
218- final ObjectNode impExtNode = (ObjectNode ) actualRequest .getImp ().getFirst ().getExt ();
219- assertThat (impExtNode .at ("/nextMillennium/adSlots/0" ).asText ()).isEqualTo ("slot1" );
220- assertThat (impExtNode .at ("/nextMillennium/adSlots/1" ).asText ()).isEqualTo ("slot2" );
221- assertThat (impExtNode .at ("/nextMillennium/allowedAds/0" ).asText ()).isEqualTo ("ad1" );
222- assertThat (impExtNode .at ("/nextMillennium/allowedAds/1" ).asText ()).isEqualTo ("ad2" );
213+ final NextMillenniumExtBidder requestExt = jacksonMapper .mapper ()
214+ .convertValue (
215+ jacksonMapper .mapper ().convertValue (actualRequest .getExt (), NextMillenniumExt .class ).getNextMillennium (),
216+ NextMillenniumExtBidder .class );
217+
218+ final NextMillenniumExtBidder impExt = jacksonMapper .mapper ()
219+ .convertValue (
220+ jacksonMapper .mapper ().convertValue (actualRequest .getImp ().getFirst ().getExt (), NextMillenniumExt .class ).getNextMillennium (),
221+ NextMillenniumExtBidder .class );
222+
223+ assertThat (requestExt )
224+ .extracting (NextMillenniumExtBidder ::getAdSlots , NextMillenniumExtBidder ::getAllowedAds )
225+ .containsExactly (adSlots , allowedAds );
226+
227+ assertThat (impExt )
228+ .extracting (NextMillenniumExtBidder ::getAdSlots , NextMillenniumExtBidder ::getAllowedAds )
229+ .containsExactly (adSlots , allowedAds );
223230 }
224231
225232 @ Test
@@ -229,12 +236,12 @@ public void makeHttpRequestsShouldUseFirstImpBannerSizeForStoredRequestIds() {
229236 identity (),
230237 givenImpWithExt (
231238 imp -> imp .banner (Banner .builder ().w (7 ).h (8 ).build ()),
232- ExtImpNextMillennium . of ( null , "group1" , null , null )),
239+ givenExtImpWithGroupId ( "group1" )),
233240 givenImpWithExt (
234241 imp -> imp .banner (Banner .builder ()
235242 .format (singletonList (Format .builder ().w (1 ).h (2 ).build ()))
236243 .build ()),
237- ExtImpNextMillennium . of ( null , "group2" , null , null )));
244+ givenExtImpWithGroupId ( "group2" )));
238245
239246 // when
240247 final Result <List <HttpRequest <BidRequest >>> result = target .makeHttpRequests (bidRequest );
@@ -255,8 +262,8 @@ public void makeHttpRequestsShouldUseAppDomainForStoredRequestId() {
255262 // given
256263 final BidRequest bidRequest = givenBidRequest (
257264 request -> request .app (App .builder ().domain ("appDomain" ).build ()),
258- givenImpWithExt (identity (), ExtImpNextMillennium . of ( null , "group1" , null , null )),
259- givenImpWithExt (identity (), ExtImpNextMillennium . of ( null , "group2" , null , null )));
265+ givenImpWithExt (identity (), givenExtImpWithGroupId ( "group1" )),
266+ givenImpWithExt (identity (), givenExtImpWithGroupId ( "group2" )));
260267
261268 // when
262269 final Result <List <HttpRequest <BidRequest >>> result = target .makeHttpRequests (bidRequest );
@@ -277,8 +284,8 @@ public void makeHttpRequestsShouldUseSiteDomainForStoredRequestId() {
277284 // given
278285 final BidRequest bidRequest = givenBidRequest (
279286 request -> request .site (Site .builder ().domain ("siteDomain" ).build ()),
280- givenImpWithExt (identity (), ExtImpNextMillennium . of ("placement1" , "group1" , null , null )),
281- givenImpWithExt (identity (), ExtImpNextMillennium . of ("placement2" , "group2" , null , null )));
287+ givenImpWithExt (identity (), givenExtImpWithPlacementIdAndGroupId ("placement1" , "group1" )),
288+ givenImpWithExt (identity (), givenExtImpWithPlacementIdAndGroupId ("placement2" , "group2" )));
282289
283290 // when
284291 final Result <List <HttpRequest <BidRequest >>> result = target .makeHttpRequests (bidRequest );
@@ -638,4 +645,16 @@ private static Imp givenImpWithExt(UnaryOperator<Imp.ImpBuilder> impCustomizer,
638645 return givenImp (impCustomizer .andThen (imp -> imp .ext (mapper .valueToTree (
639646 ExtPrebid .of (null , extImpNextMillennium ))))::apply );
640647 }
648+
649+ private static ExtImpNextMillennium givenExtImpWithGroupId (String groupId ) {
650+ return ExtImpNextMillennium .of (null , groupId , null , null );
651+ }
652+
653+ private static ExtImpNextMillennium givenExtImpWithPlacementId (String placementId ) {
654+ return ExtImpNextMillennium .of (placementId , null , null , null );
655+ }
656+
657+ private static ExtImpNextMillennium givenExtImpWithPlacementIdAndGroupId (String placementId , String groupId ) {
658+ return ExtImpNextMillennium .of (placementId , groupId , null , null );
659+ }
641660}
0 commit comments