22
33import com .fasterxml .jackson .core .JsonProcessingException ;
44import com .fasterxml .jackson .databind .node .BooleanNode ;
5+ import com .fasterxml .jackson .databind .node .ObjectNode ;
56import com .iab .openrtb .request .Banner ;
67import com .iab .openrtb .request .BidRequest ;
78import com .iab .openrtb .request .Device ;
@@ -917,15 +918,101 @@ public void makeBidsShouldPopulateBidWidthWithNullWhenInlineContentsDataWidthEmp
917918 }
918919
919920 @ Test
920- public void makeBidsShouldPopulateBidHeightWithZeroWhenInlineContentsIsPresent () throws JsonProcessingException {
921+ public void makeBidsShouldPopulateBidDefaultStandardHeightWhenInlineCustomDataIsAbsent ()
922+ throws JsonProcessingException {
923+
921924 // given
922- final BidRequest bidRequest = givenBidRequest (identity ());
925+ final BidRequest bidRequest = givenBidRequest (givenImp (identity (), extImp -> extImp
926+ .options (ExtImpFlippOptions .of (false , null , null ))));
927+
928+ final ObjectNode customData = mapper .createObjectNode ()
929+ .put ("compactHeight" , 20 )
930+ .put ("standardHeight" , 30 );
923931
924- // and
925932 final BidderCall <CampaignRequestBody > httpCall = givenHttpCall (CampaignRequestBody .builder ().build (),
926- mapper .writeValueAsString (givenCampaignResponseBody (inlineBuilder ->
927- inlineBuilder .contents (singletonList (
928- Content .of ("any" , "custom" , Data .of (null , 10 , 20 ), "type" ))))));
933+ mapper .writeValueAsString (givenCampaignResponseBody (inlineBuilder -> inlineBuilder
934+ .contents (singletonList (Content .of (
935+ "any" , "custom" , Data .of (null , 10 , 20 ), "type" ))))));
936+
937+ // when
938+ final Result <List <BidderBid >> result = target .makeBids (httpCall , bidRequest );
939+
940+ // then
941+ assertThat (result .getErrors ()).isEmpty ();
942+ assertThat (result .getValue ()).hasSize (1 )
943+ .extracting (BidderBid ::getBid )
944+ .extracting (Bid ::getH )
945+ .containsExactly (2400 );
946+ }
947+
948+ @ Test
949+ public void makeBidsShouldPopulateBidDefaultCompactHeightWhenInlineCustomDataIsAbsent ()
950+ throws JsonProcessingException {
951+
952+ // given
953+ final BidRequest bidRequest = givenBidRequest (givenImp (identity (), extImp -> extImp
954+ .options (ExtImpFlippOptions .of (true , null , null ))));
955+
956+ final BidderCall <CampaignRequestBody > httpCall = givenHttpCall (CampaignRequestBody .builder ().build (),
957+ mapper .writeValueAsString (givenCampaignResponseBody (inlineBuilder -> inlineBuilder
958+ .contents (singletonList (Content .of (
959+ "any" , "custom" , Data .of (null , 10 , 20 ), "type" ))))));
960+
961+ // when
962+ final Result <List <BidderBid >> result = target .makeBids (httpCall , bidRequest );
963+
964+ // then
965+ assertThat (result .getErrors ()).isEmpty ();
966+ assertThat (result .getValue ()).hasSize (1 )
967+ .extracting (BidderBid ::getBid )
968+ .extracting (Bid ::getH )
969+ .containsExactly (600 );
970+ }
971+
972+ @ Test
973+ public void makeBidsShouldPopulateBidCompactHeightFromCustomDataWhenStartCompactIsTrue ()
974+ throws JsonProcessingException {
975+
976+ // given
977+ final BidRequest bidRequest = givenBidRequest (givenImp (identity (), extImp -> extImp
978+ .options (ExtImpFlippOptions .of (true , null , null ))));
979+
980+ final ObjectNode customData = mapper .createObjectNode ()
981+ .put ("compactHeight" , 20 )
982+ .put ("standardHeight" , 30 );
983+
984+ final BidderCall <CampaignRequestBody > httpCall = givenHttpCall (CampaignRequestBody .builder ().build (),
985+ mapper .writeValueAsString (givenCampaignResponseBody (inlineBuilder -> inlineBuilder
986+ .contents (singletonList (Content .of (
987+ "any" , "custom" , Data .of (customData , 10 , 20 ), "type" ))))));
988+
989+ // when
990+ final Result <List <BidderBid >> result = target .makeBids (httpCall , bidRequest );
991+
992+ // then
993+ assertThat (result .getErrors ()).isEmpty ();
994+ assertThat (result .getValue ()).hasSize (1 )
995+ .extracting (BidderBid ::getBid )
996+ .extracting (Bid ::getH )
997+ .containsExactly (20 );
998+ }
999+
1000+ @ Test
1001+ public void makeBidsShouldPopulateBidStandardHeightFromCustomDataWhenStartCompactIsFalse ()
1002+ throws JsonProcessingException {
1003+
1004+ // given
1005+ final BidRequest bidRequest = givenBidRequest (givenImp (identity (), extImp -> extImp
1006+ .options (ExtImpFlippOptions .of (false , null , null ))));
1007+
1008+ final ObjectNode customData = mapper .createObjectNode ()
1009+ .put ("compactHeight" , 20 )
1010+ .put ("standardHeight" , 30 );
1011+
1012+ final BidderCall <CampaignRequestBody > httpCall = givenHttpCall (CampaignRequestBody .builder ().build (),
1013+ mapper .writeValueAsString (givenCampaignResponseBody (inlineBuilder -> inlineBuilder
1014+ .contents (singletonList (Content .of (
1015+ "any" , "custom" , Data .of (customData , 10 , 20 ), "type" ))))));
9291016
9301017 // when
9311018 final Result <List <BidderBid >> result = target .makeBids (httpCall , bidRequest );
@@ -935,7 +1022,7 @@ public void makeBidsShouldPopulateBidHeightWithZeroWhenInlineContentsIsPresent()
9351022 assertThat (result .getValue ()).hasSize (1 )
9361023 .extracting (BidderBid ::getBid )
9371024 .extracting (Bid ::getH )
938- .containsExactly (0 );
1025+ .containsExactly (30 );
9391026 }
9401027
9411028 @ Test
@@ -1011,14 +1098,27 @@ private static BidRequest givenBidRequest(UnaryOperator<Imp.ImpBuilder> impCusto
10111098 return givenBidRequest (identity (), impCustomizer );
10121099 }
10131100
1101+ private static BidRequest givenBidRequest (Imp givenImp ) {
1102+ return BidRequest .builder ()
1103+ .device (Device .builder ().ip ("anyId" ).build ())
1104+ .imp (singletonList (givenImp ))
1105+ .build ();
1106+ }
1107+
10141108 private static Imp givenImp (UnaryOperator <Imp .ImpBuilder > impCustomizer ) {
1109+ return givenImp (impCustomizer , identity ());
1110+ }
1111+
1112+ private static Imp givenImp (UnaryOperator <Imp .ImpBuilder > impCustomizer ,
1113+ UnaryOperator <ExtImpFlipp .ExtImpFlippBuilder > extImpBuilder ) {
1114+
10151115 return impCustomizer .apply (Imp .builder ()
10161116 .id ("123" )
10171117 .banner (Banner .builder ().w (23 ).h (25 ).build ())
1018- .ext (mapper .valueToTree (ExtPrebid .of (null , ExtImpFlipp .builder ()
1118+ .ext (mapper .valueToTree (ExtPrebid .of (null , extImpBuilder . apply ( ExtImpFlipp .builder ()
10191119 .publisherNameIdentifier ("publisherName" )
10201120 .creativeType ("Any" )
1021- .zoneIds (List .of (12 ))
1121+ .zoneIds (List .of (12 )))
10221122 .build ()))))
10231123 .build ();
10241124 }
0 commit comments