Skip to content

Commit

Permalink
Tests: Native stored response with missing asset id (#1781)
Browse files Browse the repository at this point in the history
  • Loading branch information
mtuchkova authored Mar 24, 2022
1 parent ccd839b commit c012d8e
Show file tree
Hide file tree
Showing 28 changed files with 237 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ private Future<TcfContext> prepareTcfContext(Privacy privacy,

final String gdpr = privacy.getGdpr();
if (StringUtils.isNotEmpty(gdpr)) {
return Future.succeededFuture(defaultContext.toBuilder().inGdprScope((inScopeOfGdpr(gdpr))).build());
return Future.succeededFuture(defaultContext.toBuilder().inGdprScope(inScopeOfGdpr(gdpr)).build());
}

if (country != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ import javax.persistence.Entity
import javax.persistence.GeneratedValue
import javax.persistence.Id
import javax.persistence.Table
import org.prebid.server.functional.model.db.typeconverter.StoredResponseConfigTypeConverter
import org.prebid.server.functional.model.db.typeconverter.StoredAuctionResponseConfigTypeConverter
import org.prebid.server.functional.model.db.typeconverter.StoredBidResponseConfigTypeConverter
import org.prebid.server.functional.model.response.auction.BidResponse
import org.prebid.server.functional.model.response.auction.SeatBid

import static javax.persistence.GenerationType.IDENTITY

Expand All @@ -23,7 +25,10 @@ class StoredResponse {
Integer id
@Column(name = "resid")
String resid
@Column(name = "responseData")
@Convert(converter = StoredResponseConfigTypeConverter)
BidResponse responseData
@Column(name = "storedAuctionResponse")
@Convert(converter = StoredAuctionResponseConfigTypeConverter)
SeatBid storedAuctionResponse
@Column(name = "storedBidResponse")
@Convert(converter = StoredBidResponseConfigTypeConverter)
BidResponse storedBidResponse
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package org.prebid.server.functional.model.db.typeconverter

import javax.persistence.AttributeConverter
import org.prebid.server.functional.model.response.auction.SeatBid
import org.prebid.server.functional.testcontainers.Dependencies

class StoredAuctionResponseConfigTypeConverter implements AttributeConverter<SeatBid, String> {

@Override
String convertToDatabaseColumn(SeatBid seatBid) {
seatBid ? Dependencies.objectMapperWrapper.encode(seatBid) : null
}

@Override
SeatBid convertToEntityAttribute(String value) {
value ? Dependencies.objectMapperWrapper.decode(value, SeatBid) : null
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import javax.persistence.AttributeConverter
import org.prebid.server.functional.model.response.auction.BidResponse
import org.prebid.server.functional.testcontainers.Dependencies

class StoredResponseConfigTypeConverter implements AttributeConverter<BidResponse, String> {
class StoredBidResponseConfigTypeConverter implements AttributeConverter<BidResponse, String> {

@Override
String convertToDatabaseColumn(BidResponse bidResponse) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
package org.prebid.server.functional.model.request.auction

import groovy.transform.ToString
import org.prebid.server.functional.util.PBSUtils

@ToString(includeNames = true, ignoreNulls = true)
class AssetImage {

Integer type
String url
Integer w
Integer wmin
Integer h
Integer hmin
List<String> mimes

static AssetImage getDefaultAssetImage() {
new AssetImage(type: 1, url: PBSUtils.randomString)
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
package org.prebid.server.functional.model.request.auction

import com.fasterxml.jackson.annotation.JsonValue

enum DistributionChannel {

SITE, APP

@JsonValue
String getValue() {
name().toLowerCase()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class Imp {
}
}

private static Imp getDefaultImp() {
private static Imp getDefaultImp() {
new Imp().tap {
id = UUID.randomUUID()
ext = ImpExt.defaultImpExt
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import com.fasterxml.jackson.databind.annotation.JsonNaming
import groovy.transform.ToString

@ToString(includeNames = true, ignoreNulls = true)
@JsonNaming(PropertyNamingStrategies.LowerCamelCaseStrategy)
@JsonNaming(PropertyNamingStrategies.LowerCaseStrategy)
class ImpExtPrebid {

Bidder bidder
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,25 @@
package org.prebid.server.functional.model.request.auction

import com.fasterxml.jackson.annotation.JsonGetter
import com.fasterxml.jackson.annotation.JsonSetter
import groovy.transform.ToString
import org.prebid.server.functional.testcontainers.Dependencies

@ToString(includeNames = true, ignoreNulls = true)
class Native {

String request
Request request
String ver
List<Integer> api
List<Integer> battr

@JsonGetter("request")
String getRequest() {
Dependencies.objectMapperWrapper.encode(request)
}

@JsonSetter("request")
void getRequest(String request) {
this.request = Dependencies.objectMapperWrapper.decode(request, Request)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package org.prebid.server.functional.model.request.auction

import com.fasterxml.jackson.databind.PropertyNamingStrategies
import com.fasterxml.jackson.databind.annotation.JsonNaming
import com.iab.openrtb.request.EventTracker
import groovy.transform.ToString

@JsonNaming(PropertyNamingStrategies.LowerCaseStrategy)
@ToString(includeNames = true, ignoreNulls = true)
class Request {

String ver
Integer context
Integer contextSubtype
Integer plcmtType
Integer plcmtcnt
Integer seq
List<Asset> assets
Integer aurlSupport
Integer durlSupport
List<EventTracker> eventTrackers
Integer privacy
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package org.prebid.server.functional.model.response.auction

import org.prebid.server.functional.model.request.auction.Asset

class Adm {

List<Asset> assets
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
package org.prebid.server.functional.model.response.auction

import com.fasterxml.jackson.annotation.JsonGetter
import com.fasterxml.jackson.annotation.JsonSetter
import groovy.transform.ToString
import org.prebid.server.functional.model.request.auction.Imp
import org.prebid.server.functional.testcontainers.Dependencies
import org.prebid.server.functional.util.PBSUtils

@ToString(includeNames = true, ignoreNulls = true)
class Bid {
Expand All @@ -12,7 +16,7 @@ class Bid {
String nurl
String burl
String lurl
String adm
Adm adm
String adid
List<String> adomain
String bundle
Expand All @@ -33,16 +37,26 @@ class Bid {
Integer exp
BidExt ext

static Bid getDefaultBid(Imp imp) {
getDefaultBid(imp.id)
static List<Bid> getDefaultBids(List<Imp> imps) {
imps.collect { getDefaultBid(it.id) }
}

static Bid getDefaultBid(String impId) {
new Bid().tap {
id = UUID.randomUUID()
impid = impId
price = 1.23
price = PBSUtils.randomPrice
crid = 1
}
}

@JsonGetter("adm")
String getAdm() {
Dependencies.objectMapperWrapper.encode(adm)
}

@JsonSetter("adm")
void getAdm(String adm) {
this.adm = Dependencies.objectMapperWrapper.decode(adm, Adm)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ class BidExt {

Prebid prebid
BigDecimal origbidcpm
String origbidcur
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import org.prebid.server.functional.model.ResponseModel
import org.prebid.server.functional.model.mock.services.generalplanner.PlansResponse
import org.prebid.server.functional.model.request.auction.BidRequest

import static org.prebid.server.functional.model.bidder.BidderName.GENERIC

@EqualsAndHashCode
@ToString(includeNames = true, ignoreNulls = true)
class BidResponse implements ResponseModel {
Expand All @@ -19,13 +21,9 @@ class BidResponse implements ResponseModel {
BidResponseExt ext

static BidResponse getDefaultBidResponse(BidRequest bidRequest) {
getDefaultBidResponse(bidRequest.id, bidRequest.imp*.id)
}

static BidResponse getDefaultBidResponse(String id, List<String> impIds) {
def bidResponse = new BidResponse(id: id)
def bids = getDefaultBids(impIds)
def seatBid = new SeatBid(bid: bids)
def bidResponse = new BidResponse(id: bidRequest.id)
def bids = Bid.getDefaultBids(bidRequest.imp)
def seatBid = new SeatBid(bid: bids, seat: GENERIC)
bidResponse.seatbid = [seatBid]
bidResponse
}
Expand All @@ -39,8 +37,4 @@ class BidResponse implements ResponseModel {
bid.h = lineItem.sizes[0].h
bidResponse
}

static private List<Bid> getDefaultBids(List<String> impIds) {
impIds.collect { Bid.getDefaultBid(it) }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import com.fasterxml.jackson.annotation.JsonValue

enum MediaType {

BANNER, VIDEO
BANNER, VIDEO, NATIVE

@JsonValue
String getValue() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
package org.prebid.server.functional.model.response.auction

import groovy.transform.ToString
import org.prebid.server.functional.model.bidder.BidderName
import org.prebid.server.functional.model.request.auction.BidRequest

import static org.prebid.server.functional.model.bidder.BidderName.*

@ToString(includeNames = true, ignoreNulls = true)
class SeatBid {

List<Bid> bid
String seat
BidderName seat
Integer group

static SeatBid getStoredResponse(BidRequest bidRequest) {
def bids = Bid.getDefaultBids(bidRequest.imp)
new SeatBid(bid: bids, seat: GENERIC)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ LIMIT 1
"settings.database.account-query" : DB_ACCOUNT_QUERY,
"settings.database.stored-requests-query" : "SELECT accountId, reqid, requestData, 'request' as dataType FROM stored_requests WHERE reqid IN (%REQUEST_ID_LIST%) UNION ALL SELECT accountId, reqid, requestData, 'imp' as dataType FROM stored_requests WHERE reqid IN (%IMP_ID_LIST%)",
"settings.database.amp-stored-requests-query": "SELECT accountId, reqid, requestData, 'request' as dataType FROM stored_requests WHERE reqid IN (%REQUEST_ID_LIST%)",
"settings.database.stored-responses-query" : "SELECT resid, responseData FROM stored_responses WHERE resid IN (%RESPONSE_ID_LIST%)"
"settings.database.stored-responses-query" : "SELECT resid, COALESCE(storedAuctionResponse, storedBidResponse) as responseData FROM stored_responses WHERE resid IN (%RESPONSE_ID_LIST%)"
]

PrebidServerContainer(Map<String, String> config) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ import org.mockserver.matchers.Times
import org.mockserver.model.HttpRequest
import org.mockserver.model.HttpResponse
import org.prebid.server.functional.model.bidderspecific.BidderRequest
import org.prebid.server.functional.model.request.auction.Banner
import org.prebid.server.functional.model.request.auction.BidRequest
import org.prebid.server.functional.model.request.auction.Format
import org.prebid.server.functional.model.request.auction.Imp
import org.prebid.server.functional.model.response.auction.BidResponse
import org.prebid.server.functional.util.ObjectMapperWrapper
import org.testcontainers.containers.MockServerContainer
Expand Down Expand Up @@ -60,9 +64,15 @@ class Bidder extends NetworkScaffolding {
def requestString = request.bodyAsString
def jsonNode = mapper.toJsonNode(requestString)
def id = jsonNode.get("id").asText()
def imp = jsonNode.get("imp")
def impIds = imp.collect { it.get("id").asText() } as List<String>
def response = BidResponse.getDefaultBidResponse(id, impIds)
def impNode = jsonNode.get("imp")
def imps = impNode.collect {
def formatNode = it.get("banner") != null ? it.get("banner").get("format") : null
new Imp(id: it.get("id").asText(),
banner: formatNode != null
? new Banner(format: [new Format(w: formatNode.first().get("w").asInt(), h: formatNode.first().get("h").asInt())])
: null)}
def bidRequest = new BidRequest(id: id, imp: imps)
def response = BidResponse.getDefaultBidResponse(bidRequest)
mapper.encode(response)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ class BidValidationSpec extends BaseSpec {

and: "Bid response with 2 bids"
def bidResponse = BidResponse.getDefaultBidResponse(bidRequest)
bidResponse.seatbid[0].bid << Bid.getDefaultBid(bidRequest.imp.first())
bidResponse.seatbid[0].bid << Bid.getDefaultBid(bidRequest.imp.first().id)

and: "One of the bids is invalid"
def invalidBid = bidResponse.seatbid.first().bid.first()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package org.prebid.server.functional.tests

import org.prebid.server.functional.model.request.auction.Asset
import org.prebid.server.functional.model.request.auction.BidRequest
import org.prebid.server.functional.model.request.auction.Targeting
import org.prebid.server.functional.model.request.vtrack.VtrackRequest
import org.prebid.server.functional.model.request.vtrack.xml.Vast
import org.prebid.server.functional.model.response.auction.Adm
import org.prebid.server.functional.model.response.auction.BidResponse
import org.prebid.server.functional.testcontainers.PBSTest
import org.prebid.server.functional.util.PBSUtils
Expand Down Expand Up @@ -43,9 +45,10 @@ class CacheSpec extends BaseSpec {
bidRequest.enableCache()

and: "Default basic bid with banner creative"
def bidResponse = BidResponse.getDefaultBidResponse(bidRequest)
def adm = PBSUtils.randomString
bidResponse.seatbid[0].bid[0].adm = adm
def asset = new Asset(id: PBSUtils.randomNumber)
def bidResponse = BidResponse.getDefaultBidResponse(bidRequest).tap {
seatbid[0].bid[0].adm = new Adm(assets: [asset])
}

and: "Set bidder response"
bidder.setResponse(bidRequest.id, bidResponse)
Expand All @@ -57,6 +60,7 @@ class CacheSpec extends BaseSpec {
def metrics = defaultPbsService.sendCollectedMetricsRequest()

then: "prebid_cache.creative_size.json should be update"
def adm = bidResponse.seatbid[0].bid[0].getAdm()
def creativeSize = adm.bytes.length
assert metrics["prebid_cache.creative_size.json"] == creativeSize
assert metrics["prebid_cache.requests.ok"] == initialValue + 1
Expand Down
Loading

0 comments on commit c012d8e

Please sign in to comment.