diff --git a/src/main/java/org/prebid/server/bidder/pubrise/PubriseBidder.java b/src/main/java/org/prebid/server/bidder/pubrise/PubriseBidder.java new file mode 100644 index 00000000000..f8fe37197b0 --- /dev/null +++ b/src/main/java/org/prebid/server/bidder/pubrise/PubriseBidder.java @@ -0,0 +1,138 @@ +package org.prebid.server.bidder.pubrise; + +import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.databind.node.ObjectNode; +import com.iab.openrtb.request.BidRequest; +import com.iab.openrtb.request.Imp; +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.apache.commons.lang3.StringUtils; +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.bidder.pubrise.proto.PubriseImpExtBidder; +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.pubrise.ExtImpPubrise; +import org.prebid.server.proto.openrtb.ext.response.BidType; +import org.prebid.server.util.BidderUtil; +import org.prebid.server.util.HttpUtil; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.List; +import java.util.Objects; + +public class PubriseBidder implements Bidder { + + private static final TypeReference> TYPE_REFERENCE = new TypeReference<>() { + }; + + private final String endpointUrl; + private final JacksonMapper mapper; + + public PubriseBidder(String endpointUrl, JacksonMapper mapper) { + this.endpointUrl = HttpUtil.validateUrl(Objects.requireNonNull(endpointUrl)); + this.mapper = Objects.requireNonNull(mapper); + } + + @Override + public Result>> makeHttpRequests(BidRequest request) { + final List> outgoingRequests = new ArrayList<>(); + final List errors = new ArrayList<>(); + + for (Imp imp : request.getImp()) { + final ExtImpPubrise extImp; + try { + extImp = parseImpExt(imp); + outgoingRequests.add(makeRequest(modifyImp(imp, extImp), request)); + } catch (PreBidException e) { + errors.add(BidderError.badInput(e.getMessage())); + } + } + + return CollectionUtils.isEmpty(outgoingRequests) + ? Result.withError(BidderError.badInput("found no valid impressions")) + : Result.of(outgoingRequests, errors); + } + + private ExtImpPubrise parseImpExt(Imp imp) { + try { + return mapper.mapper().convertValue(imp.getExt(), TYPE_REFERENCE).getBidder(); + } catch (IllegalArgumentException e) { + throw new PreBidException(e.getMessage()); + } + } + + private Imp modifyImp(Imp imp, ExtImpPubrise extImp) { + final PubriseImpExtBidder impExtBidder = getImpExtWithType(extImp); + final ObjectNode modifiedImpExtBidder = mapper.mapper().createObjectNode(); + + modifiedImpExtBidder.set("bidder", mapper.mapper().valueToTree(impExtBidder)); + + return imp.toBuilder().ext(modifiedImpExtBidder).build(); + } + + private PubriseImpExtBidder getImpExtWithType(ExtImpPubrise extImpQt) { + final boolean hasPlacementId = StringUtils.isNotBlank(extImpQt.getPlacementId()); + final boolean hasEndpointId = StringUtils.isNotBlank(extImpQt.getEndpointId()); + + return PubriseImpExtBidder.builder() + .type(hasPlacementId ? "publisher" : hasEndpointId ? "network" : null) + .placementId(hasPlacementId ? extImpQt.getPlacementId() : null) + .endpointId(hasEndpointId ? extImpQt.getEndpointId() : null) + .build(); + } + + private HttpRequest makeRequest(Imp imp, BidRequest request) { + final BidRequest outgoingRequest = request.toBuilder().imp(Collections.singletonList(imp)).build(); + return BidderUtil.defaultRequest(outgoingRequest, endpointUrl, mapper); + } + + @Override + public Result> makeBids(BidderCall httpCall, BidRequest bidRequest) { + try { + final BidResponse bidResponse = mapper.decodeValue(httpCall.getResponse().getBody(), BidResponse.class); + return Result.withValues(extractBids(bidResponse)); + } catch (DecodeException | PreBidException e) { + return Result.withError(BidderError.badServerResponse(e.getMessage())); + } + } + + private static List extractBids(BidResponse bidResponse) { + if (bidResponse == null || CollectionUtils.isEmpty(bidResponse.getSeatbid())) { + return Collections.emptyList(); + } + + return bidResponse.getSeatbid().stream() + .filter(Objects::nonNull) + .map(SeatBid::getBid).filter(Objects::nonNull) + .flatMap(Collection::stream) + .filter(Objects::nonNull) + .map(bid -> BidderBid.of(bid, getBidType(bid), bidResponse.getCur())) + .toList(); + } + + private static BidType getBidType(Bid bid) { + final Integer markupType = bid.getMtype(); + if (markupType == null) { + throw new PreBidException("Missing MType for bid: " + bid.getId()); + } + + return switch (markupType) { + case 1 -> BidType.banner; + case 2 -> BidType.video; + case 4 -> BidType.xNative; + default -> throw new PreBidException("Unable to fetch mediaType in multi-format: %s" + .formatted(bid.getImpid())); + }; + } +} diff --git a/src/main/java/org/prebid/server/bidder/pubrise/proto/PubriseImpExtBidder.java b/src/main/java/org/prebid/server/bidder/pubrise/proto/PubriseImpExtBidder.java new file mode 100644 index 00000000000..2cb89d4d287 --- /dev/null +++ b/src/main/java/org/prebid/server/bidder/pubrise/proto/PubriseImpExtBidder.java @@ -0,0 +1,18 @@ +package org.prebid.server.bidder.pubrise.proto; + +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.Builder; +import lombok.Value; + +@Builder +@Value +public class PubriseImpExtBidder { + + String type; + + @JsonProperty("placementId") + String placementId; + + @JsonProperty("endpointId") + String endpointId; +} diff --git a/src/main/java/org/prebid/server/bidder/qt/QtBidder.java b/src/main/java/org/prebid/server/bidder/qt/QtBidder.java index a53ca985d6a..4b07ff86e97 100644 --- a/src/main/java/org/prebid/server/bidder/qt/QtBidder.java +++ b/src/main/java/org/prebid/server/bidder/qt/QtBidder.java @@ -20,7 +20,7 @@ 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.ExtImpQt; +import org.prebid.server.proto.openrtb.ext.request.qt.ExtImpQt; import org.prebid.server.proto.openrtb.ext.response.BidType; import org.prebid.server.util.BidderUtil; import org.prebid.server.util.HttpUtil; diff --git a/src/main/java/org/prebid/server/proto/openrtb/ext/request/pubrise/ExtImpPubrise.java b/src/main/java/org/prebid/server/proto/openrtb/ext/request/pubrise/ExtImpPubrise.java new file mode 100644 index 00000000000..6cac7640123 --- /dev/null +++ b/src/main/java/org/prebid/server/proto/openrtb/ext/request/pubrise/ExtImpPubrise.java @@ -0,0 +1,14 @@ +package org.prebid.server.proto.openrtb.ext.request.pubrise; + +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.Value; + +@Value(staticConstructor = "of") +public class ExtImpPubrise { + + @JsonProperty("placementId") + String placementId; + + @JsonProperty("endpointId") + String endpointId; +} diff --git a/src/main/java/org/prebid/server/proto/openrtb/ext/request/ExtImpQt.java b/src/main/java/org/prebid/server/proto/openrtb/ext/request/qt/ExtImpQt.java similarity index 81% rename from src/main/java/org/prebid/server/proto/openrtb/ext/request/ExtImpQt.java rename to src/main/java/org/prebid/server/proto/openrtb/ext/request/qt/ExtImpQt.java index 084e236a063..0f5df5f144d 100644 --- a/src/main/java/org/prebid/server/proto/openrtb/ext/request/ExtImpQt.java +++ b/src/main/java/org/prebid/server/proto/openrtb/ext/request/qt/ExtImpQt.java @@ -1,4 +1,4 @@ -package org.prebid.server.proto.openrtb.ext.request; +package org.prebid.server.proto.openrtb.ext.request.qt; import com.fasterxml.jackson.annotation.JsonProperty; import lombok.Value; diff --git a/src/main/java/org/prebid/server/spring/config/bidder/PubriseConfiguration.java b/src/main/java/org/prebid/server/spring/config/bidder/PubriseConfiguration.java new file mode 100644 index 00000000000..e8fd5755a58 --- /dev/null +++ b/src/main/java/org/prebid/server/spring/config/bidder/PubriseConfiguration.java @@ -0,0 +1,41 @@ +package org.prebid.server.spring.config.bidder; + +import org.prebid.server.bidder.BidderDeps; +import org.prebid.server.bidder.pubrise.PubriseBidder; +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.config.bidder.util.UsersyncerCreator; +import org.prebid.server.spring.env.YamlPropertySourceFactory; +import org.springframework.beans.factory.annotation.Value; +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; + +import jakarta.validation.constraints.NotBlank; + +@Configuration +@PropertySource(value = "classpath:/bidder-config/pubrise.yaml", factory = YamlPropertySourceFactory.class) +public class PubriseConfiguration { + + private static final String BIDDER_NAME = "pubrise"; + + @Bean("pubriseConfigurationProperties") + @ConfigurationProperties("adapters.pubrise") + BidderConfigurationProperties configurationProperties() { + return new BidderConfigurationProperties(); + } + + @Bean + BidderDeps pubriseBidderDeps(BidderConfigurationProperties pubriseConfigurationProperties, + @NotBlank @Value("${external-url}") String externalUrl, + JacksonMapper mapper) { + + return BidderDepsAssembler.forBidder(BIDDER_NAME) + .withConfig(pubriseConfigurationProperties) + .usersyncerCreator(UsersyncerCreator.create(externalUrl)) + .bidderCreator(config -> new PubriseBidder(config.getEndpoint(), mapper)) + .assemble(); + } +} diff --git a/src/main/resources/bidder-config/pubrise.yaml b/src/main/resources/bidder-config/pubrise.yaml new file mode 100644 index 00000000000..ae7768d44b2 --- /dev/null +++ b/src/main/resources/bidder-config/pubrise.yaml @@ -0,0 +1,25 @@ +adapters: + pubrise: + endpoint: https://backend.pubrise.ai/ + meta-info: + maintainer-email: prebid@pubrise.ai + app-media-types: + - banner + - video + - native + site-media-types: + - banner + - video + - native + supported-vendors: + vendor-id: 0 + usersync: + cookie-family-name: pubrise + redirect: + support-cors: false + url: https://sync.pubrise.ai/pbserver?gdpr={{gdpr}}&gdpr_consent={{gdpr_consent}}&ccpa={{us_privacy}}&gpp={{gpp}}&gpp_sid={{gpp_sid}}&redir={{redirect_url}} + uid-macro: '[UID]' + iframe: + support-cors: false + url: https://sync.pubrise.ai/pbserverIframe?gdpr={{gdpr}}&gdpr_consent={{gdpr_consent}}&ccpa={{us_privacy}}&gpp={{gpp}}&gpp_sid={{gpp_sid}}&pbserverUrl={{redirect_url}} + uid-macro: '[UID]' diff --git a/src/main/resources/static/bidder-params/pubrise.json b/src/main/resources/static/bidder-params/pubrise.json new file mode 100644 index 00000000000..9dd2a1e4c80 --- /dev/null +++ b/src/main/resources/static/bidder-params/pubrise.json @@ -0,0 +1,30 @@ +{ + "$schema": "http://json-schema.org/draft-04/schema#", + "title": "Pubrise Adapter Params", + "description": "A schema which validates params accepted by the Pubrise adapter", + "type": "object", + "properties": { + "placementId": { + "type": "string", + "minLength": 1, + "description": "Placement ID" + }, + "endpointId": { + "type": "string", + "minLength": 1, + "description": "Endpoint ID" + } + }, + "oneOf": [ + { + "required": [ + "placementId" + ] + }, + { + "required": [ + "endpointId" + ] + } + ] +} diff --git a/src/test/java/org/prebid/server/bidder/pubrise/PubriseBidderTest.java b/src/test/java/org/prebid/server/bidder/pubrise/PubriseBidderTest.java new file mode 100644 index 00000000000..82d33a0b838 --- /dev/null +++ b/src/test/java/org/prebid/server/bidder/pubrise/PubriseBidderTest.java @@ -0,0 +1,333 @@ +package org.prebid.server.bidder.pubrise; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.node.ObjectNode; +import com.iab.openrtb.request.BidRequest; +import com.iab.openrtb.request.Imp; +import com.iab.openrtb.response.Bid; +import com.iab.openrtb.response.BidResponse; +import com.iab.openrtb.response.SeatBid; +import org.junit.jupiter.api.Test; +import org.prebid.server.VertxTest; +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.bidder.pubrise.proto.PubriseImpExtBidder; +import org.prebid.server.proto.openrtb.ext.ExtPrebid; +import org.prebid.server.proto.openrtb.ext.request.pubrise.ExtImpPubrise; + +import java.util.Arrays; +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.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; +import static org.prebid.server.util.HttpUtil.ACCEPT_HEADER; +import static org.prebid.server.util.HttpUtil.APPLICATION_JSON_CONTENT_TYPE; +import static org.prebid.server.util.HttpUtil.CONTENT_TYPE_HEADER; +import static org.springframework.util.MimeTypeUtils.APPLICATION_JSON_VALUE; + +public class PubriseBidderTest extends VertxTest { + + private static final String ENDPOINT_URL = "https://test.endpoint.com/"; + + private final PubriseBidder target = new PubriseBidder(ENDPOINT_URL, jacksonMapper); + + @Test + public void creationShouldFailOnInvalidEndpointUrl() { + assertThatIllegalArgumentException().isThrownBy(() -> new PubriseBidder("invalid_url", jacksonMapper)); + } + + @Test + public void makeHttpRequestsShouldReturnExpectedHeaders() { + // given + final BidRequest bidRequest = givenBidRequest(identity()); + + // when + final Result>> result = target.makeHttpRequests(bidRequest); + + // then + assertThat(result.getValue()).hasSize(1).first() + .extracting(HttpRequest::getHeaders) + .satisfies(headers -> assertThat(headers.get(CONTENT_TYPE_HEADER)) + .isEqualTo(APPLICATION_JSON_CONTENT_TYPE)) + .satisfies(headers -> assertThat(headers.get(ACCEPT_HEADER)) + .isEqualTo(APPLICATION_JSON_VALUE)); + assertThat(result.getErrors()).isEmpty(); + } + + @Test + public void makeHttpRequestsShouldUseCorrectUri() { + // given + final BidRequest bidRequest = givenBidRequest(identity()); + + // when + final Result>> result = target.makeHttpRequests(bidRequest); + + // then + assertThat(result.getErrors()).isEmpty(); + assertThat(result.getValue()) + .extracting(HttpRequest::getUri) + .containsExactly("https://test.endpoint.com/"); + } + + @Test + public void makeHttpRequestsShouldHaveImpIds() { + // given + final BidRequest bidRequest = givenBidRequest(imp -> imp.id("givenImp1"), imp -> imp.id("givenImp2")); + + //when + final Result>> result = target.makeHttpRequests(bidRequest); + + //then + assertThat(result.getErrors()).isEmpty(); + assertThat(result.getValue()).hasSize(2) + .extracting(HttpRequest::getImpIds) + .containsExactlyInAnyOrder(Collections.singleton("givenImp1"), Collections.singleton("givenImp2")); + } + + @Test + public void makeHttpRequestsShouldMakeOneRequestWhenOneImpIsValidAndAnotherIsNot() { + // given + final BidRequest bidRequest = givenBidRequest( + imp -> imp + .id("invalidImpId") + .ext(mapper.valueToTree(ExtPrebid.of(null, mapper.createArrayNode()))), + imp -> imp.id("validImpId")); + + //when + final Result>> result = target.makeHttpRequests(bidRequest); + + //then + assertThat(result.getValue()).hasSize(1) + .extracting(HttpRequest::getPayload) + .flatExtracting(BidRequest::getImp) + .extracting(Imp::getId) + .containsExactly("validImpId"); + } + + @Test + public void makeHttpRequestsShouldReturnErrorWhenNoValidImps() { + // given + final BidRequest bidRequest = givenBidRequest( + imp -> imp + .id("invalidImpId") + .ext(mapper.valueToTree(ExtPrebid.of(null, mapper.createArrayNode())))); + + //when + final Result>> result = target.makeHttpRequests(bidRequest); + + //then + assertThat(result.getValue()).isEmpty(); + assertThat(result.getErrors()).containsOnly(BidderError.badInput("found no valid impressions")); + } + + @Test + public void makeHttpRequestsShouldMakeOneRequestPerImp() { + // given + final BidRequest bidRequest = givenBidRequest(imp -> imp.id("givenImp1"), imp -> imp.id("givenImp2")); + + // when + final Result>> result = target.makeHttpRequests(bidRequest); + + // then + assertThat(result.getErrors()).isEmpty(); + assertThat(result.getValue()).hasSize(2) + .extracting(HttpRequest::getPayload) + .extracting(BidRequest::getImp) + .extracting(List::size) + .containsOnly(1); + } + + @Test + public void makeHttpRequestsShouldReturnExtTypePublisher() { + // given + final BidRequest bidRequest = givenBidRequest(imp -> + imp.ext(mapper.valueToTree(ExtPrebid.of(null, + ExtImpPubrise.of("somePlacementId", ""))))); + + // when + final Result>> result = target.makeHttpRequests(bidRequest); + + // then + assertThat(result.getErrors()).isEmpty(); + assertThat(result.getValue()) + .extracting(HttpRequest::getPayload) + .flatExtracting(BidRequest::getImp) + .extracting(Imp::getExt) + .containsExactly(givenImpExt(ext -> ext.type("publisher").placementId("somePlacementId"))); + } + + @Test + public void makeHttpRequestsShouldReturnExtTypeNetwork() { + // given + final BidRequest bidRequest = givenBidRequest(imp -> + imp.ext(mapper.valueToTree(ExtPrebid.of(null, + ExtImpPubrise.of("", "someEndpointId"))))); + + // when + final Result>> result = target.makeHttpRequests(bidRequest); + + // then + assertThat(result.getErrors()).isEmpty(); + assertThat(result.getValue()) + .extracting(HttpRequest::getPayload) + .flatExtracting(BidRequest::getImp) + .extracting(Imp::getExt) + .containsExactly(givenImpExt(ext -> ext.type("network").endpointId("someEndpointId"))); + } + + @Test + public void makeBidsShouldReturnEmptyListIfBidResponseIsNull() throws JsonProcessingException { + // given + final BidderCall httpCall = givenHttpCall(mapper.writeValueAsString(null)); + + // when + final Result> result = target.makeBids(httpCall, null); + + // then + assertThat(result.getErrors()).isEmpty(); + assertThat(result.getValue()).isEmpty(); + } + + @Test + public void makeBidsShouldReturnErrorIfResponseBodyCouldNotBeParsed() { + // given + final BidderCall httpCall = givenHttpCall("invalid"); + + // when + final Result> result = target.makeBids(httpCall, null); + + // then + assertThat(result.getValue()).isEmpty(); + assertThat(result.getErrors()).hasSize(1) + .allSatisfy(error -> { + assertThat(error.getMessage()).startsWith("Failed to decode: Unrecognized token 'invalid':"); + assertThat(error.getType()).isEqualTo(BidderError.Type.bad_server_response); + }); + } + + @Test + public void makeBidsShouldReturnEmptyListIfBidResponseSeatBidIsNull() throws JsonProcessingException { + // given + final BidderCall httpCall = givenHttpCall(mapper.writeValueAsString(BidResponse.builder().build())); + + // when + final Result> result = target.makeBids(httpCall, null); + + // then + assertThat(result.getErrors()).isEmpty(); + assertThat(result.getValue()).isEmpty(); + } + + @Test + public void makeBidsShouldReturnxNativeBid() throws JsonProcessingException { + // given + final BidderCall httpCall = givenHttpCall( + givenBidResponse(bidBuilder -> bidBuilder.mtype(4).impid("impId"))); + + // when + final Result> result = target.makeBids(httpCall, null); + + // then + assertThat(result.getErrors()).isEmpty(); + assertThat(result.getValue()) + .containsExactly(BidderBid.of(Bid.builder().impid("impId").mtype(4).build(), xNative, "USD")); + } + + @Test + public void makeBidsShouldReturnBannerBid() throws JsonProcessingException { + // given + final BidderCall httpCall = givenHttpCall( + givenBidResponse(bidBuilder -> bidBuilder.mtype(1).impid("impId"))); + + // when + final Result> result = target.makeBids(httpCall, null); + + // then + assertThat(result.getErrors()).isEmpty(); + assertThat(result.getValue()) + .containsExactly(BidderBid.of(Bid.builder().mtype(1).impid("impId").build(), banner, "USD")); + } + + @Test + public void makeBidsShouldReturnVideoBid() throws JsonProcessingException { + // given + final BidderCall httpCall = givenHttpCall( + givenBidResponse(bidBuilder -> bidBuilder.mtype(2).impid("impId"))); + + // when + final Result> result = target.makeBids(httpCall, null); + + // then + assertThat(result.getErrors()).isEmpty(); + assertThat(result.getValue()) + .containsExactly(BidderBid.of(Bid.builder().mtype(2).impid("impId").build(), video, "USD")); + } + + @Test + public void makeBidsShouldThrowErrorWhenMediaTypeIsMissing() throws JsonProcessingException { + // given + final BidderCall httpCall = givenHttpCall( + givenBidResponse(bidBuilder -> bidBuilder.impid("impId"))); + + // when + final Result> result = target.makeBids(httpCall, null); + + // then + assertThat(result.getValue()).isEmpty(); + assertThat(result.getErrors()).hasSize(1) + .allSatisfy(error -> { + assertThat(error.getMessage()).startsWith("Missing MType for bid: null"); + assertThat(error.getType()).isEqualTo(BidderError.Type.bad_server_response); + }); + } + + private static BidRequest givenBidRequest(UnaryOperator... impCustomizers) { + return BidRequest.builder() + .imp(Arrays.stream(impCustomizers).map(PubriseBidderTest::givenImp).toList()) + .build(); + } + + private static Imp givenImp(UnaryOperator impCustomizer) { + return impCustomizer.apply(Imp.builder() + .id("impId") + .ext(mapper.valueToTree(ExtPrebid.of(null, + ExtImpPubrise.of("placementId", "endpointId"))))) + .build(); + } + + private String givenBidResponse(UnaryOperator bidCustomizer) throws JsonProcessingException { + return mapper.writeValueAsString(BidResponse.builder() + .cur("USD") + .seatbid(singletonList(SeatBid.builder() + .bid(singletonList(bidCustomizer.apply(Bid.builder()).build())) + .build())) + .build()); + } + + private static BidderCall givenHttpCall(String body) { + return BidderCall.succeededHttp( + HttpRequest.builder().payload(null).build(), + HttpResponse.of(200, null, body), + null); + } + + private ObjectNode givenImpExt(UnaryOperator impExt) { + final ObjectNode modifiedImpExtBidder = mapper.createObjectNode(); + + return modifiedImpExtBidder.set("bidder", mapper.convertValue( + impExt.apply(PubriseImpExtBidder.builder()).build(), + JsonNode.class)); + } +} diff --git a/src/test/java/org/prebid/server/bidder/qt/QtBidderTest.java b/src/test/java/org/prebid/server/bidder/qt/QtBidderTest.java index 660049e507a..71daee260a6 100644 --- a/src/test/java/org/prebid/server/bidder/qt/QtBidderTest.java +++ b/src/test/java/org/prebid/server/bidder/qt/QtBidderTest.java @@ -19,7 +19,7 @@ import org.prebid.server.bidder.qt.proto.QtImpExtBidder; import org.prebid.server.bidder.qt.proto.QtImpExtBidder.QtImpExtBidderBuilder; import org.prebid.server.proto.openrtb.ext.ExtPrebid; -import org.prebid.server.proto.openrtb.ext.request.ExtImpQt; +import org.prebid.server.proto.openrtb.ext.request.qt.ExtImpQt; import java.util.Collections; import java.util.List; diff --git a/src/test/java/org/prebid/server/it/PubriseTest.java b/src/test/java/org/prebid/server/it/PubriseTest.java new file mode 100644 index 00000000000..c5ab3812e24 --- /dev/null +++ b/src/test/java/org/prebid/server/it/PubriseTest.java @@ -0,0 +1,33 @@ +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 PubriseTest extends IntegrationTest { + + @Test + public void openrtb2AuctionShouldRespondWithBidsFromPubrise() throws IOException, JSONException { + // given + WIRE_MOCK_RULE.stubFor(post(urlPathEqualTo("/pubrise-exchange")) + .withRequestBody(equalToJson(jsonFrom("openrtb2/pubrise/test-pubrise-bid-request.json"))) + .willReturn(aResponse().withBody(jsonFrom("openrtb2/pubrise/test-pubrise-bid-response.json")))); + + // when + final Response response = responseFor("openrtb2/pubrise/test-auction-pubrise-request.json", + Endpoint.openrtb2_auction); + + // then + assertJsonEquals("openrtb2/pubrise/test-auction-pubrise-response.json", response, + singletonList("pubrise")); + } +} diff --git a/src/test/resources/org/prebid/server/it/openrtb2/pubrise/test-auction-pubrise-request.json b/src/test/resources/org/prebid/server/it/openrtb2/pubrise/test-auction-pubrise-request.json new file mode 100644 index 00000000000..ae786238146 --- /dev/null +++ b/src/test/resources/org/prebid/server/it/openrtb2/pubrise/test-auction-pubrise-request.json @@ -0,0 +1,26 @@ +{ + "id": "request_id", + "imp": [ + { + "id": "imp_id", + "video": { + "mimes": [ + "video/mp4" + ], + "w": 800, + "h": 600 + }, + "ext": { + "pubrise": { + "endpointId": "test" + } + } + } + ], + "tmax": 5000, + "regs": { + "ext": { + "gdpr": 0 + } + } +} diff --git a/src/test/resources/org/prebid/server/it/openrtb2/pubrise/test-auction-pubrise-response.json b/src/test/resources/org/prebid/server/it/openrtb2/pubrise/test-auction-pubrise-response.json new file mode 100644 index 00000000000..a49d1f99e75 --- /dev/null +++ b/src/test/resources/org/prebid/server/it/openrtb2/pubrise/test-auction-pubrise-response.json @@ -0,0 +1,37 @@ +{ + "id": "request_id", + "seatbid": [ + { + "bid": [ + { + "id": "bid_id", + "impid": "imp_id", + "price": 1.25, + "adm": "adm001", + "crid": "crid", + "w": 800, + "h": 600, + "ext": { + "prebid": { + "type": "video" + }, + "origbidcpm": 1.25 + }, + "mtype": 2 + } + ], + "seat": "pubrise", + "group": 0 + } + ], + "cur": "USD", + "ext": { + "responsetimemillis": { + "pubrise": "{{ pubrise.response_time_ms }}" + }, + "prebid": { + "auctiontimestamp": 0 + }, + "tmaxrequest": 5000 + } +} diff --git a/src/test/resources/org/prebid/server/it/openrtb2/pubrise/test-pubrise-bid-request.json b/src/test/resources/org/prebid/server/it/openrtb2/pubrise/test-pubrise-bid-request.json new file mode 100644 index 00000000000..5da47810a6b --- /dev/null +++ b/src/test/resources/org/prebid/server/it/openrtb2/pubrise/test-pubrise-bid-request.json @@ -0,0 +1,59 @@ +{ + "id": "request_id", + "imp": [ + { + "id": "imp_id", + "secure": 1, + "video": { + "mimes": [ + "video/mp4" + ], + "w": 800, + "h": 600 + }, + "ext": { + "bidder": { + "type": "network", + "endpointId": "test" + } + } + } + ], + "source": { + "tid": "${json-unit.any-string}" + }, + "site": { + "domain": "www.example.com", + "page": "http://www.example.com", + "publisher": { + "domain": "example.com" + }, + "ext": { + "amp": 0 + } + }, + "device": { + "ua": "userAgent", + "ip": "193.168.244.1" + }, + "at": 1, + "tmax": "${json-unit.any-number}", + "cur": [ + "USD" + ], + "regs": { + "ext": { + "gdpr": 0 + } + }, + "ext": { + "prebid": { + "server": { + "externalurl": "http://localhost:8080", + "gvlid": 1, + "datacenter": "local", + "endpoint": "/openrtb2/auction" + } + } + } +} diff --git a/src/test/resources/org/prebid/server/it/openrtb2/pubrise/test-pubrise-bid-response.json b/src/test/resources/org/prebid/server/it/openrtb2/pubrise/test-pubrise-bid-response.json new file mode 100644 index 00000000000..b00165a1652 --- /dev/null +++ b/src/test/resources/org/prebid/server/it/openrtb2/pubrise/test-pubrise-bid-response.json @@ -0,0 +1,20 @@ +{ + "id": "request_id", + "seatbid": [ + { + "bid": [ + { + "id": "bid_id", + "impid": "imp_id", + "price": 1.25, + "crid": "crid", + "adm": "adm001", + "h": 600, + "w": 800, + "mtype": 2 + } + ] + } + ], + "bidid": "bid001" +} 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 7837504196b..3e43d0e35e2 100644 --- a/src/test/resources/org/prebid/server/it/test-application.properties +++ b/src/test/resources/org/prebid/server/it/test-application.properties @@ -342,6 +342,8 @@ adapters.pubmatic.enabled=true adapters.pubmatic.endpoint=http://localhost:8090/pubmatic-exchange adapters.pubnative.enabled=true adapters.pubnative.endpoint=http://localhost:8090/pubnative-exchange +adapters.pubrise.enabled=true +adapters.pubrise.endpoint=http://localhost:8090/pubrise-exchange adapters.pulsepoint.enabled=true adapters.pulsepoint.endpoint=http://localhost:8090/pulsepoint-exchange adapters.pwbid.enabled=true