diff --git a/src/main/java/org/prebid/server/auction/BidResponseCreator.java b/src/main/java/org/prebid/server/auction/BidResponseCreator.java index 16a572afbc9..c1e65c01950 100644 --- a/src/main/java/org/prebid/server/auction/BidResponseCreator.java +++ b/src/main/java/org/prebid/server/auction/BidResponseCreator.java @@ -24,11 +24,10 @@ import org.apache.commons.lang3.ObjectUtils; import org.apache.commons.lang3.StringUtils; import org.prebid.server.auction.model.AuctionContext; +import org.prebid.server.auction.model.BidInfo; import org.prebid.server.auction.model.BidRequestCacheInfo; import org.prebid.server.auction.model.BidderResponse; -import org.prebid.server.auction.model.GeneratedBidIds; import org.prebid.server.bidder.BidderCatalog; -import org.prebid.server.bidder.model.BidderBid; import org.prebid.server.bidder.model.BidderError; import org.prebid.server.bidder.model.BidderSeatBid; import org.prebid.server.cache.CacheService; @@ -69,12 +68,14 @@ import org.prebid.server.settings.model.Account; import org.prebid.server.settings.model.AccountAnalyticsConfig; import org.prebid.server.settings.model.VideoStoredDataResult; +import org.prebid.server.vast.VastModifier; import java.math.BigDecimal; import java.time.Clock; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; +import java.util.Comparator; import java.util.EnumMap; import java.util.HashMap; import java.util.HashSet; @@ -99,6 +100,7 @@ public class BidResponseCreator { private final CacheService cacheService; private final BidderCatalog bidderCatalog; + private final VastModifier vastModifier; private final EventsService eventsService; private final StoredRequestProcessor storedRequestProcessor; private final BidResponseReducer bidResponseReducer; @@ -113,6 +115,7 @@ public class BidResponseCreator { public BidResponseCreator(CacheService cacheService, BidderCatalog bidderCatalog, + VastModifier vastModifier, EventsService eventsService, StoredRequestProcessor storedRequestProcessor, BidResponseReducer bidResponseReducer, @@ -123,6 +126,7 @@ public BidResponseCreator(CacheService cacheService, this.cacheService = Objects.requireNonNull(cacheService); this.bidderCatalog = Objects.requireNonNull(bidderCatalog); + this.vastModifier = Objects.requireNonNull(vastModifier); this.eventsService = Objects.requireNonNull(eventsService); this.storedRequestProcessor = Objects.requireNonNull(storedRequestProcessor); this.bidResponseReducer = Objects.requireNonNull(bidResponseReducer); @@ -201,23 +205,25 @@ private Future cacheBidsAndCreateResponse(List bidd .map(bidResponseReducer::removeRedundantBids) .collect(Collectors.toList()); - ExtRequestTargeting targeting = targeting(bidRequest); - final Set winningBids = newOrEmptySet(targeting); - final Set winningBidsByBidder = newOrEmptySet(targeting); + final List imps = bidRequest.getImp(); + final Map> bidResponseToBidInfos = updatedBidderResponses.stream() + .collect(Collectors.toMap(Function.identity(), bidderResponse -> toBidInfo(bidderResponse, imps))); - final GeneratedBidIds generatedBidIds = GeneratedBidIds.of(bidderResponses, - (ignored, bid) -> bidIdGenerator.getType() != IdGeneratorType.none - ? bidIdGenerator.generateId() - : bid.getId()); + final Set bidInfos = bidResponseToBidInfos.values().stream() + .filter(CollectionUtils::isNotEmpty) + .flatMap(Collection::stream) + .collect(Collectors.toSet()); + + final ExtRequestTargeting targeting = targeting(bidRequest); + final Set winningBids = newOrEmptySet(targeting); + final Set winningBidsByBidder = newOrEmptySet(targeting); // determine winning bids only if targeting is present if (targeting != null) { - populateWinningBids(updatedBidderResponses, winningBids, winningBidsByBidder); + populateWinningBids(bidInfos, winningBids, winningBidsByBidder); } - final Set bidsToCache = cacheInfo.isShouldCacheWinningBidsOnly() - ? winningBids - : updatedBidderResponses.stream().flatMap(BidResponseCreator::getBids).collect(Collectors.toSet()); + final Set bidsToCache = cacheInfo.isShouldCacheWinningBidsOnly() ? winningBids : bidInfos; final EventsContext eventsContext = EventsContext.builder() .enabledForAccount(eventsEnabledForAccount(auctionContext)) @@ -226,23 +232,16 @@ private Future cacheBidsAndCreateResponse(List bidd .integration(integrationFrom(auctionContext)) .build(); - return toBidsWithCacheIds( - updatedBidderResponses, - bidsToCache, - generatedBidIds, - auctionContext, - cacheInfo, - eventsContext) + return cacheBids(bidsToCache, auctionContext, cacheInfo, eventsContext) .compose(cacheResult -> videoStoredDataResult(auctionContext) .map(videoStoredDataResult -> toBidResponse( - updatedBidderResponses, + bidResponseToBidInfos, auctionContext, targeting, winningBids, winningBidsByBidder, cacheInfo, cacheResult, - generatedBidIds, videoStoredDataResult, eventsContext, auctionTimestamp, @@ -255,6 +254,37 @@ private static ExtRequestTargeting targeting(BidRequest bidRequest) { return prebid != null ? prebid.getTargeting() : null; } + private List toBidInfo(BidderResponse bidderResponse, List imps) { + return Stream.of(bidderResponse) + .map(BidderResponse::getSeatBid) + .filter(Objects::nonNull) + .map(BidderSeatBid::getBids) + .filter(Objects::nonNull) + .flatMap(Collection::stream) + .map(bidderBid -> toBidInfo(bidderBid.getBid(), bidderBid.getType(), imps, bidderResponse.getBidder())) + .collect(Collectors.toList()); + } + + private BidInfo toBidInfo(Bid bid, BidType type, List imps, String bidder) { + return BidInfo.builder() + .generatedBidId(bidIdGenerator.getType() != IdGeneratorType.none ? bidIdGenerator.generateId() : null) + .bid(bid) + .bidType(type) + .bidder(bidder) + .correspondingImp(correspondingImp(bid, imps)) + .build(); + } + + private static Imp correspondingImp(Bid bid, List imps) { + final String impId = bid.getImpid(); + return imps.stream() + .filter(imp -> Objects.equals(impId, imp.getId())) + .findFirst() + // Should never occur. See ResponseBidValidator + .orElseThrow( + () -> new PreBidException(String.format("Bid with impId %s doesn't have matched imp", impId))); + } + /** * Extracts auction timestamp from {@link ExtRequest} or get it from {@link Clock} if it is null. */ @@ -269,7 +299,7 @@ private long auctionTimestamp(AuctionContext auctionContext) { * Returns {@link ExtBidResponse} object, populated with response time, errors and debug info (if requested) * from all bidders. */ - private ExtBidResponse toExtBidResponse(List bidderResponses, + private ExtBidResponse toExtBidResponse(Collection bidderResponses, AuctionContext auctionContext, CacheServiceResult cacheResult, VideoStoredDataResult videoStoredDataResult, @@ -293,7 +323,7 @@ private ExtBidResponse toExtBidResponse(List bidderResponses, /** * Returns new {@link HashSet} in case of existing keywordsCreator or empty collection if null. */ - private static Set newOrEmptySet(ExtRequestTargeting targeting) { + private static Set newOrEmptySet(ExtRequestTargeting targeting) { return targeting != null ? new HashSet<>() : Collections.emptySet(); } @@ -306,171 +336,81 @@ private static Set newOrEmptySet(ExtRequestTargeting targeting) { *

* Winning bid is the one with the highest price. */ - private static void populateWinningBids(List bidderResponses, Set winningBids, - Set winningBidsByBidder) { - final Map winningBidsMap = new HashMap<>(); // impId -> Bid - final Map> winningBidsByBidderMap = new HashMap<>(); // impId -> [bidder -> Bid] - - for (BidderResponse bidderResponse : bidderResponses) { - final String bidder = bidderResponse.getBidder(); - - for (BidderBid bidderBid : bidderResponse.getSeatBid().getBids()) { - final Bid bid = bidderBid.getBid(); - - tryAddWinningBid(bid, winningBidsMap); - tryAddWinningBidByBidder(bid, bidder, winningBidsByBidderMap); - } - } - - winningBids.addAll(winningBidsMap.values()); - - final List bidsByBidder = winningBidsByBidderMap.values().stream() - .flatMap(bidsByBidderMap -> bidsByBidderMap.values().stream()) - .collect(Collectors.toList()); - winningBidsByBidder.addAll(bidsByBidder); - } - - /** - * Tries to add a winning bid for each impId. - */ - private static void tryAddWinningBid(Bid bid, Map winningBids) { - final String impId = bid.getImpid(); - - if (!winningBids.containsKey(impId) || bid.getPrice().compareTo(winningBids.get(impId).getPrice()) > 0) { - winningBids.put(impId, bid); - } - } - - /** - * Tries to add a winning bid for each impId for separate bidder. - */ - private static void tryAddWinningBidByBidder(Bid bid, String bidder, - Map> winningBidsByBidder) { - final String impId = bid.getImpid(); - - if (!winningBidsByBidder.containsKey(impId)) { - final Map bidsByBidder = new HashMap<>(); - bidsByBidder.put(bidder, bid); - - winningBidsByBidder.put(impId, bidsByBidder); - } else { - final Map bidsByBidder = winningBidsByBidder.get(impId); - - if (!bidsByBidder.containsKey(bidder) - || bid.getPrice().compareTo(bidsByBidder.get(bidder).getPrice()) > 0) { - bidsByBidder.put(bidder, bid); - } + private static void populateWinningBids(Set bidInfos, + Set winningBids, + Set winningBidsByBidder) { + final Map> impIdToBidderToBidInfo = bidInfos.stream() + .collect(Collectors.groupingBy( + bidInfo -> bidInfo.getCorrespondingImp().getId(), + Collectors.toMap(BidInfo::getBidder, Function.identity(), BidResponseCreator::winningBidInfo))); + + for (Map bidderToBidInfo : impIdToBidderToBidInfo.values()) { + winningBidsByBidder.addAll(bidderToBidInfo.values()); + + bidderToBidInfo.values().stream() + .max(Comparator.comparing(o -> o.getBid().getPrice())) + .ifPresent(winningBids::add); } } - private static Stream getBids(BidderResponse bidderResponse) { - return Stream.of(bidderResponse) - .map(BidderResponse::getSeatBid) - .filter(Objects::nonNull) - .map(BidderSeatBid::getBids) - .filter(Objects::nonNull) - .flatMap(Collection::stream) - .map(BidderBid::getBid); + private static BidInfo winningBidInfo(BidInfo bidInfo1, BidInfo bidInfo2) { + final Bid bid1 = bidInfo1.getBid(); + final Bid bid2 = bidInfo2.getBid(); + return bid1.getPrice().compareTo(bid2.getPrice()) > 0 ? bidInfo1 : bidInfo2; } /** * Corresponds cacheId (or null if not present) to each {@link Bid}. */ - private Future toBidsWithCacheIds(List bidderResponses, - Set bidsToCache, - GeneratedBidIds generatedBidIds, - AuctionContext auctionContext, - BidRequestCacheInfo cacheInfo, - EventsContext eventsContext) { - + private Future cacheBids(Set bidsToCache, + AuctionContext auctionContext, + BidRequestCacheInfo cacheInfo, + EventsContext eventsContext) { if (!cacheInfo.isDoCaching()) { return Future.succeededFuture(CacheServiceResult.of(null, null, toMapBidsWithEmptyCacheIds(bidsToCache))); } // do not submit non deals bids with zero price to prebid cache - final List bidsValidToBeCached = bidsToCache.stream() + final List bidsValidToBeCached = bidsToCache.stream() .filter(BidResponseCreator::isValidForCaching) .collect(Collectors.toList()); - final boolean shouldCacheVideoBids = cacheInfo.isShouldCacheVideoBids(); - - final GeneratedBidIds bidderToVideoGeneratedBidIdsToModify = - shouldCacheVideoBids && eventsEnabledForAccount(auctionContext) - ? getGeneratedVideoBidIds(bidderResponses, generatedBidIds, - auctionContext.getBidRequest().getImp()) - : GeneratedBidIds.empty(); - final CacheContext cacheContext = CacheContext.builder() .cacheBidsTtl(cacheInfo.getCacheBidsTtl()) .cacheVideoBidsTtl(cacheInfo.getCacheVideoBidsTtl()) .shouldCacheBids(cacheInfo.isShouldCacheBids()) - .shouldCacheVideoBids(shouldCacheVideoBids) - .bidderToVideoGeneratedBidIdsToModify(bidderToVideoGeneratedBidIdsToModify) - .bidderToBidsToGeneratedIds(generatedBidIds) + .shouldCacheVideoBids(cacheInfo.isShouldCacheVideoBids()) .build(); return cacheService.cacheBidsOpenrtb(bidsValidToBeCached, auctionContext, cacheContext, eventsContext) .map(cacheResult -> addNotCachedBids(cacheResult, bidsToCache)); } - private static boolean isValidForCaching(Bid bid) { + private static boolean isValidForCaching(BidInfo bidInfo) { + final Bid bid = bidInfo.getBid(); final BigDecimal price = bid.getPrice(); return bid.getDealid() != null ? price.compareTo(BigDecimal.ZERO) >= 0 : price.compareTo(BigDecimal.ZERO) > 0; } - private GeneratedBidIds getGeneratedVideoBidIds(List bidderResponses, - GeneratedBidIds generatedBidIds, - List imps) { - - final List vastModifyAllowedResponses = bidderResponses.stream() - .filter(bidderResponse -> bidderCatalog.isModifyingVastXmlAllowed(bidderResponse.getBidder())) - .map(bidderResponse -> makeVideoBidsBidderResponse(bidderResponse, imps)) - .filter(Objects::nonNull) - .collect(Collectors.toList()); - - return GeneratedBidIds.of(vastModifyAllowedResponses, - (bidder, bid) -> generatedBidIds.getGeneratedId(bidder, bid.getId(), bid.getImpid())); - } - - private static BidderResponse makeVideoBidsBidderResponse(BidderResponse bidderResponse, List imps) { - final List videoBidderBids = bidderResponse.getSeatBid().getBids().stream() - .filter(bidderBid -> isVideoBid(bidderBid, imps)) - .collect(Collectors.toList()); - - final BidderSeatBid bidderSeatBid = bidderResponse.getSeatBid(); - - return CollectionUtils.isNotEmpty(videoBidderBids) - ? BidderResponse.of( - bidderResponse.getBidder(), - BidderSeatBid.of(videoBidderBids, bidderSeatBid.getHttpCalls(), bidderSeatBid.getErrors()), - bidderResponse.getResponseTime()) - : null; - } - - private static boolean isVideoBid(BidderBid bidderBid, List imps) { - return imps.stream() - .filter(imp -> imp.getVideo() != null) - .map(Imp::getId) - .anyMatch(impId -> bidderBid.getBid().getImpid().equals(impId)); - } - /** * Creates a map with {@link Bid} as a key and null as a value. */ - private static Map toMapBidsWithEmptyCacheIds(Set bids) { + private static Map toMapBidsWithEmptyCacheIds(Set bids) { return bids.stream() + .map(BidInfo::getBid) .collect(Collectors.toMap(Function.identity(), ignored -> CacheInfo.empty())); } /** * Adds bids with no cache id info. */ - private static CacheServiceResult addNotCachedBids(CacheServiceResult cacheResult, Set bids) { + private static CacheServiceResult addNotCachedBids(CacheServiceResult cacheResult, Set bidInfos) { final Map bidToCacheId = cacheResult.getCacheBids(); - if (bids.size() > bidToCacheId.size()) { + if (bidInfos.size() > bidToCacheId.size()) { final Map updatedBidToCacheInfo = new HashMap<>(bidToCacheId); - for (Bid bid : bids) { + for (BidInfo bidInfo : bidInfos) { + final Bid bid = bidInfo.getBid(); if (!updatedBidToCacheInfo.containsKey(bid)) { updatedBidToCacheInfo.put(bid, CacheInfo.empty()); } @@ -480,10 +420,11 @@ private static CacheServiceResult addNotCachedBids(CacheServiceResult cacheResul return cacheResult; } - private static Map> toExtHttpCalls(List bidderResponses, + private static Map> toExtHttpCalls(Collection bidderResponses, CacheServiceResult cacheResult) { final Map> bidderHttpCalls = bidderResponses.stream() - .collect(Collectors.toMap(BidderResponse::getBidder, + .collect(Collectors.toMap( + BidderResponse::getBidder, bidderResponse -> ListUtils.emptyIfNull(bidderResponse.getSeatBid().getHttpCalls()))); final DebugHttpCall httpCall = cacheResult.getHttpCall(); @@ -507,7 +448,7 @@ private static ExtHttpCall toExtHttpCall(DebugHttpCall debugHttpCall) { .build(); } - private Map> toExtBidderErrors(List bidderResponses, + private Map> toExtBidderErrors(Collection bidderResponses, AuctionContext auctionContext, CacheServiceResult cacheResult, VideoStoredDataResult videoStoredDataResult, @@ -528,7 +469,7 @@ private Map> toExtBidderErrors(List /** * Returns a map with bidder name as a key and list of {@link ExtBidderError}s as a value. */ - private static Map> extractBidderErrors(List bidderResponses) { + private static Map> extractBidderErrors(Collection bidderResponses) { return bidderResponses.stream() .filter(bidderResponse -> CollectionUtils.isNotEmpty(bidderResponse.getSeatBid().getErrors())) .collect(Collectors.toMap(BidderResponse::getBidder, @@ -632,7 +573,7 @@ private static Stream asStream(Iterator iterator) { /** * Returns a map with response time by bidders and cache. */ - private static Map toResponseTimes(List bidderResponses, + private static Map toResponseTimes(Collection bidderResponses, CacheServiceResult cacheResult) { final Map responseTimeMillis = bidderResponses.stream() .collect(Collectors.toMap(BidderResponse::getBidder, BidderResponse::getResponseTime)); @@ -648,14 +589,13 @@ private static Map toResponseTimes(List bidderR /** * Returns {@link BidResponse} based on list of {@link BidderResponse}s and {@link CacheServiceResult}. */ - private BidResponse toBidResponse(List bidderResponses, + private BidResponse toBidResponse(Map> bidResponseToBidInfos, AuctionContext auctionContext, ExtRequestTargeting targeting, - Set winningBids, - Set winningBidsByBidder, + Set winningBids, + Set winningBidsByBidder, BidRequestCacheInfo requestCacheInfo, CacheServiceResult cacheResult, - GeneratedBidIds generatedBidIds, VideoStoredDataResult videoStoredDataResult, EventsContext eventsContext, long auctionTimestamp, @@ -665,17 +605,16 @@ private BidResponse toBidResponse(List bidderResponses, final Account account = auctionContext.getAccount(); final Map> bidErrors = new HashMap<>(); - final List seatBids = bidderResponses.stream() - .filter(bidderResponse -> !bidderResponse.getSeatBid().getBids().isEmpty()) - .map(bidderResponse -> toSeatBid( - bidderResponse, + final List seatBids = bidResponseToBidInfos.values().stream() + .filter(CollectionUtils::isNotEmpty) + .map(bidInfos -> toSeatBid( + bidInfos, targeting, bidRequest, winningBids, winningBidsByBidder, requestCacheInfo, cacheResult.getCacheBids(), - generatedBidIds, videoStoredDataResult, account, bidErrors, @@ -683,7 +622,7 @@ private BidResponse toBidResponse(List bidderResponses, .collect(Collectors.toList()); final ExtBidResponse extBidResponse = toExtBidResponse( - bidderResponses, + bidResponseToBidInfos.keySet(), auctionContext, cacheResult, videoStoredDataResult, @@ -745,32 +684,33 @@ private boolean checkEchoVideoAttrs(Imp imp) { * Creates an OpenRTB {@link SeatBid} for a bidder. It will contain all the bids supplied by a bidder and a "bidder" * extension field populated. */ - private SeatBid toSeatBid(BidderResponse bidderResponse, + private SeatBid toSeatBid(List bidInfos, ExtRequestTargeting targeting, BidRequest bidRequest, - Set winningBids, - Set winningBidsByBidder, + Set winningBids, + Set winningBidsByBidder, BidRequestCacheInfo requestCacheInfo, Map bidToCacheInfo, - GeneratedBidIds generatedBidIds, VideoStoredDataResult videoStoredDataResult, Account account, Map> bidErrors, EventsContext eventsContext) { - final String bidder = bidderResponse.getBidder(); + final String bidder = bidInfos.stream() + .map(BidInfo::getBidder) + .findFirst() + // Should never occur + .orElseThrow(() -> new IllegalArgumentException("Bidder was not defined for bidInfo")); - final List bids = bidderResponse.getSeatBid().getBids().stream() - .map(bidderBid -> toBid( - bidderBid, - bidder, + final List bids = bidInfos.stream() + .map(bidInfo -> toBid( + bidInfo, targeting, bidRequest, winningBids, winningBidsByBidder, requestCacheInfo, bidToCacheInfo, - generatedBidIds, videoStoredDataResult.getImpIdToStoredVideo(), account, eventsContext, @@ -788,26 +728,24 @@ private SeatBid toSeatBid(BidderResponse bidderResponse, /** * Returns an OpenRTB {@link Bid} with "prebid" and "bidder" extension fields populated. */ - private Bid toBid(BidderBid bidderBid, - String bidder, + private Bid toBid(BidInfo bidInfo, ExtRequestTargeting targeting, BidRequest bidRequest, - Set winningBids, - Set winningBidsByBidder, + Set winningBids, + Set winningBidsByBidder, BidRequestCacheInfo requestCacheInfo, Map bidsWithCacheIds, - GeneratedBidIds generatedBidIds, Map impIdToStoredVideo, Account account, EventsContext eventsContext, Map> bidErrors) { - - final Bid bid = bidderBid.getBid(); - final BidType bidType = bidderBid.getType(); + final Bid bid = bidInfo.getBid(); + final BidType bidType = bidInfo.getBidType(); + final String bidder = bidInfo.getBidder(); // preliminary variables are needed because bid is changing below, so we can lost it in winning bids sets - final boolean isWinningBid = winningBids.contains(bid); - final boolean isWinningBidByBidder = winningBidsByBidder.contains(bid); + final boolean isWinningBid = winningBids.contains(bidInfo); + final boolean isWinningBidByBidder = winningBidsByBidder.contains(bidInfo); final CacheInfo cacheInfo = bidsWithCacheIds.get(bid); final String cacheId = cacheInfo != null ? cacheInfo.getCacheId() : null; @@ -816,6 +754,16 @@ private Bid toBid(BidderBid bidderBid, if ((videoCacheId != null && !requestCacheInfo.isReturnCreativeVideoBids()) || (cacheId != null && !requestCacheInfo.isReturnCreativeBids())) { bid.setAdm(null); + } else if (bidType.equals(BidType.video)) { + final String adm = vastModifier.createBidVastXml( + bidder, + bid.getAdm(), + bid.getNurl(), + bidInfo.getBidId(), + account.getId(), + eventsContext); + + bid.setAdm(adm); } final boolean isApp = bidRequest.getApp() != null; @@ -823,8 +771,7 @@ private Bid toBid(BidderBid bidderBid, try { addNativeMarkup(bid, bidRequest.getImp()); } catch (PreBidException e) { - bidErrors.putIfAbsent(bidder, new ArrayList<>()); - bidErrors.get(bidder) + bidErrors.computeIfAbsent(bidder, ignored -> new ArrayList<>()) .add(ExtBidderError.of(BidderError.Type.bad_server_response.getCode(), e.getMessage())); return null; } @@ -845,13 +792,12 @@ private Bid toBid(BidderBid bidderBid, final CacheAsset vastXml = videoCacheId != null ? toCacheAsset(videoCacheId) : null; final ExtResponseCache cache = bids != null || vastXml != null ? ExtResponseCache.of(bids, vastXml) : null; - final String generatedBidId = generatedBidIds.getGeneratedId(bidder, bid.getId(), bid.getImpid()); final Video storedVideo = impIdToStoredVideo.get(bid.getImpid()); - final Events events = createEvents(bidder, account, generatedBidId, eventsContext); + final Events events = createEvents(bidder, account, bidInfo.getBidId(), eventsContext); final ExtBidPrebidVideo extBidPrebidVideo = getExtBidPrebidVideo(bid.getExt()); final ExtBidPrebid extBidPrebid = ExtBidPrebid.builder() - .bidid(bidIdGenerator.getType() != IdGeneratorType.none ? generatedBidId : null) + .bidid(bidInfo.getGeneratedBidId()) .type(bidType) .targeting(targetingKeywords) .cache(cache) @@ -985,9 +931,8 @@ private TargetingKeywordsCreator resolveKeywordsCreator(BidType bidType, boolean isApp, BidRequest bidRequest, Account account) { - - final Map keywordsCreatorByBidType = keywordsCreatorByBidType(targeting, - isApp, bidRequest, account); + final Map keywordsCreatorByBidType = + keywordsCreatorByBidType(targeting, isApp, bidRequest, account); return keywordsCreatorByBidType.getOrDefault(bidType, keywordsCreator(targeting, isApp, bidRequest, account)); } @@ -1100,6 +1045,7 @@ private CacheAsset toCacheAsset(String cacheId) { private String integrationFrom(AuctionContext auctionContext) { final ExtRequest extRequest = auctionContext.getBidRequest().getExt(); final ExtRequestPrebid prebid = extRequest == null ? null : extRequest.getPrebid(); + return prebid != null ? prebid.getIntegration() : null; } diff --git a/src/main/java/org/prebid/server/auction/model/BidInfo.java b/src/main/java/org/prebid/server/auction/model/BidInfo.java new file mode 100644 index 00000000000..27a7dfd73ea --- /dev/null +++ b/src/main/java/org/prebid/server/auction/model/BidInfo.java @@ -0,0 +1,26 @@ +package org.prebid.server.auction.model; + +import com.iab.openrtb.request.Imp; +import com.iab.openrtb.response.Bid; +import lombok.Builder; +import lombok.Value; +import org.prebid.server.proto.openrtb.ext.response.BidType; + +@Builder(toBuilder = true) +@Value +public class BidInfo { + + String generatedBidId; + + Bid bid; + + Imp correspondingImp; + + String bidder; + + BidType bidType; + + public String getBidId() { + return generatedBidId != null ? generatedBidId : bid.getId(); + } +} diff --git a/src/main/java/org/prebid/server/auction/model/GeneratedBidIds.java b/src/main/java/org/prebid/server/auction/model/GeneratedBidIds.java deleted file mode 100644 index 4eb6e2f6603..00000000000 --- a/src/main/java/org/prebid/server/auction/model/GeneratedBidIds.java +++ /dev/null @@ -1,81 +0,0 @@ -package org.prebid.server.auction.model; - -import com.iab.openrtb.response.Bid; -import lombok.AllArgsConstructor; -import org.prebid.server.bidder.model.BidderBid; - -import java.util.Collections; -import java.util.List; -import java.util.Map; -import java.util.Optional; -import java.util.function.BiFunction; -import java.util.stream.Collectors; - - -/** - * Class creates and holds generated bid ids per bidder per imp. - */ -@AllArgsConstructor -public class GeneratedBidIds { - - private static final String BID_IMP_ID_PATTERN = "%s-%s"; - - private final Map> bidderToBidIds; - - /** - * Creates an object of {@link GeneratedBidIds} with {@link Map} where key is a bidder and value is another map, - * that have pair of bidId-impId to uniquely identify the bid withing the bidder and as value has bid Id generated - * by idGenerationStrategy parameter. - */ - public static GeneratedBidIds of(List bidderResponses, - BiFunction idGenerationStrategy) { - final Map> generatedBidIds = bidderResponses.stream() - .collect(Collectors.toMap(BidderResponse::getBidder, - bidderResponse -> bidderResponse.getSeatBid() - .getBids().stream() - .map(BidderBid::getBid) - .collect(Collectors.toMap(bid -> makeUniqueBidId(bid.getId(), bid.getImpid()), - bid -> idGenerationStrategy.apply(bidderResponse.getBidder(), bid))))); - return new GeneratedBidIds(generatedBidIds); - } - - /** - * Returns empty {@link GeneratedBidIds}. - */ - public static GeneratedBidIds empty() { - return new GeneratedBidIds(Collections.emptyMap()); - } - - /** - * Creates unique identifier for bid that consist from pair bidId-impId. - */ - private static String makeUniqueBidId(String bidId, String impId) { - return String.format(BID_IMP_ID_PATTERN, bidId, impId); - } - - /** - * Returns bidder for bidId and impId parameters. - */ - public Optional getBidderForBid(String bidId, String impId) { - final String uniqueBidId = makeUniqueBidId(bidId, impId); - return bidderToBidIds.entrySet().stream() - .filter(bidIdToGeneratedId -> bidIdToGeneratedId.getValue().containsKey(uniqueBidId)) - .findFirst() - .map(Map.Entry::getKey); - } - - /** - * Returns generated id for bid identified by bidder, bidId and impId parameters. - */ - public String getGeneratedId(String bidder, String bidId, String impId) { - if (bidderToBidIds.containsKey(bidder)) { - return bidderToBidIds.get(bidder).get(makeUniqueBidId(bidId, impId)); - } else { - return null; - } - } - - public Map> getBidderToBidIds() { - return bidderToBidIds; - } -} diff --git a/src/main/java/org/prebid/server/cache/CacheService.java b/src/main/java/org/prebid/server/cache/CacheService.java index fde07b2922f..a7ab3788f69 100644 --- a/src/main/java/org/prebid/server/cache/CacheService.java +++ b/src/main/java/org/prebid/server/cache/CacheService.java @@ -11,7 +11,7 @@ import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.lang3.ObjectUtils; import org.prebid.server.auction.model.AuctionContext; -import org.prebid.server.auction.model.GeneratedBidIds; +import org.prebid.server.auction.model.BidInfo; import org.prebid.server.cache.model.CacheBid; import org.prebid.server.cache.model.CacheContext; import org.prebid.server.cache.model.CacheHttpRequest; @@ -31,15 +31,16 @@ import org.prebid.server.json.DecodeException; import org.prebid.server.json.JacksonMapper; import org.prebid.server.metric.Metrics; +import org.prebid.server.proto.openrtb.ext.response.BidType; import org.prebid.server.settings.model.Account; import org.prebid.server.util.HttpUtil; +import org.prebid.server.vast.VastModifier; import org.prebid.server.vertx.http.HttpClient; import org.prebid.server.vertx.http.model.HttpClientResponse; import java.net.MalformedURLException; import java.net.URL; import java.time.Clock; -import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; import java.util.List; @@ -66,6 +67,7 @@ public class CacheService { private final HttpClient httpClient; private final URL endpointUrl; private final String cachedAssetUrlTemplate; + private final VastModifier vastModifier; private final EventsService eventsService; private final Metrics metrics; private final Clock clock; @@ -75,6 +77,7 @@ public CacheService(CacheTtl mediaTypeCacheTtl, HttpClient httpClient, URL endpointUrl, String cachedAssetUrlTemplate, + VastModifier vastModifier, EventsService eventsService, Metrics metrics, Clock clock, @@ -84,6 +87,7 @@ public CacheService(CacheTtl mediaTypeCacheTtl, this.httpClient = Objects.requireNonNull(httpClient); this.endpointUrl = Objects.requireNonNull(endpointUrl); this.cachedAssetUrlTemplate = Objects.requireNonNull(cachedAssetUrlTemplate); + this.vastModifier = Objects.requireNonNull(vastModifier); this.eventsService = Objects.requireNonNull(eventsService); this.metrics = Objects.requireNonNull(metrics); this.clock = Objects.requireNonNull(clock); @@ -147,12 +151,13 @@ private Future failResponse(Throwable exception, String accoun * The returned result will always have the number of elements equals putObjects list size. */ public Future cachePutObjects(List putObjects, + Boolean isEventsEnabled, Set biddersAllowingVastUpdate, String accountId, - String integration, Timeout timeout) { - + String integration, + Timeout timeout) { final List cachedCreatives = - updatePutObjects(putObjects, biddersAllowingVastUpdate, accountId, integration); + updatePutObjects(putObjects, isEventsEnabled, biddersAllowingVastUpdate, accountId, integration); updateCreativeMetrics(accountId, cachedCreatives); @@ -163,115 +168,49 @@ public Future cachePutObjects(List putObjects, * Modify VAST value in putObjects. */ private List updatePutObjects(List putObjects, - Set biddersAllowingVastUpdate, + Boolean isEventsEnabled, + Set allowedBidders, String accountId, String integration) { - - final List result = new ArrayList<>(); - - for (final PutObject putObject : putObjects) { - final PutObject.PutObjectBuilder builder = putObject.toBuilder() - // remove "/vtrack" specific fields - .bidid(null) - .bidder(null) - .timestamp(null); - - final JsonNode value = putObject.getValue(); - if (biddersAllowingVastUpdate.contains(putObject.getBidder()) && value != null) { - final String eventUrl = eventsService.vastUrlTracking( - putObject.getBidid(), - putObject.getBidder(), - accountId, - putObject.getTimestamp(), - integration); - final String updatedVastXml = appendTrackingUrlToVastXml(value.asText(), eventUrl); - builder.value(new TextNode(updatedVastXml)).build(); - } - - final PutObject payload = builder.build(); - - result.add(CachedCreative.of(payload, creativeSizeFromTextNode(payload.getValue()))); - } - - return result; + return putObjects.stream() + .map(putObject -> putObject.toBuilder() + // remove "/vtrack" specific fields + .bidid(null) + .bidder(null) + .timestamp(null) + + .value(vastModifier.modifyVastXml(isEventsEnabled, allowedBidders, putObject, accountId, + integration)) + .build()) + .map(payload -> CachedCreative.of(payload, creativeSizeFromTextNode(payload.getValue()))) + .collect(Collectors.toList()); } - /** - * Makes cache for OpenRTB {@link com.iab.openrtb.response.Bid}s. - */ - public Future cacheBidsOpenrtb(List bids, + public Future cacheBidsOpenrtb(List bidsToCache, AuctionContext auctionContext, CacheContext cacheContext, EventsContext eventsContext) { - - if (CollectionUtils.isEmpty(bids)) { + if (CollectionUtils.isEmpty(bidsToCache)) { return Future.succeededFuture(CacheServiceResult.empty()); } final List imps = auctionContext.getBidRequest().getImp(); - - final Map impIdToTtl = new HashMap<>(imps.size()); - boolean impWithNoExpExists = false; // indicates at least one impression without expire presents - final List videoImpIds = new ArrayList<>(); - final boolean shouldCacheVideoBids = cacheContext.isShouldCacheVideoBids(); - for (final Imp imp : imps) { - final String impId = imp.getId(); - impIdToTtl.put(impId, imp.getExp()); - impWithNoExpExists |= imp.getExp() == null; - if (shouldCacheVideoBids && impId != null && imp.getVideo() != null) { - videoImpIds.add(impId); - } - } + final boolean isAnyEmptyExpImp = imps.stream() + .map(Imp::getExp) + .anyMatch(Objects::isNull); final Account account = auctionContext.getAccount(); + final CacheTtl accountCacheTtl = accountCacheTtl(isAnyEmptyExpImp, account); - final List cacheBids = getCacheBids(cacheContext.isShouldCacheBids(), bids, impIdToTtl, - impWithNoExpExists, cacheContext.getCacheBidsTtl(), account); - - final List videoCacheBids = getVideoCacheBids(shouldCacheVideoBids, bids, - impIdToTtl, videoImpIds, impWithNoExpExists, cacheContext.getCacheVideoBidsTtl(), account); - - return doCacheOpenrtb( - cacheBids, - videoCacheBids, - auctionContext, - cacheContext.getBidderToVideoGeneratedBidIdsToModify(), - cacheContext.getBidderToBidsToGeneratedIds(), - eventsContext); - } - - /** - * Creates list of {@link CacheBid}s from the list of {@link com.iab.openrtb.response.Bid}s. - */ - private List getCacheBids(boolean shouldCacheBids, - List bids, - Map impIdToTtl, - boolean impWithNoExpExists, - Integer cacheBidsTtl, - Account account) { - - return shouldCacheBids - ? bids.stream() - .map(bid -> toCacheBid(bid, impIdToTtl, cacheBidsTtl, - accountCacheTtlFrom(impWithNoExpExists, account), false)) - .collect(Collectors.toList()) + final List cacheBids = cacheContext.isShouldCacheBids() + ? getCacheBids(bidsToCache, cacheContext.getCacheBidsTtl(), accountCacheTtl) : Collections.emptyList(); - } - /** - * Creates list of video {@link CacheBid}s from the list of {@link com.iab.openrtb.response.Bid}s. - */ - private List getVideoCacheBids( - boolean shouldCacheVideoBids, List bids, Map impIdToTtl, - List videoImpIds, boolean impWithNoExpExists, Integer cacheVideoBidsTtl, Account account) { - - return shouldCacheVideoBids - ? bids.stream() - .filter(bid -> videoImpIds.contains(bid.getImpid())) // bid is video - .map(bid -> toCacheBid(bid, impIdToTtl, cacheVideoBidsTtl, - accountCacheTtlFrom(impWithNoExpExists, account), true)) - .collect(Collectors.toList()) + final List videoCacheBids = cacheContext.isShouldCacheVideoBids() + ? getVideoCacheBids(bidsToCache, cacheContext.getCacheVideoBidsTtl(), accountCacheTtl) : Collections.emptyList(); + + return doCacheOpenrtb(cacheBids, videoCacheBids, auctionContext, eventsContext); } /** @@ -280,22 +219,40 @@ private List getVideoCacheBids( * Returns empty {@link CacheTtl} when there are no impressions without expiration or * if{@link Account} has neither of banner or video cache ttl. */ - private CacheTtl accountCacheTtlFrom(boolean impWithNoExpExists, Account account) { + private CacheTtl accountCacheTtl(boolean impWithNoExpExists, Account account) { return impWithNoExpExists && (account.getBannerCacheTtl() != null || account.getVideoCacheTtl() != null) ? CacheTtl.of(account.getBannerCacheTtl(), account.getVideoCacheTtl()) : CacheTtl.empty(); } + private List getCacheBids(List bidInfos, + Integer cacheBidsTtl, + CacheTtl accountCacheTtl) { + return bidInfos.stream() + .map(bidInfo -> toCacheBid(bidInfo, cacheBidsTtl, accountCacheTtl, false)) + .collect(Collectors.toList()); + } + + private List getVideoCacheBids(List bidInfos, + Integer cacheBidsTtl, + CacheTtl accountCacheTtl) { + return bidInfos.stream() + .filter(bidInfo -> bidInfo.getBidType().equals(BidType.video)) + .map(bidInfo -> toCacheBid(bidInfo, cacheBidsTtl, accountCacheTtl, true)) + .collect(Collectors.toList()); + } + /** - * Creates {@link CacheBid} from given {@link com.iab.openrtb.response.Bid} and determined cache ttl. + * Creates {@link CacheBid} from given {@link BidInfo} and determined cache ttl. */ - private CacheBid toCacheBid(com.iab.openrtb.response.Bid bid, - Map impIdToTtl, + private CacheBid toCacheBid(BidInfo bidInfo, Integer requestTtl, CacheTtl accountCacheTtl, boolean isVideoBid) { + final com.iab.openrtb.response.Bid bid = bidInfo.getBid(); final Integer bidTtl = bid.getExp(); - final Integer impTtl = impIdToTtl.get(bid.getImpid()); + final Imp correspondingImp = bidInfo.getCorrespondingImp(); + final Integer impTtl = correspondingImp.getExp(); final Integer accountMediaTypeTtl = isVideoBid ? accountCacheTtl.getVideoCacheTtl() : accountCacheTtl.getBannerCacheTtl(); @@ -304,7 +261,7 @@ private CacheBid toCacheBid(com.iab.openrtb.response.Bid bid, : mediaTypeCacheTtl.getBannerCacheTtl(); final Integer ttl = ObjectUtils.firstNonNull(bidTtl, impTtl, requestTtl, accountMediaTypeTtl, mediaTypeTtl); - return CacheBid.of(bid, ttl); + return CacheBid.of(bidInfo, ttl); } /** @@ -318,17 +275,14 @@ private CacheBid toCacheBid(com.iab.openrtb.response.Bid bid, private Future doCacheOpenrtb(List bids, List videoBids, AuctionContext auctionContext, - GeneratedBidIds bidderToVideoBidIdsToModify, - GeneratedBidIds biddersToCacheBidIds, EventsContext eventsContext) { final Account account = auctionContext.getAccount(); + final String accountId = account.getId(); final List cachedCreatives = Stream.concat( - bids.stream().map(cacheBid -> createJsonPutObjectOpenrtb( - cacheBid, biddersToCacheBidIds, account, eventsContext)), - videoBids.stream().map(cacheBid -> createXmlPutObjectOpenrtb( - cacheBid, bidderToVideoBidIdsToModify, account, eventsContext))) + bids.stream().map(cacheBid -> createJsonPutObjectOpenrtb(cacheBid, accountId, eventsContext)), + videoBids.stream().map(cacheBid -> createXmlPutObjectOpenrtb(cacheBid, accountId, eventsContext))) .collect(Collectors.toList()); if (cachedCreatives.isEmpty()) { @@ -343,7 +297,6 @@ private Future doCacheOpenrtb(List bids, final BidCacheRequest bidCacheRequest = toBidCacheRequest(cachedCreatives); - final String accountId = account.getId(); updateCreativeMetrics(accountId, cachedCreatives); final String url = endpointUrl.toString(); @@ -427,14 +380,13 @@ private int responseTime(long startTime) { * Used for OpenRTB auction request. Also, adds win url to result object if events are enabled. */ private CachedCreative createJsonPutObjectOpenrtb(CacheBid cacheBid, - GeneratedBidIds biddersToCacheBidIds, - Account account, + String accountId, EventsContext eventsContext) { - - final com.iab.openrtb.response.Bid bid = cacheBid.getBid(); + final BidInfo bidInfo = cacheBid.getBidInfo(); + final com.iab.openrtb.response.Bid bid = bidInfo.getBid(); final ObjectNode bidObjectNode = mapper.mapper().valueToTree(bid); - final String eventUrl = generateWinUrl(biddersToCacheBidIds, bid, account, eventsContext); + final String eventUrl = generateWinUrl(bidInfo.getBidId(), bidInfo.getBidder(), accountId, eventsContext); if (eventUrl != null) { bidObjectNode.put(BID_WURL_ATTRIBUTE, eventUrl); } @@ -445,104 +397,59 @@ private CachedCreative createJsonPutObjectOpenrtb(CacheBid cacheBid, .expiry(cacheBid.getTtl()) .build(); - return CachedCreative.of(payload, creativeSizeFromAdm(bid)); + return CachedCreative.of(payload, creativeSizeFromAdm(bid.getAdm())); } /** * Makes XML type {@link PutObject} from {@link com.iab.openrtb.response.Bid}. Used for OpenRTB auction request. */ private CachedCreative createXmlPutObjectOpenrtb(CacheBid cacheBid, - GeneratedBidIds bidderToVideoBidIdsToModify, - Account account, + String accountId, EventsContext eventsContext) { - - final com.iab.openrtb.response.Bid bid = cacheBid.getBid(); - final String vastXml = resolveVastXmlFrom(bid); - - final String eventUrl = generateVastUrlTracking(bidderToVideoBidIdsToModify, bid, account, eventsContext); - final String effectiveVastXml = eventUrl != null ? appendTrackingUrlToVastXml(vastXml, eventUrl) : vastXml; + final BidInfo bidInfo = cacheBid.getBidInfo(); + final com.iab.openrtb.response.Bid bid = bidInfo.getBid(); + final String vastXml = vastModifier.createBidVastXml( + bidInfo.getBidder(), + bid.getAdm(), + bid.getNurl(), + bidInfo.getBidId(), + accountId, + eventsContext); final PutObject payload = PutObject.builder() .type("xml") - .value(new TextNode(effectiveVastXml)) + .value(vastXml != null ? new TextNode(vastXml) : null) .expiry(cacheBid.getTtl()) .build(); return CachedCreative.of(payload, creativeSizeFromTextNode(payload.getValue())); } - private static String resolveVastXmlFrom(com.iab.openrtb.response.Bid bid) { - if (bid.getAdm() == null) { - return "" - + "prebid.org wrapper" - + "" - + "" - + ""; - } - - return bid.getAdm(); - } - - private String generateWinUrl(GeneratedBidIds biddersToCacheBidIds, - com.iab.openrtb.response.Bid bid, - Account account, + private String generateWinUrl(String bidId, + String bidder, + String accountId, EventsContext eventsContext) { if (eventsContext.isEnabledForAccount() && eventsContext.isEnabledForRequest()) { - final String bidId = bid.getId(); - final String impId = bid.getImpid(); - return biddersToCacheBidIds.getBidderForBid(bidId, impId) - .map(bidder -> eventsService.winUrl( - biddersToCacheBidIds.getGeneratedId(bidder, bidId, impId), - bidder, - account.getId(), - eventsContext.getAuctionTimestamp(), - eventsContext.getIntegration())) - .orElse(null); + return eventsService.winUrl( + bidId, + bidder, + accountId, + eventsContext.getAuctionTimestamp(), + eventsContext.getIntegration()); } return null; } - private String generateVastUrlTracking(GeneratedBidIds bidderToVideoBidIdsToModify, - com.iab.openrtb.response.Bid bid, - Account account, - EventsContext eventsContext) { - - if (eventsContext.isEnabledForAccount()) { - final String bidId = bid.getId(); - final String impId = bid.getImpid(); - return bidderToVideoBidIdsToModify.getBidderForBid(bidId, impId) - .map(bidder -> eventsService.vastUrlTracking( - bidderToVideoBidIdsToModify.getGeneratedId(bidder, bidId, impId), - bidder, - account.getId(), - eventsContext.getAuctionTimestamp(), - eventsContext.getIntegration())) - .orElse(null); - } - - return null; - } - - private String appendTrackingUrlToVastXml(String vastXml, String vastUrlTracking) { - final String closeTag = ""; - final int closeTagIndex = vastXml.indexOf(closeTag); - - // no impression tag - pass it as it is - if (closeTagIndex == -1) { - return vastXml; - } - - final String impressionUrl = ""; - final String openTag = ""; - - // empty impression tag - just insert the link - if (closeTagIndex - vastXml.indexOf(openTag) == openTag.length()) { - return vastXml.replaceFirst(openTag, openTag + impressionUrl); - } + private static List bidsToCachedCreatives( + List bids, Function requestItemCreator) { - return vastXml.replaceFirst(closeTag, closeTag + openTag + impressionUrl + closeTag); + return bids.stream() + .filter(Objects::nonNull) + .map(requestItemCreator) + .filter(Objects::nonNull) + .collect(Collectors.toList()); } /** @@ -595,13 +502,15 @@ private static Map toResultMap(List videoBids = cacheVideoBids.stream() - .map(CacheBid::getBid) + .map(CacheBid::getBidInfo) + .map(BidInfo::getBid) .collect(Collectors.toList()); final int bidsSize = cacheBids.size(); for (int i = 0; i < bidsSize; i++) { final CacheBid cacheBid = cacheBids.get(i); - final com.iab.openrtb.response.Bid bid = cacheBid.getBid(); + final BidInfo bidInfo = cacheBid.getBidInfo(); + final com.iab.openrtb.response.Bid bid = bidInfo.getBid(); final Integer ttl = cacheBid.getTtl(); // determine uuid for video bid @@ -614,7 +523,8 @@ private static Map toResultMap(List cached } } - private static int creativeSizeFromAdm(com.iab.openrtb.response.Bid bid) { - return lengthOrZero(bid.getAdm()); + private static int creativeSizeFromAdm(String adm) { + return lengthOrZero(adm); } private static int lengthOrZero(String adm) { diff --git a/src/main/java/org/prebid/server/cache/model/CacheBid.java b/src/main/java/org/prebid/server/cache/model/CacheBid.java index 1c63f23a454..a10ab9a7a3b 100644 --- a/src/main/java/org/prebid/server/cache/model/CacheBid.java +++ b/src/main/java/org/prebid/server/cache/model/CacheBid.java @@ -3,6 +3,7 @@ import com.iab.openrtb.response.Bid; import lombok.AllArgsConstructor; import lombok.Value; +import org.prebid.server.auction.model.BidInfo; import org.prebid.server.cache.CacheService; /** @@ -12,7 +13,7 @@ @Value public class CacheBid { - Bid bid; + BidInfo bidInfo; Integer ttl; } diff --git a/src/main/java/org/prebid/server/cache/model/CacheContext.java b/src/main/java/org/prebid/server/cache/model/CacheContext.java index 7c418808387..4d64bf6e3ad 100644 --- a/src/main/java/org/prebid/server/cache/model/CacheContext.java +++ b/src/main/java/org/prebid/server/cache/model/CacheContext.java @@ -2,7 +2,6 @@ import lombok.Builder; import lombok.Value; -import org.prebid.server.auction.model.GeneratedBidIds; /** * Holds the state needed to perform caching response bids. @@ -18,8 +17,4 @@ public class CacheContext { boolean shouldCacheVideoBids; Integer cacheVideoBidsTtl; - - GeneratedBidIds bidderToVideoGeneratedBidIdsToModify; - - GeneratedBidIds bidderToBidsToGeneratedIds; } diff --git a/src/main/java/org/prebid/server/handler/VtrackHandler.java b/src/main/java/org/prebid/server/handler/VtrackHandler.java index 3ed16761d4f..e422a0c74c9 100644 --- a/src/main/java/org/prebid/server/handler/VtrackHandler.java +++ b/src/main/java/org/prebid/server/handler/VtrackHandler.java @@ -25,7 +25,6 @@ import org.prebid.server.settings.ApplicationSettings; import org.prebid.server.settings.model.Account; -import java.util.Collections; import java.util.List; import java.util.Objects; import java.util.Set; @@ -143,10 +142,10 @@ private void handleAccountResult(AsyncResult asyncAccount, respondWithServerError(context, "Error occurred while fetching account", asyncAccount.cause()); } else { // insert impression tracking if account allows events and bidder allows VAST modification - final Set biddersAllowingVastUpdate = Objects.equals(asyncAccount.result().getEventsEnabled(), true) - ? biddersAllowingVastUpdate(vtrackPuts) - : Collections.emptySet(); - cacheService.cachePutObjects(vtrackPuts, biddersAllowingVastUpdate, accountId, integration, timeout) + final Account account = asyncAccount.result(); + final Boolean isEventEnabled = account.getEventsEnabled(); + final Set allowedBidders = biddersAllowingVastUpdate(vtrackPuts); + cacheService.cachePutObjects(vtrackPuts, isEventEnabled, allowedBidders, accountId, integration, timeout) .setHandler(asyncCache -> handleCacheResult(asyncCache, context)); } } diff --git a/src/main/java/org/prebid/server/spring/config/ServiceConfiguration.java b/src/main/java/org/prebid/server/spring/config/ServiceConfiguration.java index 6d9b7d2e53a..26c1cb786b9 100644 --- a/src/main/java/org/prebid/server/spring/config/ServiceConfiguration.java +++ b/src/main/java/org/prebid/server/spring/config/ServiceConfiguration.java @@ -58,6 +58,7 @@ import org.prebid.server.validation.RequestValidator; import org.prebid.server.validation.ResponseBidValidator; import org.prebid.server.validation.VideoRequestValidator; +import org.prebid.server.vast.VastModifier; import org.prebid.server.vertx.http.BasicHttpClient; import org.prebid.server.vertx.http.CircuitBreakerSecuredHttpClient; import org.prebid.server.vertx.http.HttpClient; @@ -92,6 +93,7 @@ CacheService cacheService( @Value("${cache.query}") String query, @Value("${cache.banner-ttl-seconds:#{null}}") Integer bannerCacheTtl, @Value("${cache.video-ttl-seconds:#{null}}") Integer videoCacheTtl, + VastModifier vastModifier, EventsService eventsService, HttpClient httpClient, Metrics metrics, @@ -103,12 +105,18 @@ CacheService cacheService( httpClient, CacheService.getCacheEndpointUrl(scheme, host, path), CacheService.getCachedAssetUrlTemplate(scheme, host, path, query), + vastModifier, eventsService, metrics, clock, mapper); } + @Bean + VastModifier vastModifier(BidderCatalog bidderCatalog, EventsService eventsService) { + return new VastModifier(bidderCatalog, eventsService); + } + @Bean ImplicitParametersExtractor implicitParametersExtractor(PublicSuffixList psl) { return new ImplicitParametersExtractor(psl); @@ -446,6 +454,7 @@ BidderErrorNotifier bidderErrorNotifier( BidResponseCreator bidResponseCreator( CacheService cacheService, BidderCatalog bidderCatalog, + VastModifier vastModifier, EventsService eventsService, StoredRequestProcessor storedRequestProcessor, BidResponseReducer bidResponseReducer, @@ -457,6 +466,7 @@ BidResponseCreator bidResponseCreator( return new BidResponseCreator( cacheService, bidderCatalog, + vastModifier, eventsService, storedRequestProcessor, bidResponseReducer, diff --git a/src/main/java/org/prebid/server/validation/ResponseBidValidator.java b/src/main/java/org/prebid/server/validation/ResponseBidValidator.java index f0e6ac31d89..2b2388e5d57 100644 --- a/src/main/java/org/prebid/server/validation/ResponseBidValidator.java +++ b/src/main/java/org/prebid/server/validation/ResponseBidValidator.java @@ -55,6 +55,7 @@ public ValidationResult validate( try { validateCommonFields(bidderBid.getBid()); + validateTypeSpecific(bidderBid); validateCurrency(bidderBid.getBidCurrency()); if (bidderBid.getType() == BidType.banner) { @@ -100,6 +101,14 @@ private static void validateCommonFields(Bid bid) throws ValidationException { } } + private static void validateTypeSpecific(BidderBid bidderBid) throws ValidationException { + final Bid bid = bidderBid.getBid(); + final boolean isVastSpecificAbsent = bid.getAdm() == null && bid.getNurl() == null; + if (Objects.equals(bidderBid.getType(), BidType.video) && isVastSpecificAbsent) { + throw new ValidationException("Bid \"%s\" with video type missing adm and nurl", bid.getId()); + } + } + private static void validateCurrency(String currency) { try { if (StringUtils.isNotBlank(currency)) { diff --git a/src/main/java/org/prebid/server/vast/VastModifier.java b/src/main/java/org/prebid/server/vast/VastModifier.java new file mode 100644 index 00000000000..f02139461f2 --- /dev/null +++ b/src/main/java/org/prebid/server/vast/VastModifier.java @@ -0,0 +1,99 @@ +package org.prebid.server.vast; + +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.node.TextNode; +import org.apache.commons.lang3.BooleanUtils; +import org.prebid.server.bidder.BidderCatalog; +import org.prebid.server.cache.proto.request.PutObject; +import org.prebid.server.events.EventsContext; +import org.prebid.server.events.EventsService; + +import java.util.Objects; +import java.util.Set; + +public class VastModifier { + + private final BidderCatalog bidderCatalog; + private final EventsService eventsService; + + public VastModifier(BidderCatalog bidderCatalog, EventsService eventsService) { + this.bidderCatalog = Objects.requireNonNull(bidderCatalog); + this.eventsService = Objects.requireNonNull(eventsService); + } + + public JsonNode modifyVastXml(Boolean isEventsEnabled, + Set allowedBidders, + PutObject putObject, + String accountId, + String integration) { + final JsonNode value = putObject.getValue(); + final String bidder = putObject.getBidder(); + final boolean isValueValid = value != null && !value.isNull(); + if (BooleanUtils.isTrue(isEventsEnabled) && allowedBidders.contains(bidder) && isValueValid) { + final String vastUrlTracking = eventsService.vastUrlTracking( + putObject.getBidid(), + bidder, + accountId, + putObject.getTimestamp(), + integration); + + final String vastXml = appendTrackingUrlToVastXml(value.asText(), vastUrlTracking); + return new TextNode(vastXml); + } + + return value; + } + + public String createBidVastXml(String bidder, + String bidAdm, + String bidNurl, + String eventBidId, + String accountId, + EventsContext eventsContext) { + if (!bidderCatalog.isModifyingVastXmlAllowed(bidder)) { + return bidAdm; + } + + final String vastXml = resolveVastXmlFrom(bidAdm, bidNurl); + if (!eventsContext.isEnabledForAccount()) { + return vastXml; + } + + final Long auctionTimestamp = eventsContext.getAuctionTimestamp(); + final String integration = eventsContext.getIntegration(); + + final String vastUrl = eventsService.vastUrlTracking(eventBidId, bidder, accountId, auctionTimestamp, + integration); + return appendTrackingUrlToVastXml(vastXml, vastUrl); + } + + private static String resolveVastXmlFrom(String bidAdm, String bidNurl) { + return bidAdm == null && bidNurl != null + ? "" + + "prebid.org wrapper" + + "" + + "" + + "" + : bidAdm; + } + + private String appendTrackingUrlToVastXml(String vastXml, String vastUrlTracking) { + final String closeTag = ""; + final int closeTagIndex = vastXml.indexOf(closeTag); + + // no impression tag - pass it as it is + if (closeTagIndex == -1) { + return vastXml; + } + + final String impressionUrl = ""; + final String openTag = ""; + + // empty impression tag - just insert the link + if (closeTagIndex - vastXml.indexOf(openTag) == openTag.length()) { + return vastXml.replaceFirst(openTag, openTag + impressionUrl); + } + + return vastXml.replaceFirst(closeTag, closeTag + openTag + impressionUrl + closeTag); + } +} diff --git a/src/test/java/org/prebid/server/auction/BidResponseCreatorTest.java b/src/test/java/org/prebid/server/auction/BidResponseCreatorTest.java index b3ccd2076a7..8134af14fe7 100644 --- a/src/test/java/org/prebid/server/auction/BidResponseCreatorTest.java +++ b/src/test/java/org/prebid/server/auction/BidResponseCreatorTest.java @@ -17,6 +17,7 @@ import com.iab.openrtb.response.Response; import com.iab.openrtb.response.SeatBid; import io.vertx.core.Future; +import org.apache.commons.collections4.CollectionUtils; import org.junit.Before; import org.junit.Rule; import org.junit.Test; @@ -26,6 +27,7 @@ import org.mockito.junit.MockitoRule; import org.prebid.server.VertxTest; import org.prebid.server.auction.model.AuctionContext; +import org.prebid.server.auction.model.BidInfo; import org.prebid.server.auction.model.BidRequestCacheInfo; import org.prebid.server.auction.model.BidderResponse; import org.prebid.server.bidder.BidderCatalog; @@ -56,6 +58,7 @@ import org.prebid.server.proto.openrtb.ext.request.ExtRequestPrebidChannel; import org.prebid.server.proto.openrtb.ext.request.ExtRequestTargeting; import org.prebid.server.proto.openrtb.ext.request.ExtStoredRequest; +import org.prebid.server.proto.openrtb.ext.response.BidType; import org.prebid.server.proto.openrtb.ext.response.CacheAsset; import org.prebid.server.proto.openrtb.ext.response.Events; import org.prebid.server.proto.openrtb.ext.response.ExtBidPrebid; @@ -68,6 +71,7 @@ import org.prebid.server.settings.model.Account; import org.prebid.server.settings.model.AccountAnalyticsConfig; import org.prebid.server.settings.model.VideoStoredDataResult; +import org.prebid.server.vast.VastModifier; import java.io.IOException; import java.math.BigDecimal; @@ -76,7 +80,6 @@ import java.time.ZoneId; import java.time.ZoneOffset; import java.util.Arrays; -import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.function.UnaryOperator; @@ -104,12 +107,17 @@ import static org.mockito.Mockito.verify; import static org.prebid.server.proto.openrtb.ext.request.ExtRequestPrebidAdservertargetingRule.Source.xStatic; import static org.prebid.server.proto.openrtb.ext.response.BidType.banner; +import static org.prebid.server.proto.openrtb.ext.response.BidType.video; import static org.prebid.server.proto.openrtb.ext.response.BidType.xNative; public class BidResponseCreatorTest extends VertxTest { private static final BidRequestCacheInfo CACHE_INFO = BidRequestCacheInfo.builder().build(); + private static final String IMP_ID = "impId1"; + private static final String BID_ADM = "adm"; + private static final String BID_NURL = "nurl"; + @Rule public final MockitoRule mockitoRule = MockitoJUnit.rule(); @@ -118,6 +126,8 @@ public class BidResponseCreatorTest extends VertxTest { @Mock private BidderCatalog bidderCatalog; @Mock + private VastModifier vastModifier; + @Mock private EventsService eventsService; @Mock private StoredRequestProcessor storedRequestProcessor; @@ -149,6 +159,7 @@ public void setUp() { bidResponseCreator = new BidResponseCreator( cacheService, bidderCatalog, + vastModifier, eventsService, storedRequestProcessor, bidResponseReducer, @@ -163,11 +174,11 @@ public void setUp() { @Test public void shouldPassOriginalTimeoutToCacheServiceIfCachingIsRequested() { // given - final AuctionContext auctionContext = givenAuctionContext(givenBidRequest()); + final AuctionContext auctionContext = givenAuctionContext(givenBidRequest(givenImp())); final Bid bid = Bid.builder() .id("bidId1") - .impid("impId1") + .impid(IMP_ID) .price(BigDecimal.valueOf(5.67)) .build(); final List bidderResponses = singletonList( @@ -187,10 +198,13 @@ public void shouldPassOriginalTimeoutToCacheServiceIfCachingIsRequested() { @Test public void shouldRequestCacheServiceWithExpectedArguments() { // given + final Imp imp1 = givenImp("impId1"); + final Imp imp2 = givenImp("impId2"); final AuctionContext auctionContext = givenAuctionContext( givenBidRequest(builder -> builder.ext(ExtRequest.of(ExtRequestPrebid.builder() - .events(mapper.createObjectNode()) - .build()))), + .events(mapper.createObjectNode()) + .build())), + imp1, imp2), builder -> builder.account(Account.builder() .id("accountId") .eventsEnabled(true) @@ -201,10 +215,16 @@ public void shouldRequestCacheServiceWithExpectedArguments() { final Bid bid3 = Bid.builder().id("bidId3").impid("impId1").price(BigDecimal.valueOf(3.74)).build(); final Bid bid4 = Bid.builder().id("bidId4").impid("impId2").price(BigDecimal.valueOf(6.74)).build(); final List bidderResponses = asList( - BidderResponse.of("bidder1", givenSeatBid(BidderBid.of(bid1, banner, "USD"), - BidderBid.of(bid2, banner, "USD")), 100), - BidderResponse.of("bidder2", givenSeatBid(BidderBid.of(bid3, banner, "USD"), - BidderBid.of(bid4, banner, "USD")), 100)); + BidderResponse.of("bidder1", + givenSeatBid( + BidderBid.of(bid1, banner, "USD"), + BidderBid.of(bid2, banner, "USD")), + 100), + BidderResponse.of("bidder2", + givenSeatBid( + BidderBid.of(bid3, banner, "USD"), + BidderBid.of(bid4, banner, "USD")), + 100)); final BidRequestCacheInfo cacheInfo = BidRequestCacheInfo.builder() .doCaching(true) @@ -221,9 +241,13 @@ public void shouldRequestCacheServiceWithExpectedArguments() { bidResponseCreator.create(bidderResponses, auctionContext, cacheInfo, false); // then + final BidInfo bidInfo1 = toBidInfo(bid1, imp1, "bidder1", banner); + final BidInfo bidInfo2 = toBidInfo(bid2, imp2, "bidder1", banner); + final BidInfo bidInfo3 = toBidInfo(bid3, imp1, "bidder2", banner); + final BidInfo bidInfo4 = toBidInfo(bid4, imp2, "bidder2", banner); ArgumentCaptor contextArgumentCaptor = ArgumentCaptor.forClass(CacheContext.class); verify(cacheService).cacheBidsOpenrtb( - argThat(t -> t.containsAll(asList(bid1, bid4, bid3, bid2))), + argThat(t -> t.containsAll(asList(bidInfo1, bidInfo2, bidInfo3, bidInfo4))), same(auctionContext), contextArgumentCaptor.capture(), eq(EventsContext.builder() @@ -232,41 +256,45 @@ public void shouldRequestCacheServiceWithExpectedArguments() { .auctionTimestamp(1000L) .build())); - Map> biddersToCacheBidIds = doubleMap( - "bidder1", doubleMap("bidId1-impId1", "bidId1", "bidId2-impId2", "bidId2"), - "bidder2", doubleMap("bidId3-impId1", "bidId3", "bidId4-impId2", "bidId4")); - assertThat(contextArgumentCaptor.getValue()) .satisfies(context -> { assertThat(context.isShouldCacheBids()).isTrue(); assertThat(context.isShouldCacheVideoBids()).isTrue(); assertThat(context.getCacheBidsTtl()).isEqualTo(99); assertThat(context.getCacheVideoBidsTtl()).isEqualTo(101); - assertThat(contextArgumentCaptor.getValue().getBidderToBidsToGeneratedIds().getBidderToBidIds()) - .containsAllEntriesOf(biddersToCacheBidIds); - assertThat(context.getBidderToVideoGeneratedBidIdsToModify().getBidderToBidIds()).isEmpty(); }); } @Test public void shouldRequestCacheServiceWithWinningBidsOnlyWhenWinningonlyIsTrue() { // given + final Imp imp1 = givenImp("impId1"); + final Imp imp2 = givenImp("impId2"); final AuctionContext auctionContext = givenAuctionContext(givenBidRequest( identity(), - extBuilder -> extBuilder.targeting(givenTargeting()))); + extBuilder -> extBuilder.targeting(givenTargeting()), + imp1, imp2, givenImp("impId3"), givenImp("impId4"))); final Bid bid1 = Bid.builder().id("bidId1").impid("impId1").price(BigDecimal.valueOf(5.67)).build(); final Bid bid2 = Bid.builder().id("bidId2").impid("impId2").price(BigDecimal.valueOf(7.19)).build(); final Bid bid3 = Bid.builder().id("bidId3").impid("impId1").price(BigDecimal.valueOf(3.74)).build(); final Bid bid4 = Bid.builder().id("bidId4").impid("impId2").price(BigDecimal.valueOf(6.74)).build(); final List bidderResponses = asList( - BidderResponse.of("bidder1", givenSeatBid(BidderBid.of(bid1, banner, "USD"), - BidderBid.of(bid2, banner, "USD")), 100), - BidderResponse.of("bidder2", givenSeatBid(BidderBid.of(bid3, banner, "USD"), - BidderBid.of(bid4, banner, "USD")), 100)); + BidderResponse.of("bidder1", + givenSeatBid( + BidderBid.of(bid1, banner, "USD"), + BidderBid.of(bid2, banner, "USD")), + 100), + BidderResponse.of("bidder2", + givenSeatBid( + BidderBid.of(bid3, banner, "USD"), + BidderBid.of(bid4, banner, "USD")), + 100)); final BidRequestCacheInfo cacheInfo = BidRequestCacheInfo.builder() - .doCaching(true).shouldCacheWinningBidsOnly(true).build(); + .doCaching(true) + .shouldCacheWinningBidsOnly(true) + .build(); // just a stub to get through method call chain givenCacheServiceResult(singletonMap(bid1, CacheInfo.empty())); @@ -275,33 +303,22 @@ public void shouldRequestCacheServiceWithWinningBidsOnlyWhenWinningonlyIsTrue() bidResponseCreator.create(bidderResponses, auctionContext, cacheInfo, false); // then - ArgumentCaptor contextArgumentCaptor = ArgumentCaptor.forClass(CacheContext.class); + final BidInfo bidInfo1 = toBidInfo(bid1, imp1, "bidder1", banner); + final BidInfo bidInfo2 = toBidInfo(bid2, imp2, "bidder1", banner); verify(cacheService).cacheBidsOpenrtb( - eq(asList(bid1, bid2)), + argThat(t -> t.containsAll(asList(bidInfo1, bidInfo2))), same(auctionContext), - contextArgumentCaptor.capture(), + any(), eq(EventsContext.builder().auctionTimestamp(1000L).build())); - - final Map> biddersToCacheBidIds = doubleMap( - "bidder1", doubleMap("bidId1-impId1", "bidId1", "bidId2-impId2", "bidId2"), - "bidder2", doubleMap("bidId3-impId1", "bidId3", "bidId4-impId2", "bidId4")); - - assertThat(contextArgumentCaptor.getValue()) - .satisfies(context -> { - assertThat(contextArgumentCaptor.getValue().getBidderToBidsToGeneratedIds().getBidderToBidIds()) - .containsAllEntriesOf(biddersToCacheBidIds); - assertThat(context.getBidderToVideoGeneratedBidIdsToModify().getBidderToBidIds()).isEmpty(); - }); } @Test - public void shouldRequestCacheServiceWithVideoBidsToModifyWhenEventsEnabledAndForBidderThatAllowsModifyVastXml() { + public void shouldRequestCacheServiceWithVideoBidsToModify() { // given final Account account = Account.builder().id("accountId").eventsEnabled(true).build(); - final Imp imp1 = Imp.builder().id("impId1").video(Video.builder().build()).build(); - final Imp imp2 = Imp.builder().id("impId2").video(Video.builder().build()).build(); - + final Imp imp1 = givenImp("impId1"); + final Imp imp2 = givenImp("impId2"); final AuctionContext auctionContext = givenAuctionContext( givenBidRequest( identity(), @@ -312,7 +329,7 @@ public void shouldRequestCacheServiceWithVideoBidsToModifyWhenEventsEnabledAndFo final Bid bid1 = Bid.builder().id("bidId1").impid("impId1").price(BigDecimal.valueOf(5.67)).build(); final Bid bid2 = Bid.builder().id("bidId2").impid("impId2").price(BigDecimal.valueOf(7.19)).build(); final List bidderResponses = asList( - BidderResponse.of("bidder1", givenSeatBid(BidderBid.of(bid1, banner, "USD")), 100), + BidderResponse.of("bidder1", givenSeatBid(BidderBid.of(bid1, video, "USD")), 100), BidderResponse.of("bidder2", givenSeatBid(BidderBid.of(bid2, banner, "USD")), 100)); final BidRequestCacheInfo cacheInfo = BidRequestCacheInfo.builder() @@ -323,44 +340,30 @@ public void shouldRequestCacheServiceWithVideoBidsToModifyWhenEventsEnabledAndFo // just a stub to get through method call chain givenCacheServiceResult(singletonMap(bid1, CacheInfo.empty())); - given(bidderCatalog.isModifyingVastXmlAllowed(eq("bidder1"))).willReturn(true); - // when bidResponseCreator.create(bidderResponses, auctionContext, cacheInfo, false); // then - final Map> biddersToCacheBidIds = doubleMap( - "bidder1", singletonMap("bidId1-impId1", "bidId1"), - "bidder2", singletonMap("bidId2-impId2", "bidId2")); - - final ArgumentCaptor cacheContextArgumentCaptor = ArgumentCaptor.forClass(CacheContext.class); - + final BidInfo bidInfo1 = toBidInfo(bid1, imp1, "bidder1", video); + final BidInfo bidInfo2 = toBidInfo(bid2, imp2, "bidder2", banner); verify(cacheService).cacheBidsOpenrtb( - argThat(t -> t.containsAll(asList(bid1, bid2))), + argThat(argument -> CollectionUtils.isEqualCollection(argument, asList(bidInfo1, bidInfo2))), same(auctionContext), - cacheContextArgumentCaptor.capture(), + eq(CacheContext.builder().shouldCacheVideoBids(true).build()), eq(EventsContext.builder() .enabledForAccount(true) .enabledForRequest(true) .auctionTimestamp(1000L) .build())); - - assertThat(cacheContextArgumentCaptor.getValue()) - .satisfies(context -> { - assertThat(context.getBidderToVideoGeneratedBidIdsToModify().getBidderToBidIds()) - .containsAllEntriesOf(singletonMap("bidder1", singletonMap("bidId1-impId1", "bidId1"))); - assertThat(context.getBidderToBidsToGeneratedIds().getBidderToBidIds()) - .containsAllEntriesOf(biddersToCacheBidIds); - assertThat(context.isShouldCacheVideoBids()).isTrue(); - }); } @Test public void shouldCallCacheServiceEvenRoundedCpmIsZero() { // given - final AuctionContext auctionContext = givenAuctionContext(givenBidRequest()); + final Imp imp1 = givenImp(); + final AuctionContext auctionContext = givenAuctionContext(givenBidRequest(imp1)); - final Bid bid1 = Bid.builder().id("bidId1").impid("impId1").price(BigDecimal.valueOf(0.05)).build(); + final Bid bid1 = Bid.builder().id("bidId1").impid(IMP_ID).price(BigDecimal.valueOf(0.05)).build(); final List bidderResponses = singletonList( BidderResponse.of("bidder1", givenSeatBid(BidderBid.of(bid1, banner, "USD")), 100)); @@ -372,25 +375,18 @@ public void shouldCallCacheServiceEvenRoundedCpmIsZero() { bidResponseCreator.create(bidderResponses, auctionContext, cacheInfo, false); // then - final ArgumentCaptor cacheContextArgumentCaptor = ArgumentCaptor.forClass(CacheContext.class); + final BidInfo bidInfo1 = toBidInfo(bid1, imp1, "bidder1", banner); verify(cacheService).cacheBidsOpenrtb( - argThat(bids -> bids.contains(bid1)), + eq(singletonList(bidInfo1)), same(auctionContext), - cacheContextArgumentCaptor.capture(), + eq(CacheContext.builder().build()), eq(EventsContext.builder().auctionTimestamp(1000L).build())); - - assertThat(cacheContextArgumentCaptor.getValue()) - .satisfies(context -> { - assertThat(context.getBidderToVideoGeneratedBidIdsToModify().getBidderToBidIds()).isEmpty(); - assertThat(context.getBidderToBidsToGeneratedIds().getBidderToBidIds()) - .containsAllEntriesOf(singletonMap("bidder1", singletonMap("bidId1-impId1", "bidId1"))); - }); } @Test public void shouldSetExpectedConstantResponseFields() { // given - final AuctionContext auctionContext = givenAuctionContext(givenBidRequest()); + final AuctionContext auctionContext = givenAuctionContext(givenBidRequest(givenImp())); final List bidderResponses = singletonList(BidderResponse.of("bidder1", givenSeatBid(), 100)); @@ -417,7 +413,7 @@ public void shouldSetExpectedConstantResponseFields() { @Test public void shouldSetNbrValueTwoAndEmptySeatbidWhenIncomingBidResponsesAreEmpty() { // given - final AuctionContext auctionContext = givenAuctionContext(givenBidRequest()); + final AuctionContext auctionContext = givenAuctionContext(givenBidRequest(givenImp())); // when final BidResponse bidResponse = bidResponseCreator.create(emptyList(), auctionContext, null, false).result(); @@ -432,7 +428,7 @@ public void shouldSetNbrValueTwoAndEmptySeatbidWhenIncomingBidResponsesAreEmpty( @Test public void shouldSetNbrValueTwoAndEmptySeatbidWhenIncomingBidResponsesDoNotContainAnyBids() { // given - final AuctionContext auctionContext = givenAuctionContext(givenBidRequest()); + final AuctionContext auctionContext = givenAuctionContext(givenBidRequest(givenImp())); final List bidderResponses = singletonList(BidderResponse.of("bidder1", givenSeatBid(), 100)); @@ -450,11 +446,11 @@ public void shouldSetNbrValueTwoAndEmptySeatbidWhenIncomingBidResponsesDoNotCont @Test public void shouldSetNbrNullAndPopulateSeatbidWhenAtLeastOneBidIsPresent() { // given - final AuctionContext auctionContext = givenAuctionContext(givenBidRequest()); + final AuctionContext auctionContext = givenAuctionContext(givenBidRequest(givenImp())); - final Bid bid = Bid.builder().impid("imp1").id("bidId").build(); + final Bid bid = Bid.builder().impid(IMP_ID).id("bidId").build(); final List bidderResponses = singletonList(BidderResponse.of("bidder1", - givenSeatBid(BidderBid.of(bid, null, null)), 100)); + givenSeatBid(BidderBid.of(bid, banner, null)), 100)); // when final BidResponse bidResponse = @@ -470,9 +466,9 @@ public void shouldSetNbrNullAndPopulateSeatbidWhenAtLeastOneBidIsPresent() { @Test public void shouldSkipBidderResponsesWhereSeatBidContainEmptyBids() { // given - final AuctionContext auctionContext = givenAuctionContext(givenBidRequest()); + final AuctionContext auctionContext = givenAuctionContext(givenBidRequest(givenImp())); - final Bid bid = Bid.builder().impid("imp1").id("bidId").build(); + final Bid bid = Bid.builder().impid(IMP_ID).id("bidId").build(); final List bidderResponses = asList( BidderResponse.of("bidder1", givenSeatBid(), 0), BidderResponse.of("bidder2", givenSeatBid(BidderBid.of(bid, banner, "USD")), 0)); @@ -488,31 +484,21 @@ public void shouldSkipBidderResponsesWhereSeatBidContainEmptyBids() { } @Test - public void shouldOverrideBidIdWhenGenerateBidIdIsTurnedOn() { + public void shouldOverrideBidIdWhenIdGeneratorIsUUID() { // given - final AuctionContext auctionContext = givenAuctionContext(givenBidRequest()); + final AuctionContext auctionContext = givenAuctionContext(givenBidRequest(givenImp())); final ExtPrebid prebid = ExtPrebid.of(ExtBidPrebid.builder().type(banner).build(), null); final Bid bid = Bid.builder() .id("123") - .impid("imp123") + .impid(IMP_ID) .ext(mapper.valueToTree(prebid)) .build(); final List bidderResponses = singletonList( BidderResponse.of("bidder2", givenSeatBid(BidderBid.of(bid, banner, "USD")), 0)); + given(idGenerator.getType()).willReturn(IdGeneratorType.uuid); given(idGenerator.generateId()).willReturn("de7fc739-0a6e-41ad-8961-701c30c82166"); - final BidResponseCreator bidResponseCreator = new BidResponseCreator( - cacheService, - bidderCatalog, - eventsService, - storedRequestProcessor, - bidResponseReducer, - idGenerator, - 0, - clock, - jacksonMapper); - // when final BidResponse bidResponse = bidResponseCreator.create(bidderResponses, auctionContext, CACHE_INFO, false).result(); @@ -532,15 +518,18 @@ public void shouldOverrideBidIdWhenGenerateBidIdIsTurnedOn() { } @Test - public void shouldUseGeneratedBidIdForEventAndCacheWhenGeneratedIdIsTurnedOn() { + public void shouldUseGeneratedBidIdForEventAndCacheWhenIdGeneratorIsUUIDAndEventEnabledForAccountAndRequest() { // given final Account account = Account.builder().id("accountId").eventsEnabled(true).build(); + final Imp imp = givenImp(); + + // Allow events for request final BidRequest bidRequest = givenBidRequest( identity(), extBuilder -> extBuilder .events(mapper.createObjectNode()) - .integration("pbjs")); - + .integration("pbjs"), + imp); final AuctionContext auctionContext = givenAuctionContext( bidRequest, contextBuilder -> contextBuilder.account(account)); @@ -548,13 +537,14 @@ public void shouldUseGeneratedBidIdForEventAndCacheWhenGeneratedIdIsTurnedOn() { final ExtPrebid prebid = ExtPrebid.of(ExtBidPrebid.builder().type(banner).build(), null); final Bid bid = Bid.builder() .id("bidId1") - .impid("impId1") + .impid(IMP_ID) .price(BigDecimal.ONE) .ext(mapper.valueToTree(prebid)) .build(); + final String bidder = "bidder1"; final List bidderResponses = singletonList( - BidderResponse.of("bidder1", givenSeatBid(BidderBid.of(bid, banner, "USD")), 0)); + BidderResponse.of(bidder, givenSeatBid(BidderBid.of(bid, banner, "USD")), 0)); final String generatedBid = "de7fc739-0a6e-41ad-8961-701c30c82166"; given(idGenerator.getType()).willReturn(IdGeneratorType.uuid); @@ -563,35 +553,12 @@ public void shouldUseGeneratedBidIdForEventAndCacheWhenGeneratedIdIsTurnedOn() { final BidRequestCacheInfo cacheInfo = BidRequestCacheInfo.builder().doCaching(true).build(); givenCacheServiceResult(singletonMap(bid, CacheInfo.of("id", null, null, null))); - final Events events = Events.of("http://event-type-win", "http://event-type-view"); - given(eventsService.createEvent(anyString(), anyString(), anyString(), anyLong(), anyString())) - .willReturn(events); - - final BidResponseCreator bidResponseCreator = new BidResponseCreator( - cacheService, - bidderCatalog, - eventsService, - storedRequestProcessor, - bidResponseReducer, - idGenerator, - 0, - clock, - jacksonMapper); - // when bidResponseCreator.create(bidderResponses, auctionContext, cacheInfo, false).result(); // then - final ArgumentCaptor cacheContextArgumentCaptor = ArgumentCaptor.forClass(CacheContext.class); - verify(cacheService).cacheBidsOpenrtb(any(), any(), cacheContextArgumentCaptor.capture(), any()); - - assertThat(cacheContextArgumentCaptor.getValue()) - .satisfies(context -> { - assertThat(context.isShouldCacheVideoBids()).isFalse(); - assertThat(context.getBidderToVideoGeneratedBidIdsToModify().getBidderToBidIds()).isEmpty(); - assertThat(context.getBidderToBidsToGeneratedIds().getBidderToBidIds()) - .containsAllEntriesOf(singletonMap("bidder1", singletonMap("bidId1-impId1", generatedBid))); - }); + final BidInfo expectedBidInfo = toBidInfo(bid, generatedBid, imp, bidder, banner); + verify(cacheService).cacheBidsOpenrtb(eq(singletonList(expectedBidInfo)), any(), any(), any()); verify(eventsService).createEvent(eq(generatedBid), anyString(), anyString(), anyLong(), anyString()); } @@ -599,10 +566,17 @@ public void shouldUseGeneratedBidIdForEventAndCacheWhenGeneratedIdIsTurnedOn() { @Test public void shouldSetExpectedResponseSeatBidAndBidFields() { // given - final AuctionContext auctionContext = givenAuctionContext(givenBidRequest()); - final Bid bid = Bid.builder().id("bidId").price(BigDecimal.ONE).adm("adm").impid("i1") - .ext(mapper.valueToTree(singletonMap("bidExt", 1))).build(); - final List bidderResponses = singletonList(BidderResponse.of("bidder1", + final AuctionContext auctionContext = givenAuctionContext(givenBidRequest(givenImp())); + final Bid bid = Bid.builder() + .id("bidId") + .price(BigDecimal.ONE) + .adm(BID_ADM) + .impid(IMP_ID) + .ext(mapper.valueToTree(singletonMap("bidExt", 1))) + .build(); + + final String bidder = "bidder1"; + final List bidderResponses = singletonList(BidderResponse.of(bidder, givenSeatBid(BidderBid.of(bid, banner, "USD")), 100)); // when @@ -610,19 +584,20 @@ public void shouldSetExpectedResponseSeatBidAndBidFields() { bidResponseCreator.create(bidderResponses, auctionContext, CACHE_INFO, false).result(); // then - assertThat(bidResponse.getSeatbid()).containsOnly(SeatBid.builder() - .seat("bidder1") - .group(0) - .bid(singletonList(Bid.builder() - .id("bidId") - .impid("i1") - .price(BigDecimal.ONE) - .adm("adm") - .ext(mapper.valueToTree(ExtPrebid.of( - ExtBidPrebid.builder().type(banner).build(), - singletonMap("bidExt", 1)))) - .build())) - .build()); + assertThat(bidResponse.getSeatbid()) + .containsOnly(SeatBid.builder() + .seat(bidder) + .group(0) + .bid(singletonList(Bid.builder() + .id("bidId") + .impid(IMP_ID) + .price(BigDecimal.ONE) + .adm(BID_ADM) + .ext(mapper.valueToTree(ExtPrebid.of( + ExtBidPrebid.builder().type(banner).build(), + singletonMap("bidExt", 1)))) + .build())) + .build()); verify(cacheService, never()).cacheBidsOpenrtb(anyList(), any(), any(), any()); } @@ -630,7 +605,7 @@ public void shouldSetExpectedResponseSeatBidAndBidFields() { @Test public void shouldFilterBidByBidReducerResponse() { // given - final AuctionContext auctionContext = givenAuctionContext(givenBidRequest()); + final AuctionContext auctionContext = givenAuctionContext(givenBidRequest(givenImp("i1"), givenImp("i2"))); final Bid dealBid1Imp1 = Bid.builder().id("bidId1i1d").dealid("d1").price(BigDecimal.valueOf(4.98)).impid("i1") .build(); @@ -672,7 +647,7 @@ public void shouldAddTypeToNativeBidAdm() throws JsonProcessingException { .tmax(1000L) .app(App.builder().build()) .imp(singletonList(Imp.builder() - .id("imp1") + .id(IMP_ID) .xNative(Native.builder().request(mapper.writeValueAsString(nativeRequest)).build()) .build())) .build(); @@ -686,7 +661,7 @@ public void shouldAddTypeToNativeBidAdm() throws JsonProcessingException { .build())) .build(); - final Bid bid = Bid.builder().id("bidId").price(BigDecimal.ONE).impid("imp1") + final Bid bid = Bid.builder().id("bidId").price(BigDecimal.ONE).impid(IMP_ID) .adm(mapper.writeValueAsString(responseAdm)) .ext(mapper.valueToTree(singletonMap("bidExt", 1))).build(); final List bidderResponses = singletonList(BidderResponse.of("bidder1", @@ -727,7 +702,7 @@ public void shouldReturnEmptyAssetIfImageTypeIsEmpty() throws JsonProcessingExce .tmax(1000L) .app(App.builder().build()) .imp(singletonList(Imp.builder() - .id("imp1") + .id(IMP_ID) .xNative(Native.builder().request(mapper.writeValueAsString(nativeRequest)).build()) .build())) .build(); @@ -742,9 +717,13 @@ public void shouldReturnEmptyAssetIfImageTypeIsEmpty() throws JsonProcessingExce .build())) .build(); - final Bid bid = Bid.builder().id("bidId").price(BigDecimal.ONE).impid("imp1") + final Bid bid = Bid.builder() + .id("bidId") + .price(BigDecimal.ONE) + .impid(IMP_ID) .adm(mapper.writeValueAsString(responseAdm)) - .ext(mapper.valueToTree(singletonMap("bidExt", 1))).build(); + .ext(mapper.valueToTree(singletonMap("bidExt", 1))) + .build(); final List bidderResponses = singletonList(BidderResponse.of("bidder1", givenSeatBid(BidderBid.of(bid, xNative, "USD")), 100)); @@ -777,7 +756,7 @@ public void shouldReturnEmptyAssetIfDataTypeIsEmpty() throws JsonProcessingExcep .tmax(1000L) .app(App.builder().build()) .imp(singletonList(Imp.builder() - .id("imp1") + .id(IMP_ID) .xNative(Native.builder().request(mapper.writeValueAsString(nativeRequest)).build()) .build())) .build(); @@ -792,9 +771,12 @@ public void shouldReturnEmptyAssetIfDataTypeIsEmpty() throws JsonProcessingExcep .build())) .build(); - final Bid bid = Bid.builder().id("bidId").price(BigDecimal.ONE).impid("imp1") + final Bid bid = Bid.builder().id("bidId") + .price(BigDecimal.ONE) + .impid(IMP_ID) .adm(mapper.writeValueAsString(responseAdm)) - .ext(mapper.valueToTree(singletonMap("bidExt", 1))).build(); + .ext(mapper.valueToTree(singletonMap("bidExt", 1))) + .build(); final List bidderResponses = singletonList(BidderResponse.of("bidder1", givenSeatBid(BidderBid.of(bid, xNative, "USD")), 100)); @@ -816,9 +798,15 @@ public void shouldSetBidAdmToNullIfCacheIdIsPresentAndReturnCreativeBidsIsFalse( // given final AuctionContext auctionContext = givenAuctionContext(givenBidRequest( identity(), - extBuilder -> extBuilder.targeting(givenTargeting()))); + extBuilder -> extBuilder.targeting(givenTargeting()), + givenImp())); - final Bid bid = Bid.builder().price(BigDecimal.ONE).adm("adm").id("bidId").impid("i1").build(); + final Bid bid = Bid.builder() + .price(BigDecimal.ONE) + .adm(BID_ADM) + .id("bidId") + .impid(IMP_ID) + .build(); final List bidderResponses = singletonList(BidderResponse.of("bidder1", givenSeatBid(BidderBid.of(bid, banner, "USD")), 100)); @@ -844,9 +832,10 @@ public void shouldSetBidAdmToNullIfVideoCacheIdIsPresentAndReturnCreativeVideoBi // given final AuctionContext auctionContext = givenAuctionContext(givenBidRequest( identity(), - extBuilder -> extBuilder.targeting(givenTargeting()))); + extBuilder -> extBuilder.targeting(givenTargeting()), + Imp.builder().id(IMP_ID).build())); - final Bid bid = Bid.builder().price(BigDecimal.ONE).adm("adm").id("bidId").impid("i1").build(); + final Bid bid = Bid.builder().price(BigDecimal.ONE).adm(BID_ADM).id("bidId").impid(IMP_ID).build(); final List bidderResponses = singletonList(BidderResponse.of("bidder1", givenSeatBid(BidderBid.of(bid, banner, "USD")), 100)); @@ -867,14 +856,53 @@ public void shouldSetBidAdmToNullIfVideoCacheIdIsPresentAndReturnCreativeVideoBi verify(cacheService).cacheBidsOpenrtb(anyList(), any(), any(), any()); } + @Test + public void shouldModifyBidAdmWhenBidVideoAndVastModifierReturnValue() { + // given + final AuctionContext auctionContext = givenAuctionContext(givenBidRequest( + identity(), + extBuilder -> extBuilder.targeting(givenTargeting()), + givenImp())); + + final String bidId = "bid_id"; + final Bid bid = Bid.builder() + .id(bidId) + .price(BigDecimal.ONE) + .adm(BID_ADM) + .nurl(BID_NURL) + .impid(IMP_ID) + .build(); + + final String bidder = "bidder1"; + final List bidderResponses = singletonList( + BidderResponse.of(bidder, givenSeatBid(BidderBid.of(bid, video, "USD")), 100)); + + final String modifiedVast = "modifiedVast"; + given(vastModifier.createBidVastXml(anyString(), anyString(), anyString(), anyString(), anyString(), any())) + .willReturn(modifiedVast); + + // when + final BidResponse bidResponse = + bidResponseCreator.create(bidderResponses, auctionContext, CACHE_INFO, false).result(); + + // then + assertThat(bidResponse.getSeatbid()) + .flatExtracting(SeatBid::getBid).hasSize(1) + .extracting(Bid::getAdm) + .containsOnly(modifiedVast); + + verify(vastModifier).createBidVastXml(eq(bidder), eq(BID_ADM), eq(BID_NURL), eq(bidId), eq("accountId"), any()); + } + @Test public void shouldSetBidExpWhenCacheIdIsMatched() { // given final AuctionContext auctionContext = givenAuctionContext(givenBidRequest( identity(), - extBuilder -> extBuilder.targeting(givenTargeting()))); + extBuilder -> extBuilder.targeting(givenTargeting()), + givenImp())); - final Bid bid = Bid.builder().price(BigDecimal.ONE).impid("i1").id("bidId").build(); + final Bid bid = Bid.builder().price(BigDecimal.ONE).impid(IMP_ID).id("bidId").build(); final List bidderResponses = singletonList(BidderResponse.of("bidder1", givenSeatBid(BidderBid.of(bid, banner, "USD")), 100)); @@ -900,9 +928,10 @@ public void shouldSetBidExpMaxTtlWhenCacheIdIsMatchedAndBothTtlIsSet() { // given final AuctionContext auctionContext = givenAuctionContext(givenBidRequest( identity(), - extBuilder -> extBuilder.targeting(givenTargeting()))); + extBuilder -> extBuilder.targeting(givenTargeting()), + givenImp())); - final Bid bid = Bid.builder().price(BigDecimal.ONE).impid("i1").id("bidId").build(); + final Bid bid = Bid.builder().price(BigDecimal.ONE).impid(IMP_ID).id("bidId").build(); final List bidderResponses = singletonList(BidderResponse.of("bidder1", givenSeatBid(BidderBid.of(bid, banner, "USD")), 100)); @@ -926,8 +955,9 @@ public void shouldSetBidExpMaxTtlWhenCacheIdIsMatchedAndBothTtlIsSet() { @Test public void shouldTolerateMissingExtInSeatBidAndBid() { // given - final AuctionContext auctionContext = givenAuctionContext(givenBidRequest()); - final Bid bid = Bid.builder().id("bidId").price(BigDecimal.ONE).impid("i1").build(); + final AuctionContext auctionContext = givenAuctionContext(givenBidRequest(givenImp())); + + final Bid bid = Bid.builder().id("bidId").price(BigDecimal.ONE).impid(IMP_ID).build(); final List bidderResponses = singletonList(BidderResponse.of("bidder1", givenSeatBid(BidderBid.of(bid, banner, "USD")), 100)); @@ -940,7 +970,7 @@ public void shouldTolerateMissingExtInSeatBidAndBid() { .flatExtracting(SeatBid::getBid) .containsOnly(Bid.builder() .id("bidId") - .impid("i1") + .impid(IMP_ID) .price(BigDecimal.ONE) .ext(mapper.valueToTree( ExtPrebid.of(ExtBidPrebid.builder().type(banner).build(), null))) @@ -954,9 +984,10 @@ public void shouldPopulateTargetingKeywords() { // given final AuctionContext auctionContext = givenAuctionContext(givenBidRequest( identity(), - extBuilder -> extBuilder.targeting(givenTargeting()))); + extBuilder -> extBuilder.targeting(givenTargeting()), + givenImp())); - final Bid bid = Bid.builder().id("bidId1").price(BigDecimal.valueOf(5.67)).impid("i1").build(); + final Bid bid = Bid.builder().id("bidId1").price(BigDecimal.valueOf(5.67)).impid(IMP_ID).build(); final List bidderResponses = singletonList(BidderResponse.of("bidder1", givenSeatBid(BidderBid.of(bid, banner, "USD")), 100)); @@ -984,15 +1015,17 @@ public void shouldTruncateTargetingKeywordsByGlobalConfig() { // given final AuctionContext auctionContext = givenAuctionContext(givenBidRequest( identity(), - extBuilder -> extBuilder.targeting(givenTargeting()))); + extBuilder -> extBuilder.targeting(givenTargeting()), + givenImp())); - final Bid bid = Bid.builder().id("bidId1").price(BigDecimal.valueOf(5.67)).impid("i1").build(); + final Bid bid = Bid.builder().id("bidId1").price(BigDecimal.valueOf(5.67)).impid(IMP_ID).build(); final List bidderResponses = singletonList(BidderResponse.of("someVeryLongBidderName", givenSeatBid(BidderBid.of(bid, banner, "USD")), 100)); final BidResponseCreator bidResponseCreator = new BidResponseCreator( cacheService, bidderCatalog, + vastModifier, eventsService, storedRequestProcessor, bidResponseReducer, @@ -1025,12 +1058,13 @@ public void shouldTruncateTargetingKeywordsByAccountConfig() { final Account account = Account.builder().id("accountId").truncateTargetAttr(20).build(); final BidRequest bidRequest = givenBidRequest( identity(), - extBuilder -> extBuilder.targeting(givenTargeting())); + extBuilder -> extBuilder.targeting(givenTargeting()), + givenImp()); final AuctionContext auctionContext = givenAuctionContext( bidRequest, contextBuilder -> contextBuilder.account(account)); - final Bid bid = Bid.builder().id("bidId1").price(BigDecimal.valueOf(5.67)).impid("i1").build(); + final Bid bid = Bid.builder().id("bidId1").price(BigDecimal.valueOf(5.67)).impid(IMP_ID).build(); final List bidderResponses = singletonList(BidderResponse.of("someVeryLongBidderName", givenSeatBid(BidderBid.of(bid, banner, "USD")), 100)); @@ -1055,22 +1089,25 @@ public void shouldTruncateTargetingKeywordsByAccountConfig() { public void shouldTruncateTargetingKeywordsByRequestPassedValue() { // given final Account account = Account.builder().id("accountId").truncateTargetAttr(25).build(); + final ExtRequestTargeting targeting = ExtRequestTargeting.builder() + .pricegranularity(mapper.valueToTree( + ExtPriceGranularity.of(2, + singletonList(ExtGranularityRange.of(BigDecimal.valueOf(5), BigDecimal.valueOf(0.5)))))) + .includewinners(true) + .includebidderkeys(true) + .includeformat(false) + .truncateattrchars(20) + .build(); final BidRequest bidRequest = givenBidRequest( identity(), - extBuilder -> extBuilder.targeting(ExtRequestTargeting.builder() - .pricegranularity(mapper.valueToTree( - ExtPriceGranularity.of(2, singletonList(ExtGranularityRange.of(BigDecimal.valueOf(5), - BigDecimal.valueOf(0.5)))))) - .includewinners(true) - .includebidderkeys(true) - .includeformat(false) - .truncateattrchars(20) - .build())); + extBuilder -> extBuilder.targeting(targeting), + givenImp()); + final AuctionContext auctionContext = givenAuctionContext( bidRequest, contextBuilder -> contextBuilder.account(account)); - final Bid bid = Bid.builder().id("bidId1").price(BigDecimal.valueOf(5.67)).impid("i1").build(); + final Bid bid = Bid.builder().id("bidId1").price(BigDecimal.valueOf(5.67)).impid(IMP_ID).build(); final List bidderResponses = singletonList(BidderResponse.of("someVeryLongBidderName", givenSeatBid(BidderBid.of(bid, banner, "USD")), 100)); @@ -1096,7 +1133,8 @@ public void shouldPopulateTargetingKeywordsForWinningBidsAndWinningBidsByBidder( // given final AuctionContext auctionContext = givenAuctionContext(givenBidRequest( identity(), - extBuilder -> extBuilder.targeting(givenTargeting()))); + extBuilder -> extBuilder.targeting(givenTargeting()), + givenImp("i1"), givenImp("i2"))); final Bid firstBid = Bid.builder().id("bidId1").price(BigDecimal.valueOf(5.67)).impid("i1").build(); final Bid secondBid = Bid.builder().id("bidId2").price(BigDecimal.valueOf(4.98)).impid("i2").build(); @@ -1131,24 +1169,29 @@ public void shouldPopulateTargetingKeywordsForWinningBidsAndWinningBidsByBidder( @Test public void shouldPopulateTargetingKeywordsFromMediaTypePriceGranularities() { // given + final ExtMediaTypePriceGranularity extMediaTypePriceGranularity = ExtMediaTypePriceGranularity.of( + mapper.valueToTree(ExtPriceGranularity.of( + 3, + singletonList(ExtGranularityRange.of( + BigDecimal.valueOf(10), BigDecimal.valueOf(1))))), + null, + null); + final ExtPriceGranularity extPriceGranularity = ExtPriceGranularity.of(2, + singletonList(ExtGranularityRange.of(BigDecimal.valueOf(5), BigDecimal.valueOf(0.5)))); + + final ExtRequestTargeting targeting = ExtRequestTargeting.builder() + .pricegranularity(mapper.valueToTree(extPriceGranularity)) + .mediatypepricegranularity(extMediaTypePriceGranularity) + .includewinners(true) + .includebidderkeys(true) + .includeformat(false) + .build(); final AuctionContext auctionContext = givenAuctionContext(givenBidRequest( identity(), - extBuilder -> extBuilder.targeting(ExtRequestTargeting.builder() - .pricegranularity(mapper.valueToTree(ExtPriceGranularity.of(2, - singletonList(ExtGranularityRange.of(BigDecimal.valueOf(5), BigDecimal.valueOf(0.5)))))) - .mediatypepricegranularity(ExtMediaTypePriceGranularity.of( - mapper.valueToTree(ExtPriceGranularity.of( - 3, - singletonList(ExtGranularityRange.of( - BigDecimal.valueOf(10), BigDecimal.valueOf(1))))), - null, - null)) - .includewinners(true) - .includebidderkeys(true) - .includeformat(false) - .build()))); + extBuilder -> extBuilder.targeting(targeting), + givenImp())); - final Bid bid = Bid.builder().id("bidId").price(BigDecimal.valueOf(5.67)).impid("i1").build(); + final Bid bid = Bid.builder().id("bidId").price(BigDecimal.valueOf(5.67)).impid(IMP_ID).build(); final List bidderResponses = singletonList(BidderResponse.of("bidder1", givenSeatBid(BidderBid.of(bid, banner, "USD")), 100)); @@ -1176,9 +1219,10 @@ public void shouldPopulateCacheIdHostPathAndUuidTargetingKeywords() { // given final AuctionContext auctionContext = givenAuctionContext(givenBidRequest( identity(), - extBuilder -> extBuilder.targeting(givenTargeting()))); + extBuilder -> extBuilder.targeting(givenTargeting()), + givenImp())); - final Bid bid = Bid.builder().id("bidId").price(BigDecimal.valueOf(5.67)).impid("i1").build(); + final Bid bid = Bid.builder().id("bidId").price(BigDecimal.valueOf(5.67)).impid(IMP_ID).build(); final List bidderResponses = singletonList(BidderResponse.of("bidder1", givenSeatBid(BidderBid.of(bid, banner, "USD")), 100)); final BidRequestCacheInfo cacheInfo = BidRequestCacheInfo.builder().doCaching(true).build(); @@ -1220,9 +1264,10 @@ public void shouldPopulateTargetingKeywordsWithAdditionalValuesFromRequest() { extBuilder -> extBuilder .targeting(givenTargeting()) .adservertargeting(singletonList(ExtRequestPrebidAdservertargetingRule.of( - "static_keyword1", xStatic, "static_keyword1"))))); + "static_keyword1", xStatic, "static_keyword1"))), + givenImp())); - final Bid bid = Bid.builder().id("bidId1").price(BigDecimal.valueOf(5.67)).impid("i1").build(); + final Bid bid = Bid.builder().id("bidId1").price(BigDecimal.valueOf(5.67)).impid(IMP_ID).build(); final List bidderResponses = singletonList(BidderResponse.of( "bidder1", givenSeatBid(BidderBid.of(bid, banner, "USD")), 100)); @@ -1244,11 +1289,12 @@ public void shouldPopulateTargetingKeywordsIfBidWasCachedAndAdmWasRemoved() { // given final AuctionContext auctionContext = givenAuctionContext(givenBidRequest( identity(), - extBuilder -> extBuilder.targeting(givenTargeting()))); + extBuilder -> extBuilder.targeting(givenTargeting()), + givenImp())); - final Bid bid = Bid.builder().id("bidId").price(BigDecimal.valueOf(5.67)).impid("impId").adm("adm").build(); - final List bidderResponses = singletonList(BidderResponse.of("bidder1", - givenSeatBid(BidderBid.of(bid, banner, "USD")), 100)); + final Bid bid = Bid.builder().id("bidId").price(BigDecimal.valueOf(5.67)).impid(IMP_ID).adm(BID_ADM).build(); + final List bidderResponses = singletonList( + BidderResponse.of("bidder1", givenSeatBid(BidderBid.of(bid, banner, "USD")), 100)); final BidRequestCacheInfo cacheInfo = BidRequestCacheInfo.builder() .doCaching(true) @@ -1261,6 +1307,7 @@ public void shouldPopulateTargetingKeywordsIfBidWasCachedAndAdmWasRemoved() { final BidResponse bidResponse = bidResponseCreator.create(bidderResponses, auctionContext, cacheInfo, false).result(); + // Check if you didn't lost any bids because of bid change in winningBids set // then assertThat(bidResponse.getSeatbid()) .flatExtracting(SeatBid::getBid).hasSize(1) @@ -1276,7 +1323,9 @@ public void shouldAddExtPrebidEventsIfEventsAreEnabledAndExtRequestPrebidEventPr identity(), extBuilder -> extBuilder .events(mapper.createObjectNode()) - .integration("pbjs")); + .integration("pbjs"), + givenImp()); + final AuctionContext auctionContext = givenAuctionContext( bidRequest, contextBuilder -> contextBuilder.account(account)); @@ -1284,7 +1333,7 @@ public void shouldAddExtPrebidEventsIfEventsAreEnabledAndExtRequestPrebidEventPr final Bid bid = Bid.builder() .id("bidId1") .price(BigDecimal.valueOf(5.67)) - .impid("i1") + .impid(IMP_ID) .build(); final List bidderResponses = singletonList( BidderResponse.of("bidder1", givenSeatBid(BidderBid.of(bid, banner, "USD")), 100)); @@ -1318,7 +1367,8 @@ public void shouldAddExtPrebidEventsIfEventsAreEnabledAndAccountSupportEventsFor identity(), extBuilder -> extBuilder .channel(ExtRequestPrebidChannel.of("web")) - .integration("pbjs")); + .integration("pbjs"), + givenImp()); final AuctionContext auctionContext = givenAuctionContext( bidRequest, contextBuilder -> contextBuilder.account(account)); @@ -1326,7 +1376,7 @@ public void shouldAddExtPrebidEventsIfEventsAreEnabledAndAccountSupportEventsFor final Bid bid = Bid.builder() .id("bidId1") .price(BigDecimal.valueOf(5.67)) - .impid("i1") + .impid(IMP_ID) .build(); final List bidderResponses = singletonList( BidderResponse.of("bidder1", givenSeatBid(BidderBid.of(bid, banner, "USD")), 100)); @@ -1356,7 +1406,8 @@ public void shouldAddExtPrebidEventsIfEventsAreEnabledAndDefaultAccountAnalytics identity(), extBuilder -> extBuilder .channel(ExtRequestPrebidChannel.of("amp")) - .integration("pbjs")); + .integration("pbjs"), + givenImp()); final AuctionContext auctionContext = givenAuctionContext( bidRequest, contextBuilder -> contextBuilder.account(account)); @@ -1364,7 +1415,7 @@ public void shouldAddExtPrebidEventsIfEventsAreEnabledAndDefaultAccountAnalytics final Bid bid = Bid.builder() .id("bidId1") .price(BigDecimal.valueOf(5.67)) - .impid("i1") + .impid(IMP_ID) .build(); final List bidderResponses = singletonList( BidderResponse.of("bidder1", givenSeatBid(BidderBid.of(bid, banner, "USD")), 100)); @@ -1389,11 +1440,15 @@ public void shouldAddExtPrebidEventsIfEventsAreEnabledAndDefaultAccountAnalytics @Test public void shouldAddExtPrebidVideo() { // given - final AuctionContext auctionContext = givenAuctionContext(givenBidRequest()); + final AuctionContext auctionContext = givenAuctionContext(givenBidRequest(givenImp())); - final Bid bid = Bid.builder().id("bidId1").price(BigDecimal.valueOf(5.67)).impid("i1").impid("i1") - .ext(mapper.createObjectNode().set("prebid", mapper.valueToTree( - ExtBidPrebid.builder().video(ExtBidPrebidVideo.of(1, "category")).build()))).build(); + final ExtBidPrebid extBidPrebid = ExtBidPrebid.builder().video(ExtBidPrebidVideo.of(1, "category")).build(); + final Bid bid = Bid.builder() + .id("bidId1") + .price(BigDecimal.valueOf(5.67)) + .impid(IMP_ID) + .ext(mapper.createObjectNode().set("prebid", mapper.valueToTree(extBidPrebid))) + .build(); final List bidderResponses = singletonList(BidderResponse.of("bidder1", givenSeatBid(BidderBid.of(bid, banner, "USD")), 100)); @@ -1415,10 +1470,11 @@ public void shouldNotAddExtPrebidEventsIfEventsAreNotEnabled() { final AuctionContext auctionContext = givenAuctionContext( givenBidRequest( identity(), - extBuilder -> extBuilder.events(mapper.createObjectNode())), + extBuilder -> extBuilder.events(mapper.createObjectNode()), + givenImp()), contextBuilder -> contextBuilder.account(account)); - final Bid bid = Bid.builder().id("bidId1").price(BigDecimal.valueOf(5.67)).impid("i1").build(); + final Bid bid = Bid.builder().id("bidId1").price(BigDecimal.valueOf(5.67)).impid(IMP_ID).build(); final List bidderResponses = singletonList(BidderResponse.of("bidder1", givenSeatBid(BidderBid.of(bid, banner, "USD")), 100)); @@ -1438,13 +1494,13 @@ public void shouldNotAddExtPrebidEventsIfExtRequestPrebidEventsNull() { // given final Account account = Account.builder().id("accountId").eventsEnabled(true).build(); final AuctionContext auctionContext = givenAuctionContext( - givenBidRequest(), + givenBidRequest(givenImp()), contextBuilder -> contextBuilder.account(account)); final Bid bid = Bid.builder() .id("bidId1") .price(BigDecimal.valueOf(5.67)) - .impid("i1") + .impid(IMP_ID) .build(); final List bidderResponses = singletonList( BidderResponse.of("bidder1", givenSeatBid(BidderBid.of(bid, banner, "USD")), 100)); @@ -1470,7 +1526,8 @@ public void shouldNotAddExtPrebidEventsIfAccountDoesNotSupportEventsForChannel() .build(); final BidRequest bidRequest = givenBidRequest( identity(), - extBuilder -> extBuilder.channel(ExtRequestPrebidChannel.of("amp"))); + extBuilder -> extBuilder.channel(ExtRequestPrebidChannel.of("amp")), + givenImp()); final AuctionContext auctionContext = givenAuctionContext( bidRequest, contextBuilder -> contextBuilder.account(account)); @@ -1478,7 +1535,7 @@ public void shouldNotAddExtPrebidEventsIfAccountDoesNotSupportEventsForChannel() final Bid bid = Bid.builder() .id("bidId1") .price(BigDecimal.valueOf(5.67)) - .impid("i1") + .impid(IMP_ID) .build(); final List bidderResponses = singletonList( BidderResponse.of("bidder1", givenSeatBid(BidderBid.of(bid, banner, "USD")), 100)); @@ -1499,9 +1556,10 @@ public void shouldReturnCacheEntityInExt() { // given final AuctionContext auctionContext = givenAuctionContext(givenBidRequest( identity(), - extBuilder -> extBuilder.targeting(givenTargeting()))); + extBuilder -> extBuilder.targeting(givenTargeting()), + givenImp())); - final Bid bid = Bid.builder().id("bidId").price(BigDecimal.valueOf(5.67)).impid("i1").build(); + final Bid bid = Bid.builder().id("bidId").price(BigDecimal.valueOf(5.67)).impid(IMP_ID).build(); final List bidderResponses = singletonList(BidderResponse.of("bidder1", givenSeatBid(BidderBid.of(bid, banner, "USD")), 100)); @@ -1541,9 +1599,10 @@ public void shouldNotPopulateWinningBidTargetingIfIncludeWinnersFlagIsFalse() { .includewinners(false) .includebidderkeys(true) .includeformat(false) - .build()))); + .build()), + givenImp())); - final Bid bid = Bid.builder().id("bidId").price(BigDecimal.valueOf(5.67)).impid("i1").build(); + final Bid bid = Bid.builder().id("bidId").price(BigDecimal.valueOf(5.67)).impid(IMP_ID).build(); final List bidderResponses = singletonList(BidderResponse.of("bidder1", givenSeatBid(BidderBid.of(bid, banner, "USD")), 100)); @@ -1583,9 +1642,10 @@ public void shouldNotPopulateBidderKeysTargetingIfIncludeBidderKeysFlagIsFalse() .includewinners(true) .includebidderkeys(false) .includeformat(false) - .build()))); + .build()), + givenImp())); - final Bid bid = Bid.builder().id("bidId").price(BigDecimal.valueOf(5.67)).impid("i1").build(); + final Bid bid = Bid.builder().id("bidId").price(BigDecimal.valueOf(5.67)).impid(IMP_ID).build(); final List bidderResponses = singletonList(BidderResponse.of("bidder1", givenSeatBid(BidderBid.of(bid, banner, "USD")), 100)); @@ -1618,7 +1678,8 @@ public void shouldNotPopulateCacheIdTargetingKeywordsIfBidCpmIsZero() { // given final AuctionContext auctionContext = givenAuctionContext(givenBidRequest( identity(), - extBuilder -> extBuilder.targeting(givenTargeting()))); + extBuilder -> extBuilder.targeting(givenTargeting()), + givenImp("impId1"), givenImp("impId2"))); final Bid firstBid = Bid.builder().id("bidId1").impid("impId1").price(BigDecimal.ZERO).build(); final Bid secondBid = Bid.builder().id("bidId2").impid("impId2").price(BigDecimal.valueOf(5.67)).build(); @@ -1651,29 +1712,25 @@ public void shouldNotPopulateCacheIdTargetingKeywordsIfBidCpmIsZero() { @Test public void shouldNotCacheNonDealBidWithCpmIsZeroAndCacheDealBidWithZeroCpm() { // given - final AuctionContext auctionContext = givenAuctionContext(givenBidRequest()); + final Imp imp2 = givenImp("impId2"); + final AuctionContext auctionContext = givenAuctionContext(givenBidRequest(givenImp("impId1"), imp2)); - final Bid firstBid = Bid.builder().id("bidId1").impid("impId1").price(BigDecimal.ZERO).build(); - final Bid secondBid = Bid.builder().id("bidId2").impid("impId2").price(BigDecimal.ZERO).dealid("dealId2") - .build(); + final Bid bid1 = Bid.builder().id("bidId1").impid("impId1").price(BigDecimal.ZERO).build(); + final Bid bid2 = Bid.builder().id("bidId2").impid("impId2").price(BigDecimal.ZERO).dealid("dealId2").build(); final List bidderResponses = asList( - BidderResponse.of("bidder1", givenSeatBid(BidderBid.of(firstBid, banner, null)), 99), - BidderResponse.of("bidder2", givenSeatBid(BidderBid.of(secondBid, banner, null)), 99)); + BidderResponse.of("bidder1", givenSeatBid(BidderBid.of(bid1, banner, null)), 99), + BidderResponse.of("bidder2", givenSeatBid(BidderBid.of(bid2, banner, null)), 99)); final BidRequestCacheInfo cacheInfo = BidRequestCacheInfo.builder().doCaching(true).build(); - givenCacheServiceResult(singletonMap(secondBid, CacheInfo.of("cacheId2", null, null, null))); + givenCacheServiceResult(singletonMap(bid2, CacheInfo.of("cacheId2", null, null, null))); // when bidResponseCreator.create(bidderResponses, auctionContext, cacheInfo, false).result(); // then - @SuppressWarnings("unchecked") final ArgumentCaptor> cacheBidArgumentCaptor - = ArgumentCaptor.forClass(List.class); - verify(cacheService).cacheBidsOpenrtb(cacheBidArgumentCaptor.capture(), any(), any(), any()); - assertThat(cacheBidArgumentCaptor.getValue()) - .extracting(Bid::getId) - .containsOnly("bidId2"); + final BidInfo bidInfo2 = toBidInfo(bid2, imp2, "bidder2", banner); + verify(cacheService).cacheBidsOpenrtb(eq(singletonList(bidInfo2)), any(), any(), any()); } @Test @@ -1683,11 +1740,11 @@ public void shouldPopulateBidResponseExtension() throws JsonProcessingException .cur(singletonList("USD")) .tmax(1000L) .app(App.builder().build()) - .imp(emptyList()) + .imp(singletonList(givenImp())) .build(); final AuctionContext auctionContext = givenAuctionContext(bidRequest); - final Bid bid = Bid.builder().id("bidId1").impid("impId1").adm("[]").price(BigDecimal.valueOf(5.67)).build(); + final Bid bid = Bid.builder().id("bidId1").impid(IMP_ID).adm("[]").price(BigDecimal.valueOf(5.67)).build(); final List bidderResponses = singletonList(BidderResponse.of("bidder1", BidderSeatBid.of(singletonList(BidderBid.of(bid, xNative, null)), null, singletonList(BidderError.badInput("bad_input"))), 100)); @@ -1725,7 +1782,7 @@ public void shouldPopulateBidResponseExtension() throws JsonProcessingException @Test public void impToStoredVideoJsonShouldTolerateWhenStoredVideoFetchIsFailed() { // given - final Imp imp = Imp.builder().id("impId1").ext( + final Imp imp = Imp.builder().id(IMP_ID).ext( mapper.valueToTree( ExtImp.of( ExtImpPrebid.builder() @@ -1737,7 +1794,7 @@ public void impToStoredVideoJsonShouldTolerateWhenStoredVideoFetchIsFailed() { .build(); final AuctionContext auctionContext = givenAuctionContext(givenBidRequest(imp)); - final Bid bid = Bid.builder().id("bidId1").impid("impId1").price(BigDecimal.valueOf(5.67)).build(); + final Bid bid = Bid.builder().id("bidId1").impid(IMP_ID).price(BigDecimal.valueOf(5.67)).build(); final List bidderResponses = singletonList(BidderResponse.of("bidder1", givenSeatBid(BidderBid.of(bid, banner, "USD")), 100)); @@ -1813,7 +1870,7 @@ public void impToStoredVideoJsonShouldInjectStoredVideoWhenExtOptionsIsTrueAndVi @Test public void impToStoredVideoJsonShouldAddErrorsWithPrebidBidderWhenStoredVideoRequestFailed() { // given - final Imp imp1 = Imp.builder().id("impId1").ext( + final Imp imp1 = Imp.builder().id(IMP_ID).ext( mapper.valueToTree( ExtImp.of(ExtImpPrebid.builder() .storedrequest(ExtStoredRequest.of("st1")) @@ -1824,7 +1881,7 @@ public void impToStoredVideoJsonShouldAddErrorsWithPrebidBidderWhenStoredVideoRe final BidRequest bidRequest = givenBidRequest(imp1); final AuctionContext auctionContext = givenAuctionContext(bidRequest); - final Bid bid1 = Bid.builder().id("bidId1").impid("impId1").price(BigDecimal.valueOf(5.67)).build(); + final Bid bid1 = Bid.builder().id("bidId1").impid(IMP_ID).price(BigDecimal.valueOf(5.67)).build(); final List bidderBids = singletonList(BidderBid.of(bid1, banner, "USD")); final List bidderResponses = singletonList( BidderResponse.of("bidder1", BidderSeatBid.of(bidderBids, emptyList(), emptyList()), 100)); @@ -1880,10 +1937,10 @@ invalidBidderName, singletonList(ExtBidderError.of(BidderError.Type.bad_input.ge public void shouldProcessRequestAndAddErrorFromAuctionContext() { // given final AuctionContext auctionContext = givenAuctionContext( - givenBidRequest(), + givenBidRequest(givenImp()), contextBuilder -> contextBuilder.prebidErrors(singletonList("privacy error"))); - final Bid bid1 = Bid.builder().id("bidId1").impid("impId1").price(BigDecimal.valueOf(5.67)).build(); + final Bid bid1 = Bid.builder().id("bidId1").impid(IMP_ID).price(BigDecimal.valueOf(5.67)).build(); final List bidderBids = singletonList(BidderBid.of(bid1, banner, "USD")); final List bidderResponses = singletonList( BidderResponse.of("bidder1", BidderSeatBid.of(bidderBids, emptyList(), emptyList()), 100)); @@ -1903,15 +1960,20 @@ public void shouldProcessRequestAndAddErrorFromAuctionContext() { @Test public void shouldPopulateBidResponseDebugExtensionIfDebugIsEnabled() throws JsonProcessingException { // given - final BidRequest bidRequest = givenBidRequest(); + final BidRequest bidRequest = givenBidRequest(givenImp()); final AuctionContext auctionContext = givenAuctionContext(bidRequest); givenCacheServiceResult(CacheServiceResult.of( - DebugHttpCall.builder().endpoint("http://cache-service/cache") - .requestUri("test.uri").responseStatus(500).build(), null, emptyMap())); + DebugHttpCall.builder() + .endpoint("http://cache-service/cache") + .requestUri("test.uri") + .responseStatus(500) + .build(), + null, + emptyMap())); final BidRequestCacheInfo cacheInfo = BidRequestCacheInfo.builder().doCaching(true).build(); - final Bid bid = Bid.builder().id("bidId1").impid("impId1").price(BigDecimal.valueOf(5.67)).build(); + final Bid bid = Bid.builder().id("bidId1").impid(IMP_ID).price(BigDecimal.valueOf(5.67)).build(); final List bidderResponses = singletonList(BidderResponse.of("bidder1", BidderSeatBid.of(singletonList(BidderBid.of(bid, banner, null)), singletonList(ExtHttpCall.builder().status(200).build()), null), 100)); @@ -1940,7 +2002,7 @@ public void shouldPassIntegrationToCacheServiceAndBidEvents() { final Account account = Account.builder().id("accountId").eventsEnabled(true).build(); final BidRequest bidRequest = BidRequest.builder() .cur(singletonList("USD")) - .imp(emptyList()) + .imp(singletonList(givenImp())) .ext(ExtRequest.of(ExtRequestPrebid.builder() .events(mapper.createObjectNode()) .integration("integration") @@ -1950,7 +2012,7 @@ public void shouldPassIntegrationToCacheServiceAndBidEvents() { bidRequest, contextBuilder -> contextBuilder.account(account)); - final Bid bid = Bid.builder().id("bidId1").impid("impId1").price(BigDecimal.valueOf(5.67)).build(); + final Bid bid = Bid.builder().id("bidId1").impid(IMP_ID).price(BigDecimal.valueOf(5.67)).build(); final List bidderResponses = singletonList( BidderResponse.of("bidder1", givenSeatBid(BidderBid.of(bid, banner, "USD")), 100)); @@ -1987,8 +2049,7 @@ private AuctionContext givenAuctionContext(BidRequest bidRequest, .timeout(timeout) .prebidErrors(emptyList()); - return contextCustomizer.apply(auctionContextBuilder) - .build(); + return contextCustomizer.apply(auctionContextBuilder).build(); } private AuctionContext givenAuctionContext(BidRequest bidRequest) { @@ -2004,6 +2065,32 @@ private void givenCacheServiceResult(CacheServiceResult cacheServiceResult) { .willReturn(Future.succeededFuture(cacheServiceResult)); } + private static BidInfo toBidInfo(Bid bid, Imp correspondingImp, String bidder, BidType bidType) { + return BidInfo.builder().bid(bid).correspondingImp(correspondingImp).bidder(bidder).bidType(bidType).build(); + } + + private static BidInfo toBidInfo(Bid bid, + String generatedBidId, + Imp correspondingImp, + String bidder, + BidType bidType) { + return BidInfo.builder() + .generatedBidId(generatedBidId) + .bid(bid) + .correspondingImp(correspondingImp) + .bidder(bidder) + .bidType(bidType) + .build(); + } + + private static Imp givenImp() { + return Imp.builder().id(IMP_ID).build(); + } + + private static Imp givenImp(String impId) { + return Imp.builder().id(impId).build(); + } + private static BidRequest givenBidRequest( UnaryOperator bidRequestCustomizer, UnaryOperator extRequestCustomizer, @@ -2061,22 +2148,6 @@ private static String toTargetingByKey(Bid bid, String targetingKey) { return targeting != null ? targeting.get(targetingKey) : null; } - @SuppressWarnings("unchecked") - private static void assertMapWithUnorderedList(Map> map, Map> expectedMap) { - assertThat(map).hasSize(expectedMap.size()); - for (Map.Entry> keyToValues : expectedMap.entrySet()) { - final V[] values = (V[]) keyToValues.getValue().toArray(); - assertThat(expectedMap.get(keyToValues.getKey())).containsOnly(values); - } - } - - private Map doubleMap(K key1, V value1, K key2, V value2) { - final Map result = new HashMap<>(); - result.put(key1, value1); - result.put(key2, value2); - return result; - } - @SafeVarargs private static List mutableList(T... values) { return Arrays.stream(values).collect(Collectors.toList()); diff --git a/src/test/java/org/prebid/server/auction/model/GeneratedBidIdsTest.java b/src/test/java/org/prebid/server/auction/model/GeneratedBidIdsTest.java deleted file mode 100644 index f704d68d962..00000000000 --- a/src/test/java/org/prebid/server/auction/model/GeneratedBidIdsTest.java +++ /dev/null @@ -1,157 +0,0 @@ -package org.prebid.server.auction.model; - -import com.iab.openrtb.response.Bid; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.mockito.Mock; -import org.mockito.junit.MockitoJUnit; -import org.mockito.junit.MockitoRule; -import org.prebid.server.bidder.model.BidderBid; -import org.prebid.server.bidder.model.BidderSeatBid; -import org.prebid.server.identity.IdGenerator; - -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Optional; - -import static java.util.Arrays.asList; -import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.BDDMockito.given; - -public class GeneratedBidIdsTest { - - @Rule - public final MockitoRule mockitoRule = MockitoJUnit.rule(); - - @Mock - private IdGenerator idGenerator; - - private BidderResponse bidderResponse1; - - private BidderResponse bidderResponse2; - - @Before - public void setup() { - bidderResponse1 = givenBidderResponse("bidder1", asList( - givenBidderBid("bidId1", "impId1"), givenBidderBid("bidId1", "impId2"))); - bidderResponse2 = givenBidderResponse("bidder2", asList(givenBidderBid("bidId1", "impId1"), - givenBidderBid("bidId2", "impId2"))); - - given(idGenerator.generateId()) - .willReturn("20dc17a4-4030-4c9f-a2b2-0a95a14af7e9", "a09fb35b-9406-4d1e-9ec3-10c5d33dd249", - "b90a06ad-cfd9-4e6e-bc44-4cf723ef5677", "8269d3fc-3304-4ecd-8221-4e0304bf11c2"); - } - - @Test - public void shouldCreateGeneratedBidIdsTestFromBidderResponses() { - // when - final GeneratedBidIds generatedBidIds = GeneratedBidIds.of(asList(bidderResponse1, bidderResponse2), - (ignored1, ignored2) -> idGenerator.generateId()); - - // then - final Map> expectedResult = - doubleMap("bidder1", - doubleMap("bidId1-impId1", "20dc17a4-4030-4c9f-a2b2-0a95a14af7e9", - "bidId1-impId2", "a09fb35b-9406-4d1e-9ec3-10c5d33dd249"), - "bidder2", - doubleMap("bidId1-impId1", "b90a06ad-cfd9-4e6e-bc44-4cf723ef5677", - "bidId2-impId2", "8269d3fc-3304-4ecd-8221-4e0304bf11c2")); - assertThat(generatedBidIds.getBidderToBidIds()) - .containsAllEntriesOf(expectedResult); - } - - @Test - public void getBidderForBidShouldReturnOptionalWithBidderIfExists() { - // given - final GeneratedBidIds generatedBidIds = GeneratedBidIds.of(asList(bidderResponse1, bidderResponse2), - (ignored1, ignored2) -> idGenerator.generateId()); - - // when - final Optional result = generatedBidIds.getBidderForBid("bidId1", "impId2"); - // then - assertThat(result).isPresent(); - assertThat(result.get()).isEqualTo("bidder1"); - } - - @Test - public void getBidderForBidShouldReturnEmptyOptionalIfBidderNotExists() { - // given - final GeneratedBidIds generatedBidIds = GeneratedBidIds.of(asList(bidderResponse1, bidderResponse2), - (ignored1, ignored2) -> idGenerator.generateId()); - - // when - final Optional result = generatedBidIds.getBidderForBid("bidId1", "impId3"); - - // then - assertThat(result).isEmpty(); - } - - @Test - public void getGeneratedIdShouldReturnGeneratedId() { - // given - final GeneratedBidIds generatedBidIds = GeneratedBidIds.of(asList(bidderResponse1, bidderResponse2), - (ignored1, ignored2) -> idGenerator.generateId()); - - // when - final String result = generatedBidIds.getGeneratedId("bidder1", "bidId1", "impId1"); - - // then - assertThat(result).isEqualTo("20dc17a4-4030-4c9f-a2b2-0a95a14af7e9"); - } - - @Test - public void getGeneratedIdShouldReturnNullIfBidWithBidIdAndImpIdPairWasNotFound() { - // given - final GeneratedBidIds generatedBidIds = GeneratedBidIds.of(asList(bidderResponse1, bidderResponse2), - (ignored1, ignored2) -> idGenerator.generateId()); - - // when - final String result = generatedBidIds.getGeneratedId("bidder1", "bidId1", "impId3"); - - // then - assertThat(result).isNull(); - } - - @Test - public void getGeneratedIdShouldReturnNullIfBidderNotFound() { - // given - final GeneratedBidIds generatedBidIds = GeneratedBidIds.of(asList(bidderResponse1, bidderResponse2), - (ignored1, ignored2) -> idGenerator.generateId()); - - // when - final String result = generatedBidIds.getGeneratedId("bidder3", "bidId1", "impId1"); - - // then - assertThat(result).isNull(); - } - - @Test - public void getGeneratedIdShouldReturnNullIfGeneratedIdCreatedFromEmptyMap() { - // given - final GeneratedBidIds generatedBidIds = GeneratedBidIds.empty(); - - // when - final String result = generatedBidIds.getGeneratedId("bidder3", "bidId1", "impId1"); - - // then - assertThat(result).isNull(); - } - - private static BidderBid givenBidderBid(String bidId, String impId) { - return BidderBid.of(Bid.builder().id(bidId).impid(impId).build(), null, null); - } - - private static BidderResponse givenBidderResponse(String bidder, List bidderBids) { - return BidderResponse.of(bidder, BidderSeatBid.of(bidderBids, null, null), 0); - } - - private Map doubleMap(K key1, V value1, K key2, V value2) { - final Map result = new HashMap<>(); - result.put(key1, value1); - result.put(key2, value2); - return result; - } - -} diff --git a/src/test/java/org/prebid/server/cache/CacheServiceTest.java b/src/test/java/org/prebid/server/cache/CacheServiceTest.java index 3959b0379f4..9ea10cffaf2 100644 --- a/src/test/java/org/prebid/server/cache/CacheServiceTest.java +++ b/src/test/java/org/prebid/server/cache/CacheServiceTest.java @@ -4,7 +4,6 @@ import com.fasterxml.jackson.databind.node.TextNode; import com.iab.openrtb.request.BidRequest; import com.iab.openrtb.request.Imp; -import com.iab.openrtb.request.Video; import com.iab.openrtb.response.Bid; import io.vertx.core.Future; import org.junit.Before; @@ -16,7 +15,7 @@ import org.mockito.junit.MockitoRule; import org.prebid.server.VertxTest; import org.prebid.server.auction.model.AuctionContext; -import org.prebid.server.auction.model.GeneratedBidIds; +import org.prebid.server.auction.model.BidInfo; import org.prebid.server.cache.model.CacheContext; import org.prebid.server.cache.model.CacheHttpRequest; import org.prebid.server.cache.model.CacheInfo; @@ -33,7 +32,9 @@ import org.prebid.server.execution.Timeout; import org.prebid.server.execution.TimeoutFactory; import org.prebid.server.metric.Metrics; +import org.prebid.server.proto.openrtb.ext.response.BidType; import org.prebid.server.settings.model.Account; +import org.prebid.server.vast.VastModifier; import org.prebid.server.vertx.http.HttpClient; import org.prebid.server.vertx.http.model.HttpClientResponse; @@ -45,7 +46,6 @@ import java.time.ZoneId; import java.util.ArrayList; import java.util.List; -import java.util.Optional; import java.util.function.UnaryOperator; import static java.util.Arrays.asList; @@ -69,6 +69,7 @@ public class CacheServiceTest extends VertxTest { + public static final String ACCOUNT_ID = "accountId"; @Rule public final MockitoRule mockitoRule = MockitoJUnit.rule(); @@ -79,11 +80,9 @@ public class CacheServiceTest extends VertxTest { @Mock private EventsService eventsService; @Mock - private Metrics metrics; - @Mock - private GeneratedBidIds allBidIds; + private VastModifier vastModifier; @Mock - private GeneratedBidIds videoCachedBidIds; + private Metrics metrics; private Clock clock; @@ -104,6 +103,7 @@ public void setUp() throws MalformedURLException, JsonProcessingException { httpClient, new URL("http://cache-service/cache"), "http://cache-service-host/cache?uuid=", + vastModifier, eventsService, metrics, clock, @@ -178,11 +178,10 @@ public void cacheBidsOpenrtbShouldNeverCallCacheServiceIfNoBidsPassed() { public void cacheBidsOpenrtbShouldPerformHttpRequestWithExpectedTimeout() { // when cacheService.cacheBidsOpenrtb( - singletonList(givenBidOpenrtb(identity())), + singletonList(givenBidInfo(identity())), givenAuctionContext(), CacheContext.builder() .shouldCacheBids(true) - .bidderToBidsToGeneratedIds(allBidIds) .build(), eventsContext); @@ -194,11 +193,10 @@ public void cacheBidsOpenrtbShouldPerformHttpRequestWithExpectedTimeout() { public void cacheBidsOpenrtbShouldTolerateGlobalTimeoutAlreadyExpired() { // when final Future future = cacheService.cacheBidsOpenrtb( - singletonList(givenBidOpenrtb(identity())), + singletonList(givenBidInfo(identity())), givenAuctionContext().toBuilder().timeout(expiredTimeout).build(), CacheContext.builder() .shouldCacheBids(true) - .bidderToBidsToGeneratedIds(allBidIds) .build(), eventsContext); @@ -210,113 +208,114 @@ public void cacheBidsOpenrtbShouldTolerateGlobalTimeoutAlreadyExpired() { } @Test - public void cacheBidsOpenrtbShouldStoreWinUrlWithGeneratedBidId() { - // given - final Bid bid = givenBidOpenrtb(builder -> builder.id("bidId1").impid("impId1")); - final String generatedBidId = "GeneratedBidId"; - given(allBidIds.getGeneratedId(any(), any(), any())).willReturn(generatedBidId); - given(allBidIds.getBidderForBid(any(), any())).willReturn(Optional.of("bidder")); - + public void cacheBidsOpenrtbShouldStoreWinUrl() { // when cacheService.cacheBidsOpenrtb( - singletonList(bid), - givenAuctionContext(bidRequestBuilder -> bidRequestBuilder - .imp(singletonList(givenImp(builder -> builder.id("impId1"))))), + singletonList(givenBidInfo(builder -> builder.id("bidId1"))), + givenAuctionContext(), CacheContext.builder() .shouldCacheBids(true) - .bidderToBidsToGeneratedIds(allBidIds) .build(), EventsContext.builder().enabledForAccount(true).enabledForRequest(true).build()); // then - verify(eventsService).winUrl(eq(generatedBidId), eq("bidder"), eq("accountId"), isNull(), isNull()); + verify(eventsService).winUrl(eq("bidId1"), eq("bidder"), eq(ACCOUNT_ID), isNull(), isNull()); } @Test public void cacheBidsOpenrtbShouldTolerateReadingHttpResponseFails() throws JsonProcessingException { // given givenHttpClientProducesException(new RuntimeException("Response exception")); - - final Bid bid = givenBidOpenrtb(builder -> builder.id("bidId1").impid("impId1")); + final BidInfo bidinfo = givenBidInfo(builder -> builder.id("bidId1")); // when final Future future = cacheService.cacheBidsOpenrtb( - singletonList(bid), - givenAuctionContext(bidRequestBuilder -> bidRequestBuilder - .imp(singletonList(givenImp(builder -> builder.id("impId1"))))), + singletonList(bidinfo), + givenAuctionContext(), CacheContext.builder() .shouldCacheBids(true) - .bidderToBidsToGeneratedIds(allBidIds) .build(), eventsContext); // then - verify(metrics).updateCacheRequestFailedTime(eq("accountId"), anyLong()); + verify(metrics).updateCacheRequestFailedTime(eq(ACCOUNT_ID), anyLong()); final CacheServiceResult result = future.result(); - final CacheHttpRequest request = givenCacheHttpRequest(bid); assertThat(result.getCacheBids()).isEmpty(); assertThat(result.getError()).isInstanceOf(RuntimeException.class).hasMessage("Response exception"); - assertThat(result.getHttpCall()).isNotNull() - .isEqualTo(DebugHttpCall.builder().requestUri(request.getUri()).requestBody(request.getBody()) - .endpoint("http://cache-service/cache").responseTimeMillis(0).build()); + + final CacheHttpRequest request = givenCacheHttpRequest(bidinfo.getBid()); + assertThat(result.getHttpCall()) + .isEqualTo(DebugHttpCall.builder() + .endpoint("http://cache-service/cache") + .requestBody(request.getBody()) + .requestUri(request.getUri()) + .responseTimeMillis(0) + .build()); } @Test public void cacheBidsOpenrtbShouldTolerateResponseCodeIsNot200() throws JsonProcessingException { // given givenHttpClientReturnsResponse(503, "response"); - - final Bid bid = givenBidOpenrtb(builder -> builder.id("bidId1").impid("impId1")); + final BidInfo bidinfo = givenBidInfo(builder -> builder.id("bidId1")); // when final Future future = cacheService.cacheBidsOpenrtb( - singletonList(bid), - givenAuctionContext(bidRequestBuilder -> bidRequestBuilder - .imp(singletonList(givenImp(builder -> builder.id("impId1"))))), + singletonList(bidinfo), + givenAuctionContext(), CacheContext.builder() .shouldCacheBids(true) - .bidderToBidsToGeneratedIds(allBidIds) .build(), eventsContext); // then final CacheServiceResult result = future.result(); - final CacheHttpRequest request = givenCacheHttpRequest(bid); assertThat(result.getCacheBids()).isEmpty(); assertThat(result.getError()).isInstanceOf(PreBidException.class).hasMessage("HTTP status code 503"); - assertThat(result.getHttpCall()).isNotNull() - .isEqualTo(DebugHttpCall.builder().endpoint("http://cache-service/cache") - .requestBody(request.getBody()).requestUri(request.getUri()).responseStatus(503) - .responseBody("response").responseTimeMillis(0).build()); + + final CacheHttpRequest request = givenCacheHttpRequest(bidinfo.getBid()); + assertThat(result.getHttpCall()) + .isEqualTo(DebugHttpCall.builder() + .endpoint("http://cache-service/cache") + .requestBody(request.getBody()) + .requestUri(request.getUri()) + .responseStatus(503) + .responseBody("response") + .responseTimeMillis(0) + .build()); } @Test public void cacheBidsOpenrtbShouldTolerateResponseBodyCouldNotBeParsed() throws JsonProcessingException { // given givenHttpClientReturnsResponse(200, "response"); - final Bid bid = givenBidOpenrtb(builder -> builder.id("bidId1").impid("impId1")); + final BidInfo bidinfo = givenBidInfo(builder -> builder.id("bidId1")); // when final Future future = cacheService.cacheBidsOpenrtb( - singletonList(bid), - givenAuctionContext(bidRequestBuilder -> bidRequestBuilder - .imp(singletonList(givenImp(builder -> builder.id("impId1"))))), + singletonList(bidinfo), + givenAuctionContext(), CacheContext.builder() .shouldCacheBids(true) - .bidderToBidsToGeneratedIds(allBidIds) .build(), eventsContext); // then final CacheServiceResult result = future.result(); - final CacheHttpRequest request = givenCacheHttpRequest(bid); assertThat(result.getCacheBids()).isEmpty(); assertThat(result.getError()).isInstanceOf(PreBidException.class).hasMessage("Cannot parse response: response"); - assertThat(result.getHttpCall()).isNotNull() - .isEqualTo(DebugHttpCall.builder().endpoint("http://cache-service/cache") - .requestUri(request.getUri()).requestBody(request.getBody()) - .responseStatus(200).responseBody("response").responseTimeMillis(0).build()); + + final CacheHttpRequest request = givenCacheHttpRequest(bidinfo.getBid()); + assertThat(result.getHttpCall()) + .isEqualTo(DebugHttpCall.builder() + .endpoint("http://cache-service/cache") + .requestUri(request.getUri()) + .requestBody(request.getBody()) + .responseStatus(200) + .responseBody("response") + .responseTimeMillis(0) + .build()); } @Test @@ -324,106 +323,115 @@ public void cacheBidsOpenrtbShouldTolerateCacheEntriesNumberDoesNotMatchBidsNumb throws JsonProcessingException { // given givenHttpClientReturnsResponse(200, "{}"); - - final Bid bid = givenBidOpenrtb(builder -> builder.id("bidId1").impid("impId1")); + final BidInfo bidinfo = givenBidInfo(builder -> builder.id("bidId1")); // when final Future future = cacheService.cacheBidsOpenrtb( - singletonList(bid), - givenAuctionContext(bidRequestBuilder -> bidRequestBuilder - .imp(singletonList(givenImp(builder -> builder.id("impId1"))))), + singletonList(bidinfo), + givenAuctionContext(), CacheContext.builder() .shouldCacheBids(true) - .bidderToBidsToGeneratedIds(allBidIds) .build(), eventsContext); // then final CacheServiceResult result = future.result(); - final CacheHttpRequest request = givenCacheHttpRequest(bid); assertThat(result.getCacheBids()).isEmpty(); - assertThat(result.getError()).isNotNull().isInstanceOf(PreBidException.class) + assertThat(result.getError()).isInstanceOf(PreBidException.class) .hasMessage("The number of response cache objects doesn't match with bids"); + + final CacheHttpRequest request = givenCacheHttpRequest(bidinfo.getBid()); assertThat(result.getHttpCall()).isNotNull() - .isEqualTo(DebugHttpCall.builder().endpoint("http://cache-service/cache") - .requestBody(request.getBody()).requestUri(request.getUri()) - .responseStatus(200).responseBody("{}").responseTimeMillis(0).build()); + .isEqualTo(DebugHttpCall.builder() + .endpoint("http://cache-service/cache") + .requestBody(request.getBody()) + .requestUri(request.getUri()) + .responseStatus(200).responseBody("{}") + .responseTimeMillis(0) + .build()); } @Test public void cacheBidsOpenrtbShouldReturnExpectedDebugInfo() throws JsonProcessingException { // given - final Bid bid = givenBidOpenrtb(builder -> builder.id("bidId1").impid("impId1")); + final BidInfo bidinfo = givenBidInfo(builder -> builder.id("bidId1")); // when final Future future = cacheService.cacheBidsOpenrtb( - singletonList(bid), - givenAuctionContext(bidRequestBuilder -> bidRequestBuilder - .imp(singletonList(givenImp(builder -> builder.id("impId1"))))), + singletonList(bidinfo), + givenAuctionContext(), CacheContext.builder() .shouldCacheBids(true) - .bidderToBidsToGeneratedIds(allBidIds) .build(), eventsContext); // then final CacheServiceResult result = future.result(); - final CacheHttpRequest request = givenCacheHttpRequest(bid); - assertThat(result.getHttpCall()).isNotNull() - .isEqualTo(DebugHttpCall.builder().endpoint("http://cache-service/cache") - .requestUri(request.getUri()).requestBody(request.getBody()) - .responseStatus(200).responseBody("{\"responses\":[{\"uuid\":\"uuid1\"}]}") - .responseTimeMillis(0).build()); + final CacheHttpRequest request = givenCacheHttpRequest(bidinfo.getBid()); + assertThat(result.getHttpCall()) + .isEqualTo(DebugHttpCall.builder() + .endpoint("http://cache-service/cache") + .requestUri(request.getUri()) + .requestBody(request.getBody()) + .responseStatus(200) + .responseBody("{\"responses\":[{\"uuid\":\"uuid1\"}]}") + .responseTimeMillis(0) + .build()); } @Test public void cacheBidsOpenrtbShouldReturnExpectedCacheBids() { // given - final Bid bid = givenBidOpenrtb(builder -> builder.id("bidId1").impid("impId1")); + final BidInfo bidinfo = givenBidInfo(builder -> builder.id("bidId1")); // when final Future future = cacheService.cacheBidsOpenrtb( - singletonList(bid), - givenAuctionContext(bidRequestBuilder -> bidRequestBuilder - .imp(singletonList(givenImp(builder -> builder.id("impId1"))))), + singletonList(bidinfo), + givenAuctionContext(), CacheContext.builder() .shouldCacheBids(true) - .bidderToBidsToGeneratedIds(allBidIds) .build(), eventsContext); // then final CacheServiceResult result = future.result(); assertThat(result.getCacheBids()).hasSize(1) - .containsEntry(bid, CacheInfo.of("uuid1", null, null, null)); + .containsEntry(bidinfo.getBid(), CacheInfo.of("uuid1", null, null, null)); } @Test public void cacheBidsOpenrtbShouldPerformHttpRequestWithExpectedBody() throws IOException { // given - final Bid bid1 = givenBidOpenrtb(builder -> builder.id("bid1").impid("impId1")); - final Bid bid2 = givenBidOpenrtb(builder -> builder.id("bid2").impid("impId2") - .adm("adm2")); - final Imp imp1 = givenImp(identity()); - final Imp imp2 = givenImp(builder -> builder.id("impId2").video(Video.builder().build())); + final String receivedBid2Adm = "adm2"; + final String generatedId = "generatedId"; + final String bidder = "bidder2"; + final BidInfo bidInfo1 = givenBidInfo(builder -> builder.id("bidId1"), null, BidType.banner, "bidder1"); + final BidInfo bidInfo2 = givenBidInfo(builder -> builder.id("bidId2").adm(receivedBid2Adm), generatedId, + BidType.video, + bidder); + + final EventsContext eventsContext = EventsContext.builder().auctionTimestamp(1000L).build(); + + given(vastModifier.createBidVastXml(any(), any(), any(), any(), any(), any())).willReturn(receivedBid2Adm); // when cacheService.cacheBidsOpenrtb( - asList(bid1, bid2), - givenAuctionContext( - accountBuilder -> accountBuilder.id("accountId"), - bidRequestBuilder -> bidRequestBuilder.imp(asList(imp1, imp2))), + asList(bidInfo1, bidInfo2), + givenAuctionContext(), CacheContext.builder() .shouldCacheBids(true) .shouldCacheVideoBids(true) - .bidderToVideoGeneratedBidIdsToModify(videoCachedBidIds) - .bidderToBidsToGeneratedIds(allBidIds) .build(), - EventsContext.builder().auctionTimestamp(1000L).build()); + eventsContext); // then - verify(metrics, times(1)).updateCacheCreativeSize(eq("accountId"), eq(0)); - verify(metrics, times(2)).updateCacheCreativeSize(eq("accountId"), eq(4)); + // Second value is adm length for each + verify(metrics, times(1)).updateCacheCreativeSize(eq(ACCOUNT_ID), eq(0)); + verify(metrics, times(2)).updateCacheCreativeSize(eq(ACCOUNT_ID), eq(4)); + + final Bid bid1 = bidInfo1.getBid(); + final Bid bid2 = bidInfo2.getBid(); + verify(vastModifier).createBidVastXml(bidder, receivedBid2Adm, null, generatedId, ACCOUNT_ID, eventsContext); final BidCacheRequest bidCacheRequest = captureBidCacheRequest(); assertThat(bidCacheRequest.getPuts()).hasSize(3) @@ -435,14 +443,17 @@ public void cacheBidsOpenrtbShouldPerformHttpRequestWithExpectedBody() throws IO @Test public void cacheBidsOpenrtbShouldSendCacheRequestWithExpectedTtlAndSetTtlFromBid() throws IOException { + // given + final BidInfo bidInfo = givenBidInfo( + bidBuilder -> bidBuilder.id("bidId1").exp(10), + impBuilder -> impBuilder.id("impId1").exp(20)); + // when final Future future = cacheService.cacheBidsOpenrtb( - singletonList(givenBidOpenrtb(builder -> builder.impid("impId1").exp(10))), - givenAuctionContext(bidRequestBuilder -> bidRequestBuilder - .imp(singletonList(givenImp(buider -> buider.id("impId1").exp(20))))), + singletonList(bidInfo), + givenAuctionContext(), CacheContext.builder() .shouldCacheBids(true) - .bidderToBidsToGeneratedIds(allBidIds) .cacheBidsTtl(30) .build(), eventsContext); @@ -461,14 +472,17 @@ public void cacheBidsOpenrtbShouldSendCacheRequestWithExpectedTtlAndSetTtlFromBi @Test public void cacheBidsOpenrtbShouldSendCacheRequestWithExpectedTtlAndSetTtlFromImp() throws IOException { + // given + final BidInfo bidInfo = givenBidInfo( + bidBuilder -> bidBuilder.id("bidId1"), + impBuilder -> impBuilder.id("impId1").exp(10)); + // when final Future future = cacheService.cacheBidsOpenrtb( - singletonList(givenBidOpenrtb(identity())), - givenAuctionContext(bidRequestBuilder -> bidRequestBuilder - .imp(singletonList(givenImp(buider -> buider.exp(10))))), + singletonList(bidInfo), + givenAuctionContext(), CacheContext.builder() .shouldCacheBids(true) - .bidderToBidsToGeneratedIds(allBidIds) .cacheBidsTtl(20) .build(), eventsContext); @@ -489,11 +503,10 @@ public void cacheBidsOpenrtbShouldSendCacheRequestWithExpectedTtlAndSetTtlFromIm public void cacheBidsOpenrtbShouldSendCacheRequestWithExpectedTtlAndSetTtlFromRequest() throws IOException { // when final Future future = cacheService.cacheBidsOpenrtb( - singletonList(givenBidOpenrtb(identity())), + singletonList(givenBidInfo(bidBuilder -> bidBuilder.id("bidId1"))), givenAuctionContext(), CacheContext.builder() .shouldCacheBids(true) - .bidderToBidsToGeneratedIds(allBidIds) .cacheBidsTtl(10) .build(), eventsContext); @@ -519,6 +532,7 @@ public void cacheBidsOpenrtbShouldSendCacheRequestWithExpectedTtlAndSetTtlFromAc httpClient, new URL("http://cache-service/cache"), "http://cache-service-host/cache?uuid=", + vastModifier, eventsService, metrics, clock, @@ -526,13 +540,10 @@ public void cacheBidsOpenrtbShouldSendCacheRequestWithExpectedTtlAndSetTtlFromAc // when final Future future = cacheService.cacheBidsOpenrtb( - singletonList(givenBidOpenrtb(identity())), - givenAuctionContext( - accountBuilder -> accountBuilder.bannerCacheTtl(10), - identity()), + singletonList(givenBidInfo(bidBuilder -> bidBuilder.id("bidId1"))), + givenAuctionContext(accountBuilder -> accountBuilder.bannerCacheTtl(10), identity()), CacheContext.builder() .shouldCacheBids(true) - .bidderToBidsToGeneratedIds(allBidIds) .build(), eventsContext); @@ -550,11 +561,13 @@ public void cacheBidsOpenrtbShouldSendCacheRequestWithExpectedTtlAndSetTtlFromAc @Test public void cacheBidsOpenrtbShouldSendCacheRequestWithExpectedTtlAndSetTtlFromMediaTypeTtl() throws IOException { + // given cacheService = new CacheService( CacheTtl.of(10, null), httpClient, new URL("http://cache-service/cache"), "http://cache-service-host/cache?uuid=", + vastModifier, eventsService, metrics, clock, @@ -562,11 +575,10 @@ public void cacheBidsOpenrtbShouldSendCacheRequestWithExpectedTtlAndSetTtlFromMe // when final Future future = cacheService.cacheBidsOpenrtb( - singletonList(givenBidOpenrtb(identity())), + singletonList(givenBidInfo(bidBuilder -> bidBuilder.id("bidId1"))), givenAuctionContext(), CacheContext.builder() .shouldCacheBids(true) - .bidderToBidsToGeneratedIds(allBidIds) .build(), eventsContext); @@ -584,11 +596,13 @@ public void cacheBidsOpenrtbShouldSendCacheRequestWithExpectedTtlAndSetTtlFromMe @Test public void cacheBidsOpenrtbShouldSendCacheRequestWithTtlFromMediaTypeWhenAccountIsEmpty() throws IOException { + // given cacheService = new CacheService( CacheTtl.of(10, null), httpClient, new URL("http://cache-service/cache"), "http://cache-service-host/cache?uuid=", + vastModifier, eventsService, metrics, clock, @@ -596,11 +610,10 @@ public void cacheBidsOpenrtbShouldSendCacheRequestWithTtlFromMediaTypeWhenAccoun // when final Future future = cacheService.cacheBidsOpenrtb( - singletonList(givenBidOpenrtb(identity())), + singletonList(givenBidInfo(bidBuilder -> bidBuilder.id("bidId1"))), givenAuctionContext(), CacheContext.builder() .shouldCacheBids(true) - .bidderToBidsToGeneratedIds(allBidIds) .build(), eventsContext); @@ -620,11 +633,10 @@ public void cacheBidsOpenrtbShouldSendCacheRequestWithTtlFromMediaTypeWhenAccoun public void cacheBidsOpenrtbShouldSendCacheRequestWithNoTtlAndSetEmptyTtl() throws IOException { // when final Future future = cacheService.cacheBidsOpenrtb( - singletonList(givenBidOpenrtb(identity())), + singletonList(givenBidInfo(bidBuilder -> bidBuilder.id("bidId1"))), givenAuctionContext(), CacheContext.builder() .shouldCacheBids(true) - .bidderToBidsToGeneratedIds(allBidIds) .build(), eventsContext); @@ -643,326 +655,122 @@ public void cacheBidsOpenrtbShouldSendCacheRequestWithNoTtlAndSetEmptyTtl() thro @Test public void cacheBidsOpenrtbShouldReturnExpectedResultForBids() { // given - final Bid bid = givenBidOpenrtb(identity()); + final BidInfo bidInfo = givenBidInfo(bidBuilder -> bidBuilder.id("bidId1")); // when final Future future = cacheService.cacheBidsOpenrtb( - singletonList(bid), + singletonList(bidInfo), givenAuctionContext(), CacheContext.builder() .shouldCacheBids(true) - .bidderToBidsToGeneratedIds(allBidIds) .build(), eventsContext); // then assertThat(future.result().getCacheBids()).hasSize(1) - .containsEntry(bid, CacheInfo.of("uuid1", null, null, null)); + .containsEntry(bidInfo.getBid(), CacheInfo.of("uuid1", null, null, null)); } @Test public void cacheBidsOpenrtbShouldReturnExpectedResultForVideoBids() { // given - final Bid bid = givenBidOpenrtb(builder -> builder.impid("impId1")); - final Imp imp = givenImp(builder -> builder.id("impId1").video(Video.builder().build())); + final String receivedAdm = "adm1"; + final String bidId = "bidId1"; + final String bidder = "bidder"; + final BidInfo bidInfo = givenBidInfo(bidBuilder -> bidBuilder.id(bidId).adm(receivedAdm), null, + BidType.video, bidder); + + given(vastModifier.createBidVastXml(anyString(), anyString(), anyString(), anyString(), anyString(), any())) + .willReturn(receivedAdm); // when final Future future = cacheService.cacheBidsOpenrtb( - singletonList(bid), - givenAuctionContext(bidRequestBuilder -> bidRequestBuilder.imp(singletonList(imp))), + singletonList(bidInfo), + givenAuctionContext(), CacheContext.builder() .shouldCacheVideoBids(true) - .bidderToVideoGeneratedBidIdsToModify(allBidIds) .build(), eventsContext); // then + verify(vastModifier).createBidVastXml(bidder, receivedAdm, null, bidId, ACCOUNT_ID, eventsContext); + assertThat(future.result().getCacheBids()).hasSize(1) - .containsEntry(bid, CacheInfo.of(null, "uuid1", null, null)); + .containsEntry(bidInfo.getBid(), CacheInfo.of(null, "uuid1", null, null)); } @Test public void cacheBidsOpenrtbShouldReturnExpectedResultForBidsAndVideoBids() throws JsonProcessingException { // given givenHttpClientReturnsResponse(200, mapper.writeValueAsString( - BidCacheResponse.of(asList(CacheObject.of("uuid1"), CacheObject.of("uuid2"), - CacheObject.of("videoUuid1"), CacheObject.of("videoUuid2"))))); - - final Bid bid1 = givenBidOpenrtb(builder -> builder.impid("impId1")); - final Bid bid2 = givenBidOpenrtb(builder -> builder.impid("impId2")); - final Imp imp1 = givenImp(builder -> builder.id("impId1").video(Video.builder().build())); - final Imp imp2 = givenImp(builder -> builder.id("impId2").video(Video.builder().build())); - - // when - final Future future = cacheService.cacheBidsOpenrtb( - asList(bid1, bid2), - givenAuctionContext(bidRequestBuilder -> bidRequestBuilder.imp(asList(imp1, imp2))), - CacheContext.builder() - .shouldCacheBids(true) - .shouldCacheVideoBids(true) - .bidderToVideoGeneratedBidIdsToModify(videoCachedBidIds) - .bidderToBidsToGeneratedIds(allBidIds) - .build(), - eventsContext); + BidCacheResponse.of(asList( + CacheObject.of("uuid1"), + CacheObject.of("uuid2"), + CacheObject.of("videoUuid1"))))); - // then - assertThat(future.result().getCacheBids()).hasSize(2) - .containsOnly( - entry(bid1, CacheInfo.of("uuid1", "videoUuid1", null, null)), - entry(bid2, CacheInfo.of("uuid2", "videoUuid2", null, null))); - } + final String bidder1 = "bidder1"; + final String bidId1 = "bidId1"; + final BidInfo bidInfo1 = givenBidInfo(builder -> builder.id(bidId1), null, BidType.video, bidder1); + final BidInfo bidInfo2 = givenBidInfo(builder -> builder.id("bidId2"), null, BidType.banner, "bidder2"); - @Test - public void cacheBidsOpenrtbShouldNotCacheVideoBidWithMissingImpId() { - // given - final Bid bid1 = givenBidOpenrtb(builder -> builder.impid("impId1")); - final Bid bid2 = givenBidOpenrtb(builder -> builder.impid("impId2")); - final Imp imp1 = givenImp(builder -> builder.id("impId1").video(Video.builder().build())); - final Imp imp2 = givenImp(builder -> builder.id(null).video(Video.builder().build())); + given(vastModifier.createBidVastXml(any(), any(), any(), any(), any(), any())).willReturn("modifiedAdm"); // when final Future future = cacheService.cacheBidsOpenrtb( - asList(bid1, bid2), - givenAuctionContext(bidRequestBuilder -> bidRequestBuilder.imp(asList(imp1, imp2))), - CacheContext.builder() - .shouldCacheVideoBids(true) - .bidderToVideoGeneratedBidIdsToModify(videoCachedBidIds) - .build(), - eventsContext); - - // then - assertThat(future.result().getCacheBids()).hasSize(1) - .containsEntry(bid1, CacheInfo.of(null, "uuid1", null, null)); - } - - @Test - public void cacheBidsOpenrtbShouldWrapEmptyAdmFieldUsingNurlFieldValue() throws IOException { - // given - final Bid bid1 = givenBidOpenrtb(builder -> builder.id("bid1").impid("impId1") - .adm("adm1")); - final Bid bid2 = givenBidOpenrtb(builder -> builder.id("bid2").impid("impId1") - .nurl("adm2")); - final Imp imp1 = givenImp(builder -> builder.id("impId1").video(Video.builder().build())); - - // when - cacheService.cacheBidsOpenrtb( - asList(bid1, bid2), - givenAuctionContext(bidRequestBuilder -> bidRequestBuilder.imp(singletonList(imp1))), - CacheContext.builder() - .shouldCacheBids(true) - .shouldCacheVideoBids(true) - .bidderToVideoGeneratedBidIdsToModify(videoCachedBidIds) - .bidderToBidsToGeneratedIds(allBidIds) - .build(), - eventsContext); - - // then - final BidCacheRequest bidCacheRequest = captureBidCacheRequest(); - assertThat(bidCacheRequest.getPuts()).hasSize(4) - .containsOnly( - PutObject.builder().type("json").value(mapper.valueToTree(bid1)).build(), - PutObject.builder().type("json").value(mapper.valueToTree(bid2)).build(), - PutObject.builder().type("xml").value(new TextNode("adm1")).build(), - PutObject.builder().type("xml").value(new TextNode( - "prebid.org wrapper" - + "" - + "")) - .build()); - } - - @Test - public void cacheBidsOpenrtbShouldNotModifyVastXmlWhenBidIdIsNotInToModifyList() throws IOException { - // given - final Bid bid = givenBidOpenrtb(builder -> - builder.id("bid1").impid("impId1").adm("adm")); - final Imp imp1 = givenImp(builder -> builder.id("impId1").video(Video.builder().build())); - - // when - cacheService.cacheBidsOpenrtb( - singletonList(bid), - givenAuctionContext(bidRequestBuilder -> bidRequestBuilder.imp(singletonList(imp1))), - CacheContext.builder() - .shouldCacheBids(true) - .shouldCacheVideoBids(true) - .bidderToVideoGeneratedBidIdsToModify(videoCachedBidIds) - .bidderToBidsToGeneratedIds(allBidIds) - .build(), - eventsContext); - - // then - final BidCacheRequest bidCacheRequest = captureBidCacheRequest(); - assertThat(bidCacheRequest.getPuts()).hasSize(2) - .containsOnly( - PutObject.builder().type("json").value(mapper.valueToTree(bid)).build(), - PutObject.builder().type("xml").value(new TextNode("adm")).build()); - } - - @Test - public void cacheBidsOpenrtbShouldNotAddTrackingImpToBidAdmWhenXmlDoesNotContainImpTag() throws IOException { - // given - final Bid bid = givenBidOpenrtb(builder -> - builder.id("bid1").impid("impId1").adm("no impression tag")); - final Imp imp1 = givenImp(builder -> builder.id("impId1").video(Video.builder().build())); - - // when - cacheService.cacheBidsOpenrtb( - singletonList(bid), - givenAuctionContext(bidRequestBuilder -> bidRequestBuilder.imp(singletonList(imp1))), + asList(bidInfo1, bidInfo2), + givenAuctionContext(), CacheContext.builder() .shouldCacheBids(true) .shouldCacheVideoBids(true) - .bidderToVideoGeneratedBidIdsToModify(videoCachedBidIds) - .bidderToBidsToGeneratedIds(allBidIds) .build(), eventsContext); // then - final BidCacheRequest bidCacheRequest = captureBidCacheRequest(); - assertThat(bidCacheRequest.getPuts()).hasSize(2) - .containsOnly( - PutObject.builder().type("json").value(mapper.valueToTree(bid)).build(), - PutObject.builder().type("xml").value(new TextNode("no impression tag")).build()); - } + verify(vastModifier).createBidVastXml(bidder1, null, null, bidId1, ACCOUNT_ID, eventsContext); - @Test - public void cacheBidsOpenrtbShouldAddTrackingLinkToImpTagWhenItIsEmpty() throws IOException { - // given - final Bid bid = givenBidOpenrtb(builder -> builder - .id("bid1") - .impid("impId1") - .adm("")); - final Imp imp1 = givenImp(builder -> builder - .id("impId1") - .video(Video.builder().build())); - - final String generatedBidId = "generatedBidId"; - final String bidder = "bidder"; - given(videoCachedBidIds.getGeneratedId(any(), any(), any())).willReturn(generatedBidId); - given(videoCachedBidIds.getBidderForBid(any(), any())).willReturn(Optional.of(bidder)); - - final String vastUrl = String.format("https://test-event.com/event?t=imp&b=%s&f=b&a=accountId", generatedBidId); - given(eventsService.vastUrlTracking(anyString(), anyString(), any(), any(), any())) - .willReturn(vastUrl); - - // when - cacheService.cacheBidsOpenrtb( - singletonList(bid), - givenAuctionContext(bidRequestBuilder -> bidRequestBuilder.imp(singletonList(imp1))), - CacheContext.builder() - .shouldCacheBids(true) - .shouldCacheVideoBids(true) - .bidderToVideoGeneratedBidIdsToModify(videoCachedBidIds) - .bidderToBidsToGeneratedIds(allBidIds) - .build(), - EventsContext.builder().enabledForAccount(true).enabledForRequest(false).build()); - - // then - verify(eventsService).vastUrlTracking(eq(generatedBidId), eq(bidder), any(), any(), any()); - - final BidCacheRequest bidCacheRequest = captureBidCacheRequest(); - assertThat(bidCacheRequest.getPuts()).hasSize(2) + assertThat(future.result().getCacheBids()).hasSize(2) .containsOnly( - PutObject.builder() - .type("json") - .value(mapper.valueToTree(bid)) - .build(), - PutObject.builder() - .type("xml") - .value(new TextNode("")) - .build()); + entry(bidInfo1.getBid(), CacheInfo.of("uuid1", "videoUuid1", null, null)), + entry(bidInfo2.getBid(), CacheInfo.of("uuid2", null, null, null))); } @Test - public void cacheBidsOpenrtbShouldAddTrackingImpToBidAdmXmlWhenThatBidShouldBeModifiedAndContainsImpTag() - throws IOException { + public void cacheBidsOpenrtbShouldModifyVastXmlWhenVastModifierReturnAdm() throws IOException { // given - final Bid bid = givenBidOpenrtb(builder -> builder - .id("bid1") - .impid("impId1") - .adm("http:/test.com")); - final Imp imp1 = givenImp(builder -> builder - .id("impId1") - .video(Video.builder().build())); - - final String generatedBidId = "generatedBidId"; - final String bidder = "bidder"; - given(videoCachedBidIds.getGeneratedId(any(), any(), any())).willReturn(generatedBidId); - given(videoCachedBidIds.getBidderForBid(any(), any())).willReturn(Optional.of(bidder)); + final String generatedId = "generatedId"; + final String bidder = "bidder1"; + final String adm = "adm1"; + final BidInfo bidInfo = givenBidInfo(builder -> builder.id("bidId1").adm(adm), generatedId, BidType.video, + bidder); - final String vastUrl = String.format("https://test-event.com/event?t=imp&b=%s&f=b&a=accountId", generatedBidId); - given(eventsService.vastUrlTracking(anyString(), anyString(), any(), any(), any())) - .willReturn(vastUrl); + given(vastModifier.createBidVastXml(any(), any(), any(), any(), any(), any())).willReturn("modifiedAdm"); // when cacheService.cacheBidsOpenrtb( - singletonList(bid), - givenAuctionContext(bidRequestBuilder -> bidRequestBuilder.imp(singletonList(imp1))), + singletonList(bidInfo), + givenAuctionContext(), CacheContext.builder() .shouldCacheBids(true) .shouldCacheVideoBids(true) - .bidderToVideoGeneratedBidIdsToModify(videoCachedBidIds) - .bidderToBidsToGeneratedIds(allBidIds) .build(), - EventsContext.builder().enabledForAccount(true).enabledForRequest(false).build()); + eventsContext); // then - final BidCacheRequest bidCacheRequest = captureBidCacheRequest(); - assertThat(bidCacheRequest.getPuts()).hasSize(2) - .containsOnly( - PutObject.builder() - .type("json") - .value(mapper.valueToTree(bid)) - .build(), - PutObject.builder() - .type("xml") - .value(new TextNode("http:/test.com" - + "")) - .build()); - } - - @Test - public void cacheBidsOpenrtbShouldNotAddTrackingImpWhenEventsNotEnabled() throws IOException { - // given - final Bid bid = givenBidOpenrtb(builder -> builder - .id("bid1") - .impid("impId1") - .adm("http:/test.com")); - final Imp imp1 = givenImp(builder -> builder - .id("impId1") - .video(Video.builder().build())); + verify(vastModifier).createBidVastXml(bidder, adm, null, generatedId, ACCOUNT_ID, eventsContext); - // when - cacheService.cacheBidsOpenrtb( - singletonList(bid), - givenAuctionContext(bidRequestBuilder -> bidRequestBuilder.imp(singletonList(imp1))), - CacheContext.builder() - .shouldCacheBids(true) - .shouldCacheVideoBids(true) - .bidderToVideoGeneratedBidIdsToModify(videoCachedBidIds) - .bidderToBidsToGeneratedIds(allBidIds) - .build(), - EventsContext.builder().enabledForAccount(false).build()); - - // then final BidCacheRequest bidCacheRequest = captureBidCacheRequest(); assertThat(bidCacheRequest.getPuts()).hasSize(2) .containsOnly( - PutObject.builder() - .type("json") - .value(mapper.valueToTree(bid)) - .build(), - PutObject.builder() - .type("xml") - .value(new TextNode("http:/test.com")) - .build()); - verifyZeroInteractions(eventsService); + PutObject.builder().type("json").value(mapper.valueToTree(bidInfo.getBid())).build(), + PutObject.builder().type("xml").value(new TextNode("modifiedAdm")).build()); } @Test public void cachePutObjectsShouldTolerateGlobalTimeoutAlreadyExpired() { // when final Future future = cacheService.cachePutObjects( - singletonList(PutObject.builder().build()), emptySet(), "", "", expiredTimeout); + singletonList(PutObject.builder().build()), true, emptySet(), "", "", + expiredTimeout); // then assertThat(future.failed()).isTrue(); @@ -972,7 +780,8 @@ public void cachePutObjectsShouldTolerateGlobalTimeoutAlreadyExpired() { @Test public void cachePutObjectsShouldReturnResultWithEmptyListWhenPutObjectsIsEmpty() { // when - final Future result = cacheService.cachePutObjects(emptyList(), emptySet(), null, null, null); + final Future result = cacheService.cachePutObjects(emptyList(), true, + emptySet(), null, null, null); // then verifyZeroInteractions(httpClient); @@ -987,9 +796,7 @@ public void cachePutObjectsShouldModifyVastAndCachePutObjects() throws IOExcepti .bidid("bidId1") .bidder("bidder1") .timestamp(1L) - .value(new TextNode("" - + "prebid.org wrapper" - + "")) + .value(new TextNode("vast")) .build(); final PutObject secondPutObject = PutObject.builder() .type("xml") @@ -999,26 +806,26 @@ public void cachePutObjectsShouldModifyVastAndCachePutObjects() throws IOExcepti .value(new TextNode("VAST")) .build(); - given(eventsService.vastUrlTracking(any(), any(), any(), any(), anyString())) - .willReturn("http://external-url/event"); + given(vastModifier.modifyVastXml(any(), any(), any(), any(), anyString())) + .willReturn(new TextNode("modifiedVast")) + .willReturn(new TextNode("VAST")); // when cacheService.cachePutObjects( - asList(firstPutObject, secondPutObject), singleton("bidder1"), "account", "pbjs", timeout); + asList(firstPutObject, secondPutObject), true, singleton("bidder1"), "account", "pbjs", timeout); // then - verify(metrics, times(1)).updateCacheCreativeSize(eq("account"), eq(224)); - verify(metrics, times(1)).updateCacheCreativeSize(eq("account"), eq(4)); + verify(metrics).updateCacheCreativeSize(eq("account"), eq(12)); + verify(metrics).updateCacheCreativeSize(eq("account"), eq(4)); + + verify(vastModifier).modifyVastXml(true, singleton("bidder1"), firstPutObject, "account", "pbjs"); + verify(vastModifier).modifyVastXml(true, singleton("bidder1"), secondPutObject, "account", "pbjs"); final PutObject modifiedFirstPutObject = firstPutObject.toBuilder() .bidid(null) .bidder(null) .timestamp(null) - .value(new TextNode("" - + "prebid.org wrapper" - + "" - + "")) + .value(new TextNode("modifiedVast")) .build(); final PutObject modifiedSecondPutObject = secondPutObject.toBuilder() .bidid(null) @@ -1030,29 +837,11 @@ public void cachePutObjectsShouldModifyVastAndCachePutObjects() throws IOExcepti .containsOnly(modifiedFirstPutObject, modifiedSecondPutObject); } - @Test - public void cachePutObjectsShouldCallEventsServiceWithExpectedArguments() { - // given - final PutObject firstPutObject = PutObject.builder() - .type("xml") - .bidid("bidId1") - .bidder("bidder1") - .timestamp(1000L) - .value(new TextNode("")) - .build(); - - // when - cacheService.cachePutObjects(singletonList(firstPutObject), singleton("bidder1"), "account", "pbjs", timeout); - - // then - verify(eventsService).vastUrlTracking(eq("bidId1"), eq("bidder1"), eq("account"), eq(1000L), eq("pbjs")); - } - private AuctionContext givenAuctionContext(UnaryOperator accountCustomizer, UnaryOperator bidRequestCustomizer) { final Account.AccountBuilder accountBuilder = Account.builder() - .id("accountId"); + .id(ACCOUNT_ID); final BidRequest.BidRequestBuilder bidRequestBuilder = BidRequest.builder() .imp(singletonList(givenImp(identity()))); return AuctionContext.builder() @@ -1074,6 +863,38 @@ private static Bid givenBidOpenrtb(UnaryOperator bidCustomizer) return bidCustomizer.apply(Bid.builder()).build(); } + private static BidInfo givenBidInfo(UnaryOperator bidCustomizer) { + return BidInfo.builder() + .bid(bidCustomizer.apply(Bid.builder()).build()) + .correspondingImp(givenImp(UnaryOperator.identity())) + .bidder("bidder") + .bidType(BidType.banner) + .build(); + } + + private static BidInfo givenBidInfo(UnaryOperator bidCustomizer, + UnaryOperator impCustomizer) { + return BidInfo.builder() + .bid(bidCustomizer.apply(Bid.builder()).build()) + .correspondingImp(impCustomizer.apply(Imp.builder()).build()) + .bidder("bidder") + .bidType(BidType.banner) + .build(); + } + + private static BidInfo givenBidInfo(UnaryOperator bidCustomizer, + String generatedBidId, + BidType bidType, + String bidder) { + return BidInfo.builder() + .bid(bidCustomizer.apply(Bid.builder()).build()) + .generatedBidId(generatedBidId) + .correspondingImp(givenImp(UnaryOperator.identity())) + .bidder(bidder) + .bidType(bidType) + .build(); + } + private static Imp givenImp(UnaryOperator impCustomizer) { return impCustomizer.apply(Imp.builder()).build(); } diff --git a/src/test/java/org/prebid/server/handler/VtrackHandlerTest.java b/src/test/java/org/prebid/server/handler/VtrackHandlerTest.java index 0f3d97a42ae..e7f5bdea64d 100644 --- a/src/test/java/org/prebid/server/handler/VtrackHandlerTest.java +++ b/src/test/java/org/prebid/server/handler/VtrackHandlerTest.java @@ -31,7 +31,6 @@ import static java.util.Arrays.asList; import static java.util.Collections.emptyList; -import static java.util.Collections.emptySet; import static java.util.Collections.singleton; import static java.util.Collections.singletonList; import static java.util.Collections.singletonMap; @@ -39,6 +38,7 @@ import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.ArgumentMatchers.isNull; import static org.mockito.BDDMockito.given; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verifyZeroInteractions; @@ -183,7 +183,7 @@ public void shouldRespondWithInternalServerErrorWhenCacheServiceReturnFailure() given(applicationSettings.getAccountById(any(), any())) .willReturn(Future.succeededFuture(Account.builder().eventsEnabled(true).build())); - given(cacheService.cachePutObjects(any(), any(), any(), any(), any())) + given(cacheService.cachePutObjects(any(), any(), any(), any(), any(), any())) .willReturn(Future.failedFuture("error")); // when @@ -204,18 +204,20 @@ public void shouldTolerateNotFoundAccount() throws JsonProcessingException { given(applicationSettings.getAccountById(any(), any())) .willReturn(Future.failedFuture(new PreBidException("not found"))); - given(cacheService.cachePutObjects(any(), any(), any(), any(), any())) + given(cacheService.cachePutObjects(any(), any(), any(), any(), any(), any())) .willReturn(Future.succeededFuture(BidCacheResponse.of(emptyList()))); // when handler.handle(routingContext); // then - verify(cacheService).cachePutObjects(eq(putObjects), eq(emptySet()), eq("accountId"), eq("pbjs"), any()); + verify(cacheService).cachePutObjects(eq(putObjects), any(), eq(singleton("bidder")), eq("accountId"), + eq("pbjs"), any()); } @Test - public void shouldSendToCacheEmptyUpdatableBiddersIfAccountEventsEnabledIsNull() throws JsonProcessingException { + public void shouldSendToCacheNullInAccountEnabledAndValidBiddersWhenAccountEventsEnabledIsNull() + throws JsonProcessingException { // given final List putObjects = singletonList( PutObject.builder().bidid("bidId").bidder("bidder").value(new TextNode("value")).build()); @@ -224,16 +226,15 @@ public void shouldSendToCacheEmptyUpdatableBiddersIfAccountEventsEnabledIsNull() given(applicationSettings.getAccountById(any(), any())) .willReturn(Future.succeededFuture(Account.builder().eventsEnabled(null).build())); - given(cacheService.cachePutObjects(any(), any(), any(), any(), any())) + given(cacheService.cachePutObjects(any(), any(), any(), any(), any(), any())) .willReturn(Future.succeededFuture(BidCacheResponse.of(emptyList()))); // when handler.handle(routingContext); // then - verifyZeroInteractions(bidderCatalog); - - verify(cacheService).cachePutObjects(eq(putObjects), eq(emptySet()), eq("accountId"), eq("pbjs"), any()); + verify(cacheService).cachePutObjects(eq(putObjects), isNull(), eq(singleton("bidder")), eq("accountId"), + eq("pbjs"), any()); } @Test @@ -256,7 +257,7 @@ public void shouldSendToCacheExpectedPutsAndUpdatableBiddersWhenBidderVastNotAll given(applicationSettings.getAccountById(any(), any())) .willReturn(Future.succeededFuture(Account.builder().eventsEnabled(true).build())); - given(cacheService.cachePutObjects(any(), any(), any(), any(), any())) + given(cacheService.cachePutObjects(any(), any(), any(), any(), any(), any())) .willReturn(Future.succeededFuture(BidCacheResponse.of( singletonList(CacheObject.of("uuid1"))))); @@ -265,7 +266,7 @@ public void shouldSendToCacheExpectedPutsAndUpdatableBiddersWhenBidderVastNotAll // then verify(cacheService).cachePutObjects( - eq(putObjects), eq(singleton("updatable_bidder")), eq("accountId"), eq("pbjs"), any()); + eq(putObjects), any(), eq(singleton("updatable_bidder")), eq("accountId"), eq("pbjs"), any()); verify(httpResponse).end(eq("{\"responses\":[{\"uuid\":\"uuid1\"}]}")); } @@ -287,7 +288,7 @@ public void shouldSendToCacheExpectedPutsAndUpdatableBiddersWhenBidderVastAllowe given(applicationSettings.getAccountById(any(), any())) .willReturn(Future.succeededFuture(Account.builder().eventsEnabled(true).build())); - given(cacheService.cachePutObjects(any(), any(), any(), any(), any())) + given(cacheService.cachePutObjects(any(), any(), any(), any(), any(), any())) .willReturn(Future.succeededFuture(BidCacheResponse.of( asList(CacheObject.of("uuid1"), CacheObject.of("uuid2"))))); @@ -296,7 +297,8 @@ public void shouldSendToCacheExpectedPutsAndUpdatableBiddersWhenBidderVastAllowe // then final HashSet expectedBidders = new HashSet<>(asList("bidder", "updatable_bidder")); - verify(cacheService).cachePutObjects(eq(putObjects), eq(expectedBidders), eq("accountId"), eq("pbjs"), any()); + verify(cacheService).cachePutObjects(eq(putObjects), any(), eq(expectedBidders), eq("accountId"), eq("pbjs"), + any()); verify(httpResponse).end(eq("{\"responses\":[{\"uuid\":\"uuid1\"},{\"uuid\":\"uuid2\"}]}")); } @@ -323,7 +325,7 @@ public void shouldSendToCacheExpectedPutsAndUpdatableUnknownBiddersWhenUnknownBi given(applicationSettings.getAccountById(any(), any())) .willReturn(Future.succeededFuture(Account.builder().eventsEnabled(true).build())); - given(cacheService.cachePutObjects(any(), any(), any(), any(), any())) + given(cacheService.cachePutObjects(any(), any(), any(), any(), any(), any())) .willReturn(Future.succeededFuture(BidCacheResponse.of( asList(CacheObject.of("uuid1"), CacheObject.of("uuid2"))))); @@ -332,7 +334,8 @@ public void shouldSendToCacheExpectedPutsAndUpdatableUnknownBiddersWhenUnknownBi // then final HashSet expectedBidders = new HashSet<>(asList("bidder", "updatable_bidder")); - verify(cacheService).cachePutObjects(eq(putObjects), eq(expectedBidders), eq("accountId"), eq("pbjs"), any()); + verify(cacheService).cachePutObjects(eq(putObjects), any(), eq(expectedBidders), eq("accountId"), eq("pbjs"), + any()); verify(httpResponse).end(eq("{\"responses\":[{\"uuid\":\"uuid1\"},{\"uuid\":\"uuid2\"}]}")); } diff --git a/src/test/java/org/prebid/server/it/AdkernelAdnTest.java b/src/test/java/org/prebid/server/it/AdkernelAdnTest.java index 2203ea3a99d..266d2963c37 100644 --- a/src/test/java/org/prebid/server/it/AdkernelAdnTest.java +++ b/src/test/java/org/prebid/server/it/AdkernelAdnTest.java @@ -47,9 +47,12 @@ public void openrtb2AuctionShouldRespondWithBidsFromAdkerneladn() throws IOExcep // pre-bid cache WIRE_MOCK_RULE.stubFor(post(urlPathEqualTo("/cache")) - .withRequestBody(equalToJson(jsonFrom("openrtb2/adkerneladn/test-cache-adkerneladn-request.json"))) - .willReturn(aResponse().withBody( - jsonFrom("openrtb2/adkerneladn/test-cache-adkerneladn-response.json")))); + .withRequestBody(equalToBidCacheRequest( + jsonFrom("openrtb2/adkerneladn/test-cache-adkerneladn-request.json"))) + .willReturn(aResponse() + .withTransformers("cache-response-transformer") + .withTransformerParameter("matcherName", + "openrtb2/adkerneladn/test-cache-matcher-adkerneladn.json"))); // when final Response response = given(SPEC) diff --git a/src/test/java/org/prebid/server/it/AdmanTest.java b/src/test/java/org/prebid/server/it/AdmanTest.java index ccc17834054..75e530b831d 100644 --- a/src/test/java/org/prebid/server/it/AdmanTest.java +++ b/src/test/java/org/prebid/server/it/AdmanTest.java @@ -35,8 +35,11 @@ public void openrtb2AuctionShouldRespondWithBidsFromAdman() throws IOException, // pre-bid cache WIRE_MOCK_RULE.stubFor(post(urlPathEqualTo("/cache")) - .withRequestBody(equalToJson(jsonFrom("openrtb2/adman/test-cache-adman-request.json"))) - .willReturn(aResponse().withBody(jsonFrom("openrtb2/adman/test-cache-adman-response.json")))); + .withRequestBody(equalToBidCacheRequest( + jsonFrom("openrtb2/adman/test-cache-adman-request.json"))) + .willReturn(aResponse() + .withTransformers("cache-response-transformer") + .withTransformerParameter("matcherName", "openrtb2/adman/test-cache-matcher-adman.json"))); // when final Response response = given(SPEC) diff --git a/src/test/java/org/prebid/server/it/AdprimeTest.java b/src/test/java/org/prebid/server/it/AdprimeTest.java index 8bddfd5c74a..44fac2e369b 100644 --- a/src/test/java/org/prebid/server/it/AdprimeTest.java +++ b/src/test/java/org/prebid/server/it/AdprimeTest.java @@ -35,9 +35,11 @@ public void openrtb2AuctionShouldRespondWithBidsFromAdprime() throws IOException // pre-bid cache WIRE_MOCK_RULE.stubFor(post(urlPathEqualTo("/cache")) - .withRequestBody(equalToJson(jsonFrom("openrtb2/adprime/test-cache-adprime-request.json"))) - .willReturn(aResponse().withBody(jsonFrom("openrtb2/adprime/test-cache-adprime-response.json")))); - + .withRequestBody(equalToBidCacheRequest( + jsonFrom("openrtb2/adprime/test-cache-adprime-request.json"))) + .willReturn(aResponse().withTransformers("cache-response-transformer") + .withTransformerParameter("matcherName", + "openrtb2/adprime/test-cache-matcher-adprime.json"))); // when final Response response = given(SPEC) .header("Referer", "http://www.example.com") diff --git a/src/test/java/org/prebid/server/it/AjaTest.java b/src/test/java/org/prebid/server/it/AjaTest.java index 360d35d4aa3..cc2ac68e27f 100644 --- a/src/test/java/org/prebid/server/it/AjaTest.java +++ b/src/test/java/org/prebid/server/it/AjaTest.java @@ -10,10 +10,10 @@ import java.io.IOException; +import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; +import static com.github.tomakehurst.wiremock.client.WireMock.equalToJson; import static com.github.tomakehurst.wiremock.client.WireMock.post; import static com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo; -import static com.github.tomakehurst.wiremock.client.WireMock.equalToJson; -import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; import static io.restassured.RestAssured.given; import static java.util.Collections.singletonList; @@ -35,8 +35,10 @@ public void openrtb2AuctionShouldRespondWithBidsFromTheAjaBidder() throws IOExce // pre-bid cache WIRE_MOCK_RULE.stubFor(post(urlPathEqualTo("/cache")) - .withRequestBody(equalToJson(jsonFrom("openrtb2/aja/test-cache-aja-request.json"))) - .willReturn(aResponse().withBody(jsonFrom("openrtb2/aja/test-cache-aja-response.json")))); + .withRequestBody(equalToBidCacheRequest( + jsonFrom("openrtb2/aja/test-cache-aja-request.json"))) + .willReturn(aResponse().withTransformers("cache-response-transformer") + .withTransformerParameter("matcherName", "openrtb2/aja/test-cache-matcher-aja.json"))); // when final Response response = given(SPEC) diff --git a/src/test/java/org/prebid/server/it/ApplicationTest.java b/src/test/java/org/prebid/server/it/ApplicationTest.java index 3fcf16eea02..2fb7bb08fcb 100644 --- a/src/test/java/org/prebid/server/it/ApplicationTest.java +++ b/src/test/java/org/prebid/server/it/ApplicationTest.java @@ -108,8 +108,8 @@ public void openrtb2AuctionShouldRespondWithBidsFromRubiconAndAppnexus() throws // pre-bid cache WIRE_MOCK_RULE.stubFor(post(urlPathEqualTo("/cache")) - .withRequestBody(equalToJson(jsonFrom( - "openrtb2/rubicon_appnexus/test-cache-rubicon-appnexus-request.json"), true, false)) + .withRequestBody(equalToBidCacheRequest( + jsonFrom("openrtb2/rubicon_appnexus/test-cache-rubicon-appnexus-request.json"))) .willReturn(aResponse() .withTransformers("cache-response-transformer") .withTransformerParameter("matcherName", @@ -149,7 +149,8 @@ public void ampShouldReturnTargeting() throws IOException, JSONException { // pre-bid cache WIRE_MOCK_RULE.stubFor(post(urlPathEqualTo("/cache")) - .withRequestBody(equalToJson(jsonFrom("amp/test-cache-request.json"), true, false)) + .withRequestBody(equalToBidCacheRequest( + jsonFrom("amp/test-cache-request.json"))) .willReturn(aResponse() .withTransformers("cache-response-transformer") .withTransformerParameter("matcherName", "amp/test-cache-matcher-amp.json") @@ -175,8 +176,11 @@ public void ampShouldReturnTargeting() throws IOException, JSONException { + "&consent_string=1YNN"); // then - JSONAssert.assertEquals(jsonFrom("amp/test-amp-response.json"), response.asString(), - JSONCompareMode.NON_EXTENSIBLE); + final String expectedAuctionResponse = openrtbAuctionResponseFrom( + "amp/test-amp-response.json", + response, + asList(RUBICON, APPNEXUS)); + JSONAssert.assertEquals(expectedAuctionResponse, response.asString(), JSONCompareMode.NON_EXTENSIBLE); } @Test @@ -342,7 +346,7 @@ public void getuidsShouldReturnJsonWithUids() throws JSONException { public void vtrackShouldReturnJsonWithUids() throws JSONException, IOException { // given and when WIRE_MOCK_RULE.stubFor(post(urlPathEqualTo("/cache")) - .withRequestBody(equalToJson(jsonFrom("vtrack/test-cache-request.json"), true, false)) + .withRequestBody(equalToBidCacheRequest(jsonFrom("vtrack/test-cache-request.json"))) .willReturn(aResponse().withBody(jsonFrom("vtrack/test-vtrack-response.json")))); final Response response = given(SPEC) diff --git a/src/test/java/org/prebid/server/it/ApplogyTest.java b/src/test/java/org/prebid/server/it/ApplogyTest.java index 4a6351b4389..cd1a3a0cabd 100644 --- a/src/test/java/org/prebid/server/it/ApplogyTest.java +++ b/src/test/java/org/prebid/server/it/ApplogyTest.java @@ -40,9 +40,10 @@ public void openrtb2AuctionShouldRespondWithBidsFromApplogy() throws IOException // pre-bid cache WIRE_MOCK_RULE.stubFor(post(urlPathEqualTo("/cache")) - .withRequestBody(equalToJson(jsonFrom("openrtb2/applogy/test-cache-applogy-request.json"))) - .willReturn(aResponse().withBody(jsonFrom("openrtb2/applogy/test-cache-applogy-response.json")))); - + .withRequestBody(equalToBidCacheRequest( + jsonFrom("openrtb2/applogy/test-cache-applogy-request.json"))) + .willReturn(aResponse().withTransformers("cache-response-transformer") + .withTransformerParameter("matcherName", "openrtb2/applogy/test-cache-matcher-applogy.json"))); // when final Response response = given(SPEC) .header("Referer", "http://www.example.com") diff --git a/src/test/java/org/prebid/server/it/AppnexusVideoTest.java b/src/test/java/org/prebid/server/it/AppnexusVideoTest.java index 3de4bd25d97..957174556bd 100644 --- a/src/test/java/org/prebid/server/it/AppnexusVideoTest.java +++ b/src/test/java/org/prebid/server/it/AppnexusVideoTest.java @@ -38,8 +38,8 @@ public void openrtb2VideoShouldRespondWithBidsFromAppnexus() throws IOException, // pre-bid cache WIRE_MOCK_RULE.stubFor(post(urlPathEqualTo("/cache")) - .withRequestBody(equalToJson( - jsonFrom("openrtb2/video/test-video-cache-request.json"), true, false)) + .withRequestBody(equalToBidCacheRequest( + jsonFrom("openrtb2/video/test-video-cache-request.json"))) .willReturn(aResponse() .withTransformers("cache-response-transformer") .withTransformerParameter("matcherName", diff --git a/src/test/java/org/prebid/server/it/AvocetTest.java b/src/test/java/org/prebid/server/it/AvocetTest.java index 0793314205f..6132bc54c80 100644 --- a/src/test/java/org/prebid/server/it/AvocetTest.java +++ b/src/test/java/org/prebid/server/it/AvocetTest.java @@ -5,7 +5,6 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.skyscreamer.jsonassert.JSONAssert; -import org.skyscreamer.jsonassert.JSONCompareMode; import org.springframework.test.context.junit4.SpringRunner; import java.io.IOException; @@ -30,8 +29,10 @@ public void openrtb2AuctionShouldRespondWithBidsFromAvocet() throws IOException, // pre-bid cache WIRE_MOCK_RULE.stubFor(post(urlPathEqualTo("/cache")) - .withRequestBody(equalToJson(jsonFrom("openrtb2/avocet/test-cache-avocet-request.json"))) - .willReturn(aResponse().withBody(jsonFrom("openrtb2/avocet/test-cache-avocet-response.json")))); + .withRequestBody(equalToBidCacheRequest( + jsonFrom("openrtb2/avocet/test-cache-avocet-request.json"))) + .willReturn(aResponse().withTransformers("cache-response-transformer") + .withTransformerParameter("matcherName", "openrtb2/avocet/test-cache-matcher-avocet.json"))); // when final Response response = given(SPEC) @@ -46,11 +47,10 @@ public void openrtb2AuctionShouldRespondWithBidsFromAvocet() throws IOException, // then final String expectedAuctionResponse = openrtbAuctionResponseFrom( - "openrtb2/avocet/test-auction-avocet-response.json", - response, singletonList("avocet")); + "openrtb2/avocet/test-auction-avocet-response.json", response, singletonList("avocet")); final String actualStr = response.asString(); - JSONAssert.assertEquals(expectedAuctionResponse, actualStr, JSONCompareMode.NON_EXTENSIBLE); + JSONAssert.assertEquals(expectedAuctionResponse, actualStr, openrtbCacheDebugComparator()); } } diff --git a/src/test/java/org/prebid/server/it/BeintooTest.java b/src/test/java/org/prebid/server/it/BeintooTest.java index b13408b5523..743eeae8b6a 100644 --- a/src/test/java/org/prebid/server/it/BeintooTest.java +++ b/src/test/java/org/prebid/server/it/BeintooTest.java @@ -5,7 +5,6 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.skyscreamer.jsonassert.JSONAssert; -import org.skyscreamer.jsonassert.JSONCompareMode; import org.springframework.test.context.junit4.SpringRunner; import java.io.IOException; @@ -58,6 +57,6 @@ public void openrtb2AuctionShouldRespondWithBidsFromBeintoo() throws IOException "openrtb2/beintoo/test-auction-beintoo-response.json", response, singletonList("beintoo")); - JSONAssert.assertEquals(expectedAuctionResponse, response.asString(), JSONCompareMode.NON_EXTENSIBLE); + JSONAssert.assertEquals(expectedAuctionResponse, response.asString(), openrtbCacheDebugComparator()); } } diff --git a/src/test/java/org/prebid/server/it/ColossusTest.java b/src/test/java/org/prebid/server/it/ColossusTest.java index 9023089b3a3..55b788fa2f8 100644 --- a/src/test/java/org/prebid/server/it/ColossusTest.java +++ b/src/test/java/org/prebid/server/it/ColossusTest.java @@ -35,9 +35,11 @@ public void openrtb2AuctionShouldRespondWithBidsFromColossus() throws IOExceptio // pre-bid cache WIRE_MOCK_RULE.stubFor(post(urlPathEqualTo("/cache")) - .withRequestBody(equalToJson(jsonFrom("openrtb2/colossus/test-cache-colossus-request.json"))) - .willReturn(aResponse().withBody(jsonFrom("openrtb2/colossus/test-cache-colossus-response.json")))); - + .withRequestBody(equalToBidCacheRequest( + jsonFrom("openrtb2/colossus/test-cache-colossus-request.json"))) + .willReturn(aResponse().withTransformers("cache-response-transformer") + .withTransformerParameter("matcherName", + "openrtb2/colossus/test-cache-matcher-colossus.json"))); // when final Response response = given(SPEC) .header("Referer", "http://www.example.com") diff --git a/src/test/java/org/prebid/server/it/ConversantTest.java b/src/test/java/org/prebid/server/it/ConversantTest.java index a1e7d016614..c68e79ca488 100644 --- a/src/test/java/org/prebid/server/it/ConversantTest.java +++ b/src/test/java/org/prebid/server/it/ConversantTest.java @@ -34,9 +34,11 @@ public void openrtb2AuctionShouldRespondWithBidsFromConversant() throws IOExcept // pre-bid cache WIRE_MOCK_RULE.stubFor(post(urlPathEqualTo("/cache")) - .withRequestBody(equalToJson(jsonFrom("openrtb2/conversant/test-cache-conversant-request.json"))) - .willReturn(aResponse().withBody(jsonFrom("openrtb2/conversant/test-cache-conversant-response.json")))); - + .withRequestBody(equalToBidCacheRequest( + jsonFrom("openrtb2/conversant/test-cache-conversant-request.json"))) + .willReturn(aResponse().withTransformers("cache-response-transformer") + .withTransformerParameter("matcherName", + "openrtb2/conversant/test-cache-matcher-conversant.json"))); // when final Response response = given(SPEC) .header("Referer", "http://www.example.com") diff --git a/src/test/java/org/prebid/server/it/CpmStarTest.java b/src/test/java/org/prebid/server/it/CpmStarTest.java index 57135fb477a..97dbd67ffa0 100644 --- a/src/test/java/org/prebid/server/it/CpmStarTest.java +++ b/src/test/java/org/prebid/server/it/CpmStarTest.java @@ -33,8 +33,10 @@ public void openrtb2AuctionShouldRespondWithBidsFromCPMStar() throws IOException // pre-bid cache WIRE_MOCK_RULE.stubFor(post(urlPathEqualTo("/cache")) - .withRequestBody(equalToJson(jsonFrom("openrtb2/cpmstar/test-cache-cpmstar-request.json"))) - .willReturn(aResponse().withBody(jsonFrom("openrtb2/cpmstar/test-cache-cpmstar-response.json")))); + .withRequestBody(equalToBidCacheRequest(jsonFrom("openrtb2/cpmstar/test-cache-cpmstar-request.json"))) + .willReturn(aResponse().withTransformers("cache-response-transformer") + .withTransformerParameter("matcherName", + "openrtb2/cpmstar/test-cache-matcher-cpmstar.json"))); // when final Response response = given(SPEC) diff --git a/src/test/java/org/prebid/server/it/DatablocksTest.java b/src/test/java/org/prebid/server/it/DatablocksTest.java index dc7e8a2835b..04ec2eb48c9 100644 --- a/src/test/java/org/prebid/server/it/DatablocksTest.java +++ b/src/test/java/org/prebid/server/it/DatablocksTest.java @@ -5,7 +5,6 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.skyscreamer.jsonassert.JSONAssert; -import org.skyscreamer.jsonassert.JSONCompareMode; import org.springframework.test.context.junit4.SpringRunner; import java.io.IOException; @@ -38,8 +37,11 @@ public void openrtb2AuctionShouldRespondWithBidsFromDatablocks() throws IOExcept // pre-bid cache WIRE_MOCK_RULE.stubFor(post(urlPathEqualTo("/cache")) - .withRequestBody(equalToJson(jsonFrom("openrtb2/datablocks/test-cache-datablocks-request.json"))) - .willReturn(aResponse().withBody(jsonFrom("openrtb2/datablocks/test-cache-datablocks-response.json")))); + .withRequestBody(equalToBidCacheRequest( + jsonFrom("openrtb2/datablocks/test-cache-datablocks-request.json"))) + .willReturn(aResponse().withTransformers("cache-response-transformer") + .withTransformerParameter("matcherName", + "openrtb2/datablocks/test-cache-matcher-datablocks.json"))); // when final Response response = given(SPEC) @@ -57,6 +59,6 @@ public void openrtb2AuctionShouldRespondWithBidsFromDatablocks() throws IOExcept "openrtb2/datablocks/test-auction-datablocks-response.json", response, singletonList("datablocks")); - JSONAssert.assertEquals(expectedAuctionResponse, response.asString(), JSONCompareMode.NON_EXTENSIBLE); + JSONAssert.assertEquals(expectedAuctionResponse, response.asString(), openrtbCacheDebugComparator()); } } diff --git a/src/test/java/org/prebid/server/it/EmxdigitalTest.java b/src/test/java/org/prebid/server/it/EmxdigitalTest.java index a919a80e6be..b44271db342 100644 --- a/src/test/java/org/prebid/server/it/EmxdigitalTest.java +++ b/src/test/java/org/prebid/server/it/EmxdigitalTest.java @@ -5,7 +5,6 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.skyscreamer.jsonassert.JSONAssert; -import org.skyscreamer.jsonassert.JSONCompareMode; import org.springframework.test.context.junit4.SpringRunner; import java.io.IOException; @@ -60,7 +59,7 @@ public void openrtb2AuctionShouldRespondWithBidsFromEmxdigital() throws IOExcept "openrtb2/emxdigital/test-auction-emxdigital-response.json", response, singletonList("emx_digital")); - JSONAssert.assertEquals(expectedAuctionResponse, response.asString(), JSONCompareMode.NON_EXTENSIBLE); + JSONAssert.assertEquals(expectedAuctionResponse, response.asString(), openrtbCacheDebugComparator()); } } diff --git a/src/test/java/org/prebid/server/it/EngagebdrTest.java b/src/test/java/org/prebid/server/it/EngagebdrTest.java index 6e0491cc608..d79a6f42fe0 100644 --- a/src/test/java/org/prebid/server/it/EngagebdrTest.java +++ b/src/test/java/org/prebid/server/it/EngagebdrTest.java @@ -43,10 +43,11 @@ public void openrtb2AuctionShouldRespondWithBidsFromEngagebdr() throws IOExcepti // pre-bid cache WIRE_MOCK_RULE.stubFor(post(urlPathEqualTo("/cache")) - .withRequestBody(equalToJson(jsonFrom("openrtb2/engagebdr/test-cache-engagebdr-request.json"))) - .willReturn(aResponse().withBody( - jsonFrom("openrtb2/engagebdr/test-cache-engagebdr-response.json")))); - + .withRequestBody(equalToBidCacheRequest( + jsonFrom("openrtb2/engagebdr/test-cache-engagebdr-request.json"))) + .willReturn(aResponse().withTransformers("cache-response-transformer") + .withTransformerParameter("matcherName", + "openrtb2/engagebdr/test-cache-matcher-engagebdr.json"))); // when final Response response = given(SPEC) .header("Referer", "http://www.example.com") diff --git a/src/test/java/org/prebid/server/it/FacebookTest.java b/src/test/java/org/prebid/server/it/FacebookTest.java index 614fa7b7428..75142d82259 100644 --- a/src/test/java/org/prebid/server/it/FacebookTest.java +++ b/src/test/java/org/prebid/server/it/FacebookTest.java @@ -44,8 +44,11 @@ public void openrtb2AuctionShouldRespondWithBidsFromFacebook() throws IOExceptio // pre-bid cache WIRE_MOCK_RULE.stubFor(post(urlPathEqualTo("/cache")) - .withRequestBody(equalToJson(jsonFrom("openrtb2/facebook/test-cache-facebook-request.json"))) - .willReturn(aResponse().withBody(jsonFrom("openrtb2/facebook/test-cache-facebook-response.json")))); + .withRequestBody(equalToBidCacheRequest( + jsonFrom("openrtb2/facebook/test-cache-facebook-request.json"))) + .willReturn(aResponse().withTransformers("cache-response-transformer") + .withTransformerParameter("matcherName", + "openrtb2/facebook/test-cache-matcher-facebook.json"))); // when final Response response = given(SPEC) diff --git a/src/test/java/org/prebid/server/it/GamoshiTest.java b/src/test/java/org/prebid/server/it/GamoshiTest.java index 7d14af354c9..74973d60b97 100644 --- a/src/test/java/org/prebid/server/it/GamoshiTest.java +++ b/src/test/java/org/prebid/server/it/GamoshiTest.java @@ -39,8 +39,11 @@ public void openrtb2AuctionShouldRespondWithBidsFromGamoshi() throws IOException // pre-bid cache WIRE_MOCK_RULE.stubFor(post(urlPathEqualTo("/cache")) - .withRequestBody(equalToJson(jsonFrom("openrtb2/gamoshi/test-cache-gamoshi-request.json"))) - .willReturn(aResponse().withBody(jsonFrom("openrtb2/gamoshi/test-cache-gamoshi-response.json")))); + .withRequestBody(equalToBidCacheRequest( + jsonFrom("openrtb2/gamoshi/test-cache-gamoshi-request.json"))) + .willReturn(aResponse().withTransformers("cache-response-transformer") + .withTransformerParameter("matcherName", + "openrtb2/gamoshi/test-cache-matcher-gamoshi.json"))); // when final Response response = given(SPEC) diff --git a/src/test/java/org/prebid/server/it/GumgumTest.java b/src/test/java/org/prebid/server/it/GumgumTest.java index 16e53a7385c..09c95026866 100644 --- a/src/test/java/org/prebid/server/it/GumgumTest.java +++ b/src/test/java/org/prebid/server/it/GumgumTest.java @@ -34,8 +34,11 @@ public void openrtb2AuctionShouldRespondWithBidsFromGumGum() throws IOException, // pre-bid cache WIRE_MOCK_RULE.stubFor(post(urlPathEqualTo("/cache")) - .withRequestBody(equalToJson(jsonFrom("openrtb2/gumgum/test-cache-gumgum-request.json"))) - .willReturn(aResponse().withBody(jsonFrom("openrtb2/gumgum/test-cache-gumgum-response.json")))); + .withRequestBody(equalToBidCacheRequest( + jsonFrom("openrtb2/gumgum/test-cache-gumgum-request.json"))) + .willReturn(aResponse().withTransformers("cache-response-transformer") + .withTransformerParameter("matcherName", + "openrtb2/gumgum/test-cache-matcher-gumgum.json"))); // when final Response response = given(SPEC) diff --git a/src/test/java/org/prebid/server/it/IntegrationTest.java b/src/test/java/org/prebid/server/it/IntegrationTest.java index eb7a9248774..50562374cc7 100644 --- a/src/test/java/org/prebid/server/it/IntegrationTest.java +++ b/src/test/java/org/prebid/server/it/IntegrationTest.java @@ -21,6 +21,7 @@ import org.prebid.server.cache.proto.request.PutObject; import org.prebid.server.cache.proto.response.BidCacheResponse; import org.prebid.server.cache.proto.response.CacheObject; +import org.prebid.server.it.util.BidCacheRequestPattern; import org.skyscreamer.jsonassert.ArrayValueMatcher; import org.skyscreamer.jsonassert.Customization; import org.skyscreamer.jsonassert.JSONCompare; @@ -98,7 +99,8 @@ private static String auctionResponseFrom(String templatePath, Response response .replaceAll("\\{\\{ cache.endpoint }}", cacheEndpoint) .replaceAll("\\{\\{ cache.resource_url }}", cacheEndpoint + "?uuid=") .replaceAll("\\{\\{ cache.host }}", hostAndPort) - .replaceAll("\\{\\{ cache.path }}", cachePath); + .replaceAll("\\{\\{ cache.path }}", cachePath) + .replaceAll("\\{\\{ event.url }}", "http://localhost:8080/event?"); for (final String bidder : bidders) { result = result.replaceAll("\\{\\{ " + bidder + "\\.exchange_uri }}", @@ -176,6 +178,10 @@ static CustomComparator openrtbCacheDebugComparator() { new Customization("ext.debug.httpcalls.cache", arrayValueMatcher)); } + static BidCacheRequestPattern equalToBidCacheRequest(String json) { + return new BidCacheRequestPattern(json); + } + public static class CacheResponseTransformer extends ResponseTransformer { @Override @@ -185,7 +191,8 @@ public com.github.tomakehurst.wiremock.http.Response transform( final String newResponse; try { - newResponse = cacheResponseFromRequestJson(request.getBodyAsString(), + newResponse = cacheResponseFromRequestJson( + request.getBodyAsString(), parameters.getString("matcherName")); } catch (IOException e) { return com.github.tomakehurst.wiremock.http.Response.response() diff --git a/src/test/java/org/prebid/server/it/KidozTest.java b/src/test/java/org/prebid/server/it/KidozTest.java index 660b3ea4629..00824280d33 100644 --- a/src/test/java/org/prebid/server/it/KidozTest.java +++ b/src/test/java/org/prebid/server/it/KidozTest.java @@ -42,8 +42,10 @@ public void openrtb2AuctionShouldRespondWithBidsFromKidoz() throws IOException, // pre-bid cache WIRE_MOCK_RULE.stubFor(post(urlPathEqualTo("/cache")) - .withRequestBody(equalToJson(jsonFrom("openrtb2/kidoz/test-cache-kidoz-request.json"))) - .willReturn(aResponse().withBody(jsonFrom("openrtb2/kidoz/test-cache-kidoz-response.json")))); + .withRequestBody(equalToBidCacheRequest(jsonFrom("openrtb2/kidoz/test-cache-kidoz-request.json"))) + .willReturn(aResponse().withTransformers("cache-response-transformer") + .withTransformerParameter("matcherName", + "openrtb2/kidoz/test-cache-matcher-kidoz.json"))); // when final Response response = given(SPEC) diff --git a/src/test/java/org/prebid/server/it/KubientTest.java b/src/test/java/org/prebid/server/it/KubientTest.java index 600bd6b79be..20af3f842db 100644 --- a/src/test/java/org/prebid/server/it/KubientTest.java +++ b/src/test/java/org/prebid/server/it/KubientTest.java @@ -5,7 +5,6 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.skyscreamer.jsonassert.JSONAssert; -import org.skyscreamer.jsonassert.JSONCompareMode; import org.springframework.test.context.junit4.SpringRunner; import java.io.IOException; @@ -49,7 +48,7 @@ public void openrtb2AuctionShouldRespondWithBidsFromKubient() throws IOException "openrtb2/kubient/test-auction-kubient-response.json", response, singletonList("kubient")); - JSONAssert.assertEquals(expectedAuctionResponse, response.asString(), JSONCompareMode.NON_EXTENSIBLE); + JSONAssert.assertEquals(expectedAuctionResponse, response.asString(), openrtbCacheDebugComparator()); } } diff --git a/src/test/java/org/prebid/server/it/LifestreetTest.java b/src/test/java/org/prebid/server/it/LifestreetTest.java index 04e4baab043..e180f8519e3 100644 --- a/src/test/java/org/prebid/server/it/LifestreetTest.java +++ b/src/test/java/org/prebid/server/it/LifestreetTest.java @@ -37,9 +37,11 @@ public void openrtb2AuctionShouldRespondWithBidsFromLifestreet() throws IOExcept // pre-bid cache WIRE_MOCK_RULE.stubFor(post(urlPathEqualTo("/cache")) - .withRequestBody(equalToJson(jsonFrom("openrtb2/lifestreet/test-cache-lifestreet-request.json"))) - .willReturn(aResponse().withBody(jsonFrom("openrtb2/lifestreet/test-cache-lifestreet-response.json")))); - + .withRequestBody(equalToBidCacheRequest( + jsonFrom("openrtb2/lifestreet/test-cache-lifestreet-request.json"))) + .willReturn(aResponse().withTransformers("cache-response-transformer") + .withTransformerParameter("matcherName", + "openrtb2/lifestreet/test-cache-matcher-lifestreet.json"))); // when final Response response = given(SPEC) .header("Referer", "http://www.example.com") diff --git a/src/test/java/org/prebid/server/it/OpenxTest.java b/src/test/java/org/prebid/server/it/OpenxTest.java index 3da4d82290c..4c598c86f4c 100644 --- a/src/test/java/org/prebid/server/it/OpenxTest.java +++ b/src/test/java/org/prebid/server/it/OpenxTest.java @@ -40,7 +40,8 @@ public void openrtb2AuctionShouldRespondWithBidsFromOpenx() throws IOException, // pre-bid cache WIRE_MOCK_RULE.stubFor(post(urlPathEqualTo("/cache")) - .withRequestBody(equalToJson(jsonFrom("openrtb2/openx/test-cache-openx-request.json"), true, false)) + .withRequestBody(equalToBidCacheRequest( + jsonFrom("openrtb2/openx/test-cache-openx-request.json"))) .willReturn(aResponse() .withTransformers("cache-response-transformer") .withTransformerParameter("matcherName", "openrtb2/openx/test-cache-matcher-openx.json") diff --git a/src/test/java/org/prebid/server/it/PubmaticTest.java b/src/test/java/org/prebid/server/it/PubmaticTest.java index 3736746f1a7..72eadcd7ec6 100644 --- a/src/test/java/org/prebid/server/it/PubmaticTest.java +++ b/src/test/java/org/prebid/server/it/PubmaticTest.java @@ -32,8 +32,8 @@ public void openrtb2AuctionShouldRespondWithBidsFromPubmatic() throws IOExceptio // pre-bid cache WIRE_MOCK_RULE.stubFor(post(urlPathEqualTo("/cache")) - .withRequestBody(equalToJson(jsonFrom("openrtb2/pubmatic/test-cache-pubmatic-request.json"), true, - false)) + .withRequestBody(equalToBidCacheRequest( + jsonFrom("openrtb2/pubmatic/test-cache-pubmatic-request.json"))) .willReturn(aResponse() .withTransformers("cache-response-transformer") .withTransformerParameter("matcherName", diff --git a/src/test/java/org/prebid/server/it/PubnativeTest.java b/src/test/java/org/prebid/server/it/PubnativeTest.java index 2f1b8a3b1aa..0a837830d12 100644 --- a/src/test/java/org/prebid/server/it/PubnativeTest.java +++ b/src/test/java/org/prebid/server/it/PubnativeTest.java @@ -47,8 +47,12 @@ public void openrtb2AuctionShouldRespondWithBidsFromThePubnative() throws IOExce // pre-bid cache WIRE_MOCK_RULE.stubFor(post(urlPathEqualTo("/cache")) - .withRequestBody(equalToJson(jsonFrom("openrtb2/pubnative/test-cache-pubnative-request.json"))) - .willReturn(aResponse().withBody(jsonFrom("openrtb2/pubnative/test-cache-pubnative-response.json")))); + .withRequestBody(equalToBidCacheRequest( + jsonFrom("openrtb2/pubnative/test-cache-pubnative-request.json"))) + .willReturn(aResponse() + .withTransformers("cache-response-transformer") + .withTransformerParameter("matcherName", + "openrtb2/pubnative/test-cache-matcher-pubnative.json"))); // when final Response response = given(SPEC) diff --git a/src/test/java/org/prebid/server/it/PulsepointTest.java b/src/test/java/org/prebid/server/it/PulsepointTest.java index 5a0250db6f4..0175a7e5d0c 100644 --- a/src/test/java/org/prebid/server/it/PulsepointTest.java +++ b/src/test/java/org/prebid/server/it/PulsepointTest.java @@ -32,8 +32,11 @@ public void openrtb2AuctionShouldRespondWithBidsFromPulsepoint() throws IOExcept // pre-bid cache WIRE_MOCK_RULE.stubFor(post(urlPathEqualTo("/cache")) - .withRequestBody(equalToJson(jsonFrom("openrtb2/pulsepoint/test-cache-pulsepoint-request.json"))) - .willReturn(aResponse().withBody(jsonFrom("openrtb2/pulsepoint/test-cache-pulsepoint-response.json")))); + .withRequestBody(equalToBidCacheRequest( + jsonFrom("openrtb2/pulsepoint/test-cache-pulsepoint-request.json"))) + .willReturn(aResponse().withTransformers("cache-response-transformer") + .withTransformerParameter("matcherName", + "openrtb2/pulsepoint/test-cache-matcher-pulsepoint.json"))); // when final Response response = given(SPEC) diff --git a/src/test/java/org/prebid/server/it/RhythmoneTest.java b/src/test/java/org/prebid/server/it/RhythmoneTest.java index e983632ae1e..18fc4130e77 100644 --- a/src/test/java/org/prebid/server/it/RhythmoneTest.java +++ b/src/test/java/org/prebid/server/it/RhythmoneTest.java @@ -33,8 +33,11 @@ public void openrtb2AuctionShouldRespondWithBidsFromRhythmone() throws IOExcepti // pre-bid cache WIRE_MOCK_RULE.stubFor(post(urlPathEqualTo("/cache")) - .withRequestBody(equalToJson(jsonFrom("openrtb2/rhythmone/test-cache-rhythmone-request.json"))) - .willReturn(aResponse().withBody(jsonFrom("openrtb2/rhythmone/test-cache-rhythmone-response.json")))); + .withRequestBody(equalToBidCacheRequest( + jsonFrom("openrtb2/rhythmone/test-cache-rhythmone-request.json"))) + .willReturn(aResponse().withTransformers("cache-response-transformer") + .withTransformerParameter("matcherName", + "openrtb2/rhythmone/test-cache-matcher-rhythmone.json"))); // when final Response response = given(SPEC) diff --git a/src/test/java/org/prebid/server/it/SharethroughTest.java b/src/test/java/org/prebid/server/it/SharethroughTest.java index 9c5774437a6..f3d867d195b 100644 --- a/src/test/java/org/prebid/server/it/SharethroughTest.java +++ b/src/test/java/org/prebid/server/it/SharethroughTest.java @@ -6,7 +6,6 @@ import org.junit.runner.RunWith; import org.prebid.server.util.HttpUtil; import org.skyscreamer.jsonassert.JSONAssert; -import org.skyscreamer.jsonassert.JSONCompareMode; import org.springframework.test.context.junit4.SpringRunner; import java.io.IOException; @@ -83,6 +82,6 @@ response, singletonList("sharethrough")) .replace("{{ TEST_FORMATTED_TIME }}", HttpUtil.encodeUrl(TEST_FORMATTED_TIME)) .replace("{{ DEADLINE_FORMATTED_TIME }}", DEADLINE_FORMATTED_TIME); - JSONAssert.assertEquals(expectedAuctionResponse, response.asString(), JSONCompareMode.NON_EXTENSIBLE); + JSONAssert.assertEquals(expectedAuctionResponse, response.asString(), openrtbCacheDebugComparator()); } } diff --git a/src/test/java/org/prebid/server/it/SmartadserverTest.java b/src/test/java/org/prebid/server/it/SmartadserverTest.java index da9a567f618..75108e909b0 100644 --- a/src/test/java/org/prebid/server/it/SmartadserverTest.java +++ b/src/test/java/org/prebid/server/it/SmartadserverTest.java @@ -5,7 +5,6 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.skyscreamer.jsonassert.JSONAssert; -import org.skyscreamer.jsonassert.JSONCompareMode; import org.springframework.test.context.junit4.SpringRunner; import java.io.IOException; @@ -53,6 +52,6 @@ public void openrtb2AuctionShouldRespondWithBidsFromSmartadserver() throws IOExc "openrtb2/smartadserver/test-auction-smartadserver-response.json", response, singletonList("smartadserver")); - JSONAssert.assertEquals(expectedAuctionResponse, response.asString(), JSONCompareMode.NON_EXTENSIBLE); + JSONAssert.assertEquals(expectedAuctionResponse, response.asString(), openrtbCacheDebugComparator()); } } diff --git a/src/test/java/org/prebid/server/it/SomoaudienceTest.java b/src/test/java/org/prebid/server/it/SomoaudienceTest.java index dff938a72df..db3303a0f2d 100644 --- a/src/test/java/org/prebid/server/it/SomoaudienceTest.java +++ b/src/test/java/org/prebid/server/it/SomoaudienceTest.java @@ -68,8 +68,8 @@ public void openrtb2AuctionShouldRespondWithBidsFromSomoaudience() throws IOExce // pre-bid cache WIRE_MOCK_RULE.stubFor(post(urlPathEqualTo("/cache")) - .withRequestBody(equalToJson(jsonFrom("openrtb2/somoaudience/test-cache-somoaudience-request.json"), - true, false)) + .withRequestBody(equalToBidCacheRequest( + jsonFrom("openrtb2/somoaudience/test-cache-somoaudience-request.json"))) .willReturn(aResponse() .withTransformers("cache-response-transformer") .withTransformerParameter("matcherName", diff --git a/src/test/java/org/prebid/server/it/SonobiTest.java b/src/test/java/org/prebid/server/it/SonobiTest.java index 1201c492fde..10674b13ecc 100644 --- a/src/test/java/org/prebid/server/it/SonobiTest.java +++ b/src/test/java/org/prebid/server/it/SonobiTest.java @@ -35,9 +35,10 @@ public void openrtb2AuctionShouldRespondWithBidsFromSonobi() throws IOException, // pre-bid cache WIRE_MOCK_RULE.stubFor(post(urlPathEqualTo("/cache")) - .withRequestBody(equalToJson(jsonFrom("openrtb2/sonobi/test-cache-sonobi-request.json"))) - .willReturn(aResponse().withBody(jsonFrom("openrtb2/sonobi/test-cache-sonobi-response.json")))); - + .withRequestBody(equalToBidCacheRequest( + jsonFrom("openrtb2/sonobi/test-cache-sonobi-request.json"))) + .willReturn(aResponse().withTransformers("cache-response-transformer") + .withTransformerParameter("matcherName", "openrtb2/sonobi/test-cache-matcher-sonobi.json"))); // when final Response response = given(SPEC) .header("Referer", "http://www.example.com") diff --git a/src/test/java/org/prebid/server/it/SynacormediaTest.java b/src/test/java/org/prebid/server/it/SynacormediaTest.java index 28d38262843..2c7a3c0ae27 100644 --- a/src/test/java/org/prebid/server/it/SynacormediaTest.java +++ b/src/test/java/org/prebid/server/it/SynacormediaTest.java @@ -32,10 +32,11 @@ public void openrtb2AuctionShouldRespondWithBidsFromSynacorMedia() throws IOExce // pre-bid cache WIRE_MOCK_RULE.stubFor(post(urlPathEqualTo("/cache")) - .withRequestBody(equalToJson( + .withRequestBody(equalToBidCacheRequest( jsonFrom("openrtb2/synacormedia/test-cache-synacormedia-request.json"))) - .willReturn(aResponse().withBody( - jsonFrom("openrtb2/synacormedia/test-cache-synacormedia-response.json")))); + .willReturn(aResponse().withTransformers("cache-response-transformer") + .withTransformerParameter("matcherName", + "openrtb2/synacormedia/test-cache-matcher-synacormedia.json"))); // when final Response response = given(SPEC) diff --git a/src/test/java/org/prebid/server/it/TelariaTest.java b/src/test/java/org/prebid/server/it/TelariaTest.java index 32ecf4e041e..888cd133839 100644 --- a/src/test/java/org/prebid/server/it/TelariaTest.java +++ b/src/test/java/org/prebid/server/it/TelariaTest.java @@ -41,8 +41,11 @@ public void openrtb2AuctionShouldRespondWithBidsFromTelaria() throws IOException // pre-bid cache WIRE_MOCK_RULE.stubFor(post(urlPathEqualTo("/cache")) - .withRequestBody(equalToJson(jsonFrom("openrtb2/telaria/test-cache-telaria-request.json"))) - .willReturn(aResponse().withBody(jsonFrom("openrtb2/telaria/test-cache-telaria-response.json")))); + .withRequestBody(equalToBidCacheRequest( + jsonFrom("openrtb2/telaria/test-cache-telaria-request.json"))) + .willReturn(aResponse().withTransformers("cache-response-transformer") + .withTransformerParameter("matcherName", + "openrtb2/telaria/test-cache-matcher-telaria.json"))); // when final Response response = given(SPEC) diff --git a/src/test/java/org/prebid/server/it/TripleliftNativeTest.java b/src/test/java/org/prebid/server/it/TripleliftNativeTest.java index 40de0046252..619a4e1517c 100644 --- a/src/test/java/org/prebid/server/it/TripleliftNativeTest.java +++ b/src/test/java/org/prebid/server/it/TripleliftNativeTest.java @@ -5,7 +5,6 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.skyscreamer.jsonassert.JSONAssert; -import org.skyscreamer.jsonassert.JSONCompareMode; import org.springframework.test.context.junit4.SpringRunner; import java.io.IOException; @@ -52,7 +51,7 @@ public void openrtb2AuctionShouldRespondWithBidsFromTriplelift() throws IOExcept "openrtb2/tripleliftnative/test-auction-triplelift-native-response.json", response, singletonList("triplelift_native")); - JSONAssert.assertEquals(expectedAuctionResponse, response.asString(), JSONCompareMode.NON_EXTENSIBLE); + JSONAssert.assertEquals(expectedAuctionResponse, response.asString(), openrtbCacheDebugComparator()); } } diff --git a/src/test/java/org/prebid/server/it/TripleliftTest.java b/src/test/java/org/prebid/server/it/TripleliftTest.java index d8016f3ae24..7990ddc6ad6 100644 --- a/src/test/java/org/prebid/server/it/TripleliftTest.java +++ b/src/test/java/org/prebid/server/it/TripleliftTest.java @@ -5,7 +5,6 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.skyscreamer.jsonassert.JSONAssert; -import org.skyscreamer.jsonassert.JSONCompareMode; import org.springframework.test.context.junit4.SpringRunner; import java.io.IOException; @@ -51,7 +50,7 @@ public void openrtb2AuctionShouldRespondWithBidsFromTriplelift() throws IOExcept "openrtb2/triplelift/test-auction-triplelift-response.json", response, singletonList("triplelift")); - JSONAssert.assertEquals(expectedAuctionResponse, response.asString(), JSONCompareMode.NON_EXTENSIBLE); + JSONAssert.assertEquals(expectedAuctionResponse, response.asString(), openrtbCacheDebugComparator()); } } diff --git a/src/test/java/org/prebid/server/it/UnrulyTest.java b/src/test/java/org/prebid/server/it/UnrulyTest.java index 3598d888414..f3b996d2255 100644 --- a/src/test/java/org/prebid/server/it/UnrulyTest.java +++ b/src/test/java/org/prebid/server/it/UnrulyTest.java @@ -35,8 +35,11 @@ public void openrtb2AuctionShouldRespondWithBidsFromUnruly() throws IOException, // pre-bid cache WIRE_MOCK_RULE.stubFor(post(urlPathEqualTo("/cache")) - .withRequestBody(equalToJson(jsonFrom("openrtb2/unruly/test-cache-unruly-request.json"))) - .willReturn(aResponse().withBody(jsonFrom("openrtb2/unruly/test-cache-unruly-response.json")))); + .withRequestBody(equalToBidCacheRequest( + jsonFrom("openrtb2/unruly/test-cache-unruly-request.json"))) + .willReturn(aResponse().withTransformers("cache-response-transformer") + .withTransformerParameter("matcherName", + "openrtb2/unruly/test-cache-matcher-unruly.json"))); // when final Response response = given(SPEC) diff --git a/src/test/java/org/prebid/server/it/ValueImpressionTest.java b/src/test/java/org/prebid/server/it/ValueImpressionTest.java index 64ecccb46b6..09ed19d62ae 100644 --- a/src/test/java/org/prebid/server/it/ValueImpressionTest.java +++ b/src/test/java/org/prebid/server/it/ValueImpressionTest.java @@ -36,9 +36,12 @@ public void openrtb2AuctionShouldRespondWithBidsFromValueImpression() throws IOE // pre-bid cache WIRE_MOCK_RULE.stubFor(post(urlPathEqualTo("/cache")) .withRequestBody( - equalToJson(jsonFrom("openrtb2/valueimpression/test-cache-valueimpression-request.json"))) + equalToBidCacheRequest( + jsonFrom("openrtb2/valueimpression/test-cache-valueimpression-request.json"))) .willReturn(aResponse() - .withBody(jsonFrom("openrtb2/valueimpression/test-cache-valueimpression-response.json")))); + .withTransformers("cache-response-transformer") + .withTransformerParameter("matcherName", + "openrtb2/valueimpression/test-cache-matcher-valueimpression.json"))); // when final Response response = given(SPEC) diff --git a/src/test/java/org/prebid/server/it/VisxTest.java b/src/test/java/org/prebid/server/it/VisxTest.java index 47e3ab58bdd..3a2282bc42a 100644 --- a/src/test/java/org/prebid/server/it/VisxTest.java +++ b/src/test/java/org/prebid/server/it/VisxTest.java @@ -30,7 +30,7 @@ public void openrtb2AuctionShouldRespondWithBidsFromVisx() throws IOException, J // pre-bid cache WIRE_MOCK_RULE.stubFor(post(urlPathEqualTo("/cache")) - .withRequestBody(equalToJson(jsonFrom("openrtb2/visx/test-cache-visx-request.json"), true, false)) + .withRequestBody(equalToBidCacheRequest(jsonFrom("openrtb2/visx/test-cache-visx-request.json"))) .willReturn(aResponse().withBody(jsonFrom("openrtb2/visx/test-cache-visx-response.json")))); // when diff --git a/src/test/java/org/prebid/server/it/YieldlabTest.java b/src/test/java/org/prebid/server/it/YieldlabTest.java index 27302d5ea8c..727764f6321 100644 --- a/src/test/java/org/prebid/server/it/YieldlabTest.java +++ b/src/test/java/org/prebid/server/it/YieldlabTest.java @@ -6,7 +6,6 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.skyscreamer.jsonassert.JSONAssert; -import org.skyscreamer.jsonassert.JSONCompareMode; import org.springframework.test.context.junit4.SpringRunner; import java.io.IOException; @@ -65,6 +64,6 @@ public void openrtb2AuctionShouldRespondWithBidsFromYieldlab() throws IOExceptio response, singletonList("yieldlab")); final String actualStr = response.asString(); - JSONAssert.assertEquals(expectedAuctionResponse, actualStr, JSONCompareMode.NON_EXTENSIBLE); + JSONAssert.assertEquals(expectedAuctionResponse, actualStr, openrtbCacheDebugComparator()); } } diff --git a/src/test/java/org/prebid/server/it/ZeroclickfraudTest.java b/src/test/java/org/prebid/server/it/ZeroclickfraudTest.java index dd707b6b9c4..a935326fe8c 100644 --- a/src/test/java/org/prebid/server/it/ZeroclickfraudTest.java +++ b/src/test/java/org/prebid/server/it/ZeroclickfraudTest.java @@ -5,7 +5,6 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.skyscreamer.jsonassert.JSONAssert; -import org.skyscreamer.jsonassert.JSONCompareMode; import org.springframework.test.context.junit4.SpringRunner; import java.io.IOException; @@ -42,10 +41,12 @@ public void openrtb2AuctionShouldRespondWithBidsFromZeroclickfraud() throws IOEx // pre-bid cache WIRE_MOCK_RULE.stubFor(post(urlPathEqualTo("/cache")) - .withRequestBody( - equalToJson(jsonFrom("openrtb2/zeroclickfraud/test-cache-zeroclickfraud-request.json"))) + .withRequestBody(equalToBidCacheRequest( + jsonFrom("openrtb2/zeroclickfraud/test-cache-zeroclickfraud-request.json"))) .willReturn(aResponse() - .withBody(jsonFrom("openrtb2/zeroclickfraud/test-cache-zeroclickfraud-response.json")))); + .withTransformers("cache-response-transformer") + .withTransformerParameter("matcherName", + "openrtb2/zeroclickfraud/test-cache-matcher-zeroclickfraud.json"))); // when final Response response = given(SPEC) @@ -63,6 +64,6 @@ public void openrtb2AuctionShouldRespondWithBidsFromZeroclickfraud() throws IOEx "openrtb2/zeroclickfraud/test-auction-zeroclickfraud-response.json", response, singletonList("zeroclickfraud")); - JSONAssert.assertEquals(expectedAuctionResponse, response.asString(), JSONCompareMode.NON_EXTENSIBLE); + JSONAssert.assertEquals(expectedAuctionResponse, response.asString(), openrtbCacheDebugComparator()); } } diff --git a/src/test/java/org/prebid/server/it/util/BidCacheRequestPattern.java b/src/test/java/org/prebid/server/it/util/BidCacheRequestPattern.java new file mode 100644 index 00000000000..c94393f98a0 --- /dev/null +++ b/src/test/java/org/prebid/server/it/util/BidCacheRequestPattern.java @@ -0,0 +1,59 @@ +package org.prebid.server.it.util; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.github.tomakehurst.wiremock.common.Json; +import com.github.tomakehurst.wiremock.matching.EqualToJsonPattern; +import com.github.tomakehurst.wiremock.matching.MatchResult; +import com.github.tomakehurst.wiremock.matching.StringValuePattern; +import org.apache.commons.collections4.CollectionUtils; +import org.prebid.server.cache.proto.request.BidCacheRequest; +import org.prebid.server.cache.proto.request.PutObject; + +import java.util.List; + +/** + * Class was created to compare complex Json object when ordering of inner array is not predetermined. + * The Wiremock equalToJson method that creates {@link EqualToJsonPattern} cannot compare such objects correctly + * even when using the unordered flag.. + */ +public class BidCacheRequestPattern extends StringValuePattern { + + private final BidCacheRequest expected; + + public BidCacheRequestPattern(@JsonProperty("equalToJson") String json) { + super(json); + expected = Json.read(json, BidCacheRequest.class); + } + + @Override + public String getExpected() { + return Json.prettyPrint(getValue()); + } + + @Override + public MatchResult match(String value) { + try { + final BidCacheRequest actual = Json.read(value, BidCacheRequest.class); + + return new MatchResult() { + @Override + public boolean isExactMatch() { + return getDistance() == 0; + } + + @Override + public double getDistance() { + final List actualPuts = actual.getPuts(); + final List expectedPuts = expected.getPuts(); + if (CollectionUtils.isEqualCollection(actualPuts, expectedPuts)) { + return 0; + } + + return CollectionUtils.disjunction(actualPuts, expectedPuts).size(); + } + }; + } catch (Exception e) { + return MatchResult.noMatch(); + } + } +} diff --git a/src/test/java/org/prebid/server/it/util/BidCacheRequestPatternTest.java b/src/test/java/org/prebid/server/it/util/BidCacheRequestPatternTest.java new file mode 100644 index 00000000000..876f050e4c4 --- /dev/null +++ b/src/test/java/org/prebid/server/it/util/BidCacheRequestPatternTest.java @@ -0,0 +1,75 @@ +package org.prebid.server.it.util; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.github.tomakehurst.wiremock.matching.MatchResult; +import org.junit.Test; +import org.prebid.server.json.ObjectMapperProvider; + +import java.io.IOException; + +import static org.assertj.core.api.Assertions.assertThat; + +public class BidCacheRequestPatternTest { + + private final ObjectMapper mapper = ObjectMapperProvider.mapper(); + + @Test + public void shouldMatchWhenPutsAreUnordered() throws IOException { + // given + final String original = jsonFrom("bidcacherequestpattern/original-bid-request.json"); + final String unordered = jsonFrom("bidcacherequestpattern/unordered-bid-request.json"); + + // when + final MatchResult result = new BidCacheRequestPattern(original).match(unordered); + + // then + assertThat(result.getDistance()).isEqualTo(0); + assertThat(result.isExactMatch()).isTrue(); + } + + @Test + public void shouldNotMatchWhenPutIsMissing() throws IOException { + // given + final String original = jsonFrom("bidcacherequestpattern/original-bid-request.json"); + final String missing = jsonFrom("bidcacherequestpattern/missing-put-bid-request.json"); + + // when + final MatchResult result = new BidCacheRequestPattern(original).match(missing); + + // then + assertThat(result.getDistance()).isEqualTo(1); + assertThat(result.isExactMatch()).isFalse(); + } + + @Test + public void shouldNotMatchWhenPutIsRedundant() throws IOException { + // given + final String original = jsonFrom("bidcacherequestpattern/original-bid-request.json"); + final String redundant = jsonFrom("bidcacherequestpattern/redundant-put-bid-request.json"); + + // when + final MatchResult result = new BidCacheRequestPattern(original).match(redundant); + + // then + assertThat(result.getDistance()).isEqualTo(1); + assertThat(result.isExactMatch()).isFalse(); + } + + @Test + public void shouldNotMatchWhenPutIsChanged() throws IOException { + // given + final String original = jsonFrom("bidcacherequestpattern/original-bid-request.json"); + final String changed = jsonFrom("bidcacherequestpattern/changed-put-bid-request.json"); + + // when + final MatchResult result = new BidCacheRequestPattern(original).match(changed); + + // then + assertThat(result.getDistance()).isEqualTo(3); + assertThat(result.isExactMatch()).isFalse(); + } + + private String jsonFrom(String file) throws IOException { + return mapper.writeValueAsString(mapper.readTree(BidCacheRequestPatternTest.class.getResourceAsStream(file))); + } +} diff --git a/src/test/java/org/prebid/server/validation/ResponseBidValidatorTest.java b/src/test/java/org/prebid/server/validation/ResponseBidValidatorTest.java index 61428c1e16e..a9a5cb6dbea 100644 --- a/src/test/java/org/prebid/server/validation/ResponseBidValidatorTest.java +++ b/src/test/java/org/prebid/server/validation/ResponseBidValidatorTest.java @@ -23,10 +23,10 @@ import org.prebid.server.validation.model.ValidationResult; import java.math.BigDecimal; -import java.util.function.Function; +import java.util.function.UnaryOperator; import static java.util.Collections.singletonList; -import static java.util.function.Function.identity; +import static java.util.function.UnaryOperator.identity; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException; import static org.mockito.ArgumentMatchers.anyString; @@ -292,6 +292,40 @@ public void validateShouldReturnSuccessIfBidHasInsecureCreativeInInsecureContext assertThat(result.hasErrors()).isFalse(); } + @Test + public void validateShouldFailedIfVideoBidHasNoNurlAndAdm() { + final ValidationResult result = responseBidValidator.validate( + givenBid(BidType.video, builder -> builder.adm(null).nurl(null)), + BIDDER_NAME, + givenAuctionContext(), + bidderAliases); + + assertThat(result.getErrors()).hasSize(1) + .containsOnly("Bid \"bidId1\" with video type missing adm and nurl"); + } + + @Test + public void validateShouldReturnSuccessfulResultForValidVideoBidWithNurl() { + final ValidationResult result = responseBidValidator.validate( + givenBid(BidType.video, builder -> builder.adm(null)), + BIDDER_NAME, + givenAuctionContext(), + bidderAliases); + + assertThat(result.hasErrors()).isFalse(); + } + + @Test + public void validateShouldReturnSuccessfulResultForValidVideoBidWithAdm() { + final ValidationResult result = responseBidValidator.validate( + givenBid(BidType.video, builder -> builder.nurl(null)), + BIDDER_NAME, + givenAuctionContext(), + bidderAliases); + + assertThat(result.hasErrors()).isFalse(); + } + @Test public void validateShouldReturnSuccessfulResultForValidBid() { // when @@ -431,13 +465,15 @@ public void validateShouldIncrementSecureValidationWarnMetrics() { verify(metrics).updateSecureValidationMetrics(BIDDER_NAME, ACCOUNT_ID, MetricName.warn); } - private static BidderBid givenBid(Function bidCustomizer) { + private static BidderBid givenBid(UnaryOperator bidCustomizer) { return givenBid(BidType.banner, bidCustomizer); } - private static BidderBid givenBid(BidType type, Function bidCustomizer) { + private static BidderBid givenBid(BidType type, UnaryOperator bidCustomizer) { final Bid.BidBuilder bidBuilder = Bid.builder() .id("bidId1") + .adm("adm1") + .nurl("nurl") .impid("impId1") .crid("crid1") .w(1) @@ -467,7 +503,7 @@ private static AuctionContext givenAuctionContext() { return givenAuctionContext(givenBidRequest(identity()), givenAccount()); } - private static BidRequest givenBidRequest(Function impCustomizer) { + private static BidRequest givenBidRequest(UnaryOperator impCustomizer) { final Imp.ImpBuilder impBuilder = Imp.builder() .id("impId1") .banner(Banner.builder() @@ -483,7 +519,7 @@ private static Account givenAccount() { return givenAccount(identity()); } - private static Account givenAccount(Function accountCustomizer) { + private static Account givenAccount(UnaryOperator accountCustomizer) { return accountCustomizer.apply(Account.builder().id(ACCOUNT_ID)).build(); } } diff --git a/src/test/java/org/prebid/server/vast/VastModifierTest.java b/src/test/java/org/prebid/server/vast/VastModifierTest.java new file mode 100644 index 00000000000..cc1cb57eef0 --- /dev/null +++ b/src/test/java/org/prebid/server/vast/VastModifierTest.java @@ -0,0 +1,237 @@ +package org.prebid.server.vast; + +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.node.TextNode; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.mockito.Mock; +import org.mockito.junit.MockitoJUnit; +import org.mockito.junit.MockitoRule; +import org.prebid.server.bidder.BidderCatalog; +import org.prebid.server.cache.proto.request.PutObject; +import org.prebid.server.events.EventsContext; +import org.prebid.server.events.EventsService; + +import static java.util.Collections.emptySet; +import static java.util.Collections.singleton; +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.BDDMockito.given; +import static org.mockito.Mockito.verify; + +public class VastModifierTest { + + private static final String ACCOUNT_ID = "accountId"; + private static final String BIDDER = "bidder"; + private static final String INTEGRATION = "integration"; + private static final String VAST_URL_TRACKING = "http://external-url/event"; + private static final String BID_ID = "bidId"; + private static final String BID_NURL = "nurl1"; + private static final long AUCTION_TIMESTAMP = 1000L; + + @Rule + public final MockitoRule mockitoRule = MockitoJUnit.rule(); + + @Mock + private BidderCatalog bidderCatalog; + @Mock + + private EventsService eventsService; + + private VastModifier target; + + @Before + public void setUp() { + given(eventsService.vastUrlTracking(any(), any(), any(), any(), anyString())) + .willReturn(VAST_URL_TRACKING); + + given(bidderCatalog.isModifyingVastXmlAllowed(any())).willReturn(true); + + target = new VastModifier(bidderCatalog, eventsService); + } + + @Test + public void modifyVastXmlShouldReturnReceivedValueWhenEventsAreNotAllowed() { + // when + final JsonNode result = target.modifyVastXml(false, singleton(BIDDER), putObject(), ACCOUNT_ID, INTEGRATION); + + // then + assertThat(result).isEqualTo(nodeAdm()); + } + + @Test + public void modifyVastXmlShouldReturnReceivedValueWhenBidderIsNotAllowed() { + // when + final JsonNode result = target.modifyVastXml(true, emptySet(), putObject(), ACCOUNT_ID, INTEGRATION); + + // then + assertThat(result).isEqualTo(nodeAdm()); + } + + @Test + public void modifyVastXmlShouldReturnReceivedValueWhenValueIsNull() { + // when + final JsonNode result = target.modifyVastXml(true, singleton(BIDDER), givenPutObject(null), ACCOUNT_ID, + INTEGRATION); + + // then + assertThat(result).isNull(); + } + + @Test + public void modifyVastXmlShouldNotModifyVastAndAppendUrlWhenValueWithoutImpression() { + // given + final TextNode vastWithoutImpression = new TextNode("vast"); + + // when + final JsonNode result = target.modifyVastXml(true, singleton(BIDDER), givenPutObject(vastWithoutImpression), + ACCOUNT_ID, INTEGRATION); + + verify(eventsService).vastUrlTracking(any(), any(), any(), any(), anyString()); + + assertThat(result).isEqualTo(vastWithoutImpression); + } + + @Test + public void modifyVastXmlShouldModifyVastAndAppendUrl() { + // given + final JsonNode result = target.modifyVastXml(true, singleton(BIDDER), putObject(), ACCOUNT_ID, + INTEGRATION); + + // then + final String modifiedVast = "" + + "prebid.org wrapper" + + "" + + ""; + + assertThat(result).isEqualTo(new TextNode(modifiedVast)); + } + + @Test + public void createBidVastXmlShouldNotModifyWhenBidderNotAllowed() { + // given + given(bidderCatalog.isModifyingVastXmlAllowed(any())).willReturn(false); + + // when + final String result = target.createBidVastXml(BIDDER, adm(), BID_NURL, BID_ID, ACCOUNT_ID, eventsContext()); + + // then + assertThat(result).isEqualTo(adm()); + } + + @Test + public void createBidVastXmlShouldInjectBidNurlWhenBidAdmIsEmptyAndEventsDisabledByAccount() { + // when + final String result = target.createBidVastXml(BIDDER, null, BID_NURL, BID_ID, ACCOUNT_ID, + givenEventsContext(false)); + + // then + assertThat(result).isEqualTo(modifiedAdm(BID_NURL)); + } + + @Test + public void createBidVastXmlShouldNotModifyWhenBidAdmIsEmptyAndNurlIsNullAndEventsDisabledByAccount() { + // when + final String result = target.createBidVastXml(BIDDER, null, null, BID_ID, ACCOUNT_ID, + givenEventsContext(false)); + + // then + assertThat(result).isNull(); + } + + @Test + public void createBidVastXmlShouldReturnAdmWhenBidAdmIsPresentAndEventsDisabledByAccount() { + // when + final String result = target.createBidVastXml(BIDDER, adm(), BID_NURL, BID_ID, ACCOUNT_ID, + givenEventsContext(false)); + + // then + assertThat(result).isEqualTo(adm()); + } + + @Test + public void createBidVastXmlShouldBeModifiedWithNewImpressionVastUrlWhenEventsEnabledAndNoEmptyTag() { + // when + final String bidAdm = "http:/test.com"; + final String result = target.createBidVastXml(BIDDER, bidAdm, BID_NURL, BID_ID, ACCOUNT_ID, eventsContext()); + + // then + verify(eventsService).vastUrlTracking(BID_ID, BIDDER, ACCOUNT_ID, AUCTION_TIMESTAMP, INTEGRATION); + + assertThat(result).isEqualTo(bidAdm + ""); + } + + @Test + public void createBidVastXmlShouldBeInjectedWithImpressionVastUrlWhenEventsEnabledAndAdmEmptyTagPresent() { + // when + final String adm = ""; + final String result = target.createBidVastXml(BIDDER, adm, BID_NURL, BID_ID, ACCOUNT_ID, eventsContext()); + + // then + verify(eventsService).vastUrlTracking(BID_ID, BIDDER, ACCOUNT_ID, AUCTION_TIMESTAMP, INTEGRATION); + + assertThat(result).isEqualTo(""); + } + + @Test + public void createBidVastXmlShouldNotModifyWhenEventsEnabledAndAdmHaveNoImpression() { + // when + final String admWithNoImpression = "no impression"; + final String result = target.createBidVastXml(BIDDER, admWithNoImpression, BID_NURL, BID_ID, ACCOUNT_ID, + eventsContext()); + + // then + verify(eventsService).vastUrlTracking(BID_ID, BIDDER, ACCOUNT_ID, AUCTION_TIMESTAMP, INTEGRATION); + + assertThat(result).isEqualTo(admWithNoImpression); + } + + public static PutObject givenPutObject(TextNode adm) { + return PutObject.builder() + .type("xml") + .bidid("bidId2") + .bidder(BIDDER) + .timestamp(1L) + .value(adm) + .build(); + } + + public static PutObject putObject() { + return givenPutObject(nodeAdm()); + } + + public static TextNode nodeAdm() { + return new TextNode(adm()); + } + + public static String adm() { + return "" + + "prebid.org wrapper" + + "" + + "" + + ""; + } + + public static String modifiedAdm(String bidNurl) { + return "" + + "prebid.org wrapper" + + "" + + "" + + ""; + } + + public static EventsContext givenEventsContext(boolean accountEnabled) { + return EventsContext.builder() + .enabledForAccount(accountEnabled) + .auctionTimestamp(AUCTION_TIMESTAMP) + .integration(INTEGRATION) + .build(); + } + + public static EventsContext eventsContext() { + return givenEventsContext(true); + } +} diff --git a/src/test/resources/org/prebid/server/it/amp/test-amp-response.json b/src/test/resources/org/prebid/server/it/amp/test-amp-response.json index dad9a1cffc6..734e6c6e282 100644 --- a/src/test/resources/org/prebid/server/it/amp/test-amp-response.json +++ b/src/test/resources/org/prebid/server/it/amp/test-amp-response.json @@ -13,12 +13,12 @@ "hb_bidder_rubicon": "rubicon", "hb_size_appnexus": "300x250", "rpfl_1001": "2_tier0100", - "hb_cache_host": "localhost:8090", - "hb_cache_path": "/cache", - "hb_cache_host_rubicon": "localhost:8090", - "hb_cache_path_rubicon": "/cache", - "hb_cache_host_appnexus": "localhost:8090", - "hb_cache_path_appnexus": "/cache", + "hb_cache_host": "{{ cache.host }}", + "hb_cache_path": "{{ cache.path }}", + "hb_cache_host_rubicon": "{{ cache.host }}", + "hb_cache_path_rubicon": "{{ cache.path }}", + "hb_cache_host_appnexus": "{{ cache.host }}", + "hb_cache_path_appnexus": "{{ cache.path }}", "static_keyword1": "static_value1" } } \ No newline at end of file diff --git a/src/test/resources/org/prebid/server/it/openrtb2/adkernel/test-auction-adkernel-response.json b/src/test/resources/org/prebid/server/it/openrtb2/adkernel/test-auction-adkernel-response.json index 96d7967545e..ef8116a9727 100644 --- a/src/test/resources/org/prebid/server/it/openrtb2/adkernel/test-auction-adkernel-response.json +++ b/src/test/resources/org/prebid/server/it/openrtb2/adkernel/test-auction-adkernel-response.json @@ -14,7 +14,6 @@ ], "cid": "1001", "crid": "2002", - "exp": 120, "ext": { "prebid": { "type": "banner", @@ -24,22 +23,16 @@ "hb_cache_id_adkernel": "71615e3d-8a18-4099-a807-3952199b532a", "hb_pb_adkernel": "2.20", "hb_cache_path": "{{ cache.path }}", - "hb_uuid": "69c0e0c9-ce20-4d91-99d1-d821afd75727", "hb_cache_host_adkernel": "{{ cache.host }}", "hb_bidder": "adkernel", "hb_cache_id": "71615e3d-8a18-4099-a807-3952199b532a", "hb_cache_host": "{{ cache.host }}", - "hb_uuid_adkernel": "69c0e0c9-ce20-4d91-99d1-d821afd75727", "hb_cache_path_adkernel": "{{ cache.path }}" }, "cache": { "bids": { "url": "{{ cache.resource_url }}71615e3d-8a18-4099-a807-3952199b532a", "cacheId": "71615e3d-8a18-4099-a807-3952199b532a" - }, - "vastXml": { - "url": "{{ cache.resource_url }}69c0e0c9-ce20-4d91-99d1-d821afd75727", - "cacheId": "69c0e0c9-ce20-4d91-99d1-d821afd75727" } } } diff --git a/src/test/resources/org/prebid/server/it/openrtb2/adkernel/test-cache-adkernel-request.json b/src/test/resources/org/prebid/server/it/openrtb2/adkernel/test-cache-adkernel-request.json index 8bbdb8380ee..24e8a750053 100644 --- a/src/test/resources/org/prebid/server/it/openrtb2/adkernel/test-cache-adkernel-request.json +++ b/src/test/resources/org/prebid/server/it/openrtb2/adkernel/test-cache-adkernel-request.json @@ -14,11 +14,6 @@ "cid": "1001", "crid": "2002" } - }, - { - "type": "xml", - "value": "", - "expiry": 120 } ] } diff --git a/src/test/resources/org/prebid/server/it/openrtb2/adkernel/test-cache-adkernel-response.json b/src/test/resources/org/prebid/server/it/openrtb2/adkernel/test-cache-adkernel-response.json index 9573e6b0140..8be52123b6e 100644 --- a/src/test/resources/org/prebid/server/it/openrtb2/adkernel/test-cache-adkernel-response.json +++ b/src/test/resources/org/prebid/server/it/openrtb2/adkernel/test-cache-adkernel-response.json @@ -2,9 +2,6 @@ "responses": [ { "uuid": "71615e3d-8a18-4099-a807-3952199b532a" - }, - { - "uuid": "69c0e0c9-ce20-4d91-99d1-d821afd75727" } ] -} \ No newline at end of file +} diff --git a/src/test/resources/org/prebid/server/it/openrtb2/adkerneladn/test-cache-adkerneladn-response.json b/src/test/resources/org/prebid/server/it/openrtb2/adkerneladn/test-cache-adkerneladn-response.json deleted file mode 100644 index 6637734dadd..00000000000 --- a/src/test/resources/org/prebid/server/it/openrtb2/adkerneladn/test-cache-adkerneladn-response.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "responses": [ - { - "uuid": "2d20ad14-7070-4edd-8b9f-fbb11eb53de9" - }, - { - "uuid": "aedec380-879a-4029-8e7a-5a51676c887c" - }, - { - "uuid": "a3558327-7696-4606-a5e9-43413bd7faea" - } - ] -} \ No newline at end of file diff --git a/src/test/resources/org/prebid/server/it/openrtb2/adkerneladn/test-cache-matcher-adkerneladn.json b/src/test/resources/org/prebid/server/it/openrtb2/adkerneladn/test-cache-matcher-adkerneladn.json new file mode 100644 index 00000000000..2f00605e026 --- /dev/null +++ b/src/test/resources/org/prebid/server/it/openrtb2/adkerneladn/test-cache-matcher-adkerneladn.json @@ -0,0 +1,5 @@ +{ + "bid02@2.25": "2d20ad14-7070-4edd-8b9f-fbb11eb53de9", + "wehM-93KGr0_0_0@0.5": "aedec380-879a-4029-8e7a-5a51676c887c", + "adm022": "a3558327-7696-4606-a5e9-43413bd7faea" +} diff --git a/src/test/resources/org/prebid/server/it/openrtb2/adman/test-cache-adman-response.json b/src/test/resources/org/prebid/server/it/openrtb2/adman/test-cache-adman-response.json deleted file mode 100644 index 64a88c27456..00000000000 --- a/src/test/resources/org/prebid/server/it/openrtb2/adman/test-cache-adman-response.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "responses": [ - { - "uuid": "9092799c-93b0-4e11-a232-2c0151d5d275" - }, - { - "uuid": "83cdc325-c816-4d2e-bf2c-9213a70671dd" - }, - { - "uuid": "99dc3357-34ac-4819-9f68-0820039a542f" - } - ] -} diff --git a/src/test/resources/org/prebid/server/it/openrtb2/adman/test-cache-matcher-adman.json b/src/test/resources/org/prebid/server/it/openrtb2/adman/test-cache-matcher-adman.json new file mode 100644 index 00000000000..e438661be9f --- /dev/null +++ b/src/test/resources/org/prebid/server/it/openrtb2/adman/test-cache-matcher-adman.json @@ -0,0 +1,5 @@ +{ + "bid001@1.25": "9092799c-93b0-4e11-a232-2c0151d5d275", + "bid01@2.25": "83cdc325-c816-4d2e-bf2c-9213a70671dd", + "adm002": "99dc3357-34ac-4819-9f68-0820039a542f" +} diff --git a/src/test/resources/org/prebid/server/it/openrtb2/adprime/test-cache-adprime-response.json b/src/test/resources/org/prebid/server/it/openrtb2/adprime/test-cache-adprime-response.json deleted file mode 100644 index c6317eb6c8c..00000000000 --- a/src/test/resources/org/prebid/server/it/openrtb2/adprime/test-cache-adprime-response.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "responses": [ - { - "uuid": "9092799c-93b0-4e11-a232-2c0151d5d275" - }, - { - "uuid": "83cdc325-c816-4d2e-bf2c-9213a70671dd" - }, - { - "uuid": "99dc3357-34ac-4819-9f68-0820039a542f" - } - ] -} \ No newline at end of file diff --git a/src/test/resources/org/prebid/server/it/openrtb2/adprime/test-cache-matcher-adprime.json b/src/test/resources/org/prebid/server/it/openrtb2/adprime/test-cache-matcher-adprime.json new file mode 100644 index 00000000000..e438661be9f --- /dev/null +++ b/src/test/resources/org/prebid/server/it/openrtb2/adprime/test-cache-matcher-adprime.json @@ -0,0 +1,5 @@ +{ + "bid001@1.25": "9092799c-93b0-4e11-a232-2c0151d5d275", + "bid01@2.25": "83cdc325-c816-4d2e-bf2c-9213a70671dd", + "adm002": "99dc3357-34ac-4819-9f68-0820039a542f" +} diff --git a/src/test/resources/org/prebid/server/it/openrtb2/aja/test-aja-bid-response-2.json b/src/test/resources/org/prebid/server/it/openrtb2/aja/test-aja-bid-response-2.json index 7a8e8c2bd88..b6a4d8fc62d 100644 --- a/src/test/resources/org/prebid/server/it/openrtb2/aja/test-aja-bid-response-2.json +++ b/src/test/resources/org/prebid/server/it/openrtb2/aja/test-aja-bid-response-2.json @@ -9,6 +9,7 @@ "price": 9.99, "crid": "crid002", "cid": "cid002", + "nurl": "https://example.com/nurl", "adomain": [ "psacentral.org" ], @@ -19,4 +20,4 @@ "seat": "datablocks" } ] -} \ No newline at end of file +} diff --git a/src/test/resources/org/prebid/server/it/openrtb2/aja/test-auction-aja-response.json b/src/test/resources/org/prebid/server/it/openrtb2/aja/test-auction-aja-response.json index e1bb13841f5..f3927626bfe 100644 --- a/src/test/resources/org/prebid/server/it/openrtb2/aja/test-auction-aja-response.json +++ b/src/test/resources/org/prebid/server/it/openrtb2/aja/test-auction-aja-response.json @@ -10,6 +10,8 @@ "adomain": [ "psacentral.org" ], + "nurl": "https://example.com/nurl", + "adm":"prebid.org wrapper", "cid": "cid002", "crid": "crid002", "w": 300, @@ -99,4 +101,4 @@ "auctiontimestamp": 1000 } } -} \ No newline at end of file +} diff --git a/src/test/resources/org/prebid/server/it/openrtb2/aja/test-cache-aja-request.json b/src/test/resources/org/prebid/server/it/openrtb2/aja/test-cache-aja-request.json index 9d4855a6222..127a65adcc2 100644 --- a/src/test/resources/org/prebid/server/it/openrtb2/aja/test-cache-aja-request.json +++ b/src/test/resources/org/prebid/server/it/openrtb2/aja/test-cache-aja-request.json @@ -23,6 +23,7 @@ "adomain": [ "psacentral.org" ], + "nurl": "https://example.com/nurl", "cid": "cid002", "crid": "crid002", "w": 300, @@ -31,8 +32,8 @@ }, { "type": "xml", - "value": "prebid.org wrapper", + "value": "prebid.org wrapper", "expiry": 120 } ] -} \ No newline at end of file +} diff --git a/src/test/resources/org/prebid/server/it/openrtb2/aja/test-cache-aja-response.json b/src/test/resources/org/prebid/server/it/openrtb2/aja/test-cache-aja-response.json deleted file mode 100644 index 7d2718f9414..00000000000 --- a/src/test/resources/org/prebid/server/it/openrtb2/aja/test-cache-aja-response.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "responses": [ - { - "uuid": "f0ab9105-cb21-4e59-b433-70f5ad6671cb" - }, - { - "uuid": "e7965b2e-0aa3-4252-a22c-580ed010e619" - }, - { - "uuid": "44a52b06-b29f-4819-a05f-db36b9e7b8fc" - } - ] -} \ No newline at end of file diff --git a/src/test/resources/org/prebid/server/it/openrtb2/aja/test-cache-matcher-aja.json b/src/test/resources/org/prebid/server/it/openrtb2/aja/test-cache-matcher-aja.json new file mode 100644 index 00000000000..a1bbba164ad --- /dev/null +++ b/src/test/resources/org/prebid/server/it/openrtb2/aja/test-cache-matcher-aja.json @@ -0,0 +1,5 @@ +{ + "bid001@3.33": "f0ab9105-cb21-4e59-b433-70f5ad6671cb", + "bid002@9.99": "e7965b2e-0aa3-4252-a22c-580ed010e619", + "prebid.org wrapper": "44a52b06-b29f-4819-a05f-db36b9e7b8fc" +} diff --git a/src/test/resources/org/prebid/server/it/openrtb2/applogy/test-cache-applogy-response.json b/src/test/resources/org/prebid/server/it/openrtb2/applogy/test-cache-applogy-response.json deleted file mode 100644 index 7d2718f9414..00000000000 --- a/src/test/resources/org/prebid/server/it/openrtb2/applogy/test-cache-applogy-response.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "responses": [ - { - "uuid": "f0ab9105-cb21-4e59-b433-70f5ad6671cb" - }, - { - "uuid": "e7965b2e-0aa3-4252-a22c-580ed010e619" - }, - { - "uuid": "44a52b06-b29f-4819-a05f-db36b9e7b8fc" - } - ] -} \ No newline at end of file diff --git a/src/test/resources/org/prebid/server/it/openrtb2/applogy/test-cache-matcher-applogy.json b/src/test/resources/org/prebid/server/it/openrtb2/applogy/test-cache-matcher-applogy.json new file mode 100644 index 00000000000..1dacfb73925 --- /dev/null +++ b/src/test/resources/org/prebid/server/it/openrtb2/applogy/test-cache-matcher-applogy.json @@ -0,0 +1,5 @@ +{ + "bid001@3.33": "f0ab9105-cb21-4e59-b433-70f5ad6671cb", + "bid002@5.55": "e7965b2e-0aa3-4252-a22c-580ed010e619", + "adm002": "44a52b06-b29f-4819-a05f-db36b9e7b8fc" +} diff --git a/src/test/resources/org/prebid/server/it/openrtb2/avocet/test-auction-avocet-response.json b/src/test/resources/org/prebid/server/it/openrtb2/avocet/test-auction-avocet-response.json index d7f70aa47e7..5b0c273da41 100644 --- a/src/test/resources/org/prebid/server/it/openrtb2/avocet/test-auction-avocet-response.json +++ b/src/test/resources/org/prebid/server/it/openrtb2/avocet/test-auction-avocet-response.json @@ -17,6 +17,7 @@ "crid": "29681110", "w": 1024, "h": 576, + "exp": 120, "ext": { "bidder": { "avocet": { @@ -26,6 +27,8 @@ "prebid": { "type": "video", "targeting": { + "hb_uuid_avocet": "ce120de7-25d0-4384-8983-8a9462149c8c", + "hb_uuid": "ce120de7-25d0-4384-8983-8a9462149c8c", "hb_pb": "0.50", "hb_bidder_avocet": "avocet", "hb_cache_path_avocet": "{{ cache.path }}", @@ -43,6 +46,10 @@ "bids": { "url": "{{ cache.resource_url }}78f9a6dd-d08c-4b80-ba0f-0159b9add9bf", "cacheId": "78f9a6dd-d08c-4b80-ba0f-0159b9add9bf" + }, + "vastXml": { + "url": "{{ cache.resource_url }}ce120de7-25d0-4384-8983-8a9462149c8c", + "cacheId": "ce120de7-25d0-4384-8983-8a9462149c8c" } } } @@ -60,8 +67,8 @@ "cache": [ { "uri": "{{ cache.endpoint }}", - "requestbody": "{\"puts\":[{\"type\":\"json\",\"value\":{\"id\":\"7706636740145184841\",\"impid\":\"test-imp-banner-id\",\"price\":0.5,\"adm\":\"some-test-ad\",\"adid\":\"29681110\",\"adomain\":[\"advertsite.com\"],\"cid\":\"772\",\"crid\":\"29681110\",\"api\":1,\"w\":1024,\"h\":576,\"ext\":{\"avocet\":{\"duration\":30}}}}]}", - "responsebody": "{\"responses\":[{\"uuid\":\"78f9a6dd-d08c-4b80-ba0f-0159b9add9bf\"}]}", + "requestbody": "{\"puts\":[{\"type\":\"json\",\"value\":{\"id\":\"7706636740145184841\",\"impid\":\"test-imp-banner-id\",\"price\":0.5,\"adm\":\"some-test-ad\",\"adid\":\"29681110\",\"adomain\":[\"advertsite.com\"],\"cid\":\"772\",\"crid\":\"29681110\",\"api\":1,\"w\":1024,\"h\":576,\"ext\":{\"avocet\":{\"duration\":30}}}},{\"type\":\"xml\",\"value\":\"some-test-ad\",\"expiry\":120}]}", + "responsebody": "{\"responses\":[{\"uuid\":\"78f9a6dd-d08c-4b80-ba0f-0159b9add9bf\"},{\"uuid\":\"ce120de7-25d0-4384-8983-8a9462149c8c\"}]}", "status": 200 } ], diff --git a/src/test/resources/org/prebid/server/it/openrtb2/avocet/test-cache-avocet-request.json b/src/test/resources/org/prebid/server/it/openrtb2/avocet/test-cache-avocet-request.json index bc89734d9f0..859a825806c 100644 --- a/src/test/resources/org/prebid/server/it/openrtb2/avocet/test-cache-avocet-request.json +++ b/src/test/resources/org/prebid/server/it/openrtb2/avocet/test-cache-avocet-request.json @@ -8,10 +8,12 @@ "price": 0.500000, "adid": "29681110", "adm": "some-test-ad", - "adomain": ["advertsite.com"], + "adomain": [ + "advertsite.com" + ], "cid": "772", "crid": "29681110", - "api" : 1, + "api": 1, "h": 576, "w": 1024, "ext": { @@ -20,6 +22,11 @@ } } } + }, + { + "type": "xml", + "value": "some-test-ad", + "expiry": 120 } ] } diff --git a/src/test/resources/org/prebid/server/it/openrtb2/avocet/test-cache-avocet-response.json b/src/test/resources/org/prebid/server/it/openrtb2/avocet/test-cache-avocet-response.json deleted file mode 100644 index 0b2fbde6c47..00000000000 --- a/src/test/resources/org/prebid/server/it/openrtb2/avocet/test-cache-avocet-response.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "responses": [ - { - "uuid": "78f9a6dd-d08c-4b80-ba0f-0159b9add9bf" - } - ] -} diff --git a/src/test/resources/org/prebid/server/it/openrtb2/avocet/test-cache-matcher-avocet.json b/src/test/resources/org/prebid/server/it/openrtb2/avocet/test-cache-matcher-avocet.json new file mode 100644 index 00000000000..d9906e7377c --- /dev/null +++ b/src/test/resources/org/prebid/server/it/openrtb2/avocet/test-cache-matcher-avocet.json @@ -0,0 +1,4 @@ +{ + "7706636740145184841@0.5": "78f9a6dd-d08c-4b80-ba0f-0159b9add9bf", + "some-test-ad": "ce120de7-25d0-4384-8983-8a9462149c8c" +} diff --git a/src/test/resources/org/prebid/server/it/openrtb2/colossus/test-cache-colossus-response.json b/src/test/resources/org/prebid/server/it/openrtb2/colossus/test-cache-colossus-response.json deleted file mode 100644 index c6317eb6c8c..00000000000 --- a/src/test/resources/org/prebid/server/it/openrtb2/colossus/test-cache-colossus-response.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "responses": [ - { - "uuid": "9092799c-93b0-4e11-a232-2c0151d5d275" - }, - { - "uuid": "83cdc325-c816-4d2e-bf2c-9213a70671dd" - }, - { - "uuid": "99dc3357-34ac-4819-9f68-0820039a542f" - } - ] -} \ No newline at end of file diff --git a/src/test/resources/org/prebid/server/it/openrtb2/colossus/test-cache-matcher-colossus.json b/src/test/resources/org/prebid/server/it/openrtb2/colossus/test-cache-matcher-colossus.json new file mode 100644 index 00000000000..e438661be9f --- /dev/null +++ b/src/test/resources/org/prebid/server/it/openrtb2/colossus/test-cache-matcher-colossus.json @@ -0,0 +1,5 @@ +{ + "bid001@1.25": "9092799c-93b0-4e11-a232-2c0151d5d275", + "bid01@2.25": "83cdc325-c816-4d2e-bf2c-9213a70671dd", + "adm002": "99dc3357-34ac-4819-9f68-0820039a542f" +} diff --git a/src/test/resources/org/prebid/server/it/openrtb2/conversant/test-cache-conversant-response.json b/src/test/resources/org/prebid/server/it/openrtb2/conversant/test-cache-conversant-response.json deleted file mode 100644 index 9e2a61bd058..00000000000 --- a/src/test/resources/org/prebid/server/it/openrtb2/conversant/test-cache-conversant-response.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "responses": [ - { - "uuid": "c9eb3deb-2054-40f5-9cf3-f9047dc240a2" - }, - { - "uuid": "8f17dd0b-e615-48d1-a7b1-08a704aae48d" - }, - { - "uuid": "8300a9d5-4654-4406-b6b9-7bc5060e8a36" - } - ] -} \ No newline at end of file diff --git a/src/test/resources/org/prebid/server/it/openrtb2/conversant/test-cache-matcher-conversant.json b/src/test/resources/org/prebid/server/it/openrtb2/conversant/test-cache-matcher-conversant.json new file mode 100644 index 00000000000..355270d9c3d --- /dev/null +++ b/src/test/resources/org/prebid/server/it/openrtb2/conversant/test-cache-matcher-conversant.json @@ -0,0 +1,5 @@ +{ + "789353336@6": "c9eb3deb-2054-40f5-9cf3-f9047dc240a2", + "981876692@5": "8f17dd0b-e615-48d1-a7b1-08a704aae48d", + "adm41": "8300a9d5-4654-4406-b6b9-7bc5060e8a36" +} diff --git a/src/test/resources/org/prebid/server/it/openrtb2/cpmstar/test-cache-cpmstar-response.json b/src/test/resources/org/prebid/server/it/openrtb2/cpmstar/test-cache-cpmstar-response.json deleted file mode 100644 index 7d2718f9414..00000000000 --- a/src/test/resources/org/prebid/server/it/openrtb2/cpmstar/test-cache-cpmstar-response.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "responses": [ - { - "uuid": "f0ab9105-cb21-4e59-b433-70f5ad6671cb" - }, - { - "uuid": "e7965b2e-0aa3-4252-a22c-580ed010e619" - }, - { - "uuid": "44a52b06-b29f-4819-a05f-db36b9e7b8fc" - } - ] -} \ No newline at end of file diff --git a/src/test/resources/org/prebid/server/it/openrtb2/cpmstar/test-cache-matcher-cpmstar.json b/src/test/resources/org/prebid/server/it/openrtb2/cpmstar/test-cache-matcher-cpmstar.json new file mode 100644 index 00000000000..1dacfb73925 --- /dev/null +++ b/src/test/resources/org/prebid/server/it/openrtb2/cpmstar/test-cache-matcher-cpmstar.json @@ -0,0 +1,5 @@ +{ + "bid001@3.33": "f0ab9105-cb21-4e59-b433-70f5ad6671cb", + "bid002@5.55": "e7965b2e-0aa3-4252-a22c-580ed010e619", + "adm002": "44a52b06-b29f-4819-a05f-db36b9e7b8fc" +} diff --git a/src/test/resources/org/prebid/server/it/openrtb2/datablocks/test-auction-datablocks-response.json b/src/test/resources/org/prebid/server/it/openrtb2/datablocks/test-auction-datablocks-response.json index 6334dca90c2..91d0f09bdff 100644 --- a/src/test/resources/org/prebid/server/it/openrtb2/datablocks/test-auction-datablocks-response.json +++ b/src/test/resources/org/prebid/server/it/openrtb2/datablocks/test-auction-datablocks-response.json @@ -7,6 +7,8 @@ "id": "bid002", "impid": "impId002", "price": 9.99, + "nurl": "https://example.com/nurl", + "adm": "prebid.org wrapper", "adomain": [ "psacentral.org" ], @@ -95,7 +97,7 @@ "cache": [ { "uri": "{{ cache.endpoint }}", - "requestbody": "{\"puts\":[{\"type\":\"json\",\"value\":{\"id\":\"bid001\",\"impid\":\"impId001\",\"price\":7.77,\"adm\":\"adm001\",\"adid\":\"adid001\",\"cid\":\"cid001\",\"crid\":\"crid001\",\"w\":300,\"h\":250}},{\"type\":\"json\",\"value\":{\"id\":\"bid002\",\"impid\":\"impId002\",\"price\":9.99,\"adomain\":[\"psacentral.org\"],\"cid\":\"cid002\",\"crid\":\"crid002\",\"w\":300,\"h\":250}},{\"type\":\"xml\",\"value\":\"prebid.org wrapper\",\"expiry\":120}]}", + "requestbody": "{\"puts\":[{\"type\":\"json\",\"value\":{\"id\":\"bid001\",\"impid\":\"impId001\",\"price\":7.77,\"adm\":\"adm001\",\"adid\":\"adid001\",\"cid\":\"cid001\",\"crid\":\"crid001\",\"w\":300,\"h\":250}},{\"type\":\"json\",\"value\":{\"id\":\"bid002\",\"impid\":\"impId002\",\"price\":9.99,\"nurl\":\"https://example.com/nurl\",\"adomain\":[\"psacentral.org\"],\"cid\":\"cid002\",\"crid\":\"crid002\",\"w\":300,\"h\":250}},{\"type\":\"xml\",\"value\":\"prebid.org wrapper\",\"expiry\":120}]}", "responsebody": "{\"responses\":[{\"uuid\":\"c1662cf6-f00a-4066-b71a-46d97abccc35\"},{\"uuid\":\"dbaa191c-5a56-4655-85eb-da079f94e09f\"},{\"uuid\":\"62019cff-d657-42fc-8366-16c34e1fd28c\"}]}", "status": 200 } @@ -104,7 +106,7 @@ { "uri": "{{ datablocks.exchange_uri }}?sid=2", "requestbody": "{\"id\":\"tid\",\"imp\":[{\"id\":\"impId002\",\"video\":{\"mimes\":[\"video/mp4\"],\"w\":300,\"h\":250,\"pos\":1},\"ext\":{\"bidder\":{\"host\":\"localhost:8090\",\"sourceId\":2}}}],\"site\":{\"domain\":\"example.com\",\"page\":\"http://www.example.com\",\"publisher\":{\"id\":\"publisherId\"},\"ext\":{\"amp\":0}},\"device\":{\"ua\":\"userAgent\",\"dnt\":2,\"ip\":\"193.168.244.1\",\"pxratio\":4.2,\"language\":\"en\",\"ifa\":\"ifaId\"},\"user\":{\"buyeruid\":\"DB-UID\",\"ext\":{\"consent\":\"consentValue\"}},\"at\":1,\"tmax\":5000,\"cur\":[\"USD\"],\"source\":{\"fd\":1,\"tid\":\"tid\"},\"regs\":{\"ext\":{\"gdpr\":0}},\"ext\":{\"prebid\":{\"debug\":1,\"targeting\":{\"pricegranularity\":{\"precision\":2,\"ranges\":[{\"max\":20,\"increment\":0.1}]},\"includewinners\":true,\"includebidderkeys\":true},\"cache\":{\"bids\":{},\"vastxml\":{\"ttlseconds\":120}},\"auctiontimestamp\":1000,\"channel\":{\"name\":\"web\"}}}}", - "responsebody": "{\"id\":\"tid\",\"seatbid\":[{\"bid\":[{\"id\":\"bid002\",\"impid\":\"impId002\",\"price\":9.99,\"crid\":\"crid002\",\"cid\":\"cid002\",\"adomain\":[\"psacentral.org\"],\"h\":250,\"w\":300}],\"seat\":\"datablocks\"}]}", + "responsebody": "{\"id\":\"tid\",\"seatbid\":[{\"bid\":[{\"id\":\"bid002\",\"impid\":\"impId002\",\"price\":9.99,\"crid\":\"crid002\",\"cid\":\"cid002\",\"nurl\":\"https://example.com/nurl\",\"adomain\":[\"psacentral.org\"],\"h\":250,\"w\":300}],\"seat\":\"datablocks\"}]}", "status": 200 }, { diff --git a/src/test/resources/org/prebid/server/it/openrtb2/datablocks/test-cache-datablocks-request.json b/src/test/resources/org/prebid/server/it/openrtb2/datablocks/test-cache-datablocks-request.json index c76c7256d07..d22654a542b 100644 --- a/src/test/resources/org/prebid/server/it/openrtb2/datablocks/test-cache-datablocks-request.json +++ b/src/test/resources/org/prebid/server/it/openrtb2/datablocks/test-cache-datablocks-request.json @@ -23,6 +23,7 @@ "adomain": [ "psacentral.org" ], + "nurl": "https://example.com/nurl", "cid": "cid002", "crid": "crid002", "w": 300, @@ -31,8 +32,8 @@ }, { "type": "xml", - "value": "prebid.org wrapper", + "value": "prebid.org wrapper", "expiry": 120 } ] -} \ No newline at end of file +} diff --git a/src/test/resources/org/prebid/server/it/openrtb2/datablocks/test-cache-datablocks-response.json b/src/test/resources/org/prebid/server/it/openrtb2/datablocks/test-cache-datablocks-response.json deleted file mode 100644 index babbed58d14..00000000000 --- a/src/test/resources/org/prebid/server/it/openrtb2/datablocks/test-cache-datablocks-response.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "responses": [ - { - "uuid": "c1662cf6-f00a-4066-b71a-46d97abccc35" - }, - { - "uuid": "dbaa191c-5a56-4655-85eb-da079f94e09f" - }, - { - "uuid": "62019cff-d657-42fc-8366-16c34e1fd28c" - } - ] -} \ No newline at end of file diff --git a/src/test/resources/org/prebid/server/it/openrtb2/datablocks/test-cache-matcher-datablocks.json b/src/test/resources/org/prebid/server/it/openrtb2/datablocks/test-cache-matcher-datablocks.json new file mode 100644 index 00000000000..82125ce1b1b --- /dev/null +++ b/src/test/resources/org/prebid/server/it/openrtb2/datablocks/test-cache-matcher-datablocks.json @@ -0,0 +1,5 @@ +{ + "bid001@7.77": "c1662cf6-f00a-4066-b71a-46d97abccc35", + "bid002@9.99": "dbaa191c-5a56-4655-85eb-da079f94e09f", + "prebid.org wrapper": "62019cff-d657-42fc-8366-16c34e1fd28c" +} diff --git a/src/test/resources/org/prebid/server/it/openrtb2/datablocks/test-datablocks-bid-response-2.json b/src/test/resources/org/prebid/server/it/openrtb2/datablocks/test-datablocks-bid-response-2.json index 7a8e8c2bd88..b6a4d8fc62d 100644 --- a/src/test/resources/org/prebid/server/it/openrtb2/datablocks/test-datablocks-bid-response-2.json +++ b/src/test/resources/org/prebid/server/it/openrtb2/datablocks/test-datablocks-bid-response-2.json @@ -9,6 +9,7 @@ "price": 9.99, "crid": "crid002", "cid": "cid002", + "nurl": "https://example.com/nurl", "adomain": [ "psacentral.org" ], @@ -19,4 +20,4 @@ "seat": "datablocks" } ] -} \ No newline at end of file +} diff --git a/src/test/resources/org/prebid/server/it/openrtb2/engagebdr/test-auction-engagebdr-response.json b/src/test/resources/org/prebid/server/it/openrtb2/engagebdr/test-auction-engagebdr-response.json index 4d70e83c891..220d77bd2dc 100644 --- a/src/test/resources/org/prebid/server/it/openrtb2/engagebdr/test-auction-engagebdr-response.json +++ b/src/test/resources/org/prebid/server/it/openrtb2/engagebdr/test-auction-engagebdr-response.json @@ -4,7 +4,7 @@ { "bid": [ { - "id": "test-imp-id", + "id": "test-imp-id2", "impid": "impId022", "price": 9.81, "adm": "\nStatic VASTStatic VAST Tag", @@ -51,7 +51,7 @@ } }, { - "id": "test-imp-id", + "id": "test-imp-id1", "impid": "impId021", "price": 9.81, "adm": "

", diff --git a/src/test/resources/org/prebid/server/it/openrtb2/engagebdr/test-cache-engagebdr-request.json b/src/test/resources/org/prebid/server/it/openrtb2/engagebdr/test-cache-engagebdr-request.json index 15a07e1bde4..f331fc452b9 100644 --- a/src/test/resources/org/prebid/server/it/openrtb2/engagebdr/test-cache-engagebdr-request.json +++ b/src/test/resources/org/prebid/server/it/openrtb2/engagebdr/test-cache-engagebdr-request.json @@ -3,7 +3,7 @@ { "type": "json", "value": { - "id": "test-imp-id", + "id": "test-imp-id1", "impid": "impId021", "price": 9.81, "adm": "
", @@ -21,7 +21,7 @@ { "type": "json", "value": { - "id": "test-imp-id", + "id": "test-imp-id2", "impid": "impId022", "price": 9.81, "adm": "\nStatic VASTStatic VAST Tag", @@ -42,4 +42,4 @@ "expiry": 120 } ] -} \ No newline at end of file +} diff --git a/src/test/resources/org/prebid/server/it/openrtb2/engagebdr/test-cache-engagebdr-response.json b/src/test/resources/org/prebid/server/it/openrtb2/engagebdr/test-cache-engagebdr-response.json deleted file mode 100644 index 4749447ab7c..00000000000 --- a/src/test/resources/org/prebid/server/it/openrtb2/engagebdr/test-cache-engagebdr-response.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "responses": [ - { - "uuid": "739f1ac0-3ac3-4c02-8b74-ceb1fa4d96a1" - }, - { - "uuid": "93bcb450-8a55-4f23-a39e-29b0b0760321" - }, - { - "uuid": "6628e262-d023-406b-b3e9-9a9aded76a7d" - } - ] -} diff --git a/src/test/resources/org/prebid/server/it/openrtb2/engagebdr/test-cache-matcher-engagebdr.json b/src/test/resources/org/prebid/server/it/openrtb2/engagebdr/test-cache-matcher-engagebdr.json new file mode 100644 index 00000000000..c67d1e0118c --- /dev/null +++ b/src/test/resources/org/prebid/server/it/openrtb2/engagebdr/test-cache-matcher-engagebdr.json @@ -0,0 +1,5 @@ +{ + "test-imp-id1@9.81": "739f1ac0-3ac3-4c02-8b74-ceb1fa4d96a1", + "test-imp-id2@9.81": "93bcb450-8a55-4f23-a39e-29b0b0760321", + "\nStatic VASTStatic VAST Tag": "6628e262-d023-406b-b3e9-9a9aded76a7d" +} diff --git a/src/test/resources/org/prebid/server/it/openrtb2/engagebdr/test-engagebdr-bid-response-1.json b/src/test/resources/org/prebid/server/it/openrtb2/engagebdr/test-engagebdr-bid-response-1.json index 762e2a1794b..7af6c8903d4 100644 --- a/src/test/resources/org/prebid/server/it/openrtb2/engagebdr/test-engagebdr-bid-response-1.json +++ b/src/test/resources/org/prebid/server/it/openrtb2/engagebdr/test-engagebdr-bid-response-1.json @@ -4,7 +4,7 @@ { "bid": [ { - "id" : "test-imp-id", + "id" : "test-imp-id1", "impid": "impId021", "price": 9.81, "adid": "abcde-12345", diff --git a/src/test/resources/org/prebid/server/it/openrtb2/engagebdr/test-engagebdr-bid-response-2.json b/src/test/resources/org/prebid/server/it/openrtb2/engagebdr/test-engagebdr-bid-response-2.json index fbee460693e..313136e0be1 100644 --- a/src/test/resources/org/prebid/server/it/openrtb2/engagebdr/test-engagebdr-bid-response-2.json +++ b/src/test/resources/org/prebid/server/it/openrtb2/engagebdr/test-engagebdr-bid-response-2.json @@ -4,7 +4,7 @@ { "bid": [ { - "id": "test-imp-id", + "id": "test-imp-id2", "impid": "impId022", "price": 9.81, "adid": "abcde-12345", diff --git a/src/test/resources/org/prebid/server/it/openrtb2/facebook/test-cache-facebook-request.json b/src/test/resources/org/prebid/server/it/openrtb2/facebook/test-cache-facebook-request.json index 160afe169af..b166d3f5a8b 100644 --- a/src/test/resources/org/prebid/server/it/openrtb2/facebook/test-cache-facebook-request.json +++ b/src/test/resources/org/prebid/server/it/openrtb2/facebook/test-cache-facebook-request.json @@ -45,4 +45,4 @@ "expiry": 120 } ] -} \ No newline at end of file +} diff --git a/src/test/resources/org/prebid/server/it/openrtb2/facebook/test-cache-facebook-response.json b/src/test/resources/org/prebid/server/it/openrtb2/facebook/test-cache-facebook-response.json deleted file mode 100644 index 8d60d3ddee5..00000000000 --- a/src/test/resources/org/prebid/server/it/openrtb2/facebook/test-cache-facebook-response.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "responses": [ - { - "uuid": "9bde9bf0-7726-4789-9f5a-b948131d778d" - }, - { - "uuid": "446d71ac-0337-4871-9fda-4552323a269b" - }, - { - "uuid": "3d90394a-0301-4faf-b0e8-5d26a88f6ef0" - }, - { - "uuid": "6d7addba-3984-4a69-b84f-6f1daa02b407" - } - ] -} \ No newline at end of file diff --git a/src/test/resources/org/prebid/server/it/openrtb2/facebook/test-cache-matcher-facebook.json b/src/test/resources/org/prebid/server/it/openrtb2/facebook/test-cache-matcher-facebook.json new file mode 100644 index 00000000000..d17911f2517 --- /dev/null +++ b/src/test/resources/org/prebid/server/it/openrtb2/facebook/test-cache-matcher-facebook.json @@ -0,0 +1,6 @@ +{ + "bid2@15": "9bde9bf0-7726-4789-9f5a-b948131d778d", + "bid3@10": "446d71ac-0337-4871-9fda-4552323a269b", + "bid1@9": "3d90394a-0301-4faf-b0e8-5d26a88f6ef0", + "{\"bid_id\":\"10\"}": "6d7addba-3984-4a69-b84f-6f1daa02b407" +} diff --git a/src/test/resources/org/prebid/server/it/openrtb2/gamoshi/test-cache-gamoshi-response.json b/src/test/resources/org/prebid/server/it/openrtb2/gamoshi/test-cache-gamoshi-response.json deleted file mode 100644 index 7d2718f9414..00000000000 --- a/src/test/resources/org/prebid/server/it/openrtb2/gamoshi/test-cache-gamoshi-response.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "responses": [ - { - "uuid": "f0ab9105-cb21-4e59-b433-70f5ad6671cb" - }, - { - "uuid": "e7965b2e-0aa3-4252-a22c-580ed010e619" - }, - { - "uuid": "44a52b06-b29f-4819-a05f-db36b9e7b8fc" - } - ] -} \ No newline at end of file diff --git a/src/test/resources/org/prebid/server/it/openrtb2/gamoshi/test-cache-matcher-gamoshi.json b/src/test/resources/org/prebid/server/it/openrtb2/gamoshi/test-cache-matcher-gamoshi.json new file mode 100644 index 00000000000..1dacfb73925 --- /dev/null +++ b/src/test/resources/org/prebid/server/it/openrtb2/gamoshi/test-cache-matcher-gamoshi.json @@ -0,0 +1,5 @@ +{ + "bid001@3.33": "f0ab9105-cb21-4e59-b433-70f5ad6671cb", + "bid002@5.55": "e7965b2e-0aa3-4252-a22c-580ed010e619", + "adm002": "44a52b06-b29f-4819-a05f-db36b9e7b8fc" +} diff --git a/src/test/resources/org/prebid/server/it/openrtb2/gumgum/test-cache-gumgum-response.json b/src/test/resources/org/prebid/server/it/openrtb2/gumgum/test-cache-gumgum-response.json deleted file mode 100644 index 1df04233977..00000000000 --- a/src/test/resources/org/prebid/server/it/openrtb2/gumgum/test-cache-gumgum-response.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "responses": [ - { - "uuid": "78f9a6dd-d08c-4b80-ba0f-0159b9add9bf" - }, - { - "uuid": "eaf3e2cd-57af-42d1-9daf-38836ae7bca7" - } - ] -} \ No newline at end of file diff --git a/src/test/resources/org/prebid/server/it/openrtb2/gumgum/test-cache-matcher-gumgum.json b/src/test/resources/org/prebid/server/it/openrtb2/gumgum/test-cache-matcher-gumgum.json new file mode 100644 index 00000000000..8ac9f9c63eb --- /dev/null +++ b/src/test/resources/org/prebid/server/it/openrtb2/gumgum/test-cache-matcher-gumgum.json @@ -0,0 +1,4 @@ +{ + "bid001@1.25": "78f9a6dd-d08c-4b80-ba0f-0159b9add9bf", + "bid002@2": "eaf3e2cd-57af-42d1-9daf-38836ae7bca7" +} diff --git a/src/test/resources/org/prebid/server/it/openrtb2/invibes/test-auction-invibes-response.json b/src/test/resources/org/prebid/server/it/openrtb2/invibes/test-auction-invibes-response.json index f013f8816aa..e645a933457 100644 --- a/src/test/resources/org/prebid/server/it/openrtb2/invibes/test-auction-invibes-response.json +++ b/src/test/resources/org/prebid/server/it/openrtb2/invibes/test-auction-invibes-response.json @@ -32,7 +32,7 @@ }, "cache":{ "bids":{ - "url":"http://localhost:8090/cache?uuid=f0ab9105-cb21-4e59-b433-70f5ad6671cb", + "url":"{{ cache.resource_url }}f0ab9105-cb21-4e59-b433-70f5ad6671cb", "cacheId":"f0ab9105-cb21-4e59-b433-70f5ad6671cb" } } diff --git a/src/test/resources/org/prebid/server/it/openrtb2/kidoz/test-cache-kidoz-response.json b/src/test/resources/org/prebid/server/it/openrtb2/kidoz/test-cache-kidoz-response.json deleted file mode 100644 index 7d2718f9414..00000000000 --- a/src/test/resources/org/prebid/server/it/openrtb2/kidoz/test-cache-kidoz-response.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "responses": [ - { - "uuid": "f0ab9105-cb21-4e59-b433-70f5ad6671cb" - }, - { - "uuid": "e7965b2e-0aa3-4252-a22c-580ed010e619" - }, - { - "uuid": "44a52b06-b29f-4819-a05f-db36b9e7b8fc" - } - ] -} \ No newline at end of file diff --git a/src/test/resources/org/prebid/server/it/openrtb2/kidoz/test-cache-matcher-kidoz.json b/src/test/resources/org/prebid/server/it/openrtb2/kidoz/test-cache-matcher-kidoz.json new file mode 100644 index 00000000000..1dacfb73925 --- /dev/null +++ b/src/test/resources/org/prebid/server/it/openrtb2/kidoz/test-cache-matcher-kidoz.json @@ -0,0 +1,5 @@ +{ + "bid001@3.33": "f0ab9105-cb21-4e59-b433-70f5ad6671cb", + "bid002@5.55": "e7965b2e-0aa3-4252-a22c-580ed010e619", + "adm002": "44a52b06-b29f-4819-a05f-db36b9e7b8fc" +} diff --git a/src/test/resources/org/prebid/server/it/openrtb2/lifestreet/test-cache-lifestreet-response.json b/src/test/resources/org/prebid/server/it/openrtb2/lifestreet/test-cache-lifestreet-response.json deleted file mode 100644 index df529f6f99f..00000000000 --- a/src/test/resources/org/prebid/server/it/openrtb2/lifestreet/test-cache-lifestreet-response.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "responses": [ - { - "uuid": "04f8b42b-7927-4930-a0b1-0ab16a441e91" - }, - { - "uuid": "f0bfa534-ca56-42bc-9b91-a801f8f202c2" - }, - { - "uuid": "7e5320e5-ad46-439e-a7eb-f4cb826d8ab6" - } - ] -} \ No newline at end of file diff --git a/src/test/resources/org/prebid/server/it/openrtb2/lifestreet/test-cache-matcher-lifestreet.json b/src/test/resources/org/prebid/server/it/openrtb2/lifestreet/test-cache-matcher-lifestreet.json new file mode 100644 index 00000000000..a3f6352e58e --- /dev/null +++ b/src/test/resources/org/prebid/server/it/openrtb2/lifestreet/test-cache-matcher-lifestreet.json @@ -0,0 +1,5 @@ +{ + "791858127@3.75": "04f8b42b-7927-4930-a0b1-0ab16a441e91", + "847761866@4.75": "f0bfa534-ca56-42bc-9b91-a801f8f202c2", + "adm71": "7e5320e5-ad46-439e-a7eb-f4cb826d8ab6" +} diff --git a/src/test/resources/org/prebid/server/it/openrtb2/openx/test-cache-matcher-openx.json b/src/test/resources/org/prebid/server/it/openrtb2/openx/test-cache-matcher-openx.json index b5a328fd0ee..d0d39de7bd5 100644 --- a/src/test/resources/org/prebid/server/it/openrtb2/openx/test-cache-matcher-openx.json +++ b/src/test/resources/org/prebid/server/it/openrtb2/openx/test-cache-matcher-openx.json @@ -5,4 +5,4 @@ "600527796@5.78": "bdf4b96c-3d1a-4c92-b8da-aece5d514e0b", "adm002": "857b3394-c5ac-402c-9cca-54ae52b927fc", "adm003": "18b7676c-f024-4a06-aa1a-5d222a643603" -} \ No newline at end of file +} diff --git a/src/test/resources/org/prebid/server/it/openrtb2/openx/test-cache-openx-request.json b/src/test/resources/org/prebid/server/it/openrtb2/openx/test-cache-openx-request.json index 1184361e515..de9ff41f810 100644 --- a/src/test/resources/org/prebid/server/it/openrtb2/openx/test-cache-openx-request.json +++ b/src/test/resources/org/prebid/server/it/openrtb2/openx/test-cache-openx-request.json @@ -59,4 +59,4 @@ "expiry": 120 } ] -} \ No newline at end of file +} diff --git a/src/test/resources/org/prebid/server/it/openrtb2/pubnative/test-cache-matcher-pubnative.json b/src/test/resources/org/prebid/server/it/openrtb2/pubnative/test-cache-matcher-pubnative.json new file mode 100644 index 00000000000..7ed22ca2abf --- /dev/null +++ b/src/test/resources/org/prebid/server/it/openrtb2/pubnative/test-cache-matcher-pubnative.json @@ -0,0 +1,6 @@ +{ + "bid001@3.33": "f3518368-72c3-42db-99f5-44c249eb92d3", + "bid002@6.66": "62ed47ac-b5d0-4526-957a-f928a0349c32", + "bid003@9.99": "4be8fb3d-18dc-4759-ac9f-aa633bced257", + "adm002": "88ec8e12-07cc-4c36-b7ab-8982b6ab104e" +} diff --git a/src/test/resources/org/prebid/server/it/openrtb2/pubnative/test-cache-pubnative-response.json b/src/test/resources/org/prebid/server/it/openrtb2/pubnative/test-cache-pubnative-response.json deleted file mode 100644 index 67dd4a9533b..00000000000 --- a/src/test/resources/org/prebid/server/it/openrtb2/pubnative/test-cache-pubnative-response.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "responses": [ - { - "uuid": "f3518368-72c3-42db-99f5-44c249eb92d3" - }, - { - "uuid": "62ed47ac-b5d0-4526-957a-f928a0349c32" - }, - { - "uuid": "4be8fb3d-18dc-4759-ac9f-aa633bced257" - }, - { - "uuid": "88ec8e12-07cc-4c36-b7ab-8982b6ab104e" - } - ] -} \ No newline at end of file diff --git a/src/test/resources/org/prebid/server/it/openrtb2/pulsepoint/test-cache-matcher-pulsepoint.json b/src/test/resources/org/prebid/server/it/openrtb2/pulsepoint/test-cache-matcher-pulsepoint.json new file mode 100644 index 00000000000..6581f961cef --- /dev/null +++ b/src/test/resources/org/prebid/server/it/openrtb2/pulsepoint/test-cache-matcher-pulsepoint.json @@ -0,0 +1,4 @@ +{ + "bidId01@4.75": "b537fcb1-28c9-4cd1-bf74-abc7730fd1f4", + "bidId02@3.75": "a4073156-828d-4a22-acdc-84dc4529149e" +} diff --git a/src/test/resources/org/prebid/server/it/openrtb2/pulsepoint/test-cache-pulsepoint-response.json b/src/test/resources/org/prebid/server/it/openrtb2/pulsepoint/test-cache-pulsepoint-response.json deleted file mode 100644 index 026d84f1381..00000000000 --- a/src/test/resources/org/prebid/server/it/openrtb2/pulsepoint/test-cache-pulsepoint-response.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "responses": [ - { - "uuid": "b537fcb1-28c9-4cd1-bf74-abc7730fd1f4" - }, - { - "uuid": "a4073156-828d-4a22-acdc-84dc4529149e" - } - ] -} \ No newline at end of file diff --git a/src/test/resources/org/prebid/server/it/openrtb2/rhythmone/test-cache-matcher-rhythmone.json b/src/test/resources/org/prebid/server/it/openrtb2/rhythmone/test-cache-matcher-rhythmone.json new file mode 100644 index 00000000000..40dd0559b18 --- /dev/null +++ b/src/test/resources/org/prebid/server/it/openrtb2/rhythmone/test-cache-matcher-rhythmone.json @@ -0,0 +1,4 @@ +{ + "bid01@2.25": "d45814b5-1a3d-4864-bc65-8076b162cb48", + "adm002": "c2bab0d6-3a78-473d-ba1f-340ed92779d2" +} diff --git a/src/test/resources/org/prebid/server/it/openrtb2/rhythmone/test-cache-rhythmone-response.json b/src/test/resources/org/prebid/server/it/openrtb2/rhythmone/test-cache-rhythmone-response.json deleted file mode 100644 index 83990e379ac..00000000000 --- a/src/test/resources/org/prebid/server/it/openrtb2/rhythmone/test-cache-rhythmone-response.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "responses": [ - { - "uuid": "d45814b5-1a3d-4864-bc65-8076b162cb48" - }, - { - "uuid": "c2bab0d6-3a78-473d-ba1f-340ed92779d2" - } - ] -} \ No newline at end of file diff --git a/src/test/resources/org/prebid/server/it/openrtb2/rubicon_appnexus/test-auction-rubicon-appnexus-response.json b/src/test/resources/org/prebid/server/it/openrtb2/rubicon_appnexus/test-auction-rubicon-appnexus-response.json index 99dc0964de7..eec6b168bc7 100644 --- a/src/test/resources/org/prebid/server/it/openrtb2/rubicon_appnexus/test-auction-rubicon-appnexus-response.json +++ b/src/test/resources/org/prebid/server/it/openrtb2/rubicon_appnexus/test-auction-rubicon-appnexus-response.json @@ -30,8 +30,8 @@ } }, "events": { - "win": "http://localhost:8080/event?t=win&b=a121a07f-1579-4465-bc5e-5c5b02a0c421&a=5001&ts=1000&bidder=appnexus&f=i&int=dmbjs", - "imp": "http://localhost:8080/event?t=imp&b=a121a07f-1579-4465-bc5e-5c5b02a0c421&a=5001&ts=1000&bidder=appnexus&f=i&int=dmbjs" + "win": "{{ event.url }}t=win&b=a121a07f-1579-4465-bc5e-5c5b02a0c421&a=5001&ts=1000&bidder=appnexus&f=i&int=dmbjs", + "imp": "{{ event.url }}t=imp&b=a121a07f-1579-4465-bc5e-5c5b02a0c421&a=5001&ts=1000&bidder=appnexus&f=i&int=dmbjs" } } } @@ -68,8 +68,8 @@ "hb_cache_path_appnexus": "{{ cache.path }}" }, "events": { - "win": "http://localhost:8080/event?t=win&b=7706636740145184841&a=5001&ts=1000&bidder=appnexus&f=i&int=dmbjs", - "imp": "http://localhost:8080/event?t=imp&b=7706636740145184841&a=5001&ts=1000&bidder=appnexus&f=i&int=dmbjs" + "win": "{{ event.url }}t=win&b=7706636740145184841&a=5001&ts=1000&bidder=appnexus&f=i&int=dmbjs", + "imp": "{{ event.url }}t=imp&b=7706636740145184841&a=5001&ts=1000&bidder=appnexus&f=i&int=dmbjs" }, "cache": { "bids": { @@ -120,8 +120,8 @@ "hb_cache_path_appnexus": "{{ cache.path }}" }, "events": { - "win": "http://localhost:8080/event?t=win&b=928185755156387460&a=5001&ts=1000&bidder=appnexus&f=i&int=dmbjs", - "imp": "http://localhost:8080/event?t=imp&b=928185755156387460&a=5001&ts=1000&bidder=appnexus&f=i&int=dmbjs" + "win": "{{ event.url }}t=win&b=928185755156387460&a=5001&ts=1000&bidder=appnexus&f=i&int=dmbjs", + "imp": "{{ event.url }}t=imp&b=928185755156387460&a=5001&ts=1000&bidder=appnexus&f=i&int=dmbjs" }, "cache": { "bids": { @@ -174,8 +174,8 @@ "hb_cache_path_appnexusAlias": "{{ cache.path }}" }, "events": { - "win": "http://localhost:8080/event?t=win&b=7706636740145184840&a=5001&ts=1000&bidder=appnexusAlias&f=i&int=dmbjs", - "imp": "http://localhost:8080/event?t=imp&b=7706636740145184840&a=5001&ts=1000&bidder=appnexusAlias&f=i&int=dmbjs" + "win": "{{ event.url }}t=win&b=7706636740145184840&a=5001&ts=1000&bidder=appnexusAlias&f=i&int=dmbjs", + "imp": "{{ event.url }}t=imp&b=7706636740145184840&a=5001&ts=1000&bidder=appnexusAlias&f=i&int=dmbjs" }, "cache": { "bids": { @@ -229,8 +229,8 @@ } }, "events": { - "win": "http://localhost:8080/event?t=win&b=f227a07f-1579-4465-bc5e-5c5b02a0c181&a=5001&ts=1000&bidder=rubicon&f=i&int=dmbjs", - "imp": "http://localhost:8080/event?t=imp&b=f227a07f-1579-4465-bc5e-5c5b02a0c181&a=5001&ts=1000&bidder=rubicon&f=i&int=dmbjs" + "win": "{{ event.url }}t=win&b=f227a07f-1579-4465-bc5e-5c5b02a0c181&a=5001&ts=1000&bidder=rubicon&f=i&int=dmbjs", + "imp": "{{ event.url }}t=imp&b=f227a07f-1579-4465-bc5e-5c5b02a0c181&a=5001&ts=1000&bidder=rubicon&f=i&int=dmbjs" } } } @@ -257,8 +257,8 @@ } }, "events": { - "win": "http://localhost:8080/event?t=win&b=f227a07f-1579-4465-bc5e-5c5b02a0c180&a=5001&ts=1000&bidder=rubicon&f=i&int=dmbjs", - "imp": "http://localhost:8080/event?t=imp&b=f227a07f-1579-4465-bc5e-5c5b02a0c180&a=5001&ts=1000&bidder=rubicon&f=i&int=dmbjs" + "win": "{{ event.url }}t=win&b=f227a07f-1579-4465-bc5e-5c5b02a0c180&a=5001&ts=1000&bidder=rubicon&f=i&int=dmbjs", + "imp": "{{ event.url }}t=imp&b=f227a07f-1579-4465-bc5e-5c5b02a0c180&a=5001&ts=1000&bidder=rubicon&f=i&int=dmbjs" } } } @@ -267,7 +267,7 @@ "id": "880290288", "impid": "impId1", "price": 8.43, - "adm": "<\/Impression>", + "adm": "", "crid": "crid1", "w": 300, "h": 250, @@ -292,8 +292,8 @@ "hb_cache_path_rubicon": "{{ cache.path }}" }, "events": { - "win": "http://localhost:8080/event?t=win&b=880290288&a=5001&ts=1000&bidder=rubicon&f=i&int=dmbjs", - "imp": "http://localhost:8080/event?t=imp&b=880290288&a=5001&ts=1000&bidder=rubicon&f=i&int=dmbjs" + "win": "{{ event.url }}t=win&b=880290288&a=5001&ts=1000&bidder=rubicon&f=i&int=dmbjs", + "imp": "{{ event.url }}t=imp&b=880290288&a=5001&ts=1000&bidder=rubicon&f=i&int=dmbjs" }, "cache": { "vastXml": { @@ -346,8 +346,8 @@ "hb_cache_path_rubicon": "{{ cache.path }}" }, "events": { - "win": "http://localhost:8080/event?t=win&b=466223845&a=5001&ts=1000&bidder=rubicon&f=i&int=dmbjs", - "imp": "http://localhost:8080/event?t=imp&b=466223845&a=5001&ts=1000&bidder=rubicon&f=i&int=dmbjs" + "win": "{{ event.url }}t=win&b=466223845&a=5001&ts=1000&bidder=rubicon&f=i&int=dmbjs", + "imp": "{{ event.url }}t=imp&b=466223845&a=5001&ts=1000&bidder=rubicon&f=i&int=dmbjs" }, "cache": { "bids": { @@ -788,4 +788,4 @@ }, "tmaxrequest": 5000 } -} \ No newline at end of file +} diff --git a/src/test/resources/org/prebid/server/it/openrtb2/rubicon_appnexus/test-cache-matcher-rubicon-appnexus.json b/src/test/resources/org/prebid/server/it/openrtb2/rubicon_appnexus/test-cache-matcher-rubicon-appnexus.json index 6465c55bfce..fff3bdb9693 100644 --- a/src/test/resources/org/prebid/server/it/openrtb2/rubicon_appnexus/test-cache-matcher-rubicon-appnexus.json +++ b/src/test/resources/org/prebid/server/it/openrtb2/rubicon_appnexus/test-cache-matcher-rubicon-appnexus.json @@ -8,4 +8,4 @@ "f227a07f-1579-4465-bc5e-5c5b02a0c180@0.8": "c75130ed-bcdd-4821-ad91-90cf835615c5", "a121a07f-1579-4465-bc5e-5c5b02a0c421@0.9": "765e116a-5773-49d5-a648-0b97a9907a4e", "f227a07f-1579-4465-bc5e-5c5b02a0c181@0.8": "734b7948-e41d-4c14-b2c3-c31634b32376" -} \ No newline at end of file +} diff --git a/src/test/resources/org/prebid/server/it/openrtb2/rubicon_appnexus/test-cache-rubicon-appnexus-request.json b/src/test/resources/org/prebid/server/it/openrtb2/rubicon_appnexus/test-cache-rubicon-appnexus-request.json index aad30dbaf2f..fdacf300534 100644 --- a/src/test/resources/org/prebid/server/it/openrtb2/rubicon_appnexus/test-cache-rubicon-appnexus-request.json +++ b/src/test/resources/org/prebid/server/it/openrtb2/rubicon_appnexus/test-cache-rubicon-appnexus-request.json @@ -1,5 +1,18 @@ { "puts": [ + { + "type": "json", + "value": { + "id": "466223845", + "impid": "impId2", + "price": 4.26, + "adm": "adm2", + "crid": "crid2", + "w": 300, + "h": 600, + "wurl": "http://localhost:8080/event?t=win&b=466223845&a=5001&ts=1000&bidder=rubicon&f=i&int=dmbjs" + } + }, { "type": "json", "value": { @@ -33,24 +46,29 @@ { "type": "json", "value": { - "id": "466223845", - "impid": "impId2", - "price": 4.26, - "adm": "adm2", - "crid": "crid2", + "id": "7706636740145184841", + "impid": "impId3", + "price": 5.5, + "adm": "some-test-ad", + "adid": "29681110", + "adomain": [ + "appnexus.com" + ], + "iurl": "http://nym1-ib.adnxs.com/cr?id=29681110", + "cid": "958", + "crid": "29681110", "w": 300, - "h": 600, - "wurl": "http://localhost:8080/event?t=win&b=466223845&a=5001&ts=1000&bidder=rubicon&f=i&int=dmbjs" - } - }, - { - "type": "json", - "value": { - "id": "a121a07f-1579-4465-bc5e-5c5b02a0c421", - "impid": "impStoredAuctionResponse", - "crid": "crid1", - "price": 0.9, - "wurl": "http://localhost:8080/event?t=win&b=a121a07f-1579-4465-bc5e-5c5b02a0c421&a=5001&ts=1000&bidder=appnexus&f=i&int=dmbjs" + "h": 250, + "wurl": "http://localhost:8080/event?t=win&b=7706636740145184841&a=5001&ts=1000&bidder=appnexus&f=i&int=dmbjs", + "ext": { + "appnexus": { + "brand_id": 1, + "auction_id": 8189378542222915032, + "bidder_id": 2, + "bid_ad_type": 0, + "ranking_price": 0.0 + } + } } }, { @@ -78,26 +96,6 @@ } } }, - { - "type": "json", - "value": { - "id": "f227a07f-1579-4465-bc5e-5c5b02a0c180", - "impid": "impStoredAuctionResponse", - "crid": "crid1", - "price": 0.8, - "wurl": "http://localhost:8080/event?t=win&b=f227a07f-1579-4465-bc5e-5c5b02a0c180&a=5001&ts=1000&bidder=rubicon&f=i&int=dmbjs" - } - }, - { - "type": "json", - "value": { - "id": "f227a07f-1579-4465-bc5e-5c5b02a0c181", - "impid": "impStoredBidResponse", - "crid": "crid1", - "price": 0.8, - "wurl": "http://localhost:8080/event?t=win&b=f227a07f-1579-4465-bc5e-5c5b02a0c181&a=5001&ts=1000&bidder=rubicon&f=i&int=dmbjs" - } - }, { "type": "json", "value": { @@ -130,29 +128,31 @@ { "type": "json", "value": { - "id": "7706636740145184841", - "impid": "impId3", - "price": 5.5, - "adm": "some-test-ad", - "adid": "29681110", - "adomain": [ - "appnexus.com" - ], - "iurl": "http://nym1-ib.adnxs.com/cr?id=29681110", - "cid": "958", - "crid": "29681110", - "w": 300, - "h": 250, - "wurl": "http://localhost:8080/event?t=win&b=7706636740145184841&a=5001&ts=1000&bidder=appnexus&f=i&int=dmbjs", - "ext": { - "appnexus": { - "brand_id": 1, - "auction_id": 8189378542222915032, - "bidder_id": 2, - "bid_ad_type": 0, - "ranking_price": 0.0 - } - } + "id": "a121a07f-1579-4465-bc5e-5c5b02a0c421", + "impid": "impStoredAuctionResponse", + "crid": "crid1", + "price": 0.9, + "wurl": "http://localhost:8080/event?t=win&b=a121a07f-1579-4465-bc5e-5c5b02a0c421&a=5001&ts=1000&bidder=appnexus&f=i&int=dmbjs" + } + }, + { + "type": "json", + "value": { + "id": "f227a07f-1579-4465-bc5e-5c5b02a0c180", + "impid": "impStoredAuctionResponse", + "crid": "crid1", + "price": 0.8, + "wurl": "http://localhost:8080/event?t=win&b=f227a07f-1579-4465-bc5e-5c5b02a0c180&a=5001&ts=1000&bidder=rubicon&f=i&int=dmbjs" + } + }, + { + "type": "json", + "value": { + "id": "f227a07f-1579-4465-bc5e-5c5b02a0c181", + "impid": "impStoredBidResponse", + "crid": "crid1", + "price": 0.8, + "wurl": "http://localhost:8080/event?t=win&b=f227a07f-1579-4465-bc5e-5c5b02a0c181&a=5001&ts=1000&bidder=rubicon&f=i&int=dmbjs" } }, { diff --git a/src/test/resources/org/prebid/server/it/openrtb2/smartrtb/test-auction-smartrtb-response.json b/src/test/resources/org/prebid/server/it/openrtb2/smartrtb/test-auction-smartrtb-response.json index e8dcb65eb06..651a7c8f18f 100644 --- a/src/test/resources/org/prebid/server/it/openrtb2/smartrtb/test-auction-smartrtb-response.json +++ b/src/test/resources/org/prebid/server/it/openrtb2/smartrtb/test-auction-smartrtb-response.json @@ -13,18 +13,18 @@ "cache": { "bids": { "cacheId": "f0ab9105-cb21-4e59-b433-70f5ad6671cb", - "url": "http://localhost:8090/cache?uuid=f0ab9105-cb21-4e59-b433-70f5ad6671cb" + "url": "{{ cache.resource_url }}f0ab9105-cb21-4e59-b433-70f5ad6671cb" } }, "targeting": { "hb_bidder": "smartrtb", "hb_bidder_smartrtb": "smartrtb", - "hb_cache_host": "localhost:8090", - "hb_cache_host_smartrtb": "localhost:8090", + "hb_cache_host": "{{ cache.host }}", + "hb_cache_host_smartrtb": "{{ cache.host }}", "hb_cache_id": "f0ab9105-cb21-4e59-b433-70f5ad6671cb", "hb_cache_id_smartrtb": "f0ab9105-cb21-4e59-b433-70f5ad6671cb", - "hb_cache_path": "/cache", - "hb_cache_path_smartrtb": "/cache", + "hb_cache_path": "{{ cache.path }}", + "hb_cache_path_smartrtb": "{{ cache.path }}", "hb_pb": "0.00", "hb_pb_smartrtb": "0.00" }, diff --git a/src/test/resources/org/prebid/server/it/openrtb2/sonobi/test-cache-matcher-sonobi.json b/src/test/resources/org/prebid/server/it/openrtb2/sonobi/test-cache-matcher-sonobi.json new file mode 100644 index 00000000000..e438661be9f --- /dev/null +++ b/src/test/resources/org/prebid/server/it/openrtb2/sonobi/test-cache-matcher-sonobi.json @@ -0,0 +1,5 @@ +{ + "bid001@1.25": "9092799c-93b0-4e11-a232-2c0151d5d275", + "bid01@2.25": "83cdc325-c816-4d2e-bf2c-9213a70671dd", + "adm002": "99dc3357-34ac-4819-9f68-0820039a542f" +} diff --git a/src/test/resources/org/prebid/server/it/openrtb2/sonobi/test-cache-sonobi-response.json b/src/test/resources/org/prebid/server/it/openrtb2/sonobi/test-cache-sonobi-response.json deleted file mode 100644 index c6317eb6c8c..00000000000 --- a/src/test/resources/org/prebid/server/it/openrtb2/sonobi/test-cache-sonobi-response.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "responses": [ - { - "uuid": "9092799c-93b0-4e11-a232-2c0151d5d275" - }, - { - "uuid": "83cdc325-c816-4d2e-bf2c-9213a70671dd" - }, - { - "uuid": "99dc3357-34ac-4819-9f68-0820039a542f" - } - ] -} \ No newline at end of file diff --git a/src/test/resources/org/prebid/server/it/openrtb2/synacormedia/test-auction-synacormedia-response.json b/src/test/resources/org/prebid/server/it/openrtb2/synacormedia/test-auction-synacormedia-response.json index f1c56c156c3..d289c467330 100644 --- a/src/test/resources/org/prebid/server/it/openrtb2/synacormedia/test-auction-synacormedia-response.json +++ b/src/test/resources/org/prebid/server/it/openrtb2/synacormedia/test-auction-synacormedia-response.json @@ -46,6 +46,8 @@ "adomain": [ "psacentral.org" ], + "nurl": "https://example.com/nurl", + "adm": "prebid.org wrapper", "cid": "cid002", "crid": "crid002", "w": 300, diff --git a/src/test/resources/org/prebid/server/it/openrtb2/synacormedia/test-cache-matcher-synacormedia.json b/src/test/resources/org/prebid/server/it/openrtb2/synacormedia/test-cache-matcher-synacormedia.json new file mode 100644 index 00000000000..82125ce1b1b --- /dev/null +++ b/src/test/resources/org/prebid/server/it/openrtb2/synacormedia/test-cache-matcher-synacormedia.json @@ -0,0 +1,5 @@ +{ + "bid001@7.77": "c1662cf6-f00a-4066-b71a-46d97abccc35", + "bid002@9.99": "dbaa191c-5a56-4655-85eb-da079f94e09f", + "prebid.org wrapper": "62019cff-d657-42fc-8366-16c34e1fd28c" +} diff --git a/src/test/resources/org/prebid/server/it/openrtb2/synacormedia/test-cache-synacormedia-request.json b/src/test/resources/org/prebid/server/it/openrtb2/synacormedia/test-cache-synacormedia-request.json index c76c7256d07..d22654a542b 100644 --- a/src/test/resources/org/prebid/server/it/openrtb2/synacormedia/test-cache-synacormedia-request.json +++ b/src/test/resources/org/prebid/server/it/openrtb2/synacormedia/test-cache-synacormedia-request.json @@ -23,6 +23,7 @@ "adomain": [ "psacentral.org" ], + "nurl": "https://example.com/nurl", "cid": "cid002", "crid": "crid002", "w": 300, @@ -31,8 +32,8 @@ }, { "type": "xml", - "value": "prebid.org wrapper", + "value": "prebid.org wrapper", "expiry": 120 } ] -} \ No newline at end of file +} diff --git a/src/test/resources/org/prebid/server/it/openrtb2/synacormedia/test-cache-synacormedia-response.json b/src/test/resources/org/prebid/server/it/openrtb2/synacormedia/test-cache-synacormedia-response.json deleted file mode 100644 index babbed58d14..00000000000 --- a/src/test/resources/org/prebid/server/it/openrtb2/synacormedia/test-cache-synacormedia-response.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "responses": [ - { - "uuid": "c1662cf6-f00a-4066-b71a-46d97abccc35" - }, - { - "uuid": "dbaa191c-5a56-4655-85eb-da079f94e09f" - }, - { - "uuid": "62019cff-d657-42fc-8366-16c34e1fd28c" - } - ] -} \ No newline at end of file diff --git a/src/test/resources/org/prebid/server/it/openrtb2/synacormedia/test-synacormedia-bid-response.json b/src/test/resources/org/prebid/server/it/openrtb2/synacormedia/test-synacormedia-bid-response.json index f1db668198e..481e9387f2b 100644 --- a/src/test/resources/org/prebid/server/it/openrtb2/synacormedia/test-synacormedia-bid-response.json +++ b/src/test/resources/org/prebid/server/it/openrtb2/synacormedia/test-synacormedia-bid-response.json @@ -20,6 +20,7 @@ "price": 9.99, "crid": "crid002", "cid": "cid002", + "nurl": "https://example.com/nurl", "adomain": [ "psacentral.org" ], @@ -30,4 +31,4 @@ "seat": "synacormedia" } ] -} \ No newline at end of file +} diff --git a/src/test/resources/org/prebid/server/it/openrtb2/telaria/test-cache-matcher-telaria.json b/src/test/resources/org/prebid/server/it/openrtb2/telaria/test-cache-matcher-telaria.json new file mode 100644 index 00000000000..0aef0eecca2 --- /dev/null +++ b/src/test/resources/org/prebid/server/it/openrtb2/telaria/test-cache-matcher-telaria.json @@ -0,0 +1,4 @@ +{ + "1@0.01": "9c0c4f2f-686f-4673-a00a-d8cae7e7a05d", + "hi": "0553c675-4afc-431a-b22c-0ea9cc01977e" +} diff --git a/src/test/resources/org/prebid/server/it/openrtb2/telaria/test-cache-telaria-response.json b/src/test/resources/org/prebid/server/it/openrtb2/telaria/test-cache-telaria-response.json deleted file mode 100644 index 1ec0c1e0b5a..00000000000 --- a/src/test/resources/org/prebid/server/it/openrtb2/telaria/test-cache-telaria-response.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "responses": [ - { - "uuid": "9c0c4f2f-686f-4673-a00a-d8cae7e7a05d" - }, - { - "uuid": "0553c675-4afc-431a-b22c-0ea9cc01977e" - } - ] -} diff --git a/src/test/resources/org/prebid/server/it/openrtb2/triplelift/test-auction-triplelift-response.json b/src/test/resources/org/prebid/server/it/openrtb2/triplelift/test-auction-triplelift-response.json index c06053eea40..70132708685 100644 --- a/src/test/resources/org/prebid/server/it/openrtb2/triplelift/test-auction-triplelift-response.json +++ b/src/test/resources/org/prebid/server/it/openrtb2/triplelift/test-auction-triplelift-response.json @@ -36,7 +36,7 @@ }, "cache": { "bids": { - "url": "http://localhost:8090/cache?uuid=5b9f507f-2ae9-4111-a697-796f3174df10", + "url": "{{ cache.resource_url }}5b9f507f-2ae9-4111-a697-796f3174df10", "cacheId": "5b9f507f-2ae9-4111-a697-796f3174df10" } } diff --git a/src/test/resources/org/prebid/server/it/openrtb2/tripleliftnative/test-auction-triplelift-native-response.json b/src/test/resources/org/prebid/server/it/openrtb2/tripleliftnative/test-auction-triplelift-native-response.json index 1e9e509aa44..c41297924c0 100644 --- a/src/test/resources/org/prebid/server/it/openrtb2/tripleliftnative/test-auction-triplelift-native-response.json +++ b/src/test/resources/org/prebid/server/it/openrtb2/tripleliftnative/test-auction-triplelift-native-response.json @@ -36,7 +36,7 @@ }, "cache": { "bids": { - "url": "http://localhost:8090/cache?uuid=029e95ca-1a14-4e45-9669-8ad8d667de50", + "url": "{{ cache.resource_url }}029e95ca-1a14-4e45-9669-8ad8d667de50", "cacheId": "029e95ca-1a14-4e45-9669-8ad8d667de50" } } diff --git a/src/test/resources/org/prebid/server/it/openrtb2/unruly/test-cache-matcher-unruly.json b/src/test/resources/org/prebid/server/it/openrtb2/unruly/test-cache-matcher-unruly.json new file mode 100644 index 00000000000..c6855eb43a2 --- /dev/null +++ b/src/test/resources/org/prebid/server/it/openrtb2/unruly/test-cache-matcher-unruly.json @@ -0,0 +1,6 @@ +{ + "bid001@1.25": "d7ec26d4-4336-4661-988a-79e96040e281", + "bid002@2.25": "51c3e63e-5ece-4d16-b781-4314ce9e3ea8", + "adm001": "54a3b0a5-e145-43cf-a1cc-1beaa8b29018", + "adm002": "41c08fce-546f-4a57-a657-1158fd62af3d" +} diff --git a/src/test/resources/org/prebid/server/it/openrtb2/unruly/test-cache-unruly-response.json b/src/test/resources/org/prebid/server/it/openrtb2/unruly/test-cache-unruly-response.json deleted file mode 100644 index 67a7f6b9984..00000000000 --- a/src/test/resources/org/prebid/server/it/openrtb2/unruly/test-cache-unruly-response.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "responses": [ - { - "uuid": "d7ec26d4-4336-4661-988a-79e96040e281" - }, - { - "uuid": "51c3e63e-5ece-4d16-b781-4314ce9e3ea8" - }, - { - "uuid": "54a3b0a5-e145-43cf-a1cc-1beaa8b29018" - }, - { - "uuid": "41c08fce-546f-4a57-a657-1158fd62af3d" - } - ] -} \ No newline at end of file diff --git a/src/test/resources/org/prebid/server/it/openrtb2/valueimpression/test-cache-matcher-valueimpression.json b/src/test/resources/org/prebid/server/it/openrtb2/valueimpression/test-cache-matcher-valueimpression.json new file mode 100644 index 00000000000..1dacfb73925 --- /dev/null +++ b/src/test/resources/org/prebid/server/it/openrtb2/valueimpression/test-cache-matcher-valueimpression.json @@ -0,0 +1,5 @@ +{ + "bid001@3.33": "f0ab9105-cb21-4e59-b433-70f5ad6671cb", + "bid002@5.55": "e7965b2e-0aa3-4252-a22c-580ed010e619", + "adm002": "44a52b06-b29f-4819-a05f-db36b9e7b8fc" +} diff --git a/src/test/resources/org/prebid/server/it/openrtb2/valueimpression/test-cache-valueimpression-response.json b/src/test/resources/org/prebid/server/it/openrtb2/valueimpression/test-cache-valueimpression-response.json deleted file mode 100644 index 7d2718f9414..00000000000 --- a/src/test/resources/org/prebid/server/it/openrtb2/valueimpression/test-cache-valueimpression-response.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "responses": [ - { - "uuid": "f0ab9105-cb21-4e59-b433-70f5ad6671cb" - }, - { - "uuid": "e7965b2e-0aa3-4252-a22c-580ed010e619" - }, - { - "uuid": "44a52b06-b29f-4819-a05f-db36b9e7b8fc" - } - ] -} \ No newline at end of file diff --git a/src/test/resources/org/prebid/server/it/openrtb2/video/test-video-appnexus-bid-response-1.json b/src/test/resources/org/prebid/server/it/openrtb2/video/test-video-appnexus-bid-response-1.json index 32918264dbe..ba91140a988 100644 --- a/src/test/resources/org/prebid/server/it/openrtb2/video/test-video-appnexus-bid-response-1.json +++ b/src/test/resources/org/prebid/server/it/openrtb2/video/test-video-appnexus-bid-response-1.json @@ -21,7 +21,7 @@ "brand_id": 1, "auction_id": 8189378542222915032, "bidder_id": 2, - "bid_ad_type": 0, + "bid_ad_type": 1, "ranking_price": 0.000000 } } @@ -43,7 +43,7 @@ "brand_id": 1, "auction_id": 8189378542222915032, "bidder_id": 2, - "bid_ad_type": 0, + "bid_ad_type": 1, "ranking_price": 0.000000 } } diff --git a/src/test/resources/org/prebid/server/it/openrtb2/video/test-video-appnexus-bid-response-2.json b/src/test/resources/org/prebid/server/it/openrtb2/video/test-video-appnexus-bid-response-2.json index dca41a64f02..0133a69bdfa 100644 --- a/src/test/resources/org/prebid/server/it/openrtb2/video/test-video-appnexus-bid-response-2.json +++ b/src/test/resources/org/prebid/server/it/openrtb2/video/test-video-appnexus-bid-response-2.json @@ -21,7 +21,7 @@ "brand_id": 1, "auction_id": 8189378542222915032, "bidder_id": 2, - "bid_ad_type": 0, + "bid_ad_type": 1, "ranking_price": 0.000000 } } diff --git a/src/test/resources/org/prebid/server/it/openrtb2/zeroclickfraud/test-auction-zeroclickfraud-response.json b/src/test/resources/org/prebid/server/it/openrtb2/zeroclickfraud/test-auction-zeroclickfraud-response.json index e4bd8fe0950..50684d8fff8 100644 --- a/src/test/resources/org/prebid/server/it/openrtb2/zeroclickfraud/test-auction-zeroclickfraud-response.json +++ b/src/test/resources/org/prebid/server/it/openrtb2/zeroclickfraud/test-auction-zeroclickfraud-response.json @@ -10,6 +10,8 @@ "adomain": [ "psacentral.org" ], + "nurl": "https://example.com/nurl", + "adm": "prebid.org wrapper", "cid": "cid002", "crid": "crid002", "w": 300, @@ -95,7 +97,7 @@ "cache": [ { "uri": "{{ cache.endpoint }}", - "requestbody": "{\"puts\":[{\"type\":\"json\",\"value\":{\"id\":\"bid001\",\"impid\":\"impId001\",\"price\":7.77,\"adm\":\"adm001\",\"adid\":\"adid001\",\"cid\":\"cid001\",\"crid\":\"crid001\",\"w\":300,\"h\":250}},{\"type\":\"json\",\"value\":{\"id\":\"bid002\",\"impid\":\"impId002\",\"price\":9.99,\"adomain\":[\"psacentral.org\"],\"cid\":\"cid002\",\"crid\":\"crid002\",\"w\":300,\"h\":250}},{\"type\":\"xml\",\"value\":\"prebid.org wrapper\",\"expiry\":120}]}", + "requestbody": "{\"puts\":[{\"type\":\"json\",\"value\":{\"id\":\"bid001\",\"impid\":\"impId001\",\"price\":7.77,\"adm\":\"adm001\",\"adid\":\"adid001\",\"cid\":\"cid001\",\"crid\":\"crid001\",\"w\":300,\"h\":250}},{\"type\":\"json\",\"value\":{\"id\":\"bid002\",\"impid\":\"impId002\",\"price\":9.99,\"nurl\":\"https://example.com/nurl\",\"adomain\":[\"psacentral.org\"],\"cid\":\"cid002\",\"crid\":\"crid002\",\"w\":300,\"h\":250}},{\"type\":\"xml\",\"value\":\"prebid.org wrapper\",\"expiry\":120}]}", "responsebody": "{\"responses\":[{\"uuid\":\"c1662cf6-f00a-4066-b71a-46d97abccc35\"},{\"uuid\":\"dbaa191c-5a56-4655-85eb-da079f94e09f\"},{\"uuid\":\"62019cff-d657-42fc-8366-16c34e1fd28c\"}]}", "status": 200 } @@ -104,7 +106,7 @@ { "uri": "{{ zeroclickfraud.exchange_uri }}?sid=2", "requestbody": "{\"id\":\"tid\",\"imp\":[{\"id\":\"impId002\",\"video\":{\"mimes\":[\"video/mp4\"],\"w\":300,\"h\":250,\"pos\":1},\"ext\":{\"bidder\":{\"host\":\"localhost:8090\",\"sourceId\":2}}}],\"site\":{\"domain\":\"example.com\",\"page\":\"http://www.example.com\",\"publisher\":{\"id\":\"publisherId\"},\"ext\":{\"amp\":0}},\"device\":{\"ua\":\"userAgent\",\"dnt\":2,\"ip\":\"193.168.244.1\",\"pxratio\":4.2,\"language\":\"en\",\"ifa\":\"ifaId\"},\"user\":{\"buyeruid\":\"ZF-UID\",\"ext\":{\"consent\":\"consentValue\"}},\"at\":1,\"tmax\":5000,\"cur\":[\"USD\"],\"source\":{\"fd\":1,\"tid\":\"tid\"},\"regs\":{\"ext\":{\"gdpr\":0}},\"ext\":{\"prebid\":{\"debug\":1,\"currency\":{\"rates\":{\"EUR\":{\"USD\":1.2406},\"USD\":{\"EUR\":0.811}}},\"targeting\":{\"pricegranularity\":{\"precision\":2,\"ranges\":[{\"max\":20,\"increment\":0.1}]},\"includewinners\":true,\"includebidderkeys\":true},\"cache\":{\"bids\":{},\"vastxml\":{\"ttlseconds\":120}},\"auctiontimestamp\":1000,\"channel\":{\"name\":\"web\"}}}}", - "responsebody": "{\"id\":\"tid\",\"seatbid\":[{\"bid\":[{\"id\":\"bid002\",\"impid\":\"impId002\",\"price\":9.99,\"crid\":\"crid002\",\"cid\":\"cid002\",\"adomain\":[\"psacentral.org\"],\"h\":250,\"w\":300}],\"seat\":\"zeroclickfraud\"}]}", + "responsebody": "{\"id\":\"tid\",\"seatbid\":[{\"bid\":[{\"id\":\"bid002\",\"impid\":\"impId002\",\"price\":9.99,\"crid\":\"crid002\",\"cid\":\"cid002\",\"adomain\":[\"psacentral.org\"],\"nurl\":\"https://example.com/nurl\",\"h\":250,\"w\":300}],\"seat\":\"zeroclickfraud\"}]}", "status": 200 }, { diff --git a/src/test/resources/org/prebid/server/it/openrtb2/zeroclickfraud/test-cache-matcher-zeroclickfraud.json b/src/test/resources/org/prebid/server/it/openrtb2/zeroclickfraud/test-cache-matcher-zeroclickfraud.json new file mode 100644 index 00000000000..82125ce1b1b --- /dev/null +++ b/src/test/resources/org/prebid/server/it/openrtb2/zeroclickfraud/test-cache-matcher-zeroclickfraud.json @@ -0,0 +1,5 @@ +{ + "bid001@7.77": "c1662cf6-f00a-4066-b71a-46d97abccc35", + "bid002@9.99": "dbaa191c-5a56-4655-85eb-da079f94e09f", + "prebid.org wrapper": "62019cff-d657-42fc-8366-16c34e1fd28c" +} diff --git a/src/test/resources/org/prebid/server/it/openrtb2/zeroclickfraud/test-cache-zeroclickfraud-request.json b/src/test/resources/org/prebid/server/it/openrtb2/zeroclickfraud/test-cache-zeroclickfraud-request.json index c76c7256d07..d22654a542b 100644 --- a/src/test/resources/org/prebid/server/it/openrtb2/zeroclickfraud/test-cache-zeroclickfraud-request.json +++ b/src/test/resources/org/prebid/server/it/openrtb2/zeroclickfraud/test-cache-zeroclickfraud-request.json @@ -23,6 +23,7 @@ "adomain": [ "psacentral.org" ], + "nurl": "https://example.com/nurl", "cid": "cid002", "crid": "crid002", "w": 300, @@ -31,8 +32,8 @@ }, { "type": "xml", - "value": "prebid.org wrapper", + "value": "prebid.org wrapper", "expiry": 120 } ] -} \ No newline at end of file +} diff --git a/src/test/resources/org/prebid/server/it/openrtb2/zeroclickfraud/test-cache-zeroclickfraud-response.json b/src/test/resources/org/prebid/server/it/openrtb2/zeroclickfraud/test-cache-zeroclickfraud-response.json deleted file mode 100644 index babbed58d14..00000000000 --- a/src/test/resources/org/prebid/server/it/openrtb2/zeroclickfraud/test-cache-zeroclickfraud-response.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "responses": [ - { - "uuid": "c1662cf6-f00a-4066-b71a-46d97abccc35" - }, - { - "uuid": "dbaa191c-5a56-4655-85eb-da079f94e09f" - }, - { - "uuid": "62019cff-d657-42fc-8366-16c34e1fd28c" - } - ] -} \ No newline at end of file diff --git a/src/test/resources/org/prebid/server/it/openrtb2/zeroclickfraud/test-zeroclickfraud-bid-response-2.json b/src/test/resources/org/prebid/server/it/openrtb2/zeroclickfraud/test-zeroclickfraud-bid-response-2.json index f6b7a00684a..5b18a4be00d 100644 --- a/src/test/resources/org/prebid/server/it/openrtb2/zeroclickfraud/test-zeroclickfraud-bid-response-2.json +++ b/src/test/resources/org/prebid/server/it/openrtb2/zeroclickfraud/test-zeroclickfraud-bid-response-2.json @@ -12,6 +12,7 @@ "adomain": [ "psacentral.org" ], + "nurl": "https://example.com/nurl", "h": 250, "w": 300 } @@ -19,4 +20,4 @@ "seat": "zeroclickfraud" } ] -} \ No newline at end of file +} diff --git a/src/test/resources/org/prebid/server/it/util/bidcacherequestpattern/changed-put-bid-request.json b/src/test/resources/org/prebid/server/it/util/bidcacherequestpattern/changed-put-bid-request.json new file mode 100644 index 00000000000..ab4b4d39252 --- /dev/null +++ b/src/test/resources/org/prebid/server/it/util/bidcacherequestpattern/changed-put-bid-request.json @@ -0,0 +1,136 @@ +{ + "puts": [ + { + "type": "json", + "value": { + "id": "a121a07f-1579-4465-bc5e-5c5b02a0c421", + "impid": "impStoredAuctionResponse", + "crid": "crid1", + "price": 0.9, + "wurl": "http://localhost:8080/event?t=win&b=a121a07f-1579-4465-bc5e-5c5b02a0c421&a=5001&ts=1000&bidder=appnexus&f=i&int=dmbjs" + } + }, + { + "type": "json", + "value": { + "id": "f227a07f-1579-4465-bc5e-5c5b02a0c180", + "impid": "impIdWasChanged", + "crid": "crid1", + "price": 0.8, + "wurl": "http://localhost:8080/event?t=win&b=f227a07f-1579-4465-bc5e-5c5b02a0c180&a=5001&ts=1000&bidder=rubicon&f=i&int=dmbjs" + } + }, + { + "type": "json", + "value": { + "id": "f227a07f-1579-4465-bc5e-5c5b02a0c181", + "impid": "impStoredBidResponse", + "crid": "crid1", + "price": 0.8, + "wurl": "http://localhost:8080/event?t=win&b=f227a07f-1579-4465-bc5e-5c5b02a0c181&a=5001&ts=1000&bidder=rubicon&f=i&int=dmbjs" + } + }, + { + "type": "json", + "value": { + "id": "880290288", + "impid": "impId1", + "price": 8.43, + "adm": "", + "crid": "crid1", + "w": 300, + "h": 250, + "wurl": "http://localhost:8080/event?t=win&b=880290288&a=5001&ts=1000&bidder=rubicon&f=i&int=dmbjs", + "ext": { + "rp": { + "targeting": [ + { + "key": "rpfl_1001", + "values": [ + "2_tier0100" + ] + } + ] + } + } + } + }, + { + "type": "json", + "value": { + "id": "928185755156387460", + "impid": "impId131", + "price": 1, + "adm": "{\"assets\":[{\"id\":0,\"img\":{\"url\":\"http://vcdn.adnxs.com/p/creative-image/5e/b6/de/c3/5eb6dec3-4854-4dcd-980a-347f36ab502e.jpg\",\"w\":3000,\"h\":2250,\"ext\":{\"appnexus\":{\"prevent_crop\":0}}}},{\"id\":1,\"title\":{\"text\":\"This is an example Prebid Native creative\"}},{\"id\":2,\"data\":{\"value\":\"Prebid.org\"}},{\"id\":3,\"data\":{\"value\":\"ThisisaPrebidNativeCreative.Therearemanylikeit,butthisoneismine.\"}}],\"link\":{\"url\":\"http://nym1-ib.adnxs.com/click?AAAAAAAA8D8AAAAAAADwPwAAAAAAAAAAAAAAAAAA8D8AAAAAAADwPwhdYz3ZyNFNG3fXpZUyLXNZ0o5aAAAAACrElgC-AwAAvgMAAAIAAAC98iUEeP4QAAAAAABVU0QAVVNEAAEAAQARIAAAAAABAgQCAAAAAAEAhBaSXgAAAAA./pp=${AUCTION_PRICE}/cnd=%21OwwGAQiGmooHEL3llyEY-PxDIAQoADoRZGVmYXVsdCNOWU0yOjQwMjM./bn=75922/test=1/referrer=prebid.org/clickenc=http%3A%2F%2Fprebid.org%2Fdev-docs%2Fshow-native-ads.html\"},\"imptrackers\":[\"http://nym1-ib.adnxs.com/openrtb_win?e=wqT_3QLFBqBFAwAAAwDWAAUBCNmku9QFEIi6jeuTm_LoTRib7t2u2tLMlnMqNgkAAAECCPA_EQEHEAAA8D8ZCQkIAAAhCQkI8D8pEQkAMQkJqAAAMKqI2wQ4vgdAvgdIAlC95ZchWPj8Q2AAaJFAeJLRBIABAYoBA1VTRJIFBvBQmAEBoAEBqAEBsAEAuAECwAEEyAEC0AEJ2AEA4AEB8AEAigI7dWYoJ2EnLCAxMzc2ODYwLCAxNTE5MzA5NDAxKTt1ZigncicsIDY5NTk1ODM3Nh4A8IqSAvUBIXRETkdfUWlHbW9vSEVMM2xseUVZQUNENF9FTXdBRGdBUUFSSXZnZFFxb2piQkZnQVlMTURhQUJ3QUhnQWdBRUFpQUVBa0FFQm1BRUJvQUVCcUFFRHNBRUF1UUVwaTRpREFBRHdQOEVCS1l1SWd3QUE4RF9KQVhfelYzek1zXzBfMlFFQUFBAQMkRHdQLUFCQVBVQgEOLEFKZ0NBS0FDQUxVQwUQBEwwCQjwTE1BQ0FNZ0NBT0FDQU9nQ0FQZ0NBSUFEQVpBREFKZ0RBYWdEaHBxS0I3b0RFV1JsWm1GMWJIUWpUbGxOTWpvME1ESXqaAjkhT3d3R0FRNvgA8E4tUHhESUFRb0FEb1JaR1ZtWVhWc2RDTk9XVTB5T2pRd01qTS7YAugH4ALH0wHqAgpwcmViaWQub3Jn8gIRCgZBRFZfSUQSBzEzNzY4NjDyARQMQ1BHXwEUNDM1MDMwOTjyAhEKBUNQARPwmQgxNDg0NzIzOIADAYgDAZADAJgDFKADAaoDAMADkBzIAwDYAwDgAwDoAwD4AwOABACSBAkvb3BlbnJ0YjKYBACiBAwxNTIuMTkzLjYuNzSoBJrMI7IEDAgAEAAYACAAMAA4ALgEAMAEAMgEANIEEWRlZmF1bHQjTllNMjo0MDIz2gQCCADgBADwBL3llyGIBQGYBQCgBf____8FA1ABqgULc29tZS1yZXEtaWTABQDJBQAFARTwP9IFCQkFC2QAAADYBQHgBQHwBd4C-gUECAAQAJAGAZgGAA..&s=08b1535744639c904684afe46e3c6c0e4786089f&test=1&referrer=prebid.org&pp=${AUCTION_PRICE}\"],\"jstracker\":\"\"}", + "adid": "69595837", + "adomain": [ + "appnexus.com" + ], + "iurl": "http://nym1-ib.adnxs.com/cr?id=69595837", + "cid": "958", + "crid": "69595837", + "cat": [ + "IAB20-3" + ], + "ext": { + "appnexus": { + "brand_id": 1, + "brand_category_id": 1, + "auction_id": 5607483846416358664, + "bidder_id": 2, + "bid_ad_type": 3 + } + }, + "wurl": "http://localhost:8080/event?t=win&b=928185755156387460&a=5001&ts=1000&bidder=appnexus&f=i&int=dmbjs" + } + }, + { + "type": "json", + "value": { + "id": "7706636740145184840", + "impid": "impId3", + "price": 5, + "adm": "some-test-ad", + "adid": "29681110", + "adomain": [ + "appnexus.com" + ], + "iurl": "http://nym1-ib.adnxs.com/cr?id=29681110", + "cid": "958", + "crid": "29681110", + "cat": [], + "w": 300, + "h": 250, + "wurl": "http://localhost:8080/event?t=win&b=7706636740145184840&a=5001&ts=1000&bidder=appnexusAlias&f=i&int=dmbjs", + "ext": { + "appnexus": { + "brand_id": 350, + "brand_category_id": 350, + "auction_id": 8189378542222915031, + "bidder_id": 2, + "bid_ad_type": 0, + "ranking_price": 0.0 + } + } + } + }, + { + "type": "json", + "value": { + "id": "466223845", + "impid": "impId2", + "price": 4.26, + "adm": "adm2", + "crid": "crid2", + "w": 300, + "h": 600, + "wurl": "http://localhost:8080/event?t=win&b=466223845&a=5001&ts=1000&bidder=rubicon&f=i&int=dmbjs" + } + }, + { + "type": "xml", + "value": "", + "expiry": 120 + } + ] +} diff --git a/src/test/resources/org/prebid/server/it/util/bidcacherequestpattern/missing-put-bid-request.json b/src/test/resources/org/prebid/server/it/util/bidcacherequestpattern/missing-put-bid-request.json new file mode 100644 index 00000000000..d72ed026ec2 --- /dev/null +++ b/src/test/resources/org/prebid/server/it/util/bidcacherequestpattern/missing-put-bid-request.json @@ -0,0 +1,134 @@ +{ + "puts": [ + { + "type": "json", + "value": { + "id": "466223845", + "impid": "impId2", + "price": 4.26, + "adm": "adm2", + "crid": "crid2", + "w": 300, + "h": 600, + "wurl": "http://localhost:8080/event?t=win&b=466223845&a=5001&ts=1000&bidder=rubicon&f=i&int=dmbjs" + } + }, + { + "type": "json", + "value": { + "id": "7706636740145184841", + "impid": "impId3", + "price": 5.5, + "adm": "some-test-ad", + "adid": "29681110", + "adomain": [ + "appnexus.com" + ], + "iurl": "http://nym1-ib.adnxs.com/cr?id=29681110", + "cid": "958", + "crid": "29681110", + "w": 300, + "h": 250, + "wurl": "http://localhost:8080/event?t=win&b=7706636740145184841&a=5001&ts=1000&bidder=appnexus&f=i&int=dmbjs", + "ext": { + "appnexus": { + "brand_id": 1, + "auction_id": 8189378542222915032, + "bidder_id": 2, + "bid_ad_type": 0, + "ranking_price": 0.0 + } + } + } + }, + { + "type": "json", + "value": { + "id": "880290288", + "impid": "impId1", + "price": 8.43, + "adm": "", + "crid": "crid1", + "w": 300, + "h": 250, + "wurl": "http://localhost:8080/event?t=win&b=880290288&a=5001&ts=1000&bidder=rubicon&f=i&int=dmbjs", + "ext": { + "rp": { + "targeting": [ + { + "key": "rpfl_1001", + "values": [ + "2_tier0100" + ] + } + ] + } + } + } + }, + { + "type": "json", + "value": { + "id": "928185755156387460", + "impid": "impId131", + "price": 1, + "adm": "{\"assets\":[{\"id\":0,\"img\":{\"url\":\"http://vcdn.adnxs.com/p/creative-image/5e/b6/de/c3/5eb6dec3-4854-4dcd-980a-347f36ab502e.jpg\",\"w\":3000,\"h\":2250,\"ext\":{\"appnexus\":{\"prevent_crop\":0}}}},{\"id\":1,\"title\":{\"text\":\"This is an example Prebid Native creative\"}},{\"id\":2,\"data\":{\"value\":\"Prebid.org\"}},{\"id\":3,\"data\":{\"value\":\"ThisisaPrebidNativeCreative.Therearemanylikeit,butthisoneismine.\"}}],\"link\":{\"url\":\"http://nym1-ib.adnxs.com/click?AAAAAAAA8D8AAAAAAADwPwAAAAAAAAAAAAAAAAAA8D8AAAAAAADwPwhdYz3ZyNFNG3fXpZUyLXNZ0o5aAAAAACrElgC-AwAAvgMAAAIAAAC98iUEeP4QAAAAAABVU0QAVVNEAAEAAQARIAAAAAABAgQCAAAAAAEAhBaSXgAAAAA./pp=${AUCTION_PRICE}/cnd=%21OwwGAQiGmooHEL3llyEY-PxDIAQoADoRZGVmYXVsdCNOWU0yOjQwMjM./bn=75922/test=1/referrer=prebid.org/clickenc=http%3A%2F%2Fprebid.org%2Fdev-docs%2Fshow-native-ads.html\"},\"imptrackers\":[\"http://nym1-ib.adnxs.com/openrtb_win?e=wqT_3QLFBqBFAwAAAwDWAAUBCNmku9QFEIi6jeuTm_LoTRib7t2u2tLMlnMqNgkAAAECCPA_EQEHEAAA8D8ZCQkIAAAhCQkI8D8pEQkAMQkJqAAAMKqI2wQ4vgdAvgdIAlC95ZchWPj8Q2AAaJFAeJLRBIABAYoBA1VTRJIFBvBQmAEBoAEBqAEBsAEAuAECwAEEyAEC0AEJ2AEA4AEB8AEAigI7dWYoJ2EnLCAxMzc2ODYwLCAxNTE5MzA5NDAxKTt1ZigncicsIDY5NTk1ODM3Nh4A8IqSAvUBIXRETkdfUWlHbW9vSEVMM2xseUVZQUNENF9FTXdBRGdBUUFSSXZnZFFxb2piQkZnQVlMTURhQUJ3QUhnQWdBRUFpQUVBa0FFQm1BRUJvQUVCcUFFRHNBRUF1UUVwaTRpREFBRHdQOEVCS1l1SWd3QUE4RF9KQVhfelYzek1zXzBfMlFFQUFBAQMkRHdQLUFCQVBVQgEOLEFKZ0NBS0FDQUxVQwUQBEwwCQjwTE1BQ0FNZ0NBT0FDQU9nQ0FQZ0NBSUFEQVpBREFKZ0RBYWdEaHBxS0I3b0RFV1JsWm1GMWJIUWpUbGxOTWpvME1ESXqaAjkhT3d3R0FRNvgA8E4tUHhESUFRb0FEb1JaR1ZtWVhWc2RDTk9XVTB5T2pRd01qTS7YAugH4ALH0wHqAgpwcmViaWQub3Jn8gIRCgZBRFZfSUQSBzEzNzY4NjDyARQMQ1BHXwEUNDM1MDMwOTjyAhEKBUNQARPwmQgxNDg0NzIzOIADAYgDAZADAJgDFKADAaoDAMADkBzIAwDYAwDgAwDoAwD4AwOABACSBAkvb3BlbnJ0YjKYBACiBAwxNTIuMTkzLjYuNzSoBJrMI7IEDAgAEAAYACAAMAA4ALgEAMAEAMgEANIEEWRlZmF1bHQjTllNMjo0MDIz2gQCCADgBADwBL3llyGIBQGYBQCgBf____8FA1ABqgULc29tZS1yZXEtaWTABQDJBQAFARTwP9IFCQkFC2QAAADYBQHgBQHwBd4C-gUECAAQAJAGAZgGAA..&s=08b1535744639c904684afe46e3c6c0e4786089f&test=1&referrer=prebid.org&pp=${AUCTION_PRICE}\"],\"jstracker\":\"\"}", + "adid": "69595837", + "adomain": [ + "appnexus.com" + ], + "iurl": "http://nym1-ib.adnxs.com/cr?id=69595837", + "cid": "958", + "crid": "69595837", + "cat": [ + "IAB20-3" + ], + "ext": { + "appnexus": { + "brand_id": 1, + "brand_category_id": 1, + "auction_id": 5607483846416358664, + "bidder_id": 2, + "bid_ad_type": 3 + } + }, + "wurl": "http://localhost:8080/event?t=win&b=928185755156387460&a=5001&ts=1000&bidder=appnexus&f=i&int=dmbjs" + } + }, + { + "type": "json", + "value": { + "id": "a121a07f-1579-4465-bc5e-5c5b02a0c421", + "impid": "impStoredAuctionResponse", + "crid": "crid1", + "price": 0.9, + "wurl": "http://localhost:8080/event?t=win&b=a121a07f-1579-4465-bc5e-5c5b02a0c421&a=5001&ts=1000&bidder=appnexus&f=i&int=dmbjs" + } + }, + { + "type": "json", + "value": { + "id": "f227a07f-1579-4465-bc5e-5c5b02a0c180", + "impid": "impStoredAuctionResponse", + "crid": "crid1", + "price": 0.8, + "wurl": "http://localhost:8080/event?t=win&b=f227a07f-1579-4465-bc5e-5c5b02a0c180&a=5001&ts=1000&bidder=rubicon&f=i&int=dmbjs" + } + }, + { + "type": "json", + "value": { + "id": "f227a07f-1579-4465-bc5e-5c5b02a0c181", + "impid": "impStoredBidResponse", + "crid": "crid1", + "price": 0.8, + "wurl": "http://localhost:8080/event?t=win&b=f227a07f-1579-4465-bc5e-5c5b02a0c181&a=5001&ts=1000&bidder=rubicon&f=i&int=dmbjs" + } + }, + { + "type": "xml", + "value": "", + "expiry": 120 + } + ] +} diff --git a/src/test/resources/org/prebid/server/it/util/bidcacherequestpattern/original-bid-request.json b/src/test/resources/org/prebid/server/it/util/bidcacherequestpattern/original-bid-request.json new file mode 100644 index 00000000000..10550f10900 --- /dev/null +++ b/src/test/resources/org/prebid/server/it/util/bidcacherequestpattern/original-bid-request.json @@ -0,0 +1,164 @@ +{ + "puts": [ + { + "type": "json", + "value": { + "id": "a121a07f-1579-4465-bc5e-5c5b02a0c421", + "impid": "impStoredAuctionResponse", + "crid": "crid1", + "price": 0.9, + "wurl": "http://localhost:8080/event?t=win&b=a121a07f-1579-4465-bc5e-5c5b02a0c421&a=5001&ts=1000&bidder=appnexus&f=i&int=dmbjs" + } + }, + { + "type": "json", + "value": { + "id": "7706636740145184841", + "impid": "impId3", + "price": 5.5, + "adm": "some-test-ad", + "adid": "29681110", + "adomain": [ + "appnexus.com" + ], + "iurl": "http://nym1-ib.adnxs.com/cr?id=29681110", + "cid": "958", + "crid": "29681110", + "w": 300, + "h": 250, + "wurl": "http://localhost:8080/event?t=win&b=7706636740145184841&a=5001&ts=1000&bidder=appnexus&f=i&int=dmbjs", + "ext": { + "appnexus": { + "brand_id": 1, + "auction_id": 8189378542222915032, + "bidder_id": 2, + "bid_ad_type": 0, + "ranking_price": 0.0 + } + } + } + }, + { + "type": "json", + "value": { + "id": "f227a07f-1579-4465-bc5e-5c5b02a0c180", + "impid": "impStoredAuctionResponse", + "crid": "crid1", + "price": 0.8, + "wurl": "http://localhost:8080/event?t=win&b=f227a07f-1579-4465-bc5e-5c5b02a0c180&a=5001&ts=1000&bidder=rubicon&f=i&int=dmbjs" + } + }, + { + "type": "json", + "value": { + "id": "f227a07f-1579-4465-bc5e-5c5b02a0c181", + "impid": "impStoredBidResponse", + "crid": "crid1", + "price": 0.8, + "wurl": "http://localhost:8080/event?t=win&b=f227a07f-1579-4465-bc5e-5c5b02a0c181&a=5001&ts=1000&bidder=rubicon&f=i&int=dmbjs" + } + }, + { + "type": "json", + "value": { + "id": "880290288", + "impid": "impId1", + "price": 8.43, + "adm": "", + "crid": "crid1", + "w": 300, + "h": 250, + "wurl": "http://localhost:8080/event?t=win&b=880290288&a=5001&ts=1000&bidder=rubicon&f=i&int=dmbjs", + "ext": { + "rp": { + "targeting": [ + { + "key": "rpfl_1001", + "values": [ + "2_tier0100" + ] + } + ] + } + } + } + }, + { + "type": "json", + "value": { + "id": "928185755156387460", + "impid": "impId131", + "price": 1, + "adm": "{\"assets\":[{\"id\":0,\"img\":{\"url\":\"http://vcdn.adnxs.com/p/creative-image/5e/b6/de/c3/5eb6dec3-4854-4dcd-980a-347f36ab502e.jpg\",\"w\":3000,\"h\":2250,\"ext\":{\"appnexus\":{\"prevent_crop\":0}}}},{\"id\":1,\"title\":{\"text\":\"This is an example Prebid Native creative\"}},{\"id\":2,\"data\":{\"value\":\"Prebid.org\"}},{\"id\":3,\"data\":{\"value\":\"ThisisaPrebidNativeCreative.Therearemanylikeit,butthisoneismine.\"}}],\"link\":{\"url\":\"http://nym1-ib.adnxs.com/click?AAAAAAAA8D8AAAAAAADwPwAAAAAAAAAAAAAAAAAA8D8AAAAAAADwPwhdYz3ZyNFNG3fXpZUyLXNZ0o5aAAAAACrElgC-AwAAvgMAAAIAAAC98iUEeP4QAAAAAABVU0QAVVNEAAEAAQARIAAAAAABAgQCAAAAAAEAhBaSXgAAAAA./pp=${AUCTION_PRICE}/cnd=%21OwwGAQiGmooHEL3llyEY-PxDIAQoADoRZGVmYXVsdCNOWU0yOjQwMjM./bn=75922/test=1/referrer=prebid.org/clickenc=http%3A%2F%2Fprebid.org%2Fdev-docs%2Fshow-native-ads.html\"},\"imptrackers\":[\"http://nym1-ib.adnxs.com/openrtb_win?e=wqT_3QLFBqBFAwAAAwDWAAUBCNmku9QFEIi6jeuTm_LoTRib7t2u2tLMlnMqNgkAAAECCPA_EQEHEAAA8D8ZCQkIAAAhCQkI8D8pEQkAMQkJqAAAMKqI2wQ4vgdAvgdIAlC95ZchWPj8Q2AAaJFAeJLRBIABAYoBA1VTRJIFBvBQmAEBoAEBqAEBsAEAuAECwAEEyAEC0AEJ2AEA4AEB8AEAigI7dWYoJ2EnLCAxMzc2ODYwLCAxNTE5MzA5NDAxKTt1ZigncicsIDY5NTk1ODM3Nh4A8IqSAvUBIXRETkdfUWlHbW9vSEVMM2xseUVZQUNENF9FTXdBRGdBUUFSSXZnZFFxb2piQkZnQVlMTURhQUJ3QUhnQWdBRUFpQUVBa0FFQm1BRUJvQUVCcUFFRHNBRUF1UUVwaTRpREFBRHdQOEVCS1l1SWd3QUE4RF9KQVhfelYzek1zXzBfMlFFQUFBAQMkRHdQLUFCQVBVQgEOLEFKZ0NBS0FDQUxVQwUQBEwwCQjwTE1BQ0FNZ0NBT0FDQU9nQ0FQZ0NBSUFEQVpBREFKZ0RBYWdEaHBxS0I3b0RFV1JsWm1GMWJIUWpUbGxOTWpvME1ESXqaAjkhT3d3R0FRNvgA8E4tUHhESUFRb0FEb1JaR1ZtWVhWc2RDTk9XVTB5T2pRd01qTS7YAugH4ALH0wHqAgpwcmViaWQub3Jn8gIRCgZBRFZfSUQSBzEzNzY4NjDyARQMQ1BHXwEUNDM1MDMwOTjyAhEKBUNQARPwmQgxNDg0NzIzOIADAYgDAZADAJgDFKADAaoDAMADkBzIAwDYAwDgAwDoAwD4AwOABACSBAkvb3BlbnJ0YjKYBACiBAwxNTIuMTkzLjYuNzSoBJrMI7IEDAgAEAAYACAAMAA4ALgEAMAEAMgEANIEEWRlZmF1bHQjTllNMjo0MDIz2gQCCADgBADwBL3llyGIBQGYBQCgBf____8FA1ABqgULc29tZS1yZXEtaWTABQDJBQAFARTwP9IFCQkFC2QAAADYBQHgBQHwBd4C-gUECAAQAJAGAZgGAA..&s=08b1535744639c904684afe46e3c6c0e4786089f&test=1&referrer=prebid.org&pp=${AUCTION_PRICE}\"],\"jstracker\":\"\"}", + "adid": "69595837", + "adomain": [ + "appnexus.com" + ], + "iurl": "http://nym1-ib.adnxs.com/cr?id=69595837", + "cid": "958", + "crid": "69595837", + "cat": [ + "IAB20-3" + ], + "ext": { + "appnexus": { + "brand_id": 1, + "brand_category_id": 1, + "auction_id": 5607483846416358664, + "bidder_id": 2, + "bid_ad_type": 3 + } + }, + "wurl": "http://localhost:8080/event?t=win&b=928185755156387460&a=5001&ts=1000&bidder=appnexus&f=i&int=dmbjs" + } + }, + { + "type": "json", + "value": { + "id": "7706636740145184840", + "impid": "impId3", + "price": 5, + "adm": "some-test-ad", + "adid": "29681110", + "adomain": [ + "appnexus.com" + ], + "iurl": "http://nym1-ib.adnxs.com/cr?id=29681110", + "cid": "958", + "crid": "29681110", + "cat": [], + "w": 300, + "h": 250, + "wurl": "http://localhost:8080/event?t=win&b=7706636740145184840&a=5001&ts=1000&bidder=appnexusAlias&f=i&int=dmbjs", + "ext": { + "appnexus": { + "brand_id": 350, + "brand_category_id": 350, + "auction_id": 8189378542222915031, + "bidder_id": 2, + "bid_ad_type": 0, + "ranking_price": 0.0 + } + } + } + }, + { + "type": "json", + "value": { + "id": "466223845", + "impid": "impId2", + "price": 4.26, + "adm": "adm2", + "crid": "crid2", + "w": 300, + "h": 600, + "wurl": "http://localhost:8080/event?t=win&b=466223845&a=5001&ts=1000&bidder=rubicon&f=i&int=dmbjs" + } + }, + { + "type": "xml", + "value": "", + "expiry": 120 + } + ] +} diff --git a/src/test/resources/org/prebid/server/it/util/bidcacherequestpattern/redundant-put-bid-request.json b/src/test/resources/org/prebid/server/it/util/bidcacherequestpattern/redundant-put-bid-request.json new file mode 100644 index 00000000000..6bc682d5835 --- /dev/null +++ b/src/test/resources/org/prebid/server/it/util/bidcacherequestpattern/redundant-put-bid-request.json @@ -0,0 +1,174 @@ +{ + "puts": [ + { + "type": "json", + "value": { + "id": "a121a07f-1579-4465-bc5e-5c5b02a0c421", + "impid": "impStoredAuctionResponse", + "crid": "crid1", + "price": 0.9, + "wurl": "http://localhost:8080/event?t=win&b=a121a07f-1579-4465-bc5e-5c5b02a0c421&a=5001&ts=1000&bidder=appnexus&f=i&int=dmbjs" + } + }, + { + "type": "json", + "value": { + "id": "466223845", + "impid": "impId2", + "price": 4.26, + "adm": "adm2", + "crid": "crid2", + "w": 300, + "h": 600, + "wurl": "http://localhost:8080/event?t=win&b=466223845&a=5001&ts=1000&bidder=rubicon&f=i&int=dmbjs" + } + }, + { + "type": "json", + "value": { + "id": "7706636740145184840", + "impid": "impId3", + "price": 5, + "adm": "some-test-ad", + "adid": "29681110", + "adomain": [ + "appnexus.com" + ], + "iurl": "http://nym1-ib.adnxs.com/cr?id=29681110", + "cid": "958", + "crid": "29681110", + "cat": [], + "w": 300, + "h": 250, + "wurl": "http://localhost:8080/event?t=win&b=7706636740145184840&a=5001&ts=1000&bidder=appnexusAlias&f=i&int=dmbjs", + "ext": { + "appnexus": { + "brand_id": 350, + "brand_category_id": 350, + "auction_id": 8189378542222915031, + "bidder_id": 2, + "bid_ad_type": 0, + "ranking_price": 0.0 + } + } + } + }, + { + "type": "json", + "value": { + "id": "7706636740145184841", + "impid": "impId3", + "price": 5.5, + "adm": "some-test-ad", + "adid": "29681110", + "adomain": [ + "appnexus.com" + ], + "iurl": "http://nym1-ib.adnxs.com/cr?id=29681110", + "cid": "958", + "crid": "29681110", + "w": 300, + "h": 250, + "wurl": "http://localhost:8080/event?t=win&b=7706636740145184841&a=5001&ts=1000&bidder=appnexus&f=i&int=dmbjs", + "ext": { + "appnexus": { + "brand_id": 1, + "auction_id": 8189378542222915032, + "bidder_id": 2, + "bid_ad_type": 0, + "ranking_price": 0.0 + } + } + } + }, + { + "type": "json", + "value": { + "id": "880290288", + "impid": "impId1", + "price": 8.43, + "adm": "", + "crid": "crid1", + "w": 300, + "h": 250, + "wurl": "http://localhost:8080/event?t=win&b=880290288&a=5001&ts=1000&bidder=rubicon&f=i&int=dmbjs", + "ext": { + "rp": { + "targeting": [ + { + "key": "rpfl_1001", + "values": [ + "2_tier0100" + ] + } + ] + } + } + } + }, + { + "type": "json", + "value": { + "id": "928185755156387460", + "impid": "impId131", + "price": 1, + "adm": "{\"assets\":[{\"id\":0,\"img\":{\"url\":\"http://vcdn.adnxs.com/p/creative-image/5e/b6/de/c3/5eb6dec3-4854-4dcd-980a-347f36ab502e.jpg\",\"w\":3000,\"h\":2250,\"ext\":{\"appnexus\":{\"prevent_crop\":0}}}},{\"id\":1,\"title\":{\"text\":\"This is an example Prebid Native creative\"}},{\"id\":2,\"data\":{\"value\":\"Prebid.org\"}},{\"id\":3,\"data\":{\"value\":\"ThisisaPrebidNativeCreative.Therearemanylikeit,butthisoneismine.\"}}],\"link\":{\"url\":\"http://nym1-ib.adnxs.com/click?AAAAAAAA8D8AAAAAAADwPwAAAAAAAAAAAAAAAAAA8D8AAAAAAADwPwhdYz3ZyNFNG3fXpZUyLXNZ0o5aAAAAACrElgC-AwAAvgMAAAIAAAC98iUEeP4QAAAAAABVU0QAVVNEAAEAAQARIAAAAAABAgQCAAAAAAEAhBaSXgAAAAA./pp=${AUCTION_PRICE}/cnd=%21OwwGAQiGmooHEL3llyEY-PxDIAQoADoRZGVmYXVsdCNOWU0yOjQwMjM./bn=75922/test=1/referrer=prebid.org/clickenc=http%3A%2F%2Fprebid.org%2Fdev-docs%2Fshow-native-ads.html\"},\"imptrackers\":[\"http://nym1-ib.adnxs.com/openrtb_win?e=wqT_3QLFBqBFAwAAAwDWAAUBCNmku9QFEIi6jeuTm_LoTRib7t2u2tLMlnMqNgkAAAECCPA_EQEHEAAA8D8ZCQkIAAAhCQkI8D8pEQkAMQkJqAAAMKqI2wQ4vgdAvgdIAlC95ZchWPj8Q2AAaJFAeJLRBIABAYoBA1VTRJIFBvBQmAEBoAEBqAEBsAEAuAECwAEEyAEC0AEJ2AEA4AEB8AEAigI7dWYoJ2EnLCAxMzc2ODYwLCAxNTE5MzA5NDAxKTt1ZigncicsIDY5NTk1ODM3Nh4A8IqSAvUBIXRETkdfUWlHbW9vSEVMM2xseUVZQUNENF9FTXdBRGdBUUFSSXZnZFFxb2piQkZnQVlMTURhQUJ3QUhnQWdBRUFpQUVBa0FFQm1BRUJvQUVCcUFFRHNBRUF1UUVwaTRpREFBRHdQOEVCS1l1SWd3QUE4RF9KQVhfelYzek1zXzBfMlFFQUFBAQMkRHdQLUFCQVBVQgEOLEFKZ0NBS0FDQUxVQwUQBEwwCQjwTE1BQ0FNZ0NBT0FDQU9nQ0FQZ0NBSUFEQVpBREFKZ0RBYWdEaHBxS0I3b0RFV1JsWm1GMWJIUWpUbGxOTWpvME1ESXqaAjkhT3d3R0FRNvgA8E4tUHhESUFRb0FEb1JaR1ZtWVhWc2RDTk9XVTB5T2pRd01qTS7YAugH4ALH0wHqAgpwcmViaWQub3Jn8gIRCgZBRFZfSUQSBzEzNzY4NjDyARQMQ1BHXwEUNDM1MDMwOTjyAhEKBUNQARPwmQgxNDg0NzIzOIADAYgDAZADAJgDFKADAaoDAMADkBzIAwDYAwDgAwDoAwD4AwOABACSBAkvb3BlbnJ0YjKYBACiBAwxNTIuMTkzLjYuNzSoBJrMI7IEDAgAEAAYACAAMAA4ALgEAMAEAMgEANIEEWRlZmF1bHQjTllNMjo0MDIz2gQCCADgBADwBL3llyGIBQGYBQCgBf____8FA1ABqgULc29tZS1yZXEtaWTABQDJBQAFARTwP9IFCQkFC2QAAADYBQHgBQHwBd4C-gUECAAQAJAGAZgGAA..&s=08b1535744639c904684afe46e3c6c0e4786089f&test=1&referrer=prebid.org&pp=${AUCTION_PRICE}\"],\"jstracker\":\"\"}", + "adid": "69595837", + "adomain": [ + "appnexus.com" + ], + "iurl": "http://nym1-ib.adnxs.com/cr?id=69595837", + "cid": "958", + "crid": "69595837", + "cat": [ + "IAB20-3" + ], + "ext": { + "appnexus": { + "brand_id": 1, + "brand_category_id": 1, + "auction_id": 5607483846416358664, + "bidder_id": 2, + "bid_ad_type": 3 + } + }, + "wurl": "http://localhost:8080/event?t=win&b=928185755156387460&a=5001&ts=1000&bidder=appnexus&f=i&int=dmbjs" + } + }, + { + "type": "json", + "value": { + "id": "a121a07f-1579-4465-bc5e-5c5b02a0c421", + "impid": "impStoredAuctionResponse", + "crid": "crid1", + "price": 0.9, + "wurl": "http://localhost:8080/event?t=win&b=a121a07f-1579-4465-bc5e-5c5b02a0c421&a=5001&ts=1000&bidder=appnexus&f=i&int=dmbjs" + } + }, + { + "type": "json", + "value": { + "id": "f227a07f-1579-4465-bc5e-5c5b02a0c180", + "impid": "impStoredAuctionResponse", + "crid": "crid1", + "price": 0.8, + "wurl": "http://localhost:8080/event?t=win&b=f227a07f-1579-4465-bc5e-5c5b02a0c180&a=5001&ts=1000&bidder=rubicon&f=i&int=dmbjs" + } + }, + { + "type": "json", + "value": { + "id": "f227a07f-1579-4465-bc5e-5c5b02a0c181", + "impid": "impStoredBidResponse", + "crid": "crid1", + "price": 0.8, + "wurl": "http://localhost:8080/event?t=win&b=f227a07f-1579-4465-bc5e-5c5b02a0c181&a=5001&ts=1000&bidder=rubicon&f=i&int=dmbjs" + } + }, + { + "type": "xml", + "value": "", + "expiry": 120 + } + ] +} diff --git a/src/test/resources/org/prebid/server/it/util/bidcacherequestpattern/unordered-bid-request.json b/src/test/resources/org/prebid/server/it/util/bidcacherequestpattern/unordered-bid-request.json new file mode 100644 index 00000000000..fdacf300534 --- /dev/null +++ b/src/test/resources/org/prebid/server/it/util/bidcacherequestpattern/unordered-bid-request.json @@ -0,0 +1,164 @@ +{ + "puts": [ + { + "type": "json", + "value": { + "id": "466223845", + "impid": "impId2", + "price": 4.26, + "adm": "adm2", + "crid": "crid2", + "w": 300, + "h": 600, + "wurl": "http://localhost:8080/event?t=win&b=466223845&a=5001&ts=1000&bidder=rubicon&f=i&int=dmbjs" + } + }, + { + "type": "json", + "value": { + "id": "7706636740145184840", + "impid": "impId3", + "price": 5, + "adm": "some-test-ad", + "adid": "29681110", + "adomain": [ + "appnexus.com" + ], + "iurl": "http://nym1-ib.adnxs.com/cr?id=29681110", + "cid": "958", + "crid": "29681110", + "cat": [], + "w": 300, + "h": 250, + "wurl": "http://localhost:8080/event?t=win&b=7706636740145184840&a=5001&ts=1000&bidder=appnexusAlias&f=i&int=dmbjs", + "ext": { + "appnexus": { + "brand_id": 350, + "brand_category_id": 350, + "auction_id": 8189378542222915031, + "bidder_id": 2, + "bid_ad_type": 0, + "ranking_price": 0.0 + } + } + } + }, + { + "type": "json", + "value": { + "id": "7706636740145184841", + "impid": "impId3", + "price": 5.5, + "adm": "some-test-ad", + "adid": "29681110", + "adomain": [ + "appnexus.com" + ], + "iurl": "http://nym1-ib.adnxs.com/cr?id=29681110", + "cid": "958", + "crid": "29681110", + "w": 300, + "h": 250, + "wurl": "http://localhost:8080/event?t=win&b=7706636740145184841&a=5001&ts=1000&bidder=appnexus&f=i&int=dmbjs", + "ext": { + "appnexus": { + "brand_id": 1, + "auction_id": 8189378542222915032, + "bidder_id": 2, + "bid_ad_type": 0, + "ranking_price": 0.0 + } + } + } + }, + { + "type": "json", + "value": { + "id": "880290288", + "impid": "impId1", + "price": 8.43, + "adm": "", + "crid": "crid1", + "w": 300, + "h": 250, + "wurl": "http://localhost:8080/event?t=win&b=880290288&a=5001&ts=1000&bidder=rubicon&f=i&int=dmbjs", + "ext": { + "rp": { + "targeting": [ + { + "key": "rpfl_1001", + "values": [ + "2_tier0100" + ] + } + ] + } + } + } + }, + { + "type": "json", + "value": { + "id": "928185755156387460", + "impid": "impId131", + "price": 1, + "adm": "{\"assets\":[{\"id\":0,\"img\":{\"url\":\"http://vcdn.adnxs.com/p/creative-image/5e/b6/de/c3/5eb6dec3-4854-4dcd-980a-347f36ab502e.jpg\",\"w\":3000,\"h\":2250,\"ext\":{\"appnexus\":{\"prevent_crop\":0}}}},{\"id\":1,\"title\":{\"text\":\"This is an example Prebid Native creative\"}},{\"id\":2,\"data\":{\"value\":\"Prebid.org\"}},{\"id\":3,\"data\":{\"value\":\"ThisisaPrebidNativeCreative.Therearemanylikeit,butthisoneismine.\"}}],\"link\":{\"url\":\"http://nym1-ib.adnxs.com/click?AAAAAAAA8D8AAAAAAADwPwAAAAAAAAAAAAAAAAAA8D8AAAAAAADwPwhdYz3ZyNFNG3fXpZUyLXNZ0o5aAAAAACrElgC-AwAAvgMAAAIAAAC98iUEeP4QAAAAAABVU0QAVVNEAAEAAQARIAAAAAABAgQCAAAAAAEAhBaSXgAAAAA./pp=${AUCTION_PRICE}/cnd=%21OwwGAQiGmooHEL3llyEY-PxDIAQoADoRZGVmYXVsdCNOWU0yOjQwMjM./bn=75922/test=1/referrer=prebid.org/clickenc=http%3A%2F%2Fprebid.org%2Fdev-docs%2Fshow-native-ads.html\"},\"imptrackers\":[\"http://nym1-ib.adnxs.com/openrtb_win?e=wqT_3QLFBqBFAwAAAwDWAAUBCNmku9QFEIi6jeuTm_LoTRib7t2u2tLMlnMqNgkAAAECCPA_EQEHEAAA8D8ZCQkIAAAhCQkI8D8pEQkAMQkJqAAAMKqI2wQ4vgdAvgdIAlC95ZchWPj8Q2AAaJFAeJLRBIABAYoBA1VTRJIFBvBQmAEBoAEBqAEBsAEAuAECwAEEyAEC0AEJ2AEA4AEB8AEAigI7dWYoJ2EnLCAxMzc2ODYwLCAxNTE5MzA5NDAxKTt1ZigncicsIDY5NTk1ODM3Nh4A8IqSAvUBIXRETkdfUWlHbW9vSEVMM2xseUVZQUNENF9FTXdBRGdBUUFSSXZnZFFxb2piQkZnQVlMTURhQUJ3QUhnQWdBRUFpQUVBa0FFQm1BRUJvQUVCcUFFRHNBRUF1UUVwaTRpREFBRHdQOEVCS1l1SWd3QUE4RF9KQVhfelYzek1zXzBfMlFFQUFBAQMkRHdQLUFCQVBVQgEOLEFKZ0NBS0FDQUxVQwUQBEwwCQjwTE1BQ0FNZ0NBT0FDQU9nQ0FQZ0NBSUFEQVpBREFKZ0RBYWdEaHBxS0I3b0RFV1JsWm1GMWJIUWpUbGxOTWpvME1ESXqaAjkhT3d3R0FRNvgA8E4tUHhESUFRb0FEb1JaR1ZtWVhWc2RDTk9XVTB5T2pRd01qTS7YAugH4ALH0wHqAgpwcmViaWQub3Jn8gIRCgZBRFZfSUQSBzEzNzY4NjDyARQMQ1BHXwEUNDM1MDMwOTjyAhEKBUNQARPwmQgxNDg0NzIzOIADAYgDAZADAJgDFKADAaoDAMADkBzIAwDYAwDgAwDoAwD4AwOABACSBAkvb3BlbnJ0YjKYBACiBAwxNTIuMTkzLjYuNzSoBJrMI7IEDAgAEAAYACAAMAA4ALgEAMAEAMgEANIEEWRlZmF1bHQjTllNMjo0MDIz2gQCCADgBADwBL3llyGIBQGYBQCgBf____8FA1ABqgULc29tZS1yZXEtaWTABQDJBQAFARTwP9IFCQkFC2QAAADYBQHgBQHwBd4C-gUECAAQAJAGAZgGAA..&s=08b1535744639c904684afe46e3c6c0e4786089f&test=1&referrer=prebid.org&pp=${AUCTION_PRICE}\"],\"jstracker\":\"\"}", + "adid": "69595837", + "adomain": [ + "appnexus.com" + ], + "iurl": "http://nym1-ib.adnxs.com/cr?id=69595837", + "cid": "958", + "crid": "69595837", + "cat": [ + "IAB20-3" + ], + "ext": { + "appnexus": { + "brand_id": 1, + "brand_category_id": 1, + "auction_id": 5607483846416358664, + "bidder_id": 2, + "bid_ad_type": 3 + } + }, + "wurl": "http://localhost:8080/event?t=win&b=928185755156387460&a=5001&ts=1000&bidder=appnexus&f=i&int=dmbjs" + } + }, + { + "type": "json", + "value": { + "id": "a121a07f-1579-4465-bc5e-5c5b02a0c421", + "impid": "impStoredAuctionResponse", + "crid": "crid1", + "price": 0.9, + "wurl": "http://localhost:8080/event?t=win&b=a121a07f-1579-4465-bc5e-5c5b02a0c421&a=5001&ts=1000&bidder=appnexus&f=i&int=dmbjs" + } + }, + { + "type": "json", + "value": { + "id": "f227a07f-1579-4465-bc5e-5c5b02a0c180", + "impid": "impStoredAuctionResponse", + "crid": "crid1", + "price": 0.8, + "wurl": "http://localhost:8080/event?t=win&b=f227a07f-1579-4465-bc5e-5c5b02a0c180&a=5001&ts=1000&bidder=rubicon&f=i&int=dmbjs" + } + }, + { + "type": "json", + "value": { + "id": "f227a07f-1579-4465-bc5e-5c5b02a0c181", + "impid": "impStoredBidResponse", + "crid": "crid1", + "price": 0.8, + "wurl": "http://localhost:8080/event?t=win&b=f227a07f-1579-4465-bc5e-5c5b02a0c181&a=5001&ts=1000&bidder=rubicon&f=i&int=dmbjs" + } + }, + { + "type": "xml", + "value": "", + "expiry": 120 + } + ] +}