43
43
import org .prebid .server .execution .TimeoutFactory ;
44
44
import org .prebid .server .proto .openrtb .ext .ExtPrebid ;
45
45
import org .prebid .server .proto .openrtb .ext .request .ExtGranularityRange ;
46
+ import org .prebid .server .proto .openrtb .ext .request .ExtImp ;
47
+ import org .prebid .server .proto .openrtb .ext .request .ExtImpPrebid ;
46
48
import org .prebid .server .proto .openrtb .ext .request .ExtMediaTypePriceGranularity ;
49
+ import org .prebid .server .proto .openrtb .ext .request .ExtOptions ;
47
50
import org .prebid .server .proto .openrtb .ext .request .ExtPriceGranularity ;
48
51
import org .prebid .server .proto .openrtb .ext .request .ExtRequestTargeting ;
52
+ import org .prebid .server .proto .openrtb .ext .request .ExtStoredRequest ;
49
53
import org .prebid .server .proto .openrtb .ext .response .CacheAsset ;
50
54
import org .prebid .server .proto .openrtb .ext .response .Events ;
51
55
import org .prebid .server .proto .openrtb .ext .response .ExtBidPrebid ;
54
58
import org .prebid .server .proto .openrtb .ext .response .ExtHttpCall ;
55
59
import org .prebid .server .proto .openrtb .ext .response .ExtResponseCache ;
56
60
import org .prebid .server .settings .model .Account ;
61
+ import org .prebid .server .settings .model .VideoStoredDataResult ;
57
62
58
63
import java .io .IOException ;
59
64
import java .math .BigDecimal ;
60
65
import java .time .Clock ;
61
66
import java .time .Instant ;
62
67
import java .time .ZoneId ;
68
+ import java .util .Arrays ;
63
69
import java .util .List ;
64
70
import java .util .Map ;
65
71
@@ -98,6 +104,8 @@ public class BidResponseCreatorTest extends VertxTest {
98
104
private BidderCatalog bidderCatalog ;
99
105
@ Mock
100
106
private EventsService eventsService ;
107
+ @ Mock
108
+ private StoredRequestProcessor storedRequestProcessor ;
101
109
102
110
private Timeout timeout ;
103
111
@@ -109,7 +117,10 @@ public void setUp() {
109
117
given (cacheService .getEndpointPath ()).willReturn ("testPath" );
110
118
given (cacheService .getCachedAssetURLTemplate ()).willReturn ("uuid=" );
111
119
112
- bidResponseCreator = new BidResponseCreator (cacheService , bidderCatalog , eventsService );
120
+ given (storedRequestProcessor .videoStoredDataResult (any (), any (), any ()))
121
+ .willReturn (Future .succeededFuture (VideoStoredDataResult .empty ()));
122
+
123
+ bidResponseCreator = new BidResponseCreator (cacheService , bidderCatalog , eventsService , storedRequestProcessor );
113
124
114
125
timeout = new TimeoutFactory (Clock .fixed (Instant .now (), ZoneId .systemDefault ())).create (500 );
115
126
}
@@ -382,7 +393,7 @@ public void shouldSetExpectedResponseSeatBidAndBidFields() {
382
393
.price (BigDecimal .ONE )
383
394
.adm ("adm" )
384
395
.ext (mapper .valueToTree (ExtPrebid .of (
385
- ExtBidPrebid .of (banner , null , null , null , null ), singletonMap ("bidExt" , 1 ))))
396
+ ExtBidPrebid .of (banner , null , null , null , null , null ), singletonMap ("bidExt" , 1 ))))
386
397
.build ()))
387
398
.build ());
388
399
@@ -516,7 +527,7 @@ public void shouldTolerateMissingExtInSeatBidAndBid() {
516
527
.containsOnly (Bid .builder ()
517
528
.id ("bidId" )
518
529
.price (BigDecimal .ONE )
519
- .ext (mapper .valueToTree (ExtPrebid .of (ExtBidPrebid .of (banner , null , null , null , null ), null )))
530
+ .ext (mapper .valueToTree (ExtPrebid .of (ExtBidPrebid .of (banner , null , null , null , null , null ), null )))
520
531
.build ());
521
532
522
533
verify (cacheService , never ()).cacheBidsOpenrtb (anyList (), anyList (), any (), any (), any ());
@@ -924,6 +935,106 @@ public void shouldPopulateBidResponseExtension() throws JsonProcessingException
924
935
verify (cacheService ).cacheBidsOpenrtb (anyList (), anyList (), any (), any (), any ());
925
936
}
926
937
938
+ @ Test
939
+ public void impToStoredVideoJsonShouldTolerateWhenStoredVideoFetchIsFailed () {
940
+ // given
941
+ final Imp imp = Imp .builder ().id ("impId1" ).ext (
942
+ Json .mapper .valueToTree (
943
+ ExtImp .of (ExtImpPrebid .of (ExtStoredRequest .of ("st1" ), ExtOptions .of (true ), null , null ), null )))
944
+ .build ();
945
+ final BidRequest bidRequest = givenBidRequest (imp );
946
+
947
+ final Bid bid = Bid .builder ().id ("bidId1" ).impid ("impId1" ).price (BigDecimal .valueOf (5.67 )).build ();
948
+ final List <BidderResponse > bidderResponses = singletonList (BidderResponse .of ("bidder1" ,
949
+ givenSeatBid (BidderBid .of (bid , banner , "USD" )), 100 ));
950
+
951
+ given (storedRequestProcessor .videoStoredDataResult (any (), any (), any ())).willReturn (Future .failedFuture ("Fetch failed" ));
952
+
953
+ // when
954
+ final Future <BidResponse > result =
955
+ bidResponseCreator .create (bidderResponses , bidRequest , null , CACHE_INFO , ACCOUNT , timeout , false );
956
+
957
+ // then
958
+ verify (storedRequestProcessor ).videoStoredDataResult (eq (singletonList (imp )), any (), eq (timeout ));
959
+
960
+ assertThat (result .succeeded ()).isTrue ();
961
+ }
962
+
963
+ @ Test
964
+ public void impToStoredVideoJsonShouldInjectStoredVideoWhenExtOptionsIsTrueAndVideoNotEmpty () {
965
+ // given
966
+ final Imp imp1 = Imp .builder ().id ("impId1" ).ext (
967
+ Json .mapper .valueToTree (
968
+ ExtImp .of (ExtImpPrebid .of (ExtStoredRequest .of ("st1" ), ExtOptions .of (true ), null , null ), null )))
969
+ .build ();
970
+ final Imp imp2 = Imp .builder ().id ("impId2" ).ext (
971
+ Json .mapper .valueToTree (
972
+ ExtImp .of (ExtImpPrebid .of (ExtStoredRequest .of ("st2" ), ExtOptions .of (false ), null , null ), null )))
973
+ .build ();
974
+ final Imp imp3 = Imp .builder ().id ("impId3" ).ext (
975
+ Json .mapper .valueToTree (
976
+ ExtImp .of (ExtImpPrebid .of (ExtStoredRequest .of ("st3" ), ExtOptions .of (true ), null , null ), null )))
977
+ .build ();
978
+ final BidRequest bidRequest = givenBidRequest (imp1 , imp2 , imp3 );
979
+
980
+ final Bid bid1 = Bid .builder ().id ("bidId1" ).impid ("impId1" ).price (BigDecimal .valueOf (5.67 )).build ();
981
+ final Bid bid2 = Bid .builder ().id ("bidId2" ).impid ("impId2" ).price (BigDecimal .valueOf (2 )).build ();
982
+ final Bid bid3 = Bid .builder ().id ("bidId3" ).impid ("impId3" ).price (BigDecimal .valueOf (3 )).build ();
983
+ final List <BidderBid > bidderBids = Arrays .asList (
984
+ BidderBid .of (bid1 , banner , "USD" ),
985
+ BidderBid .of (bid2 , banner , "USD" ),
986
+ BidderBid .of (bid3 , banner , "USD" ));
987
+ final List <BidderResponse > bidderResponses = singletonList (
988
+ BidderResponse .of ("bidder1" , BidderSeatBid .of (bidderBids , emptyList (), emptyList ()), 100 ));
989
+
990
+ final Video storedVideo = Video .builder ().maxduration (100 ).h (2 ).w (2 ).build ();
991
+ given (storedRequestProcessor .videoStoredDataResult (any (), any (), any ()))
992
+ .willReturn (Future .succeededFuture (VideoStoredDataResult .of (singletonMap ("impId1" , storedVideo ), emptyList ())));
993
+
994
+ // when
995
+ final Future <BidResponse > result =
996
+ bidResponseCreator .create (bidderResponses , bidRequest , null , CACHE_INFO , ACCOUNT , timeout , false );
997
+
998
+ // then
999
+ verify (storedRequestProcessor ).videoStoredDataResult (eq (Arrays .asList (imp1 , imp3 )), any (), eq (timeout ));
1000
+
1001
+ assertThat (result .result ().getSeatbid ())
1002
+ .flatExtracting (SeatBid ::getBid ).hasSize (3 )
1003
+ .extracting (extractedBid -> toExtPrebid (extractedBid .getExt ()).getPrebid ().getStoredRequestAttributes ())
1004
+ .containsOnly (storedVideo , null , null );
1005
+ }
1006
+
1007
+ @ Test
1008
+ public void impToStoredVideoJsonShouldAddErrorsWithPrebidBidderWhenStoredVideoRequestFailed () {
1009
+ // given
1010
+ final Imp imp1 = Imp .builder ().id ("impId1" ).ext (
1011
+ Json .mapper .valueToTree (
1012
+ ExtImp .of (ExtImpPrebid .of (ExtStoredRequest .of ("st1" ), ExtOptions .of (true ), null , null ), null )))
1013
+ .build ();
1014
+ final BidRequest bidRequest = givenBidRequest (imp1 );
1015
+
1016
+ final Bid bid1 = Bid .builder ().id ("bidId1" ).impid ("impId1" ).price (BigDecimal .valueOf (5.67 )).build ();
1017
+ final List <BidderBid > bidderBids = Arrays .asList (
1018
+ BidderBid .of (bid1 , banner , "USD" ));
1019
+ final List <BidderResponse > bidderResponses = singletonList (
1020
+ BidderResponse .of ("bidder1" , BidderSeatBid .of (bidderBids , emptyList (), emptyList ()), 100 ));
1021
+
1022
+ given (storedRequestProcessor .videoStoredDataResult (any (), any (), any ()))
1023
+ .willReturn (Future .failedFuture ("Bad timeout" ));
1024
+
1025
+ // when
1026
+ final Future <BidResponse > result =
1027
+ bidResponseCreator .create (bidderResponses , bidRequest , null , CACHE_INFO , ACCOUNT , timeout , false );
1028
+
1029
+ // then
1030
+ verify (storedRequestProcessor ).videoStoredDataResult (eq (singletonList (imp1 )), any (), eq (timeout ));
1031
+
1032
+ assertThat (result .result ().getExt ()).isEqualTo (
1033
+ mapper .valueToTree (ExtBidResponse .of (null , singletonMap (
1034
+ "prebid" , singletonList (ExtBidderError .of (BidderError .Type .generic .getCode (),
1035
+ "Bad timeout" ))), singletonMap ("bidder1" , 100 ), 1000L , null )));
1036
+ }
1037
+
927
1038
@ Test
928
1039
public void shouldProcessRequestAndAddErrorAboutDeprecatedBidder () {
929
1040
// given
0 commit comments