diff --git a/src/main/java/org/prebid/server/bidder/playdigo/PlaydigoBidder.java b/src/main/java/org/prebid/server/bidder/playdigo/PlaydigoBidder.java new file mode 100644 index 00000000000..0744bb83d56 --- /dev/null +++ b/src/main/java/org/prebid/server/bidder/playdigo/PlaydigoBidder.java @@ -0,0 +1,148 @@ +package org.prebid.server.bidder.playdigo; + +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 io.micrometer.common.util.StringUtils; +import org.apache.commons.collections4.CollectionUtils; +import org.apache.commons.lang3.ObjectUtils; +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.playdigo.ExtImpPlaydigo; +import org.prebid.server.proto.openrtb.ext.request.playdigo.PlaydigoImpExt; +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 PlaydigoBidder implements Bidder { + + private static final TypeReference> PLAYDIGO_EXT_TYPE_REFERENCE = + new TypeReference<>() { + }; + + private static final String PUBLISHER_PROPERTY = "publisher"; + private static final String NETWORK_PROPERTY = "network"; + private static final String BIDDER_PROPERTY = "bidder"; + + private final String endpointUrl; + private final JacksonMapper mapper; + + public PlaydigoBidder(String endpointUrl, JacksonMapper mapper) { + this.endpointUrl = HttpUtil.validateUrl(Objects.requireNonNull(endpointUrl)); + this.mapper = Objects.requireNonNull(mapper); + } + + @Override + public Result>> makeHttpRequests(BidRequest request) { + final List errors = new ArrayList<>(); + final List> httpRequests = new ArrayList<>(); + + for (Imp imp : request.getImp()) { + final ExtImpPlaydigo extImpPlaydigo; + try { + extImpPlaydigo = parseExtImp(imp); + final Imp modifiedImp = modifyImp(imp, extImpPlaydigo); + httpRequests.add(makeHttpRequest(request, modifiedImp)); + } catch (PreBidException e) { + errors.add(BidderError.badInput(e.getMessage())); + } + } + + if (httpRequests.isEmpty()) { + return Result.withError(BidderError.badInput("found no valid impressions")); + } + + return Result.of(httpRequests, errors); + } + + private ExtImpPlaydigo parseExtImp(Imp imp) { + try { + return mapper.mapper().convertValue(imp.getExt(), PLAYDIGO_EXT_TYPE_REFERENCE).getBidder(); + } catch (IllegalArgumentException e) { + throw new PreBidException(e.getMessage()); + } + } + + private Imp modifyImp(Imp imp, ExtImpPlaydigo extImpPlaydigo) { + final PlaydigoImpExt impExtPlaydigoWithType = resolveImpExt(extImpPlaydigo); + final ObjectNode modifiedImpExtBidder = mapper.mapper().createObjectNode(); + modifiedImpExtBidder.set(BIDDER_PROPERTY, mapper.mapper().valueToTree(impExtPlaydigoWithType)); + + return imp.toBuilder().ext(modifiedImpExtBidder).build(); + } + + private PlaydigoImpExt resolveImpExt(ExtImpPlaydigo extImpPlaydigo) { + final PlaydigoImpExt.PlaydigoImpExtBuilder builder = PlaydigoImpExt.builder(); + + if (StringUtils.isNotEmpty(extImpPlaydigo.getPlacementId())) { + builder.type(PUBLISHER_PROPERTY).placementId(extImpPlaydigo.getPlacementId()); + } else if (StringUtils.isNotEmpty(extImpPlaydigo.getEndpointId())) { + builder.type(NETWORK_PROPERTY).endpointId(extImpPlaydigo.getEndpointId()); + } + + return builder.build(); + } + + private HttpRequest makeHttpRequest(BidRequest request, Imp imp) { + final BidRequest outgoingRequest = request.toBuilder().imp(List.of(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); + final List bids = extractBids(httpCall.getRequest().getPayload(), bidResponse); + return Result.withValues(bids); + } catch (DecodeException | PreBidException e) { + return Result.withError(BidderError.badServerResponse(e.getMessage())); + } + } + + private List extractBids(BidRequest bidRequest, 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 BidType getBidType(Bid bid) { + final Integer markupType = ObjectUtils.defaultIfNull(bid.getMtype(), 0); + + return switch (markupType) { + case 1 -> BidType.banner; + case 2 -> BidType.video; + case 3 -> BidType.audio; + case 4 -> BidType.xNative; + default -> throw new PreBidException( + "could not define media type for impression: " + bid.getImpid()); + }; + } +} diff --git a/src/main/java/org/prebid/server/proto/openrtb/ext/request/playdigo/ExtImpPlaydigo.java b/src/main/java/org/prebid/server/proto/openrtb/ext/request/playdigo/ExtImpPlaydigo.java new file mode 100644 index 00000000000..e15f82a9c2d --- /dev/null +++ b/src/main/java/org/prebid/server/proto/openrtb/ext/request/playdigo/ExtImpPlaydigo.java @@ -0,0 +1,14 @@ +package org.prebid.server.proto.openrtb.ext.request.playdigo; + +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.Value; + +@Value(staticConstructor = "of") +public class ExtImpPlaydigo { + + @JsonProperty("placementId") + String placementId; + + @JsonProperty("endpointId") + String endpointId; +} diff --git a/src/main/java/org/prebid/server/proto/openrtb/ext/request/playdigo/PlaydigoImpExt.java b/src/main/java/org/prebid/server/proto/openrtb/ext/request/playdigo/PlaydigoImpExt.java new file mode 100644 index 00000000000..f46c3d5a17a --- /dev/null +++ b/src/main/java/org/prebid/server/proto/openrtb/ext/request/playdigo/PlaydigoImpExt.java @@ -0,0 +1,18 @@ +package org.prebid.server.proto.openrtb.ext.request.playdigo; + +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.Builder; +import lombok.Value; + +@Value +@Builder +public class PlaydigoImpExt { + + String type; + + @JsonProperty("placementId") + String placementId; + + @JsonProperty("endpointId") + String endpointId; +} diff --git a/src/main/java/org/prebid/server/spring/config/bidder/PlaydigoConfiguration.java b/src/main/java/org/prebid/server/spring/config/bidder/PlaydigoConfiguration.java new file mode 100644 index 00000000000..75ae60eb5af --- /dev/null +++ b/src/main/java/org/prebid/server/spring/config/bidder/PlaydigoConfiguration.java @@ -0,0 +1,41 @@ +package org.prebid.server.spring.config.bidder; + +import org.prebid.server.bidder.BidderDeps; +import org.prebid.server.bidder.playdigo.PlaydigoBidder; +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/playdigo.yaml", factory = YamlPropertySourceFactory.class) +public class PlaydigoConfiguration { + + private static final String BIDDER_NAME = "playdigo"; + + @Bean("playdigoConfigurationProperties") + @ConfigurationProperties("adapters.playdigo") + BidderConfigurationProperties configurationProperties() { + return new BidderConfigurationProperties(); + } + + @Bean + BidderDeps playdigoBidderDeps(BidderConfigurationProperties playdigoConfigurationProperties, + @NotBlank @Value("${external-url}") String externalUrl, + JacksonMapper mapper) { + + return BidderDepsAssembler.forBidder(BIDDER_NAME) + .withConfig(playdigoConfigurationProperties) + .usersyncerCreator(UsersyncerCreator.create(externalUrl)) + .bidderCreator(config -> new PlaydigoBidder(config.getEndpoint(), mapper)) + .assemble(); + } +} diff --git a/src/main/resources/bidder-config/playdigo.yaml b/src/main/resources/bidder-config/playdigo.yaml new file mode 100644 index 00000000000..6bc464fea1b --- /dev/null +++ b/src/main/resources/bidder-config/playdigo.yaml @@ -0,0 +1,17 @@ +adapters: + playdigo: + endpoint: https://server.playdigo.com/pserver + geoscope: + - USA + meta-info: + maintainer-email: yr@playdigo.com + app-media-types: + - banner + - video + - native + site-media-types: + - banner + - video + - native + supported-vendors: + vendor-id: 0 diff --git a/src/main/resources/static/bidder-params/playdigo.json b/src/main/resources/static/bidder-params/playdigo.json new file mode 100644 index 00000000000..8611f216a9e --- /dev/null +++ b/src/main/resources/static/bidder-params/playdigo.json @@ -0,0 +1,30 @@ +{ + "$schema": "http://json-schema.org/draft-04/schema#", + "title": "Playdigo Adapter Params", + "description": "A schema which validates params accepted by the Playdigo 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/playdigo/PlaydigoBidderTest.java b/src/test/java/org/prebid/server/bidder/playdigo/PlaydigoBidderTest.java new file mode 100644 index 00000000000..0f8aa3f8bb2 --- /dev/null +++ b/src/test/java/org/prebid/server/bidder/playdigo/PlaydigoBidderTest.java @@ -0,0 +1,352 @@ +package org.prebid.server.bidder.playdigo; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.node.ObjectNode; +import com.iab.openrtb.request.Audio; +import com.iab.openrtb.request.Banner; +import com.iab.openrtb.request.BidRequest; +import com.iab.openrtb.request.Imp; +import com.iab.openrtb.request.Native; +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.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.proto.openrtb.ext.ExtPrebid; +import org.prebid.server.proto.openrtb.ext.request.playdigo.ExtImpPlaydigo; +import org.prebid.server.proto.openrtb.ext.request.playdigo.PlaydigoImpExt; +import org.prebid.server.proto.openrtb.ext.response.ExtBidPrebid; + +import java.util.List; +import java.util.function.UnaryOperator; + +import static java.util.Arrays.asList; +import static java.util.Collections.singletonList; +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.audio; +import static org.prebid.server.proto.openrtb.ext.response.BidType.xNative; + +public class PlaydigoBidderTest extends VertxTest { + + private static final String ENDPOINT_URL = "https://test.com/test"; + + private final PlaydigoBidder target = new PlaydigoBidder(ENDPOINT_URL, jacksonMapper); + + @Test + public void creationShouldFailOnInvalidEndpointUrl() { + assertThatIllegalArgumentException().isThrownBy(() -> new PlaydigoBidder("invalid_url", jacksonMapper)); + } + + @Test + public void makeHttpRequestsShouldMakeOneRequestPerImp() { + // given + final BidRequest bidRequest = BidRequest.builder() + .imp(asList(givenImp(UnaryOperator.identity()), givenImp(UnaryOperator.identity()))) + .build(); + + //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 shouldMakeOneRequestWhenOneImpIsValidAndAnotherIsNot() { + // given + final BidRequest bidRequest = BidRequest.builder() + .imp(asList(givenImp(UnaryOperator.identity()), givenBadImp(UnaryOperator.identity()))) + .build(); + + //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(impCustomizer -> impCustomizer + .ext(mapper.valueToTree(ExtPrebid.of(null, + ExtImpPlaydigo.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(givenImpExtPlaydigoBidder(ext -> ext + .type("publisher") + .placementId("somePlacementId"))); + } + + @Test + public void makeHttpRequestsShouldReturnExtTypeNetwork() { + // given + final BidRequest bidRequest = givenBidRequest(impCustomizer -> impCustomizer + .ext(mapper.valueToTree(ExtPrebid.of(null, + ExtImpPlaydigo.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(givenImpExtPlaydigoBidder(ext -> ext.type("network").endpointId("someEndpointId"))); + } + + @Test + public void makeHttpRequestsShouldReturnErrorIfImpExtCannotBeParsed() { + // given + final BidRequest bidRequest = givenBidRequest(impBuilder -> + impBuilder.ext(mapper.createObjectNode().set("bidder", mapper.createArrayNode()))); + + // when + final Result>> result = target.makeHttpRequests(bidRequest); + + // then + assertThat(result.getValue()).isEmpty(); + + final List errors = result.getErrors(); + assertThat(errors).hasSize(1); + assertThat(errors.get(0).getMessage()) + .startsWith("found no valid impressions"); + } + + @Test + public void makeBidsShouldReturnEmptyListIfBidResponseIsNull() throws JsonProcessingException { + // given + final BidderCall httpCall = givenHttpCall(null, + 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(null, "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(null, + 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 makeBidsShouldReturnBannerBid() throws JsonProcessingException { + // given + final ObjectNode bidExt = mapper.createObjectNode() + .putPOJO("prebid", ExtBidPrebid.builder().type(banner).build()); + final BidderCall httpCall = givenHttpCall( + BidRequest.builder() + .imp(singletonList(Imp.builder().id("123").banner(Banner.builder().build()).build())) + .build(), + mapper.writeValueAsString( + givenBidResponse(bidBuilder -> bidBuilder.ext(bidExt).impid("123").mtype(1)))); + // when + final Result> result = target.makeBids(httpCall, null); + + // then + assertThat(result.getErrors()).isEmpty(); + assertThat(result.getValue()) + .extracting(BidderBid::getType) + .containsExactly(banner); + } + + @Test + public void makeBidsShouldReturnVideoBid() throws JsonProcessingException { + // given + final ObjectNode bidExt = mapper.createObjectNode() + .putPOJO("prebid", ExtBidPrebid.builder().type(video).build()); + final BidderCall httpCall = givenHttpCall( + BidRequest.builder() + .imp(singletonList(Imp.builder().id("123").video(Video.builder().build()).build())) + .build(), + mapper.writeValueAsString( + givenBidResponse(bidBuilder -> bidBuilder.ext(bidExt).impid("123").mtype(2)))); + // when + final Result> result = target.makeBids(httpCall, null); + + // then + assertThat(result.getErrors()).isEmpty(); + assertThat(result.getValue()) + .extracting(BidderBid::getType) + .containsExactly(video); + } + + @Test + public void makeBidsShouldReturnAudioBid() throws JsonProcessingException { + // given + final ObjectNode bidExt = mapper.createObjectNode() + .putPOJO("prebid", ExtBidPrebid.builder().type(audio).build()); + final BidderCall httpCall = givenHttpCall( + BidRequest.builder() + .imp(singletonList(Imp.builder().id("123").audio(Audio.builder().build()).build())) + .build(), + mapper.writeValueAsString( + givenBidResponse(bidBuilder -> bidBuilder.ext(bidExt).impid("123").mtype(3)))); + // when + final Result> result = target.makeBids(httpCall, null); + + // then + assertThat(result.getErrors()).isEmpty(); + assertThat(result.getValue()) + .extracting(BidderBid::getType) + .containsExactly(audio); + } + + @Test + public void makeBidsShouldReturnNativeBid() throws JsonProcessingException { + // given + final ObjectNode bidExt = mapper.createObjectNode() + .putPOJO("prebid", ExtBidPrebid.builder().type(xNative).build()); + final BidderCall httpCall = givenHttpCall( + BidRequest.builder() + .imp(singletonList(Imp.builder().id("123").xNative(Native.builder().build()).build())) + .build(), + mapper.writeValueAsString( + givenBidResponse(bidBuilder -> bidBuilder.ext(bidExt).impid("123").mtype(4)))); + // when + final Result> result = target.makeBids(httpCall, null); + + // then + assertThat(result.getErrors()).isEmpty(); + assertThat(result.getValue()) + .extracting(BidderBid::getType) + .containsExactly(xNative); + } + + @Test + public void makeBidsShouldReturnErrorForUnsupportedMType() throws JsonProcessingException { + // given + final ObjectNode bidExt = mapper.createObjectNode() + .putPOJO("prebid", ExtBidPrebid.builder().type(banner).build()); + final BidderCall httpCall = givenHttpCall( + BidRequest.builder() + .imp(singletonList(Imp.builder().id("123").banner(Banner.builder().build()).build())) + .build(), + mapper.writeValueAsString( + givenBidResponse(bidBuilder -> bidBuilder.ext(bidExt).impid("123").mtype(5)))); + + // when + final Result> result = target.makeBids(httpCall, null); + + // then + assertThat(result.getErrors()).isNotEmpty(); + assertThat(result.getErrors()) + .extracting(BidderError::getMessage) + .containsExactly("could not define media type for impression: 123"); + assertThat(result.getValue()).isEmpty(); + } + + private static Imp givenImp(UnaryOperator impCustomizer) { + return impCustomizer.apply(Imp.builder() + .id("123") + .ext(mapper.valueToTree(ExtPrebid.of(null, + ExtImpPlaydigo.of("placementId", "endpointId"))))) + .build(); + } + + private static Imp givenBadImp(UnaryOperator impCustomizer) { + return impCustomizer.apply(Imp.builder() + .id("invalidImp") + .ext(mapper.valueToTree(ExtPrebid.of(null, + ExtImpPlaydigo.of(null, null))))) + .build(); + } + + private static BidRequest givenBidRequest( + UnaryOperator bidRequestCustomizer, + UnaryOperator impCustomizer) { + + return bidRequestCustomizer.apply(BidRequest.builder() + .imp(singletonList(givenImp(impCustomizer)))) + .build(); + } + + private static BidRequest givenBidRequest(UnaryOperator impCustomizer) { + return givenBidRequest(UnaryOperator.identity(), impCustomizer); + } + + private static BidResponse givenBidResponse(UnaryOperator bidCustomizer) { + return BidResponse.builder() + .cur("USD") + .seatbid(singletonList(SeatBid.builder().bid(singletonList(bidCustomizer.apply(Bid.builder()).build())) + .build())) + .build(); + } + + private static BidderCall givenHttpCall(BidRequest bidRequest, String body) { + return BidderCall.succeededHttp( + HttpRequest.builder().payload(bidRequest).build(), + HttpResponse.of(200, null, body), + null); + } + + private ObjectNode givenImpExtPlaydigoBidder( + UnaryOperator impExtPlaydigoBidderBuilder) { + final ObjectNode modifiedImpExtBidder = mapper.createObjectNode(); + + return modifiedImpExtBidder.set("bidder", mapper.convertValue( + impExtPlaydigoBidderBuilder.apply(PlaydigoImpExt.builder()) + .build(), + JsonNode.class)); + } +} diff --git a/src/test/java/org/prebid/server/it/PlaydigoTest.java b/src/test/java/org/prebid/server/it/PlaydigoTest.java new file mode 100644 index 00000000000..9978b8692fb --- /dev/null +++ b/src/test/java/org/prebid/server/it/PlaydigoTest.java @@ -0,0 +1,35 @@ +package org.prebid.server.it; + +import io.restassured.response.Response; +import org.json.JSONException; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.prebid.server.model.Endpoint; +import org.springframework.test.context.junit4.SpringRunner; + +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; + +@RunWith(SpringRunner.class) +public class PlaydigoTest extends IntegrationTest { + + @Test + public void openrtb2AuctionShouldRespondWithBidsFromPlaydigo() throws IOException, JSONException { + // given + WIRE_MOCK_RULE.stubFor(post(urlPathEqualTo("/playdigo-exchange")) + .withRequestBody(equalToJson(jsonFrom("openrtb2/playdigo/test-playdigo-bid-request.json"))) + .willReturn(aResponse().withBody(jsonFrom("openrtb2/playdigo/test-playdigo-bid-response.json")))); + + // when + final Response response = responseFor("openrtb2/playdigo/test-auction-playdigo-request.json", + Endpoint.openrtb2_auction); + + // then + assertJsonEquals("openrtb2/playdigo/test-auction-playdigo-response.json", response, singletonList("playdigo")); + } +} diff --git a/src/test/resources/org/prebid/server/it/openrtb2/playdigo/test-auction-playdigo-request.json b/src/test/resources/org/prebid/server/it/openrtb2/playdigo/test-auction-playdigo-request.json new file mode 100644 index 00000000000..72e7006e276 --- /dev/null +++ b/src/test/resources/org/prebid/server/it/openrtb2/playdigo/test-auction-playdigo-request.json @@ -0,0 +1,24 @@ +{ + "id": "request_id", + "imp": [ + { + "id": "imp_id", + "banner": { + "w": 300, + "h": 250 + }, + "ext": { + "playdigo": { + "placementId": "testPlacementId", + "type": "publisher" + } + } + } + ], + "tmax": 5000, + "regs": { + "ext": { + "gdpr": 0 + } + } +} diff --git a/src/test/resources/org/prebid/server/it/openrtb2/playdigo/test-auction-playdigo-response.json b/src/test/resources/org/prebid/server/it/openrtb2/playdigo/test-auction-playdigo-response.json new file mode 100644 index 00000000000..1c26c09c8c7 --- /dev/null +++ b/src/test/resources/org/prebid/server/it/openrtb2/playdigo/test-auction-playdigo-response.json @@ -0,0 +1,34 @@ +{ + "id": "request_id", + "seatbid": [ + { + "bid": [ + { + "id": "bid_id", + "impid": "imp_id", + "price": 3.33, + "crid": "creativeId", + "mtype": 1, + "ext": { + "origbidcpm": 3.33, + "prebid": { + "type": "banner" + } + } + } + ], + "seat": "playdigo", + "group": 0 + } + ], + "cur": "USD", + "ext": { + "responsetimemillis": { + "playdigo": "{{ playdigo.response_time_ms }}" + }, + "prebid": { + "auctiontimestamp": 0 + }, + "tmaxrequest": 5000 + } +} diff --git a/src/test/resources/org/prebid/server/it/openrtb2/playdigo/test-playdigo-bid-request.json b/src/test/resources/org/prebid/server/it/openrtb2/playdigo/test-playdigo-bid-request.json new file mode 100644 index 00000000000..dcf904ba566 --- /dev/null +++ b/src/test/resources/org/prebid/server/it/openrtb2/playdigo/test-playdigo-bid-request.json @@ -0,0 +1,56 @@ +{ + "id": "request_id", + "imp": [ + { + "id": "imp_id", + "banner": { + "w": 300, + "h": 250 + }, + "secure": 1, + "ext": { + "bidder": { + "type": "publisher", + "placementId": "testPlacementId" + } + } + } + ], + "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" + ], + "source": { + "tid": "${json-unit.any-string}" + }, + "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/playdigo/test-playdigo-bid-response.json b/src/test/resources/org/prebid/server/it/openrtb2/playdigo/test-playdigo-bid-response.json new file mode 100644 index 00000000000..180173549d8 --- /dev/null +++ b/src/test/resources/org/prebid/server/it/openrtb2/playdigo/test-playdigo-bid-response.json @@ -0,0 +1,21 @@ +{ + "id": "request_id", + "seatbid": [ + { + "bid": [ + { + "id": "bid_id", + "impid": "imp_id", + "price": 3.33, + "crid": "creativeId", + "mtype": 1, + "ext": { + "prebid": { + "type": "banner" + } + } + } + ] + } + ] +} 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 789dfffca58..d467e3e5681 100644 --- a/src/test/resources/org/prebid/server/it/test-application.properties +++ b/src/test/resources/org/prebid/server/it/test-application.properties @@ -312,6 +312,8 @@ adapters.pangle.enabled=true adapters.pangle.endpoint=http://localhost:8090/pangle-exchange adapters.pgamssp.enabled=true adapters.pgamssp.endpoint=http://localhost:8090/pgamssp-exchange +adapters.playdigo.enabled=true +adapters.playdigo.endpoint=http://localhost:8090/playdigo-exchange adapters.preciso.enabled=true adapters.preciso.endpoint=http://localhost:8090/preciso-exchange adapters.pubmatic.enabled=true