Skip to content

Commit

Permalink
Refactoring functional tests
Browse files Browse the repository at this point in the history
  • Loading branch information
osulzhenko committed Jan 13, 2025
1 parent 30d7cc3 commit 26f38ea
Show file tree
Hide file tree
Showing 44 changed files with 403 additions and 350 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package org.prebid.server.functional.model.config
import com.fasterxml.jackson.databind.PropertyNamingStrategies
import com.fasterxml.jackson.databind.annotation.JsonNaming
import groovy.transform.ToString
import org.prebid.server.functional.model.ModuleName

@ToString(includeNames = true, ignoreNulls = true)
@JsonNaming(PropertyNamingStrategies.KebabCaseStrategy)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
package org.prebid.server.functional.model.config

import groovy.transform.ToString
import org.prebid.server.functional.model.ModuleName

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

Map<Stage, StageExecutionPlan> stages

static EndpointExecutionPlan getModuleEndpointExecutionPlan(ModuleName name, List<Stage> stages) {
new EndpointExecutionPlan(stages: stages.collectEntries {
it -> [(it): StageExecutionPlan.getModuleStageExecutionPlan(name, it)] } as Map<Stage, StageExecutionPlan>)
new EndpointExecutionPlan(stages: stages.collectEntries {
it -> [(it): StageExecutionPlan.getModuleStageExecutionPlan(name, it)]
} as Map<Stage, StageExecutionPlan>)
}

static EndpointExecutionPlan getModulesEndpointExecutionPlan(Map<Stage, List<ModuleName>> modulesStages) {
Expand All @@ -24,4 +24,17 @@ class EndpointExecutionPlan {
} as Map<Stage, StageExecutionPlan>
)
}

