Skip to content

Commit

Permalink
Test: pb request correction module (#3533)
Browse files Browse the repository at this point in the history
Add functional tests for pb request correction module
  • Loading branch information
marki1an authored Nov 7, 2024
1 parent 6579ce1 commit e5a66a8
Show file tree
Hide file tree
Showing 10 changed files with 531 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ enum ModuleName {

PB_RICHMEDIA_FILTER("pb-richmedia-filter"),
PB_RESPONSE_CORRECTION ("pb-response-correction"),
ORTB2_BLOCKING("ortb2-blocking")
ORTB2_BLOCKING("ortb2-blocking"),
PB_REQUEST_CORRECTION('pb-request-correction'),

@JsonValue
final String code
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ enum ModuleHookImplementation {
PB_RICHMEDIA_FILTER_ALL_PROCESSED_RESPONSES("pb-richmedia-filter-all-processed-bid-responses-hook"),
RESPONSE_CORRECTION_ALL_PROCESSED_RESPONSES("pb-response-correction-all-processed-bid-responses"),
ORTB2_BLOCKING_BIDDER_REQUEST("ortb2-blocking-bidder-request"),
ORTB2_BLOCKING_RAW_BIDDER_RESPONSE("ortb2-blocking-raw-bidder-response")
ORTB2_BLOCKING_RAW_BIDDER_RESPONSE("ortb2-blocking-raw-bidder-response"),
PB_REQUEST_CORRECTION_PROCESSED_AUCTION_REQUEST("pb-request-correction-processed-auction-request"),

@JsonValue
final String code
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package org.prebid.server.functional.model.config

import com.fasterxml.jackson.annotation.JsonProperty
import groovy.transform.ToString

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

@JsonProperty("pbsdkAndroidInstlRemove")
Boolean interstitialCorrectionEnabled
@JsonProperty("pbsdkUaCleanup")
Boolean userAgentCorrectionEnabled
@JsonProperty("pbsdk-android-instl-remove")
Boolean interstitialCorrectionEnabledKebabCase
@JsonProperty("pbsdk-ua-cleanup")
Boolean userAgentCorrectionEnabledKebabCase

Boolean enabled

static PbRequestCorrectionConfig getDefaultConfigWithInterstitial(Boolean interstitialCorrectionEnabled = true,
Boolean enabled = true) {
new PbRequestCorrectionConfig(enabled: enabled, interstitialCorrectionEnabled: interstitialCorrectionEnabled)
}

static PbRequestCorrectionConfig getDefaultConfigWithUserAgentCorrection(Boolean userAgentCorrectionEnabled = true,
Boolean enabled = true) {
new PbRequestCorrectionConfig(enabled: enabled, userAgentCorrectionEnabled: userAgentCorrectionEnabled)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ class PbsModulesConfig {
RichmediaFilter pbRichmediaFilter
Ortb2BlockingConfig ortb2Blocking
PbResponseCorrection pbResponseCorrection
PbRequestCorrectionConfig pbRequestCorrection
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ import groovy.transform.ToString
class AppExt {

AppExtData data
AppPrebid prebid
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package org.prebid.server.functional.model.request.auction

import groovy.transform.ToString

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

String source
String version
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class Imp {
Pmp pmp
String displayManager
String displayManagerVer
Integer instl
OperationState instl
String tagId
BigDecimal bidFloor
Currency bidFloorCur
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@ package org.prebid.server.functional.tests.module

import org.prebid.server.functional.model.config.Endpoint
import org.prebid.server.functional.model.config.ExecutionPlan
import org.prebid.server.functional.model.config.Stage
import org.prebid.server.functional.tests.BaseSpec

import static org.prebid.server.functional.model.ModuleName.ORTB2_BLOCKING
import static org.prebid.server.functional.model.ModuleName.PB_REQUEST_CORRECTION
import static org.prebid.server.functional.model.ModuleName.PB_RESPONSE_CORRECTION
import static org.prebid.server.functional.model.ModuleName.PB_RICHMEDIA_FILTER
import static org.prebid.server.functional.model.config.Endpoint.OPENRTB2_AUCTION
import static org.prebid.server.functional.model.config.Stage.ALL_PROCESSED_BID_RESPONSES
import static org.prebid.server.functional.model.config.Stage.PROCESSED_AUCTION_REQUEST

class ModuleBaseSpec extends BaseSpec {

Expand Down Expand Up @@ -51,4 +54,9 @@ class ModuleBaseSpec extends BaseSpec {
protected static Map<String, String> getOrtb2BlockingSettings(boolean isEnabled = true) {
["hooks.${ORTB2_BLOCKING.code}.enabled": isEnabled as String]
}

protected static Map<String, String> getRequestCorrectionSettings(Endpoint endpoint = OPENRTB2_AUCTION, Stage stage = PROCESSED_AUCTION_REQUEST) {
["hooks.${PB_REQUEST_CORRECTION.code}.enabled": "true",
"hooks.host-execution-plan" : encode(ExecutionPlan.getSingleEndpointExecutionPlan(endpoint, PB_REQUEST_CORRECTION, [stage]))]
}
}

Large diffs are not rendered by default.

23 changes: 23 additions & 0 deletions src/test/groovy/org/prebid/server/functional/util/PBSUtils.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -128,4 +128,27 @@ class PBSUtils implements ObjectMapperWrapper {
throw new IllegalArgumentException("Unknown case type: $caseType")
}
}

static String getRandomVersion(String minVersion = "0.0.0", String maxVersion = "99.99.99") {
def minParts = minVersion.split('\\.').collect { it.toInteger() }
def maxParts = maxVersion.split('\\.').collect { it.toInteger() }
def versionParts = []

def major = getRandomNumber(minParts[0], maxParts[0])
versionParts << major

def minorMin = (major == minParts[0]) ? minParts[1] : 0
def minorMax = (major == maxParts[0]) ? maxParts[1] : 99
def minor = getRandomNumber(minorMin, minorMax)
versionParts << minor

if (minParts.size() > 2 || maxParts.size() > 2) {
def patchMin = (major == minParts[0] && minor == minParts[1]) ? minParts[2] : 0
def patchMax = (major == maxParts[0] && minor == maxParts[1]) ? maxParts[2] : 99
def patch = getRandomNumber(patchMin, patchMax)
versionParts << patch
}
def version = versionParts.join('.')
return (version >= minVersion && version <= maxVersion) ? version : getRandomVersion(minVersion, maxVersion)
}
}

0 comments on commit e5a66a8

Please sign in to comment.