11package org.prebid.server.functional.tests
22
33import org.prebid.server.functional.model.config.AccountAuctionConfig
4+ import org.prebid.server.functional.model.config.AccountCacheConfig
45import org.prebid.server.functional.model.config.AccountConfig
56import org.prebid.server.functional.model.config.AccountEventsConfig
67import org.prebid.server.functional.model.db.Account
@@ -14,6 +15,8 @@ import org.prebid.server.functional.model.response.auction.Adm
1415import org.prebid.server.functional.model.response.auction.BidResponse
1516import org.prebid.server.functional.util.PBSUtils
1617
18+ import static org.prebid.server.functional.model.AccountStatus.ACTIVE
19+ import static org.prebid.server.functional.model.bidder.BidderName.GENERIC
1720import static org.prebid.server.functional.model.response.auction.MediaType.BANNER
1821import static org.prebid.server.functional.model.response.auction.MediaType.VIDEO
1922
@@ -42,6 +45,9 @@ class CacheSpec extends BaseSpec {
4245 def creative = encodeXml(Vast . getDefaultVastModel(PBSUtils . randomString))
4346 def request = VtrackRequest . getDefaultVtrackRequest(creative)
4447
48+ and : " Flush metrics"
49+ flushMetrics(defaultPbsService)
50+
4551 when : " PBS processes vtrack request"
4652 defaultPbsService. sendVtrackRequest(request, accountId)
4753
@@ -468,6 +474,9 @@ class CacheSpec extends BaseSpec {
468474 " <${ impression} > <![CDATA[ ]]> </${ impression} ><Creatives></Creatives></${ wrapper} ></Ad></VAST>"
469475 def request = VtrackRequest . getDefaultVtrackRequest(creative)
470476
477+ and : " Flush metrics"
478+ flushMetrics(defaultPbsService)
479+
471480 when : " PBS processes vtrack request"
472481 defaultPbsService. sendVtrackRequest(request, accountId)
473482
@@ -492,4 +501,130 @@ class CacheSpec extends BaseSpec {
492501 PBSUtils . getRandomCase(" inline " ) | " ${ PBSUtils.getRandomCase(" impression ")} $PBSUtils . randomNumber "
493502 " inline ${ PBSUtils.getRandomString()} " | " ImpreSSion "
494503 }
504+
505+ def " PBS should cache bids and add targeting values when account cache config #accountAuctionConfig" () {
506+ given : " Current value of metric prebid_cache.requests.ok"
507+ def initialValue = getCurrentMetricValue(defaultPbsService, CACHE_REQUEST_OK_GLOBAL_METRIC )
508+
509+ and : " Default BidRequest with cache, targeting"
510+ def bidRequest = BidRequest . getDefaultVideoRequest(). tap {
511+ it. enableCache()
512+ }
513+
514+ and : " Account in the DB"
515+ def accountConfig = new AccountConfig (status : ACTIVE , auction : accountAuctionConfig)
516+ def account = new Account (uuid : bidRequest. accountId, config : accountConfig)
517+ accountDao. save(account)
518+
519+ and : " Default bid response"
520+ def presetBidResponse = BidResponse . getDefaultBidResponse(bidRequest)
521+ bidder. setResponse(bidRequest. id, presetBidResponse)
522+
523+ and : " Flush metrics"
524+ flushMetrics(defaultPbsService)
525+
526+ when : " PBS processes auction request"
527+ def response = defaultPbsService. sendAuctionRequest(bidRequest)
528+
529+ then : " PBS should call PBC"
530+ assert prebidCache. getRequestCount(bidRequest. imp[0 ]. id) == 1
531+
532+ and : " PBS response targeting contains bidder specific keys"
533+ def targetingKeyMap = response. seatbid?. first()?. bid?. first()?. ext?. prebid?. targeting
534+ assert targetingKeyMap. containsKey(' hb_cache_id' )
535+ assert targetingKeyMap. containsKey(" hb_cache_id_${ GENERIC} " . toString())
536+ assert targetingKeyMap. containsKey(' hb_uuid' )
537+ assert targetingKeyMap. containsKey(" hb_uuid_${ GENERIC} " . toString())
538+
539+ and : " Metrics should be updated"
540+ def metrics = defaultPbsService. sendCollectedMetricsRequest()
541+ assert metrics[CACHE_REQUEST_OK_GLOBAL_METRIC ] == initialValue + 1
542+ assert metrics[CACHE_REQUEST_OK_ACCOUNT_METRIC . formatted(bidRequest. accountId)] == 1
543+
544+ where :
545+ accountAuctionConfig << [
546+ new AccountAuctionConfig (),
547+ new AccountAuctionConfig (cache : new AccountCacheConfig ()),
548+ new AccountAuctionConfig (cache : new AccountCacheConfig (enabled : null )),
549+ new AccountAuctionConfig (cache : new AccountCacheConfig (enabled : true ))
550+ ]
551+ }
552+
553+ def " PBS shouldn't cache bids and add targeting values when account cache config disabled" () {
554+ given : " Current value of metric prebid_cache.requests.ok"
555+ def initialValue = getCurrentMetricValue(defaultPbsService, CACHE_REQUEST_OK_GLOBAL_METRIC )
556+
557+ and : " Default BidRequest with cache, targeting"
558+ def bidRequest = BidRequest . getDefaultVideoRequest(). tap {
559+ it. enableCache()
560+ }
561+
562+ and : " Account with cache config"
563+ def accountAuctionConfig = new AccountAuctionConfig (cache : new AccountCacheConfig (enabled : false ))
564+ def accountConfig = new AccountConfig (status : ACTIVE , auction : accountAuctionConfig)
565+ def account = new Account (uuid : bidRequest. accountId, config : accountConfig)
566+ accountDao. save(account)
567+
568+ and : " Default bid response"
569+ def presetBidResponse = BidResponse . getDefaultBidResponse(bidRequest)
570+ bidder. setResponse(bidRequest. id, presetBidResponse)
571+
572+ and : " Flush metrics"
573+ flushMetrics(defaultPbsService)
574+
575+ when : " PBS processes auction request"
576+ def response = defaultPbsService. sendAuctionRequest(bidRequest)
577+
578+ then : " PBS shouldn't call PBC"
579+ assert ! prebidCache. getRequestCount(bidRequest. imp[0 ]. id)
580+
581+ and : " PBS response targeting shouldn't contains bidder specific keys"
582+ def targetingKeyMap = response. seatbid?. first()?. bid?. first()?. ext?. prebid?. targeting
583+ assert ! targetingKeyMap. containsKey(' hb_cache_id' )
584+ assert ! targetingKeyMap. containsKey(" hb_cache_id_${ GENERIC} " . toString())
585+ assert ! targetingKeyMap. containsKey(' hb_uuid' )
586+ assert ! targetingKeyMap. containsKey(" hb_uuid_${ GENERIC} " . toString())
587+
588+ and : " Metrics shouldn't be updated"
589+ def metrics = defaultPbsService. sendCollectedMetricsRequest()
590+ assert metrics[CACHE_REQUEST_OK_GLOBAL_METRIC ] == initialValue
591+ assert ! metrics[CACHE_REQUEST_OK_ACCOUNT_METRIC . formatted(bidRequest. accountId)]
592+ }
593+
594+ def " PBS should update prebid_cache.creative_size.xml metric when account cache config #enabledCacheConcfig" () {
595+ given : " Current value of metric prebid_cache.requests.ok"
596+ def okInitialValue = getCurrentMetricValue(defaultPbsService, CACHE_REQUEST_OK_GLOBAL_METRIC )
597+
598+ and : " Default VtrackRequest"
599+ def accountId = PBSUtils . randomNumber. toString()
600+ def creative = encodeXml(Vast . getDefaultVastModel(PBSUtils . randomString))
601+ def request = VtrackRequest . getDefaultVtrackRequest(creative)
602+
603+ and : " Create and save enabled events config in account"
604+ def account = new Account (). tap {
605+ it. uuid = accountId
606+ it. config = new AccountConfig (). tap {
607+ it. auction = new AccountAuctionConfig (cache : new AccountCacheConfig (enabled : enabledCacheConcfig))
608+ }
609+ }
610+ accountDao. save(account)
611+
612+ and : " Flush metrics"
613+ flushMetrics(defaultPbsService)
614+
615+ when : " PBS processes vtrack request"
616+ defaultPbsService. sendVtrackRequest(request, accountId)
617+
618+ then : " prebid_cache.creative_size.xml metric should be updated"
619+ def metrics = defaultPbsService. sendCollectedMetricsRequest()
620+ def creativeSize = creative. bytes. length
621+ assert metrics[CACHE_REQUEST_OK_GLOBAL_METRIC ] == okInitialValue + 1
622+
623+ and : " account.<account-id>.prebid_cache.creative_size.xml should be updated"
624+ assert metrics[CACHE_REQUEST_OK_ACCOUNT_METRIC . formatted(accountId)] == 1
625+ assert metrics[XML_CREATIVE_SIZE_ACCOUNT_METRIC . formatted(accountId)] == creativeSize
626+
627+ where :
628+ enabledCacheConcfig << [null , false , true ]
629+ }
495630}
0 commit comments