Skip to content

Commit ec495e7

Browse files
authored
Test: Vtrack account ttl (#4241)
1 parent ae78fc5 commit ec495e7

File tree

4 files changed

+131
-3
lines changed

4 files changed

+131
-3
lines changed

src/test/groovy/org/prebid/server/functional/model/config/AccountConfig.groovy

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ class AccountConfig {
2626
AlternateBidderCodes alternateBidderCodes
2727
@JsonProperty("alternate_bidder_codes")
2828
AlternateBidderCodes alternateBidderCodesSnakeCase
29+
AccountVtrackConfig vtrack
2930

3031
static getDefaultAccountConfig() {
3132
new AccountConfig(status: AccountStatus.ACTIVE)
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package org.prebid.server.functional.model.config
2+
3+
import groovy.transform.ToString
4+
5+
@ToString(includeNames = true, ignoreNulls = true)
6+
class AccountVtrackConfig {
7+
8+
Integer ttl
9+
}

src/test/groovy/org/prebid/server/functional/service/PrebidServerService.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ class PrebidServerService implements ObjectMapperWrapper {
214214
}
215215

216216
PrebidCacheResponse sendVtrackRequest(VtrackRequest request, String account) {
217-
def response = given(requestSpecification).queryParam("a", account)
217+
def response = given(requestSpecification).queryParams(["a": account])
218218
.body(request)
219219
.post(VTRACK_ENDPOINT)
220220

src/test/groovy/org/prebid/server/functional/tests/CacheSpec.groovy

Lines changed: 120 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import org.prebid.server.functional.model.config.AccountAuctionConfig
44
import org.prebid.server.functional.model.config.AccountCacheConfig
55
import org.prebid.server.functional.model.config.AccountConfig
66
import org.prebid.server.functional.model.config.AccountEventsConfig
7+
import org.prebid.server.functional.model.config.AccountVtrackConfig
78
import org.prebid.server.functional.model.db.Account
89
import org.prebid.server.functional.model.request.auction.Asset
910
import org.prebid.server.functional.model.request.auction.BidRequest
@@ -13,8 +14,10 @@ import org.prebid.server.functional.model.request.vtrack.VtrackRequest
1314
import org.prebid.server.functional.model.request.vtrack.xml.Vast
1415
import org.prebid.server.functional.model.response.auction.Adm
1516
import org.prebid.server.functional.model.response.auction.BidResponse
17+
import org.prebid.server.functional.service.PrebidServerException
1618
import org.prebid.server.functional.util.PBSUtils
1719

20+
import static io.netty.handler.codec.http.HttpResponseStatus.BAD_REQUEST
1821
import static org.prebid.server.functional.model.response.auction.ErrorType.CACHE
1922
import static org.prebid.server.functional.model.AccountStatus.ACTIVE
2023
import static org.prebid.server.functional.model.bidder.BidderName.GENERIC
@@ -607,7 +610,7 @@ class CacheSpec extends BaseSpec {
607610
assert prebidCache.getRequestCount(bidRequest.imp[0].id) == 1
608611

609612
and: "Bid response targeting should contain value"
610-
verifyAll (bidResponse?.seatbid[0]?.bid[0]?.ext?.prebid?.targeting as Map) {
613+
verifyAll(bidResponse?.seatbid[0]?.bid[0]?.ext?.prebid?.targeting as Map) {
611614
it.get("hb_cache_id")
612615
it.get("hb_cache_id_generic")
613616
it.get("hb_cache_path") == CACHE_PATH
@@ -643,7 +646,7 @@ class CacheSpec extends BaseSpec {
643646
assert prebidCache.getRequestCount(bidRequest.imp[0].id) == 1
644647

645648
and: "Bid response targeting should contain value"
646-
verifyAll (bidResponse.seatbid[0].bid[0].ext.prebid.targeting) {
649+
verifyAll(bidResponse.seatbid[0].bid[0].ext.prebid.targeting) {
647650
it.get("hb_cache_id")
648651
it.get("hb_cache_id_generic")
649652
it.get("hb_cache_path") == INTERNAL_CACHE_PATH
@@ -785,4 +788,119 @@ class CacheSpec extends BaseSpec {
785788
where:
786789
enabledCacheConcfig << [null, false, true]
787790
}
791+
792+
def "PBS should failed VTrack request when sending request without account"() {
793+
given: "Default VtrackRequest"
794+
def creative = encodeXml(Vast.getDefaultVastModel(PBSUtils.randomString))
795+
def request = VtrackRequest.getDefaultVtrackRequest(creative)
796+
797+
and: "Flush metrics"
798+
flushMetrics(defaultPbsService)
799+
800+
when: "PBS processes vtrack request"
801+
defaultPbsService.sendVtrackRequest(request, null)
802+
803+
then: "Request should fail with an error"
804+
def exception = thrown(PrebidServerException)
805+
assert exception.statusCode == BAD_REQUEST.code()
806+
assert exception.responseBody == "Account 'a' is required query parameter and can't be empty"
807+
}
808+
809+
def "PBS shouldn't use negative value in tllSecond when account vtrack ttl is #accountTtl and request ttl second is #requestedTtl"() {
810+
given: "Default VtrackRequest"
811+
def creative = encodeXml(Vast.getDefaultVastModel(PBSUtils.randomString))
812+
def request = VtrackRequest.getDefaultVtrackRequest(creative).tap {
813+
puts[0].ttlseconds = requestedTtl
814+
}
815+
816+
and: "Create and save vtrack in account"
817+
def accountId = PBSUtils.randomNumber.toString()
818+
def account = new Account().tap {
819+
it.uuid = accountId
820+
it.config = new AccountConfig().tap {
821+
it.vtrack = new AccountVtrackConfig(ttl: accountTtl)
822+
}
823+
}
824+
accountDao.save(account)
825+
826+
and: "Flush metrics"
827+
flushMetrics(defaultPbsService)
828+
829+
when: "PBS processes vtrack request"
830+
defaultPbsService.sendVtrackRequest(request, accountId)
831+
832+
then: "Pbs should emit creative_ttl.xml with lowest value"
833+
def metrics = defaultPbsService.sendCollectedMetricsRequest()
834+
assert metrics[XML_CREATIVE_TTL_ACCOUNT_METRIC.formatted(accountId)]
835+
== [requestedTtl, accountTtl].findAll { it -> it > 0 }.min()
836+
837+
where:
838+
requestedTtl | accountTtl
839+
PBSUtils.getRandomNumber(300, 1500) as Integer | PBSUtils.getRandomNegativeNumber(-1500, 300) as Integer
840+
PBSUtils.getRandomNegativeNumber(-1500, 300) as Integer | PBSUtils.getRandomNumber(300, 1500) as Integer
841+
PBSUtils.getRandomNegativeNumber(-1500, 300) as Integer | PBSUtils.getRandomNegativeNumber(-1500, 300) as Integer
842+
}
843+
844+
def "PBS should use lowest tllSecond when account vtrack ttl is #accountTtl and request ttl second is #requestedTtl"() {
845+
given: "Default VtrackRequest"
846+
def creative = encodeXml(Vast.getDefaultVastModel(PBSUtils.randomString))
847+
def request = VtrackRequest.getDefaultVtrackRequest(creative).tap {
848+
puts[0].ttlseconds = requestedTtl
849+
}
850+
851+
and: "Create and save vtrack in account"
852+
def accountId = PBSUtils.randomNumber.toString()
853+
def account = new Account().tap {
854+
it.uuid = accountId
855+
it.config = new AccountConfig().tap {
856+
it.vtrack = new AccountVtrackConfig(ttl: accountTtl)
857+
}
858+
}
859+
accountDao.save(account)
860+
861+
and: "Flush metrics"
862+
flushMetrics(defaultPbsService)
863+
864+
when: "PBS processes vtrack request"
865+
defaultPbsService.sendVtrackRequest(request, accountId)
866+
867+
then: "Pbs should emit creative_ttl.xml with lowest value"
868+
def metrics = defaultPbsService.sendCollectedMetricsRequest()
869+
assert metrics[XML_CREATIVE_TTL_ACCOUNT_METRIC.formatted(accountId)] == [requestedTtl, accountTtl].min()
870+
871+
where:
872+
requestedTtl | accountTtl
873+
null | null
874+
null | PBSUtils.getRandomNumber(300, 1500) as Integer
875+
PBSUtils.getRandomNumber(300, 1500) as Integer | null
876+
PBSUtils.getRandomNumber(300, 1500) as Integer | PBSUtils.getRandomNumber(300, 1500) as Integer
877+
}
878+
879+
def "PBS should proceed request when account ttl and request ttl second are empty"() {
880+
given: "Default VtrackRequest"
881+
def creative = encodeXml(Vast.getDefaultVastModel(PBSUtils.randomString))
882+
def request = VtrackRequest.getDefaultVtrackRequest(creative).tap {
883+
puts[0].ttlseconds = null
884+
}
885+
886+
and: "Create and save vtrack in account"
887+
def accountId = PBSUtils.randomNumber.toString()
888+
def account = new Account().tap {
889+
it.uuid = accountId
890+
it.config = new AccountConfig().tap {
891+
it.vtrack = new AccountVtrackConfig(ttl: null)
892+
}
893+
}
894+
accountDao.save(account)
895+
896+
and: "Flush metrics"
897+
flushMetrics(defaultPbsService)
898+
899+
when: "PBS processes vtrack request"
900+
defaultPbsService.sendVtrackRequest(request, accountId)
901+
902+
then: "Pbs shouldn't emit creative_ttl.xml"
903+
def metrics = defaultPbsService.sendCollectedMetricsRequest()
904+
assert !metrics[XML_CREATIVE_TTL_ACCOUNT_METRIC.formatted(accountId)]
905+
}
788906
}

0 commit comments

Comments
 (0)