From 0b421edaa5b018489dda281c3e8bbcf6c4c0f5e8 Mon Sep 17 00:00:00 2001 From: pavlo Date: Mon, 9 Nov 2026 12:41:17 +0200 Subject: [PATCH] New Adapter: Matterfull RTB (#4647) --- .../matterfull/MatterfullrtbBidder.java | 196 +++++++++ .../matterfull/ExtImpMatterfullrtb.java | 11 + .../bidder/MatterfullrtbConfiguration.java | 34 ++ .../bidder-config/matterfullrtb.yaml | 17 + .../static/bidder-params/matterfullrtb.json | 14 + .../MatterfullrtbBidderTest.java | 380 ++++++++++++++++++ .../prebid/server/it/MatterfullRtbTest.java | 35 ++ .../test-auction-matterfullrtb-request.json | 23 ++ .../test-auction-matterfullrtb-response.json | 43 ++ .../test-matterfullrtb-bid-request.json | 52 +++ .../test-matterfullrtb-bid-response.json | 21 + .../server/it/test-application.properties | 2 + 12 files changed, 828 insertions(+) create mode 100644 src/main/java/org/prebid/server/bidder/matterfull/MatterfullrtbBidder.java create mode 100644 src/main/java/org/prebid/server/proto/openrtb/ext/request/matterfull/ExtImpMatterfullrtb.java create mode 100644 src/main/java/org/prebid/server/spring/config/bidder/MatterfullrtbConfiguration.java create mode 100644 src/main/resources/bidder-config/matterfullrtb.yaml create mode 100644 src/main/resources/static/bidder-params/matterfullrtb.json create mode 100644 src/test/java/org/prebid/server/bidder/matterfullrtb/MatterfullrtbBidderTest.java create mode 100644 src/test/java/org/prebid/server/it/MatterfullRtbTest.java create mode 100644 src/test/resources/org/prebid/server/it/openrtb2/matterfullrtb/test-auction-matterfullrtb-request.json create mode 100644 src/test/resources/org/prebid/server/it/openrtb2/matterfullrtb/test-auction-matterfullrtb-response.json create mode 100644 src/test/resources/org/prebid/server/it/openrtb2/matterfullrtb/test-matterfullrtb-bid-request.json create mode 100644 src/test/resources/org/prebid/server/it/openrtb2/matterfullrtb/test-matterfullrtb-bid-response.json diff --git a/src/main/java/org/prebid/server/bidder/matterfull/MatterfullrtbBidder.java b/src/main/java/org/prebid/server/bidder/matterfull/MatterfullrtbBidder.java new file mode 100644 index 00000000000..52f0c28b72a --- /dev/null +++ b/src/main/java/org/prebid/server/bidder/matterfull/MatterfullrtbBidder.java @@ -0,0 +1,196 @@ +package org.prebid.server.bidder.matterfull; + +import com.fasterxml.jackson.core.type.TypeReference; +import com.iab.openrtb.request.App; +import com.iab.openrtb.request.BidRequest; +import com.iab.openrtb.request.Imp; +import com.iab.openrtb.request.Site; +import com.iab.openrtb.response.Bid; +import com.iab.openrtb.response.BidResponse; +import com.iab.openrtb.response.SeatBid; +import org.apache.commons.collections4.CollectionUtils; +import org.prebid.server.bidder.Bidder; +import org.prebid.server.bidder.model.BidderBid; +import org.prebid.server.bidder.model.BidderCall; +import org.prebid.server.bidder.model.BidderError; +import org.prebid.server.bidder.model.HttpRequest; +import org.prebid.server.bidder.model.Result; +import org.prebid.server.exception.PreBidException; +import org.prebid.server.json.DecodeException; +import org.prebid.server.json.JacksonMapper; +import org.prebid.server.proto.openrtb.ext.ExtPrebid; +import org.prebid.server.proto.openrtb.ext.request.matterfull.ExtImpMatterfullrtb; +import org.prebid.server.proto.openrtb.ext.response.BidType; +import org.prebid.server.util.BidderUtil; +import org.prebid.server.util.Uri; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Objects; + +public class MatterfullrtbBidder implements Bidder { + + private static final TypeReference> TYPE_REFERENCE = new TypeReference<>() { + }; + private static final String PUBLISHER_ID_MACRO = "PublisherID"; + + private final Uri endpointUrl; + private final JacksonMapper mapper; + + public MatterfullrtbBidder(String endpointUrl, JacksonMapper mapper) { + this.endpointUrl = Uri.of(endpointUrl); + this.mapper = Objects.requireNonNull(mapper); + } + + @Override + public Result>> makeHttpRequests(BidRequest bidRequest) { + final List errors = new ArrayList<>(); + final List> httpRequests = new ArrayList<>(); + final Map> publisherIdToImps = new HashMap<>(); + + for (Imp imp : bidRequest.getImp()) { + try { + final ExtImpMatterfullrtb extImp = parseImpExt(imp); + publisherIdToImps.computeIfAbsent(extImp.getPublisherId(), _ -> new ArrayList<>()) + .add(imp); + } catch (PreBidException e) { + errors.add(BidderError.badInput(e.getMessage())); + } + } + + if (publisherIdToImps.isEmpty()) { + return Result.withErrors(errors); + } + + for (Map.Entry> publisherIdImps : publisherIdToImps.entrySet()) { + final BidRequest modifiedBidRequest = modifyRequest(publisherIdImps.getValue(), bidRequest); + httpRequests.add(BidderUtil.defaultRequest( + modifiedBidRequest, + getResolvedUrl(publisherIdImps.getKey()), + mapper + )); + } + + return Result.of(httpRequests, errors); + } + + private ExtImpMatterfullrtb parseImpExt(Imp imp) { + try { + return mapper.mapper().convertValue(imp.getExt(), TYPE_REFERENCE).getBidder(); + } catch (IllegalArgumentException e) { + throw new PreBidException( + String.format("invalid imp.ext for impression %s. %s", imp.getId(), e.getMessage())); + } + } + + private BidRequest modifyRequest(List imps, BidRequest request) { + final Site site = request.getSite(); + final App app = request.getApp(); + + return request.toBuilder() + .imp(imps) + .site(site != null ? modifySite(site) : null) + .app(app != null ? modifyApp(app) : null) + .build(); + } + + private static Site modifySite(Site site) { + return site.toBuilder().publisher(null).build(); + } + + private static App modifyApp(App app) { + return app.toBuilder().publisher(null).domain("").build(); + } + + private String getResolvedUrl(String publisherId) { + return endpointUrl.replaceMacro(PUBLISHER_ID_MACRO, publisherId).expand(); + } + + @Override + public Result> makeBids(BidderCall httpCall, BidRequest bidRequest) { + try { + final BidResponse bidResponse = mapper.decodeValue(httpCall.getResponse().getBody(), BidResponse.class); + final List errors = new ArrayList<>(); + final List bidderBids = extractBids(bidResponse, bidRequest, errors); + + return Result.of(bidderBids, errors); + } catch (DecodeException e) { + return Result.withError(BidderError.badServerResponse(e.getMessage())); + } + } + + private static List extractBids(BidResponse bidResponse, + BidRequest bidRequest, + List errors) { + if (bidResponse == null || CollectionUtils.isEmpty(bidResponse.getSeatbid())) { + return Collections.emptyList(); + } + + final List bidderBids = new ArrayList<>(); + for (SeatBid seatBid : bidResponse.getSeatbid()) { + for (Bid bid : seatBid.getBid()) { + try { + final BidType bidType = getBidMediaType(bid, bidRequest.getImp()); + bidderBids.add(BidderBid.of(bid, bidType, bidResponse.getCur())); + } catch (PreBidException e) { + errors.add(BidderError.badServerResponse(e.getMessage())); + } + } + } + return bidderBids; + } + + private static BidType getBidMediaType(Bid bid, List imps) { + final Integer mType = bid.getMtype(); + return switch (mType) { + case 1 -> BidType.banner; + case 2 -> BidType.video; + case 3 -> BidType.audio; + case 4 -> BidType.xNative; + case 0 -> getMediaTypeForImpId(bid.getImpid(), imps); + case null, default -> throw new PreBidException( + String.format("Unsupported mtype %d for impression with ID: %s", mType, bid.getImpid())); + }; + } + + private static BidType getMediaTypeForImpId(String impId, List imps) { + for (Imp imp : imps) { + if (imp.getId().equals(impId)) { + return getMediaTypeForImp(imp); + } + } + throw new PreBidException(String.format("Failed to find impression for ID: %s", impId)); + } + + private static BidType getMediaTypeForImp(Imp imp) { + int counter = 0; + BidType bidType = null; + if (imp.getBanner() != null) { + counter++; + bidType = BidType.banner; + } + if (imp.getVideo() != null) { + counter++; + bidType = BidType.video; + } + if (imp.getAudio() != null) { + counter++; + bidType = BidType.audio; + } + if (imp.getXNative() != null) { + counter++; + bidType = BidType.xNative; + } + if (counter == 0) { + throw new PreBidException( + String.format("Could not determine media type for impression with ID: %s", imp.getId())); + } else if (counter != 1) { + throw new PreBidException(String.format( + "Bid must have non-zero mtype for multi-format impression with ID: %s", imp.getId())); + } + return bidType; + } +} diff --git a/src/main/java/org/prebid/server/proto/openrtb/ext/request/matterfull/ExtImpMatterfullrtb.java b/src/main/java/org/prebid/server/proto/openrtb/ext/request/matterfull/ExtImpMatterfullrtb.java new file mode 100644 index 00000000000..d660982a73b --- /dev/null +++ b/src/main/java/org/prebid/server/proto/openrtb/ext/request/matterfull/ExtImpMatterfullrtb.java @@ -0,0 +1,11 @@ +package org.prebid.server.proto.openrtb.ext.request.matterfull; + +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.Value; + +@Value(staticConstructor = "of") +public class ExtImpMatterfullrtb { + + @JsonProperty("pid") + String publisherId; +} diff --git a/src/main/java/org/prebid/server/spring/config/bidder/MatterfullrtbConfiguration.java b/src/main/java/org/prebid/server/spring/config/bidder/MatterfullrtbConfiguration.java new file mode 100644 index 00000000000..4417beb1224 --- /dev/null +++ b/src/main/java/org/prebid/server/spring/config/bidder/MatterfullrtbConfiguration.java @@ -0,0 +1,34 @@ +package org.prebid.server.spring.config.bidder; + +import org.prebid.server.bidder.BidderDeps; +import org.prebid.server.bidder.matterfull.MatterfullrtbBidder; +import org.prebid.server.json.JacksonMapper; +import org.prebid.server.spring.config.bidder.model.BidderConfigurationProperties; +import org.prebid.server.spring.config.bidder.util.BidderDepsAssembler; +import org.prebid.server.spring.env.YamlPropertySourceFactory; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.PropertySource; + +@Configuration +@PropertySource(value = "classpath:/bidder-config/matterfullrtb.yaml", factory = YamlPropertySourceFactory.class) +public class MatterfullrtbConfiguration { + + private static final String BIDDER_NAME = "matterfullrtb"; + + @Bean("matterfullrtbConfigurationProperties") + @ConfigurationProperties("adapters.matterfullrtb") + BidderConfigurationProperties configurationProperties() { + return new BidderConfigurationProperties(); + } + + @Bean + BidderDeps matterfullrtbBidderDeps(BidderConfigurationProperties matterfullrtbConfigurationProperties, + JacksonMapper mapper) { + return BidderDepsAssembler.forBidder(BIDDER_NAME) + .withConfig(matterfullrtbConfigurationProperties) + .bidderCreator(config -> new MatterfullrtbBidder(config.getEndpoint(), mapper)) + .assemble(); + } +} diff --git a/src/main/resources/bidder-config/matterfullrtb.yaml b/src/main/resources/bidder-config/matterfullrtb.yaml new file mode 100644 index 00000000000..65ce8a7592f --- /dev/null +++ b/src/main/resources/bidder-config/matterfullrtb.yaml @@ -0,0 +1,17 @@ +adapters: + matterfullrtb: + endpoint: "https://us.matterfull.co/?uqhash={PublisherID}" + geoscope: + - USA + ortb-version: "2.6" + endpoint-compression: gzip + meta-info: + maintainer-email: prebid_support@bematterfull.com + app-media-types: + - banner + - video + site-media-types: + - banner + - video + supported-vendors: + vendor-id: 0 diff --git a/src/main/resources/static/bidder-params/matterfullrtb.json b/src/main/resources/static/bidder-params/matterfullrtb.json new file mode 100644 index 00000000000..79672095799 --- /dev/null +++ b/src/main/resources/static/bidder-params/matterfullrtb.json @@ -0,0 +1,14 @@ +{ + "$schema": "http://json-schema.org/draft-04/schema#", + "title": "Matterfull RTB Adapter Params", + "description": "A schema which validates params accepted by the Matterfull RTB adapter", + "type": "object", + "properties": { + "pid": { + "type": "string", + "description": "Publisher token for the separately provisioned Matterfull RTB OpenRTB integration.", + "minLength": 20 + } + }, + "required": ["pid"] +} diff --git a/src/test/java/org/prebid/server/bidder/matterfullrtb/MatterfullrtbBidderTest.java b/src/test/java/org/prebid/server/bidder/matterfullrtb/MatterfullrtbBidderTest.java new file mode 100644 index 00000000000..bbf93d2d0bb --- /dev/null +++ b/src/test/java/org/prebid/server/bidder/matterfullrtb/MatterfullrtbBidderTest.java @@ -0,0 +1,380 @@ +package org.prebid.server.bidder.matterfullrtb; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.node.ObjectNode; +import com.iab.openrtb.request.App; +import com.iab.openrtb.request.Banner; +import com.iab.openrtb.request.BidRequest; +import com.iab.openrtb.request.Imp; +import com.iab.openrtb.request.Publisher; +import com.iab.openrtb.request.Site; +import com.iab.openrtb.request.Video; +import com.iab.openrtb.response.Bid; +import com.iab.openrtb.response.BidResponse; +import com.iab.openrtb.response.SeatBid; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.junit.jupiter.MockitoExtension; +import org.prebid.server.VertxTest; +import org.prebid.server.bidder.matterfull.MatterfullrtbBidder; +import org.prebid.server.bidder.model.BidderBid; +import org.prebid.server.bidder.model.BidderCall; +import org.prebid.server.bidder.model.BidderError; +import org.prebid.server.bidder.model.HttpRequest; +import org.prebid.server.bidder.model.HttpResponse; +import org.prebid.server.bidder.model.Result; +import org.prebid.server.proto.openrtb.ext.ExtPrebid; +import org.prebid.server.proto.openrtb.ext.request.matterfull.ExtImpMatterfullrtb; +import org.prebid.server.proto.openrtb.ext.response.BidType; + +import java.math.BigDecimal; +import java.util.Collections; +import java.util.List; +import java.util.function.UnaryOperator; + +import static java.util.Collections.singletonList; +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.assertj.core.api.Assertions.tuple; +import static org.prebid.server.bidder.model.BidderError.badServerResponse; + +@ExtendWith(MockitoExtension.class) +public class MatterfullrtbBidderTest extends VertxTest { + + private static final String ENDPOINT_URL = "http://test.endpont.com?pid={PublisherID}"; + + private MatterfullrtbBidder target; + + @BeforeEach + public void setUp() { + target = new MatterfullrtbBidder(ENDPOINT_URL, jacksonMapper); + } + + @Test + public void creationShouldFailOnInvalidEndpointUrl() { + assertThatIllegalArgumentException().isThrownBy(() -> + new MatterfullrtbBidder("invalid_url", jacksonMapper)); + } + + @Test + public void makeHttpRequestShouldReturnErrorsWithoutRequestWhenAllImpsAreInvalid() { + // given + final BidRequest bidRequest = givenBidRequest( + imp -> imp.ext(mapper.valueToTree(ExtPrebid.of(null, mapper.createArrayNode())))); + + // when + final Result>> result = target.makeHttpRequests(bidRequest); + + // then + assertThat(result.getErrors()).hasSize(1) + .allSatisfy(error -> { + assertThat(error.getType()).isEqualTo(BidderError.Type.bad_input); + assertThat(error.getMessage()).startsWith("invalid imp.ext for impression"); + }); + assertThat(result.getValue()).isEmpty(); + } + + @Test + public void makeHttpRequestShouldReturnEmptyResultWhenImpsAreEmpty() { + // given + final BidRequest bidRequest = BidRequest.builder().imp(Collections.emptyList()).build(); + + // when + final Result>> result = target.makeHttpRequests(bidRequest); + + // then + assertThat(result.getErrors()).isEmpty(); + assertThat(result.getValue()).isEmpty(); + } + + @Test + public void makeHttpRequestShouldModifyAppAndSite() { + // given + final Site site = Site.builder() + .publisher(Publisher.builder() + .id("origPub") + .build()) + .build(); + final App app = App.builder() + .domain("origDomain") + .publisher(Publisher.builder() + .id("origPub") + .build()) + .build(); + final BidRequest bidRequest = givenBidRequest( + request -> request.site(site).app(app), + givenImp(imp -> imp.ext(givenImpExt(ExtImpMatterfullrtb.of("pub"))))); + + // when + final Result>> result = target.makeHttpRequests(bidRequest); + + // then + assertThat(result.getErrors()).isEmpty(); + assertThat(result.getValue()).hasSize(1) + .extracting(HttpRequest::getPayload) + .extracting(BidRequest::getApp, BidRequest::getSite) + .containsOnly(tuple( + App.builder().domain("").publisher(null).build(), + Site.builder().publisher(null).build())); + } + + @Test + public void makeHttpRequestShouldNotModifyWhenAppAndSiteAreNull() { + // given + final BidRequest bidRequest = givenBidRequest( + request -> request.site(null).app(null), + givenImp(imp -> imp.ext(givenImpExt(ExtImpMatterfullrtb.of("pub"))))); + + // when + final Result>> result = target.makeHttpRequests(bidRequest); + + // then + assertThat(result.getErrors()).isEmpty(); + assertThat(result.getValue()).hasSize(1) + .extracting(HttpRequest::getPayload) + .extracting(BidRequest::getApp) + .containsOnlyNulls(); + assertThat(result.getValue()) + .extracting(HttpRequest::getPayload) + .extracting(BidRequest::getSite) + .containsOnlyNulls(); + } + + @Test + public void makeHttpRequestShouldResolveUrl() { + // given + final BidRequest bidRequest = givenBidRequest( + identity(), + givenImp(imp -> imp.ext(givenImpExt(ExtImpMatterfullrtb.of("pub"))))); + + // when + final Result>> result = target.makeHttpRequests(bidRequest); + + // then + assertThat(result.getErrors()).isEmpty(); + assertThat(result.getValue()).hasSize(1) + .extracting(HttpRequest::getUri) + .containsExactly("http://test.endpont.com?pid=pub"); + } + + @Test + public void makeHttpRequestShouldCollectImpsWithSamePublisherId() { + // given + final BidRequest bidRequest = givenBidRequest( + identity(), + givenImp(imp -> imp.id("imp-1").ext(givenImpExt(ExtImpMatterfullrtb.of("pub")))), + givenImp(imp -> imp.id("imp-2").ext(givenImpExt(ExtImpMatterfullrtb.of("pub"))))); + + // when + final Result>> result = target.makeHttpRequests(bidRequest); + + // then + assertThat(result.getErrors()).isEmpty(); + assertThat(result.getValue()).hasSize(1); + assertThat(result.getValue()) + .extracting(HttpRequest::getPayload) + .extracting(BidRequest::getImp) + .extracting(List::size) + .containsOnly(2); + } + + @Test + public void makeHttpRequestShouldCreateTwoRequestForDifferentPublisherId() { + // given + final BidRequest bidRequest = givenBidRequest( + identity(), + givenImp(imp -> imp.id("imp-1").ext(givenImpExt(ExtImpMatterfullrtb.of("pub-1")))), + givenImp(imp -> imp.id("imp-2").ext(givenImpExt(ExtImpMatterfullrtb.of("pub-2"))))); + + // when + final Result>> result = target.makeHttpRequests(bidRequest); + + // then + assertThat(result.getErrors()).isEmpty(); + assertThat(result.getValue()).hasSize(2); + } + + @Test + public void makeBidsShouldReturnErrorWhenResponseBodyCouldNotBeParsed() { + // given + final BidderCall httpCall = givenHttpCall("invalid_json"); + + // when + final Result> result = target.makeBids(httpCall, null); + + // then + assertThat(result.getErrors()).hasSize(1) + .allSatisfy(error -> { + assertThat(error.getType()).isEqualTo(BidderError.Type.bad_server_response); + assertThat(error.getMessage()).startsWith("Failed to decode: Unrecognized token 'invalid_json'"); + }); + assertThat(result.getValue()).isEmpty(); + } + + @Test + public void makeBidsShouldReturnVideoBidSuccessfully() throws JsonProcessingException { + // given + final Bid videoBid = givenBid(2); + final BidderCall httpCall = givenHttpCall(givenBidResponse(videoBid)); + + // when + final Result> result = target.makeBids(httpCall, givenBidRequest(identity())); + + // then + assertThat(result.getErrors()).isEmpty(); + assertThat(result.getValue()).hasSize(1) + .containsOnly(BidderBid.of(videoBid, BidType.video, "USD")); + } + + @Test + public void makeBidsShouldReturnBannerBidSuccessfully() throws JsonProcessingException { + // given + final Bid videoBid = givenBid(1); + final BidderCall httpCall = givenHttpCall(givenBidResponse(videoBid)); + + // when + final Result> result = target.makeBids(httpCall, givenBidRequest(identity())); + + // then + assertThat(result.getErrors()).isEmpty(); + assertThat(result.getValue()).hasSize(1) + .containsOnly(BidderBid.of(videoBid, BidType.banner, "USD")); + } + + @Test + public void makeBidsShouldReturnErrorsForUnsupportedMtypes() throws JsonProcessingException { + // given + final Bid validBid = givenBid(1); + final Bid invalidBid = givenBid(5); + final BidderCall httpCall = givenHttpCall(givenBidResponse(validBid, invalidBid)); + + // when + final Result> result = target.makeBids(httpCall, givenBidRequest(identity())); + + // then + assertThat(result.getErrors()).hasSize(1) + .containsExactly(badServerResponse("Unsupported mtype 5 for impression with ID: impId")); + assertThat(result.getValue()).hasSize(1) + .containsExactly(BidderBid.of(validBid, BidType.banner, "USD")); + } + + @Test + public void makeBidShouldReturnMediaTypeFromImpWhenBidMTypeEqualsZero() throws JsonProcessingException { + // given + final Bid bid = givenBid(0, "imp-2"); + final BidderCall httpCall = givenHttpCall(givenBidResponse(bid)); + final BidRequest bidRequest = givenBidRequest( + identity(), + givenImp(imp -> imp.id("imp-2").banner(Banner.builder().build()))); + + // when + final Result> result = target.makeBids(httpCall, bidRequest); + + // then + assertThat(result.getErrors()).isEmpty(); + assertThat(result.getValue()).hasSize(1) + .containsExactly(BidderBid.of(bid, BidType.banner, "USD")); + } + + @Test + public void makeBidShouldReturnErrorWhenBidMTypeEqualsZeroAndImpInvalid() throws JsonProcessingException { + // given + final Bid bid = givenBid(0, "imp-2"); + final BidderCall httpCall = givenHttpCall(givenBidResponse(bid)); + final BidRequest bidRequest = givenBidRequest( + identity(), + givenImp(imp -> imp.id("imp-2").banner(null))); + + // when + final Result> result = target.makeBids(httpCall, bidRequest); + + // then + assertThat(result.getErrors()).hasSize(1) + .containsExactly(badServerResponse("Could not determine media type for impression with ID: imp-2")); + assertThat(result.getValue()).isEmpty(); + } + + @Test + public void makeBidShouldReturnErrorWhenImpIsMultiformatAndMTypeEqualsZero() throws JsonProcessingException { + // given + final Bid bid = givenBid(0, "imp-2"); + final BidderCall httpCall = givenHttpCall(givenBidResponse(bid)); + final BidRequest bidRequest = givenBidRequest( + identity(), + givenImp(imp -> imp.id("imp-2") + .video(Video.builder().build()) + .banner(Banner.builder().build()))); + + // when + final Result> result = target.makeBids(httpCall, bidRequest); + + // then + assertThat(result.getErrors()).hasSize(1) + .containsExactly( + badServerResponse("Bid must have non-zero mtype for multi-format impression with ID: imp-2")); + assertThat(result.getValue()).isEmpty(); + } + + @Test + public void makeBidShouldReturnErrorWhenBidMTypeEqualsZeroAndImpNotFound() throws JsonProcessingException { + // given + final Bid bid = givenBid(0, "imp-1"); + final BidderCall httpCall = givenHttpCall(givenBidResponse(bid)); + final BidRequest bidRequest = givenBidRequest( + identity(), + givenImp(imp -> imp.id("imp-2").banner(Banner.builder().build()))); + + // when + final Result> result = target.makeBids(httpCall, bidRequest); + + // then + assertThat(result.getErrors()).hasSize(1) + .containsExactly(badServerResponse("Failed to find impression for ID: imp-1")); + assertThat(result.getValue()).isEmpty(); + } + + private static BidRequest givenBidRequest(UnaryOperator bidRequestCustomizer, + Imp... imps) { + return bidRequestCustomizer.apply(BidRequest.builder().imp(List.of(imps))).build(); + } + + private static BidRequest givenBidRequest(UnaryOperator impCustomizer) { + return BidRequest.builder().imp(singletonList(givenImp(impCustomizer))).build(); + } + + private static Imp givenImp(UnaryOperator impCustomizer) { + return impCustomizer.apply(Imp.builder() + .id("impId") + .banner(Banner.builder().w(1).h(1).build()) + .ext(givenImpExt(ExtImpMatterfullrtb.of("publisherId")))) + .build(); + } + + private static ObjectNode givenImpExt(ExtImpMatterfullrtb extImpMatterfullrtb) { + return mapper.valueToTree(ExtPrebid.of(null, extImpMatterfullrtb)); + } + + private static BidderCall givenHttpCall(String body) { + return BidderCall.succeededHttp( + HttpRequest.builder().build(), + HttpResponse.of(200, null, body), + null); + } + + private static Bid givenBid(Integer mtype) { + return givenBid(mtype, "impId"); + } + + private static Bid givenBid(Integer mtype, String impId) { + return Bid.builder().id("bidId").impid(impId).price(BigDecimal.ONE).mtype(mtype).build(); + } + + private static String givenBidResponse(Bid... bids) throws JsonProcessingException { + return mapper.writeValueAsString(BidResponse.builder() + .cur("USD") + .seatbid(singletonList(SeatBid.builder().bid(List.of(bids)).build())) + .build()); + } +} diff --git a/src/test/java/org/prebid/server/it/MatterfullRtbTest.java b/src/test/java/org/prebid/server/it/MatterfullRtbTest.java new file mode 100644 index 00000000000..dfa750e916f --- /dev/null +++ b/src/test/java/org/prebid/server/it/MatterfullRtbTest.java @@ -0,0 +1,35 @@ +package org.prebid.server.it; + +import io.restassured.response.Response; +import org.json.JSONException; +import org.junit.jupiter.api.Test; +import org.prebid.server.model.Endpoint; + +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 java.util.Collections.singletonList; + +public class MatterfullRtbTest extends IntegrationTest { + + @Test + public void openrtb2AuctionShouldRespondWithBidsFromMatterfullrtb() throws IOException, JSONException { + // given + WIRE_MOCK_RULE.stubFor(post(urlPathEqualTo("/matterfullrtb-exchange")) + .withRequestBody(equalToJson( + jsonFrom("openrtb2/matterfullrtb/test-matterfullrtb-bid-request.json"))) + .willReturn(aResponse().withBody( + jsonFrom("openrtb2/matterfullrtb/test-matterfullrtb-bid-response.json")))); + + // when + final Response response = responseFor( + "openrtb2/matterfullrtb/test-auction-matterfullrtb-request.json", Endpoint.openrtb2_auction); + + // then + assertJsonEquals("openrtb2/matterfullrtb/test-auction-matterfullrtb-response.json", response, + singletonList("matterfullrtb")); + } +} diff --git a/src/test/resources/org/prebid/server/it/openrtb2/matterfullrtb/test-auction-matterfullrtb-request.json b/src/test/resources/org/prebid/server/it/openrtb2/matterfullrtb/test-auction-matterfullrtb-request.json new file mode 100644 index 00000000000..486b1fda7ba --- /dev/null +++ b/src/test/resources/org/prebid/server/it/openrtb2/matterfullrtb/test-auction-matterfullrtb-request.json @@ -0,0 +1,23 @@ +{ + "id": "request_id", + "imp": [ + { + "id": "imp_id", + "banner": { + "w": 300, + "h": 250 + }, + "ext": { + "matterfullrtb": { + "pid": "LUN2gcJFHRwysZVTm8p3" + } + } + } + ], + "tmax": 5000, + "regs": { + "ext": { + "gdpr": 0 + } + } +} diff --git a/src/test/resources/org/prebid/server/it/openrtb2/matterfullrtb/test-auction-matterfullrtb-response.json b/src/test/resources/org/prebid/server/it/openrtb2/matterfullrtb/test-auction-matterfullrtb-response.json new file mode 100644 index 00000000000..9d72df0637b --- /dev/null +++ b/src/test/resources/org/prebid/server/it/openrtb2/matterfullrtb/test-auction-matterfullrtb-response.json @@ -0,0 +1,43 @@ +{ + "id": "request_id", + "seatbid": [ + { + "bid": [ + { + "id": "bid_id", + "impid": "imp_id", + "exp": 300, + "price": 3.33, + "adm": "adm001", + "adid": "adid001", + "cid": "cid001", + "crid": "crid001", + "w": 300, + "h": 250, + "mtype": 1, + "ext": { + "prebid": { + "type": "banner", + "meta": { + "adaptercode": "matterfullrtb" + } + }, + "origbidcpm": 3.33 + } + } + ], + "seat": "matterfullrtb", + "group": 0 + } + ], + "cur": "USD", + "ext": { + "responsetimemillis": { + "matterfullrtb": "{{ matterfullrtb.response_time_ms }}" + }, + "prebid": { + "auctiontimestamp": 0 + }, + "tmaxrequest": 5000 + } +} diff --git a/src/test/resources/org/prebid/server/it/openrtb2/matterfullrtb/test-matterfullrtb-bid-request.json b/src/test/resources/org/prebid/server/it/openrtb2/matterfullrtb/test-matterfullrtb-bid-request.json new file mode 100644 index 00000000000..73b56aa46a2 --- /dev/null +++ b/src/test/resources/org/prebid/server/it/openrtb2/matterfullrtb/test-matterfullrtb-bid-request.json @@ -0,0 +1,52 @@ +{ + "id": "request_id", + "imp": [ + { + "id": "imp_id", + "secure": 1, + "banner": { + "w": 300, + "h": 250 + }, + "ext": { + "tid": "${json-unit.any-string}", + "bidder": { + "pid": "LUN2gcJFHRwysZVTm8p3" + } + } + } + ], + "source": { + "tid": "${json-unit.any-string}" + }, + "site": { + "domain": "www.example.com", + "page": "http://www.example.com", + "ext": { + "amp": 0 + } + }, + "device": { + "ua": "userAgent", + "ip": "193.168.244.1" + }, + "at": 1, + "tmax": "${json-unit.any-number}", + "cur": [ + "USD" + ], + "regs": { + "gdpr": 0 + }, + "ext": { + "prebid": { + "server": { + "externalurl": "http://localhost:8080", + "gvlid": 1, + "datacenter": "local", + "http_method": "POST", + "endpoint": "/openrtb2/auction" + } + } + } +} diff --git a/src/test/resources/org/prebid/server/it/openrtb2/matterfullrtb/test-matterfullrtb-bid-response.json b/src/test/resources/org/prebid/server/it/openrtb2/matterfullrtb/test-matterfullrtb-bid-response.json new file mode 100644 index 00000000000..2769168e6ed --- /dev/null +++ b/src/test/resources/org/prebid/server/it/openrtb2/matterfullrtb/test-matterfullrtb-bid-response.json @@ -0,0 +1,21 @@ +{ + "id": "request_id", + "seatbid": [ + { + "bid": [ + { + "id": "bid_id", + "impid": "imp_id", + "price": 3.33, + "adid": "adid001", + "crid": "crid001", + "cid": "cid001", + "adm": "adm001", + "mtype": 1, + "h": 250, + "w": 300 + } + ] + } + ] +} diff --git a/src/test/resources/org/prebid/server/it/test-application.properties b/src/test/resources/org/prebid/server/it/test-application.properties index 151edf4395a..b43ea0b532b 100644 --- a/src/test/resources/org/prebid/server/it/test-application.properties +++ b/src/test/resources/org/prebid/server/it/test-application.properties @@ -402,6 +402,8 @@ adapters.madvertise.enabled=true adapters.madvertise.endpoint=http://localhost:8090/madvertise-exchange adapters.marsmedia.enabled=true adapters.marsmedia.endpoint=http://localhost:8090/marsmedia-exchange +adapters.matterfullrtb.enabled=true +adapters.matterfullrtb.endpoint=http://localhost:8090/matterfullrtb-exchange adapters.mediago.enabled=true adapters.mediago.endpoint=http://localhost:8090/mediago-exchange adapters.mediago.aliases.mgtechnology.enabled=true