static EndpointExecutionPlan getModuleEndpointExecutionPlan(List<ModuleHookImplementation> modulesHooks) {
Map<Stage, StageExecutionPlan> stages = [:]
modulesHooks.each { moduleHook ->
def stage = Stage.forValue(moduleHook)
if (!stages.containsKey(stage)) {
stages[stage] = StageExecutionPlan.getModuleStageExecutionPlan([moduleHook])
} else {
stages[stage].addGroup(moduleHook)
}
}
new EndpointExecutionPlan(stages: stages)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import com.fasterxml.jackson.annotation.JsonProperty
import com.fasterxml.jackson.databind.PropertyNamingStrategies
import com.fasterxml.jackson.databind.annotation.JsonNaming
import groovy.transform.ToString
import org.prebid.server.functional.model.ModuleName

@ToString(includeNames = true, ignoreNulls = true)
@JsonNaming(PropertyNamingStrategies.KebabCaseStrategy)
Expand All @@ -16,6 +15,13 @@ class ExecutionGroup {
@JsonProperty("hook_sequence")
List<HookId> hookSequenceSnakeCase

static ExecutionGroup getModuleExecutionGroup(ModuleHookImplementation moduleHook) {
new ExecutionGroup().tap {
timeout = 100
hookSequence = [new HookId(moduleCode: ModuleName.forValue(moduleHook).code, hookImplCode: moduleHook.code)]
}
}

static ExecutionGroup getModuleExecutionGroup(ModuleName name, Stage stage) {
new ExecutionGroup().tap {
timeout = 100
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,20 @@ package org.prebid.server.functional.model.config
import com.fasterxml.jackson.databind.PropertyNamingStrategies
import com.fasterxml.jackson.databind.annotation.JsonNaming
import groovy.transform.ToString
import org.prebid.server.functional.model.ModuleName

import static org.prebid.server.functional.model.config.Endpoint.OPENRTB2_AUCTION

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

List<AbTest> abTests
List<ModularityAbTest> abTests
Map<Endpoint, EndpointExecutionPlan> endpoints

static ExecutionPlan getSingleEndpointExecutionPlan(List<ModuleHookImplementation> moduleHook, Endpoint endpoint = OPENRTB2_AUCTION) {
new ExecutionPlan(endpoints: [(endpoint): EndpointExecutionPlan.getModuleEndpointExecutionPlan(moduleHook)])
}

static ExecutionPlan getSingleEndpointExecutionPlan(Endpoint endpoint, ModuleName moduleName, List<Stage> stage) {
new ExecutionPlan(endpoints: [(endpoint): EndpointExecutionPlan.getModuleEndpointExecutionPlan(moduleName, stage)])
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import groovy.transform.ToString

@ToString(includeNames = true, ignoreNulls = true)
@JsonNaming(PropertyNamingStrategies.KebabCaseStrategy)
class AbTest {
class ModularityAbTest {

Boolean enabled
String moduleCode
Expand All @@ -21,8 +21,8 @@ class AbTest {
@JsonProperty("log_analytics_tag")
Boolean logAnalyticsTagSnakeCase

static AbTest getDefault(String moduleCode, List<Integer> accounts = null) {
new AbTest(enabled: true,
static ModularityAbTest getDefault(String moduleCode, List<Integer> accounts = null) {
new ModularityAbTest(enabled: true,
moduleCode: moduleCode,
accounts: accounts,
percentActive: 0,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package org.prebid.server.functional.model.config

import com.fasterxml.jackson.annotation.JsonValue
import org.prebid.server.functional.model.ModuleName

//TODO remove if module hooks implementation codes will become consistent
enum ModuleHookImplementation {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.prebid.server.functional.model
package org.prebid.server.functional.model.config

import com.fasterxml.jackson.annotation.JsonValue

Expand All @@ -15,4 +15,8 @@ enum ModuleName {
ModuleName(String code) {
this.code = code
}

static ModuleName forValue(ModuleHookImplementation moduleHook) {
values().find { moduleHook.code.contains(it.code) }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ enum Stage {
this.metricValue = metricValue
}

static Stage forValue(ModuleHookImplementation moduleHook) {
values().find { moduleHook.code.contains(it.value) }
}

@Override
String toString() {
value
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package org.prebid.server.functional.model.config

import groovy.transform.ToString
import org.prebid.server.functional.model.ModuleName

@ToString(includeNames = true, ignoreNulls = true)
class StageExecutionPlan {
Expand All @@ -11,4 +10,13 @@ class StageExecutionPlan {
static StageExecutionPlan getModuleStageExecutionPlan(ModuleName name, Stage stage) {
new StageExecutionPlan(groups: [ExecutionGroup.getModuleExecutionGroup(name, stage)])
}

static StageExecutionPlan getModuleStageExecutionPlan(List<ModuleHookImplementation> modulesHooks) {
new StageExecutionPlan(groups: modulesHooks.collect { ExecutionGroup.getModuleExecutionGroup(it) })
}

StageExecutionPlan addGroup(ModuleHookImplementation moduleHook) {
(groups ?: (groups = [])).add(ExecutionGroup.getModuleExecutionGroup(moduleHook))
this
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ import org.prebid.server.functional.util.PBSUtils
class UserExtData {

List<String> keywords
String buyeruid
List<String> buyeruids
String buyerUid
List<String> buyerUids
Geo geo

static UserExtData getFPDUserExtData() {
new UserExtData().tap {
keywords = [PBSUtils.randomString]
buyeruid = PBSUtils.randomString
buyeruids = [PBSUtils.randomString]
buyerUid = PBSUtils.randomString
buyerUids = [PBSUtils.randomString]
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import com.fasterxml.jackson.databind.PropertyNamingStrategies
import com.fasterxml.jackson.databind.annotation.JsonNaming
import groovy.transform.EqualsAndHashCode
import groovy.transform.ToString
import org.prebid.server.functional.model.request.auction.FetchStatus
import org.prebid.server.functional.model.request.auction.Imp

import static org.prebid.server.functional.model.request.auction.FetchStatus.SUCCESS
Expand All @@ -15,12 +14,12 @@ import static org.prebid.server.functional.model.request.auction.FetchStatus.SUC
class AnalyticResult {

String name
FetchStatus status
String status
List<ImpResult> results

static AnalyticResult buildFromImp(Imp imp) {
def appliedTo = new AppliedTo(impIds: [imp.id], bidders: [imp.ext.prebid.bidder.configuredBidders.first()])
def impResult = new ImpResult(status: 'success-block', values: new ModuleValue(richmediaFormat: 'mraid'), appliedTo: appliedTo)
new AnalyticResult(name: 'reject-richmedia', status: SUCCESS, results: [impResult])
new AnalyticResult(name: 'reject-richmedia', status: SUCCESS.value, results: [impResult])
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import com.fasterxml.jackson.databind.PropertyNamingStrategies
import com.fasterxml.jackson.databind.annotation.JsonNaming
import groovy.transform.EqualsAndHashCode
import groovy.transform.ToString
import org.prebid.server.functional.model.ModuleName
import org.prebid.server.functional.model.config.ModuleName

@ToString(includeNames = true, ignoreNulls = true)
@JsonNaming(PropertyNamingStrategies.KebabCaseStrategy)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.prebid.server.functional.model.response.auction


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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class Bidder extends NetworkScaffolding {
request().withPath(AUCTION_ENDPOINT)
}

HttpRequest getRequest(String bidRequestId, String requestMatchPath) {
static HttpRequest getRequest(String bidRequestId, String requestMatchPath) {
request().withPath(AUCTION_ENDPOINT)
.withBody(jsonPath("\$[?(@.$requestMatchPath == '$bidRequestId')]"))
}
Expand Down Expand Up @@ -68,7 +68,7 @@ class Bidder extends NetworkScaffolding {
return getLastRecordedRequestHeaders(bidRequestId)
}

private String getBodyByRequest(HttpRequest request) {
private static String getBodyByRequest(HttpRequest request) {
def requestString = request.bodyAsString
def jsonNode = toJsonNode(requestString)
def id = jsonNode.get("id").asText()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class FloorsProvider extends NetworkScaffolding {
: HttpResponse.notFoundResponse()}
}

private String getDefaultResponse() {
private static String getDefaultResponse() {
encode(PriceFloorData.priceFloorData)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class PrebidCache extends NetworkScaffolding {
.withBody(jsonPath("\$.puts[?(@.value =~/^.*$payload.*\$/)]"))
}

private String getBodyByRequest(HttpRequest request) {
private static String getBodyByRequest(HttpRequest request) {
def requestString = request.bodyAsString
def jsonNode = toJsonNode(requestString)
def putsSize = jsonNode.get("puts").size()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ class AmpFpdSpec extends BaseSpec {
ampStoredRequest.user.geo.zip == user.geo.zip
ampStoredRequest.user.geo.country == user.geo.country
ampStoredRequest.user.ext.data.keywords == user.ext.data.keywords
ampStoredRequest.user.ext.data.buyeruid == user.ext.data.buyeruid
ampStoredRequest.user.ext.data.buyeruids == user.ext.data.buyeruids
ampStoredRequest.user.ext.data.buyerUid == user.ext.data.buyerUid
ampStoredRequest.user.ext.data.buyerUids == user.ext.data.buyerUids
}

and: "Bidder request shouldn't contain imp[0].ext.rp"
Expand Down Expand Up @@ -195,8 +195,8 @@ class AmpFpdSpec extends BaseSpec {
ortb2.user.gender == user.gender
ortb2.user.keywords == user.keywords
ortb2.user.ext.data.keywords == user.ext.data.keywords
ortb2.user.ext.data.buyeruid == user.ext.data.buyeruid
ortb2.user.ext.data.buyeruids == user.ext.data.buyeruids
ortb2.user.ext.data.buyerUid == user.ext.data.buyerUid
ortb2.user.ext.data.buyerUids == user.ext.data.buyerUids
}

and: "Bidder request shouldn't contain imp[0].ext.rp"
Expand Down Expand Up @@ -289,8 +289,8 @@ class AmpFpdSpec extends BaseSpec {
ampStoredRequest.user.geo.zip == user.geo.zip
ampStoredRequest.user.geo.country == user.geo.country
ampStoredRequest.user.ext.data.keywords == user.ext.data.keywords
ampStoredRequest.user.ext.data.buyeruid == user.ext.data.buyeruid
ampStoredRequest.user.ext.data.buyeruids == user.ext.data.buyeruids
ampStoredRequest.user.ext.data.buyerUid == user.ext.data.buyerUid
ampStoredRequest.user.ext.data.buyerUids == user.ext.data.buyerUids
}
}

Expand Down Expand Up @@ -367,8 +367,8 @@ class AmpFpdSpec extends BaseSpec {
ortb2.user.gender == user.gender
ortb2.user.keywords == user.keywords
ortb2.user.ext.data.keywords == user.ext.data.keywords
ortb2.user.ext.data.buyeruid == user.ext.data.buyeruid
ortb2.user.ext.data.buyeruids == user.ext.data.buyeruids
ortb2.user.ext.data.buyerUid == user.ext.data.buyerUid
ortb2.user.ext.data.buyerUids == user.ext.data.buyerUids
}

and: "Bidder request shouldn't contain imp[0].ext.rp"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ class AnalyticsSpec extends BaseSpec {
ENABLED_DEBUG_LOG_MODE + ['analytics.log.enabled' : 'true',
'analytics.global.adapters': ''])


@Shared
PubStackAnalytics analytics = new PubStackAnalytics(Dependencies.networkServiceContainer).tap {
it.setResponse(PubStackResponse.getDefaultPubStackResponse(SCOPE_ID, Dependencies.networkServiceContainer.rootUri))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ abstract class BaseSpec extends Specification implements ObjectMapperWrapper {
private static final String DEFAULT_CACHE_DIRECTORY = "/app/prebid-server/data"
protected static final Map<String, String> GENERIC_ALIAS_CONFIG = ["adapters.generic.aliases.alias.enabled" : "true",
"adapters.generic.aliases.alias.endpoint": "$networkServiceContainer.rootUri/auction".toString()]
protected static final Map<String, String> EMPTY_CACHE_TTL_CONFIG = ["cache.default-ttl-seconds.banner": "",
"cache.default-ttl-seconds.video" : "",
"cache.default-ttl-seconds.native": "",
"cache.default-ttl-seconds.audio" : ""]
protected static final Map<String, String> EMPTY_CACHE_TTL_HOST_CONFIG = ["cache.banner-ttl-seconds": "",
"cache.video-ttl-seconds" : ""]

protected final PrebidServerService defaultPbsService = pbsServiceFactory.getService([:])

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,10 @@ class BidExpResponseSpec extends BaseSpec {
"cache.default-ttl-seconds.video" : VIDEO_TTL_DEFAULT_CACHE as String,
"cache.default-ttl-seconds.native": NATIVE_TTL_DEFAULT_CACHE as String,
"cache.default-ttl-seconds.audio" : AUDIO_TTL_DEFAULT_CACHE as String]
private static final Map<String, String> EMPTY_CACHE_TTL_CONFIG = ["cache.default-ttl-seconds.banner": "",
"cache.default-ttl-seconds.video" : "",
"cache.default-ttl-seconds.native": "",
"cache.default-ttl-seconds.audio" : ""]
private static final Map<String, String> EMPTY_CACHE_TTL_HOST_CONFIG = ["cache.banner-ttl-seconds": "",
"cache.video-ttl-seconds" : ""]
private static def pbsOnlyHostCacheTtlService = pbsServiceFactory.getService(CACHE_TTL_HOST_CONFIG + EMPTY_CACHE_TTL_CONFIG)
private static def pbsEmptyTtlService = pbsServiceFactory.getService(EMPTY_CACHE_TTL_CONFIG + EMPTY_CACHE_TTL_HOST_CONFIG)
private static def pbsHostAndDefaultCacheTtlService = pbsServiceFactory.getService(CACHE_TTL_HOST_CONFIG + DEFAULT_CACHE_TTL_CONFIG)


def "PBS auction should resolve bid.exp from response that is set by the bidder’s adapter"() {
given: "Default basicResponse with exp"
def bidResponseExp = PBSUtils.randomNumber
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,8 @@ class BidderInsensitiveCaseSpec extends BaseSpec {
ortb2.user.gender == user.gender
ortb2.user.keywords == user.keywords
ortb2.user.ext.data.keywords == user.ext.data.keywords
ortb2.user.ext.data.buyeruid == user.ext.data.buyeruid
ortb2.user.ext.data.buyeruids == user.ext.data.buyeruids
ortb2.user.ext.data.buyerUid == user.ext.data.buyerUid
ortb2.user.ext.data.buyerUids == user.ext.data.buyerUids
}

and: "Bidder request shouldn't contain imp[0].ext.rp"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import static org.prebid.server.functional.model.bidder.BidderName.GENERIC

class StoredResponseSpec extends BaseSpec {

private final PrebidServerService pbsService = pbsServiceFactory.getService(["cache.default-ttl-seconds.banner": ""])
private final PrebidServerService pbsService = pbsServiceFactory.getService(EMPTY_CACHE_TTL_CONFIG)

@PendingFeature
def "PBS should not fail auction with storedAuctionResponse when request bidder params doesn't satisfy json-schema"() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,7 @@ class TargetingSpec extends BaseSpec {

and: "Create and save stored response into DB"
def storedBidResponse = BidResponse.getDefaultBidResponse(ampStoredRequest).tap {
seatbid[0].bid[0].price = max.plus(1)
seatbid[0].bid[0].price = max + 1
}
def storedResponse = new StoredResponse(responseId: storedBidResponseId, storedBidResponse: storedBidResponse)
storedResponseDao.save(storedResponse)
Expand Down Expand Up @@ -509,7 +509,7 @@ class TargetingSpec extends BaseSpec {

and: "Create and save stored response into DB"
def storedBidResponse = BidResponse.getDefaultBidResponse(bidRequest).tap {
seatbid[0].bid[0].price = max.plus(1)
seatbid[0].bid[0].price = max + 1
}
def storedResponse = new StoredResponse(responseId: storedBidResponseId, storedBidResponse: storedBidResponse)
storedResponseDao.save(storedResponse)
Expand Down Expand Up @@ -1301,7 +1301,6 @@ class TargetingSpec extends BaseSpec {
def storedRequest = StoredRequest.getStoredRequest(ampRequest, ampStoredRequest)
storedRequestDao.save(storedRequest)


and: "Account in the DB"
def account = createAccountWithPriceGranularity(ampRequest.account, PBSUtils.getRandomEnum(PriceGranularityType))
accountDao.save(account)
Expand Down
Loading

0 comments on commit 26f38ea

Please sign in to comment.