diff --git a/src/main/java/org/prebid/server/bidder/showheroes/ShowheroesBidder.java b/src/main/java/org/prebid/server/bidder/showheroes/ShowheroesBidder.java new file mode 100644 index 00000000000..b212950f322 --- /dev/null +++ b/src/main/java/org/prebid/server/bidder/showheroes/ShowheroesBidder.java @@ -0,0 +1,218 @@ +package org.prebid.server.bidder.showheroes; + +import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.node.ObjectNode; +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.request.Source; +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.currency.CurrencyConversionService; +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.ExtRequest; +import org.prebid.server.proto.openrtb.ext.request.ExtRequestPrebid; +import org.prebid.server.proto.openrtb.ext.request.ExtRequestPrebidChannel; +import org.prebid.server.proto.openrtb.ext.request.ExtSource; +import org.prebid.server.proto.openrtb.ext.request.showheroes.ExtImpShowheroes; +import org.prebid.server.proto.openrtb.ext.response.BidType; +import org.prebid.server.util.BidderUtil; +import org.prebid.server.util.HttpUtil; +import org.prebid.server.version.PrebidVersionProvider; + +import java.math.BigDecimal; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.List; +import java.util.Objects; +import java.util.Optional; + +public class ShowheroesBidder implements Bidder { + + private static final String BID_CURRENCY = "EUR"; + private static final String PBSP_JAVA = "java"; + private static final TypeReference> SHOWHEROES_EXT_TYPE_REFERENCE = + new TypeReference<>() { + }; + + private final String endpointUrl; + private final CurrencyConversionService currencyConversionService; + private final JacksonMapper mapper; + private final String pbsVersion; + + public ShowheroesBidder(String endpointUrl, + CurrencyConversionService currencyConversionService, + PrebidVersionProvider prebidVersionProvider, + JacksonMapper mapper) { + + this.endpointUrl = HttpUtil.validateUrl(Objects.requireNonNull(endpointUrl)); + this.currencyConversionService = Objects.requireNonNull(currencyConversionService); + this.mapper = Objects.requireNonNull(mapper); + + this.pbsVersion = prebidVersionProvider.getNameVersionRecord(); + } + + @Override + public Result>> makeHttpRequests(BidRequest request) { + final BidderError validationError = validate(request.getSite(), request.getApp()); + if (validationError != null) { + return Result.withError(validationError); + } + + final List errors = new ArrayList<>(); + + final ExtRequestPrebidChannel prebidChannel = getPrebidChannel(request); + final List modifiedImps = new ArrayList<>(request.getImp().size()); + + for (Imp impression : request.getImp()) { + try { + modifiedImps.add(modifyImp(request, impression, prebidChannel)); + } catch (Exception e) { + errors.add(BidderError.badInput(e.getMessage())); + } + } + + if (modifiedImps.isEmpty()) { + return Result.withErrors(errors); + } + + final Source source = modifySource(request); + final BidRequest modifiedRequest = request.toBuilder().imp(modifiedImps).source(source).build(); + final HttpRequest httpRequest = BidderUtil.defaultRequest(modifiedRequest, endpointUrl, mapper); + + return Result.of(Collections.singletonList(httpRequest), errors); + } + + private static BidderError validate(Site site, App app) { + if (site == null && app == null) { + return BidderError.badInput("BidRequest must contain one of site or app"); + } + if (site != null && site.getPage() == null) { + return BidderError.badInput("BidRequest.site.page is required"); + } + if (app != null && app.getBundle() == null) { + return BidderError.badInput("BidRequest.app.bundle is required"); + } + return null; + } + + private static ExtRequestPrebidChannel getPrebidChannel(BidRequest bidRequest) { + return Optional.ofNullable(bidRequest.getExt()) + .map(ExtRequest::getPrebid) + .map(ExtRequestPrebid::getChannel) + .orElse(null); + } + + private Imp modifyImp(BidRequest bidRequest, Imp imp, ExtRequestPrebidChannel prebidChannel) { + final ExtImpShowheroes extImpShowheroes = parseImpExt(imp); + + final boolean shouldSetDisplayManager = prebidChannel != null && imp.getDisplaymanager() == null; + final boolean shouldConvertFloor = shouldConvertFloor(imp); + + return imp.toBuilder() + .displaymanager(shouldSetDisplayManager ? prebidChannel.getName() : imp.getDisplaymanager()) + .displaymanagerver(shouldSetDisplayManager ? prebidChannel.getVersion() : imp.getDisplaymanagerver()) + .bidfloorcur(shouldConvertFloor ? BID_CURRENCY : imp.getBidfloorcur()) + .bidfloor(shouldConvertFloor ? resolveBidFloor(bidRequest, imp) : imp.getBidfloor()) + .ext(modifyImpExt(imp.getExt(), extImpShowheroes)) + .build(); + } + + private ExtImpShowheroes parseImpExt(Imp imp) { + try { + return mapper.mapper().convertValue(imp.getExt(), SHOWHEROES_EXT_TYPE_REFERENCE).getBidder(); + } catch (IllegalArgumentException e) { + throw new PreBidException(e.getMessage()); + } + } + + private ObjectNode modifyImpExt(ObjectNode impExt, ExtImpShowheroes shImpExt) { + impExt.set("params", mapper.mapper().createObjectNode().put("unitId", shImpExt.getUnitId())); + return impExt; + } + + private static boolean shouldConvertFloor(Imp imp) { + return BidderUtil.isValidPrice(imp.getBidfloor()) + && !StringUtils.equalsIgnoreCase(imp.getBidfloorcur(), BID_CURRENCY); + } + + private BigDecimal resolveBidFloor(BidRequest bidRequest, Imp imp) { + return currencyConversionService.convertCurrency( + imp.getBidfloor(), bidRequest, imp.getBidfloorcur(), BID_CURRENCY); + } + + private Source modifySource(BidRequest bidRequest) { + if (pbsVersion == null) { + return bidRequest.getSource(); + } + + final Source source = bidRequest.getSource(); + + final ExtSource extSource = Optional.ofNullable(source) + .map(Source::getExt) + .orElse(ExtSource.of(null)); + final ObjectNode prebidExtSource = Optional.ofNullable(extSource.getProperty("pbs")) + .filter(JsonNode::isObject) + .map(ObjectNode.class::cast) + .orElseGet(mapper.mapper()::createObjectNode) + .put("pbsv", pbsVersion) + .put("pbsp", PBSP_JAVA); + extSource.addProperty("pbs", prebidExtSource); + + return Optional.ofNullable(source) + .map(Source::toBuilder) + .orElseGet(Source::builder) + .ext(extSource) + .build(); + } + + @Override + public Result> makeBids(BidderCall httpCall, BidRequest bidRequest) { + try { + final BidResponse bidResponse = mapper.decodeValue(httpCall.getResponse().getBody(), BidResponse.class); + return Result.of(extractBids(bidResponse), Collections.emptyList()); + } catch (DecodeException e) { + return Result.withError(BidderError.badServerResponse(e.getMessage())); + } + + } + + private 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())) + .filter(Objects::nonNull) + .toList(); + } + + private static BidType getBidType(Bid bid) { + return switch (bid.getMtype()) { + case 1 -> BidType.banner; + case 2 -> BidType.video; + case null, default -> BidType.video; + }; + } +} diff --git a/src/main/java/org/prebid/server/proto/openrtb/ext/request/showheroes/ExtImpShowheroes.java b/src/main/java/org/prebid/server/proto/openrtb/ext/request/showheroes/ExtImpShowheroes.java new file mode 100644 index 00000000000..77b65257fb0 --- /dev/null +++ b/src/main/java/org/prebid/server/proto/openrtb/ext/request/showheroes/ExtImpShowheroes.java @@ -0,0 +1,11 @@ +package org.prebid.server.proto.openrtb.ext.request.showheroes; + +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.Value; + +@Value(staticConstructor = "of") +public class ExtImpShowheroes { + + @JsonProperty("unitId") + String unitId; +} diff --git a/src/main/java/org/prebid/server/spring/config/bidder/ShowheroesConfiguration.java b/src/main/java/org/prebid/server/spring/config/bidder/ShowheroesConfiguration.java new file mode 100644 index 00000000000..260d8376675 --- /dev/null +++ b/src/main/java/org/prebid/server/spring/config/bidder/ShowheroesConfiguration.java @@ -0,0 +1,49 @@ +package org.prebid.server.spring.config.bidder; + +import org.prebid.server.bidder.BidderDeps; +import org.prebid.server.bidder.showheroes.ShowheroesBidder; +import org.prebid.server.currency.CurrencyConversionService; +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.prebid.server.version.PrebidVersionProvider; +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/showheroes.yaml", factory = YamlPropertySourceFactory.class) +public class ShowheroesConfiguration { + + private static final String BIDDER_NAME = "showheroes"; + + @Bean("showheroesConfigurationProperties") + @ConfigurationProperties("adapters.showheroes") + BidderConfigurationProperties configurationProperties() { + return new BidderConfigurationProperties(); + } + + @Bean + BidderDeps showheroesBidderDeps(BidderConfigurationProperties showheroesConfigurationProperties, + @NotBlank @Value("${external-url}") String externalUrl, + CurrencyConversionService currencyConversionService, + PrebidVersionProvider prebidVersionProvider, + JacksonMapper mapper) { + + return BidderDepsAssembler.forBidder(BIDDER_NAME) + .withConfig(showheroesConfigurationProperties) + .usersyncerCreator(UsersyncerCreator.create(externalUrl)) + .bidderCreator(config -> new ShowheroesBidder( + config.getEndpoint(), + currencyConversionService, + prebidVersionProvider, + mapper)) + .assemble(); + } +} diff --git a/src/main/resources/bidder-config/showheroes.yaml b/src/main/resources/bidder-config/showheroes.yaml new file mode 100644 index 00000000000..b5fd953ac71 --- /dev/null +++ b/src/main/resources/bidder-config/showheroes.yaml @@ -0,0 +1,17 @@ +adapters: + showheroes: + endpoint: https://ads.viralize.tv/openrtb2/auction/ + aliases: + showheroes-bs: ~ + showheroesBs: ~ + ortb-version: '2.6' + meta-info: + maintainer-email: tech@showheroes.com + app-media-types: + - banner + - video + site-media-types: + - banner + - video + supported-vendors: + vendor-id: 111 diff --git a/src/main/resources/static/bidder-params/showheroes.json b/src/main/resources/static/bidder-params/showheroes.json new file mode 100644 index 00000000000..3c269d118d8 --- /dev/null +++ b/src/main/resources/static/bidder-params/showheroes.json @@ -0,0 +1,14 @@ +{ + "$schema": "http://json-schema.org/draft-04/schema#", + "title": "Showheroes Adapter Params", + "description": "A schema which validates params accepted by the Showheroes adapter", + "type": "object", + "properties": { + "unitId": { + "type": "string", + "description": "Unit ID", + "minLength": 8 + } + }, + "required": ["unitId"] +} diff --git a/src/test/java/org/prebid/server/bidder/showheroes/ShowheroesBidderTest.java b/src/test/java/org/prebid/server/bidder/showheroes/ShowheroesBidderTest.java new file mode 100644 index 00000000000..acb15b91bb5 --- /dev/null +++ b/src/test/java/org/prebid/server/bidder/showheroes/ShowheroesBidderTest.java @@ -0,0 +1,361 @@ +package org.prebid.server.bidder.showheroes; + +import com.fasterxml.jackson.core.JsonProcessingException; +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.Site; +import com.iab.openrtb.request.Source; +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.Mock; +import org.mockito.junit.jupiter.MockitoExtension; +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.HttpRequest; +import org.prebid.server.bidder.model.HttpResponse; +import org.prebid.server.bidder.model.Result; +import org.prebid.server.currency.CurrencyConversionService; +import org.prebid.server.proto.openrtb.ext.ExtPrebid; +import org.prebid.server.proto.openrtb.ext.request.showheroes.ExtImpShowheroes; +import org.prebid.server.version.PrebidVersionProvider; + +import java.math.BigDecimal; +import java.util.List; +import java.util.function.Function; + +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mock.Strictness.LENIENT; +import static org.mockito.Mockito.never; +import static org.mockito.Mockito.verify; +import static org.mockito.BDDMockito.given; +import static java.util.Collections.singletonList; +import static java.util.function.Function.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.proto.openrtb.ext.response.BidType.banner; +import static org.prebid.server.proto.openrtb.ext.response.BidType.video; +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; + +@ExtendWith(MockitoExtension.class) +public class ShowheroesBidderTest extends VertxTest { + + private static final String ENDPOINT_URL = "https://ads.showheroes.com/"; + + @Mock(strictness = LENIENT) + private CurrencyConversionService currencyConversionService; + + @Mock(strictness = LENIENT) + private PrebidVersionProvider prebidVersionProvider; + + private ShowheroesBidder target; + + @BeforeEach + public void setUp() { + given(prebidVersionProvider.getNameVersionRecord()).willReturn("test_version"); + target = new ShowheroesBidder(ENDPOINT_URL, currencyConversionService, prebidVersionProvider, jacksonMapper); + } + + @Test + public void creationShouldFailOnInvalidEndpointUrl() { + assertThatIllegalArgumentException().isThrownBy(() -> new ShowheroesBidder("invalid_url", + currencyConversionService, prebidVersionProvider, jacksonMapper)); + } + + @Test + public void makeHttpRequestsShouldReturnErrorIfImpExtCouldNotBeParsed() { + // given + final BidRequest bidRequest = BidRequest.builder() + .site(Site.builder().page("https://test-example.com").build()) + .imp(singletonList(Imp.builder() + .ext(mapper.valueToTree(ExtPrebid.of(null, mapper.createArrayNode()))) + .build())) + .build(); + + // when + final Result>> result = target.makeHttpRequests(bidRequest); + + // then + assertThat(result.getErrors()).hasSize(1); + assertThat(result.getErrors().get(0).getMessage()).startsWith("Cannot deserialize value"); + assertThat(result.getValue()).isEmpty(); + } + + @Test + public void makeHttpRequestsShouldReturnErrorWhenSitePageIsEmpty() { + // given + final BidRequest bidRequest = BidRequest.builder() + .imp(singletonList(givenImp(identity()))) + .site(Site.builder().build()) + .build(); + + // when + final Result>> result = target.makeHttpRequests(bidRequest); + + // then + assertThat(result.getErrors()).hasSize(1); + assertThat(result.getErrors().get(0).getMessage()).isEqualTo("BidRequest.site.page is required"); + assertThat(result.getValue()).isEmpty(); + } + + @Test + public void makeHttpRequestsShouldReturnErrorWhenAppBundleIsEmpty() { + // given + final BidRequest bidRequest = BidRequest.builder() + .imp(singletonList(givenImp(identity()))) + .app(App.builder().build()) + .build(); + + // when + final Result>> result = target.makeHttpRequests(bidRequest); + + // then + assertThat(result.getErrors()).hasSize(1); + assertThat(result.getErrors().get(0).getMessage()).isEqualTo("BidRequest.app.bundle is required"); + assertThat(result.getValue()).isEmpty(); + } + + @Test + public void makeHttpRequestsShouldCreateCorrectURL() { + // given + final BidRequest bidRequest = givenBidRequest(); + + // when + final Result>> result = target.makeHttpRequests(bidRequest); + + // then + assertThat(result.getErrors()).isEmpty(); + assertThat(result.getValue()).hasSize(1); + assertThat(result.getValue().get(0).getUri()).isEqualTo(ENDPOINT_URL); + } + + @Test + public void makeHttpRequestsShouldReturnPbsVersion() { + // given + final BidRequest bidRequest = givenBidRequest(); + + // when + final Result>> result = target.makeHttpRequests(bidRequest); + + // then + assertThat(result.getErrors()).isEmpty(); + assertThat(result.getValue()) + .extracting(HttpRequest::getPayload) + .extracting(BidRequest::getSource) + .extracting(Source::getExt) + .extracting(ext -> ext.getProperty("pbs")) + .containsExactly(mapper.createObjectNode() + .put("pbsv", "test_version") + .put("pbsp", "java")); + } + + @Test + public void makeHttpRequestsShouldConvertCurrencyFromUsdToEur() { + // given + final BidRequest bidRequest = BidRequest.builder() + .imp(List.of(givenImp(impBuilder -> impBuilder.bidfloor(BigDecimal.ONE).bidfloorcur("USD")))) + .app(App.builder().bundle("test_bundle").build()) + .build(); + + given(currencyConversionService.convertCurrency(any(), any(), anyString(), anyString())) + .willReturn(BigDecimal.TEN); + + // when + final Result>> result = target.makeHttpRequests(bidRequest); + + // then + assertThat(result.getErrors()).isEmpty(); + verify(currencyConversionService).convertCurrency(eq(BigDecimal.ONE), any(), eq("USD"), eq("EUR")); + assertThat(result.getValue()).hasSize(1).doesNotContainNull() + .extracting(httpRequest -> mapper.readValue(httpRequest.getBody(), BidRequest.class)) + .flatExtracting(BidRequest::getImp).doesNotContainNull() + .extracting(Imp::getBidfloor, Imp::getBidfloorcur) + .containsOnly(tuple(BigDecimal.TEN, "EUR")); + } + + @Test + public void makeHttpRequestsShouldNotConvertCurrencyEur() { + // given + final BidRequest bidRequest = BidRequest.builder() + .imp(List.of(givenImp(impBuilder -> impBuilder.bidfloor(BigDecimal.ONE).bidfloorcur("EUR")))) + .app(App.builder().bundle("test_bundle").build()) + .build(); + + given(currencyConversionService.convertCurrency(any(), any(), anyString(), anyString())) + .willReturn(BigDecimal.TEN); + + // when + final Result>> result = target.makeHttpRequests(bidRequest); + + // then + assertThat(result.getErrors()).isEmpty(); + verify(currencyConversionService, never()).convertCurrency(any(), any(), anyString(), anyString()); + assertThat(result.getValue()).hasSize(1).doesNotContainNull() + .extracting(httpRequest -> mapper.readValue(httpRequest.getBody(), BidRequest.class)) + .flatExtracting(BidRequest::getImp).doesNotContainNull() + .extracting(Imp::getBidfloor, Imp::getBidfloorcur) + .containsOnly(tuple(BigDecimal.ONE, "EUR")); + } + + @Test + public void makeHttpRequestsShouldCreateSingleRequestForAllImps() { + // given + final BidRequest bidRequest = BidRequest.builder() + .site(Site.builder().page("https://test-example.com").build()) + .imp(List.of( + givenImp(impBuilder -> impBuilder.id("imp1")), + givenImp(impBuilder -> impBuilder.id("imp2")))) + .build(); + + // when + final Result>> result = target.makeHttpRequests(bidRequest); + + // then + assertThat(result.getErrors()).isEmpty(); + assertThat(result.getValue()).hasSize(1) + .extracting(HttpRequest::getPayload) + .flatExtracting(BidRequest::getImp) + .extracting(Imp::getId) + .containsExactly("imp1", "imp2"); + } + + @Test + public void makeHttpRequestsShouldSetCorrectHeaders() { + // given + final BidRequest bidRequest = givenBidRequest(); + + // when + final Result>> result = target.makeHttpRequests(bidRequest); + + // then + assertThat(result.getErrors()).isEmpty(); + 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)); + } + + @Test + public void makeBidsShouldReturnEmptyListIfBidResponseIsNull() throws JsonProcessingException { + // given + final BidderCall httpCall = givenHttpCall(null); + + // when + final Result> result = target.makeBids(httpCall, null); + + // then + assertThat(result.getErrors()).isEmpty(); + assertThat(result.getValue()).isEmpty(); + } + + @Test + public void makeBidsShouldReturnEmptyListIfBidResponseSeatBidIsNull() throws JsonProcessingException { + // given + final BidderCall httpCall = givenHttpCall(BidResponse.builder().build()); + + // when + final Result> result = target.makeBids(httpCall, null); + + // then + assertThat(result.getErrors()).isEmpty(); + assertThat(result.getValue()).isEmpty(); + } + + @Test + public void makeBidsShouldReturnEmptyListIfBidResponseSeatBidIsEmpty() throws JsonProcessingException { + // given + final BidderCall httpCall = givenHttpCall(BidResponse.builder().seatbid(List.of()).build()); + + // when + final Result> result = target.makeBids(httpCall, null); + + // then + assertThat(result.getErrors()).isEmpty(); + assertThat(result.getValue()).isEmpty(); + } + + @Test + public void makeBidsShouldReturnVideoBidByDefaultWhenMtypeIsUnknown() throws JsonProcessingException { + // given + final BidderCall httpCall = givenHttpCall( + givenBidResponse(bidBuilder -> bidBuilder.impid("123").mtype(99))); + + // when + final Result> result = target.makeBids(httpCall, null); + + // then + assertThat(result.getErrors()).isEmpty(); + assertThat(result.getValue()) + .containsOnly(BidderBid.of(Bid.builder().impid("123").mtype(99).build(), video, null)); + } + + @Test + public void makeBidsShouldReturnMultipleBids() throws JsonProcessingException { + // given + final BidderCall httpCall = givenHttpCall( + BidResponse.builder() + .seatbid(singletonList(SeatBid.builder() + .bid(List.of( + Bid.builder().impid("123").mtype(1).price(BigDecimal.ONE).build(), + Bid.builder().impid("456").mtype(2).price(BigDecimal.TEN).build())) + .build())) + .build()); + + // when + final Result> result = target.makeBids(httpCall, null); + + // then + assertThat(result.getErrors()).isEmpty(); + assertThat(result.getValue()).hasSize(2) + .extracting(BidderBid::getBid, BidderBid::getType) + .containsExactlyInAnyOrder( + tuple(Bid.builder().impid("123").mtype(1).price(BigDecimal.ONE).build(), banner), + tuple(Bid.builder().impid("456").mtype(2).price(BigDecimal.TEN).build(), video)); + } + + private static BidRequest givenBidRequest() { + return BidRequest.builder() + .site(Site.builder().page("https://test-example.com").build()) + .imp(singletonList(givenImp(identity()))) + .build(); + } + + private static Imp givenImp(Function impCustomizer) { + return impCustomizer.apply(Imp.builder() + .id("123") + .banner(Banner.builder().build()) + .ext(mapper.valueToTree(ExtPrebid.of(null, ExtImpShowheroes.of("unitId"))))) + .build(); + } + + private static BidResponse givenBidResponse(Function bidCustomizer) { + return BidResponse.builder() + .seatbid(singletonList(SeatBid.builder() + .bid(singletonList(bidCustomizer.apply(Bid.builder()).build())) + .build())) + .build(); + } + + private static BidderCall givenHttpCall(BidResponse bidResponse) + throws JsonProcessingException { + + return BidderCall.succeededHttp( + null, + HttpResponse.of(200, null, mapper.writeValueAsString(bidResponse)), + null); + } +} diff --git a/src/test/java/org/prebid/server/it/ShowheroesBSTest.java b/src/test/java/org/prebid/server/it/ShowheroesBSTest.java new file mode 100644 index 00000000000..c291bceedb9 --- /dev/null +++ b/src/test/java/org/prebid/server/it/ShowheroesBSTest.java @@ -0,0 +1,40 @@ +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 org.prebid.server.version.PrebidVersionProvider; +import org.springframework.beans.factory.annotation.Autowired; + +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 ShowheroesBSTest extends IntegrationTest { + + @Autowired + private PrebidVersionProvider prebidVersionProvider; + + @Test + public void openrtb2AuctionShouldRespondWithBidsFromShowheroesBS() throws IOException, JSONException { + // given + WIRE_MOCK_RULE.stubFor(post(urlPathEqualTo("/showheroes-exchange")) + .withRequestBody(equalToJson(jsonFrom("openrtb2/showheroesBs/test-showheroes-bid-request.json", + prebidVersionProvider))) + .willReturn( + aResponse().withBody(jsonFrom("openrtb2/showheroesBs/test-showheroes-bid-response.json")))); + + // when + final Response response = responseFor("openrtb2/showheroesBs/test-auction-showheroes-request.json", + Endpoint.openrtb2_auction); + + // then + assertJsonEquals("openrtb2/showheroesBs/test-auction-showheroes-response.json", response, + singletonList("showheroesBs")); + } +} diff --git a/src/test/java/org/prebid/server/it/ShowheroesTest.java b/src/test/java/org/prebid/server/it/ShowheroesTest.java new file mode 100644 index 00000000000..42e6f7a6edb --- /dev/null +++ b/src/test/java/org/prebid/server/it/ShowheroesTest.java @@ -0,0 +1,40 @@ +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 org.prebid.server.version.PrebidVersionProvider; +import org.springframework.beans.factory.annotation.Autowired; + +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 ShowheroesTest extends IntegrationTest { + + @Autowired + private PrebidVersionProvider prebidVersionProvider; + + @Test + public void openrtb2AuctionShouldRespondWithBidsFromShowheroes() throws IOException, JSONException { + // given + WIRE_MOCK_RULE.stubFor(post(urlPathEqualTo("/showheroes-exchange")) + .withRequestBody(equalToJson(jsonFrom("openrtb2/showheroes/test-showheroes-bid-request.json", + prebidVersionProvider))) + .willReturn( + aResponse().withBody(jsonFrom("openrtb2/showheroes/test-showheroes-bid-response.json")))); + + // when + final Response response = responseFor("openrtb2/showheroes/test-auction-showheroes-request.json", + Endpoint.openrtb2_auction); + + // then + assertJsonEquals("openrtb2/showheroes/test-auction-showheroes-response.json", response, + singletonList("showheroes")); + } +} diff --git a/src/test/java/org/prebid/server/it/ShowheroesbsTest.java b/src/test/java/org/prebid/server/it/ShowheroesbsTest.java new file mode 100644 index 00000000000..2d60a348ae2 --- /dev/null +++ b/src/test/java/org/prebid/server/it/ShowheroesbsTest.java @@ -0,0 +1,40 @@ +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 org.prebid.server.version.PrebidVersionProvider; +import org.springframework.beans.factory.annotation.Autowired; + +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 ShowheroesbsTest extends IntegrationTest { + + @Autowired + private PrebidVersionProvider prebidVersionProvider; + + @Test + public void openrtb2AuctionShouldRespondWithBidsFromShowheroesbs() throws IOException, JSONException { + // given + WIRE_MOCK_RULE.stubFor(post(urlPathEqualTo("/showheroes-exchange")) + .withRequestBody(equalToJson(jsonFrom("openrtb2/showheroes_bs/test-showheroes-bid-request.json", + prebidVersionProvider))) + .willReturn( + aResponse().withBody(jsonFrom("openrtb2/showheroes_bs/test-showheroes-bid-response.json")))); + + // when + final Response response = responseFor("openrtb2/showheroes_bs/test-auction-showheroes-request.json", + Endpoint.openrtb2_auction); + + // then + assertJsonEquals("openrtb2/showheroes_bs/test-auction-showheroes-response.json", response, + singletonList("showheroes-bs")); + } +} diff --git a/src/test/resources/org/prebid/server/it/openrtb2/showheroes/test-auction-showheroes-request.json b/src/test/resources/org/prebid/server/it/openrtb2/showheroes/test-auction-showheroes-request.json new file mode 100644 index 00000000000..2f50c3466e7 --- /dev/null +++ b/src/test/resources/org/prebid/server/it/openrtb2/showheroes/test-auction-showheroes-request.json @@ -0,0 +1,24 @@ +{ + "id": "request_id", + "imp": [ + { + "id": "imp_id", + "banner": { + "w": 320, + "h": 250 + }, + "ext": { + "showheroes": { + "unitId": "12345678" + } + }, + "tagid": "tag_id" + } + ], + "tmax": 5000, + "regs": { + "ext": { + "gdpr": 0 + } + } +} diff --git a/src/test/resources/org/prebid/server/it/openrtb2/showheroes/test-auction-showheroes-response.json b/src/test/resources/org/prebid/server/it/openrtb2/showheroes/test-auction-showheroes-response.json new file mode 100644 index 00000000000..74377edd182 --- /dev/null +++ b/src/test/resources/org/prebid/server/it/openrtb2/showheroes/test-auction-showheroes-response.json @@ -0,0 +1,41 @@ +{ + "id": "request_id", + "seatbid": [ + { + "bid": [ + { + "id": "bid_id", + "impid": "imp_id", + "exp": 300, + "price": 0.01, + "adid": "adid", + "cid": "cid", + "crid": "crid", + "mtype": 1, + "ext": { + "prebid": { + "type": "banner", + "meta": { + "adaptercode": "showheroes" + } + }, + "origbidcpm": 0.01, + "origbidcur": "USD" + } + } + ], + "seat": "showheroes", + "group": 0 + } + ], + "cur": "USD", + "ext": { + "responsetimemillis": { + "showheroes": "{{ showheroes.response_time_ms }}" + }, + "prebid": { + "auctiontimestamp": 0 + }, + "tmaxrequest": 5000 + } +} diff --git a/src/test/resources/org/prebid/server/it/openrtb2/showheroes/test-showheroes-bid-request.json b/src/test/resources/org/prebid/server/it/openrtb2/showheroes/test-showheroes-bid-request.json new file mode 100644 index 00000000000..7b0681643f0 --- /dev/null +++ b/src/test/resources/org/prebid/server/it/openrtb2/showheroes/test-showheroes-bid-request.json @@ -0,0 +1,62 @@ +{ + "id": "request_id", + "imp": [ + { + "id": "imp_id", + "secure": 1, + "banner": { + "w": 320, + "h": 250 + }, + "tagid": "tag_id", + "ext": { + "tid": "${json-unit.any-string}", + "bidder": { + "unitId": "12345678" + }, + "params": { + "unitId": "12345678" + } + } + } + ], + "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}", + "ext": { + "pbs": { + "pbsv": "{{ pbs.java.version }}", + "pbsp": "java" + } + } + }, + "regs": { + "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/showheroes/test-showheroes-bid-response.json b/src/test/resources/org/prebid/server/it/openrtb2/showheroes/test-showheroes-bid-response.json new file mode 100644 index 00000000000..2dde90a94ce --- /dev/null +++ b/src/test/resources/org/prebid/server/it/openrtb2/showheroes/test-showheroes-bid-response.json @@ -0,0 +1,25 @@ +{ + "id": "request_id", + "seatbid": [ + { + "bid": [ + { + "crid": "crid", + "adid": "adid", + "price": 0.01, + "id": "bid_id", + "impid": "imp_id", + "cid": "cid", + "mtype": 1, + "ext": { + "prebid": { + "type": "banner" + } + } + } + ], + "type": "banner" + } + ], + "cur": "USD" +} diff --git a/src/test/resources/org/prebid/server/it/openrtb2/showheroesBs/test-auction-showheroes-request.json b/src/test/resources/org/prebid/server/it/openrtb2/showheroesBs/test-auction-showheroes-request.json new file mode 100644 index 00000000000..33078a75ab3 --- /dev/null +++ b/src/test/resources/org/prebid/server/it/openrtb2/showheroesBs/test-auction-showheroes-request.json @@ -0,0 +1,24 @@ +{ + "id": "request_id", + "imp": [ + { + "id": "imp_id", + "banner": { + "w": 320, + "h": 250 + }, + "ext": { + "showheroesBs": { + "unitId": "12345678" + } + }, + "tagid": "tag_id" + } + ], + "tmax": 5000, + "regs": { + "ext": { + "gdpr": 0 + } + } +} diff --git a/src/test/resources/org/prebid/server/it/openrtb2/showheroesBs/test-auction-showheroes-response.json b/src/test/resources/org/prebid/server/it/openrtb2/showheroesBs/test-auction-showheroes-response.json new file mode 100644 index 00000000000..2655490d994 --- /dev/null +++ b/src/test/resources/org/prebid/server/it/openrtb2/showheroesBs/test-auction-showheroes-response.json @@ -0,0 +1,41 @@ +{ + "id": "request_id", + "seatbid": [ + { + "bid": [ + { + "id": "bid_id", + "impid": "imp_id", + "exp": 300, + "price": 0.01, + "adid": "adid", + "cid": "cid", + "crid": "crid", + "mtype": 1, + "ext": { + "prebid": { + "type": "banner", + "meta": { + "adaptercode": "showheroesBs" + } + }, + "origbidcpm": 0.01, + "origbidcur": "USD" + } + } + ], + "seat": "showheroesBs", + "group": 0 + } + ], + "cur": "USD", + "ext": { + "responsetimemillis": { + "showheroesBs": "{{ showheroesBs.response_time_ms }}" + }, + "prebid": { + "auctiontimestamp": 0 + }, + "tmaxrequest": 5000 + } +} diff --git a/src/test/resources/org/prebid/server/it/openrtb2/showheroesBs/test-showheroes-bid-request.json b/src/test/resources/org/prebid/server/it/openrtb2/showheroesBs/test-showheroes-bid-request.json new file mode 100644 index 00000000000..7b0681643f0 --- /dev/null +++ b/src/test/resources/org/prebid/server/it/openrtb2/showheroesBs/test-showheroes-bid-request.json @@ -0,0 +1,62 @@ +{ + "id": "request_id", + "imp": [ + { + "id": "imp_id", + "secure": 1, + "banner": { + "w": 320, + "h": 250 + }, + "tagid": "tag_id", + "ext": { + "tid": "${json-unit.any-string}", + "bidder": { + "unitId": "12345678" + }, + "params": { + "unitId": "12345678" + } + } + } + ], + "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}", + "ext": { + "pbs": { + "pbsv": "{{ pbs.java.version }}", + "pbsp": "java" + } + } + }, + "regs": { + "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/showheroesBs/test-showheroes-bid-response.json b/src/test/resources/org/prebid/server/it/openrtb2/showheroesBs/test-showheroes-bid-response.json new file mode 100644 index 00000000000..2dde90a94ce --- /dev/null +++ b/src/test/resources/org/prebid/server/it/openrtb2/showheroesBs/test-showheroes-bid-response.json @@ -0,0 +1,25 @@ +{ + "id": "request_id", + "seatbid": [ + { + "bid": [ + { + "crid": "crid", + "adid": "adid", + "price": 0.01, + "id": "bid_id", + "impid": "imp_id", + "cid": "cid", + "mtype": 1, + "ext": { + "prebid": { + "type": "banner" + } + } + } + ], + "type": "banner" + } + ], + "cur": "USD" +} diff --git a/src/test/resources/org/prebid/server/it/openrtb2/showheroes_bs/test-auction-showheroes-request.json b/src/test/resources/org/prebid/server/it/openrtb2/showheroes_bs/test-auction-showheroes-request.json new file mode 100644 index 00000000000..e44185fb537 --- /dev/null +++ b/src/test/resources/org/prebid/server/it/openrtb2/showheroes_bs/test-auction-showheroes-request.json @@ -0,0 +1,24 @@ +{ + "id": "request_id", + "imp": [ + { + "id": "imp_id", + "banner": { + "w": 320, + "h": 250 + }, + "ext": { + "showheroes-bs": { + "unitId": "12345678" + } + }, + "tagid": "tag_id" + } + ], + "tmax": 5000, + "regs": { + "ext": { + "gdpr": 0 + } + } +} diff --git a/src/test/resources/org/prebid/server/it/openrtb2/showheroes_bs/test-auction-showheroes-response.json b/src/test/resources/org/prebid/server/it/openrtb2/showheroes_bs/test-auction-showheroes-response.json new file mode 100644 index 00000000000..53ce08b83ab --- /dev/null +++ b/src/test/resources/org/prebid/server/it/openrtb2/showheroes_bs/test-auction-showheroes-response.json @@ -0,0 +1,41 @@ +{ + "id": "request_id", + "seatbid": [ + { + "bid": [ + { + "id": "bid_id", + "impid": "imp_id", + "exp": 300, + "price": 0.01, + "adid": "adid", + "cid": "cid", + "crid": "crid", + "mtype": 1, + "ext": { + "prebid": { + "type": "banner", + "meta": { + "adaptercode": "showheroes-bs" + } + }, + "origbidcpm": 0.01, + "origbidcur": "USD" + } + } + ], + "seat": "showheroes-bs", + "group": 0 + } + ], + "cur": "USD", + "ext": { + "responsetimemillis": { + "showheroes-bs": "{{ showheroes-bs.response_time_ms }}" + }, + "prebid": { + "auctiontimestamp": 0 + }, + "tmaxrequest": 5000 + } +} diff --git a/src/test/resources/org/prebid/server/it/openrtb2/showheroes_bs/test-showheroes-bid-request.json b/src/test/resources/org/prebid/server/it/openrtb2/showheroes_bs/test-showheroes-bid-request.json new file mode 100644 index 00000000000..7b0681643f0 --- /dev/null +++ b/src/test/resources/org/prebid/server/it/openrtb2/showheroes_bs/test-showheroes-bid-request.json @@ -0,0 +1,62 @@ +{ + "id": "request_id", + "imp": [ + { + "id": "imp_id", + "secure": 1, + "banner": { + "w": 320, + "h": 250 + }, + "tagid": "tag_id", + "ext": { + "tid": "${json-unit.any-string}", + "bidder": { + "unitId": "12345678" + }, + "params": { + "unitId": "12345678" + } + } + } + ], + "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}", + "ext": { + "pbs": { + "pbsv": "{{ pbs.java.version }}", + "pbsp": "java" + } + } + }, + "regs": { + "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/showheroes_bs/test-showheroes-bid-response.json b/src/test/resources/org/prebid/server/it/openrtb2/showheroes_bs/test-showheroes-bid-response.json new file mode 100644 index 00000000000..2dde90a94ce --- /dev/null +++ b/src/test/resources/org/prebid/server/it/openrtb2/showheroes_bs/test-showheroes-bid-response.json @@ -0,0 +1,25 @@ +{ + "id": "request_id", + "seatbid": [ + { + "bid": [ + { + "crid": "crid", + "adid": "adid", + "price": 0.01, + "id": "bid_id", + "impid": "imp_id", + "cid": "cid", + "mtype": 1, + "ext": { + "prebid": { + "type": "banner" + } + } + } + ], + "type": "banner" + } + ], + "cur": "USD" +} 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 3d57277ff9d..8f1af30cfd5 100644 --- a/src/test/resources/org/prebid/server/it/test-application.properties +++ b/src/test/resources/org/prebid/server/it/test-application.properties @@ -539,6 +539,10 @@ adapters.sspbc.enabled=true adapters.sspbc.endpoint=http://localhost:8090/sspbc-exchange adapters.sharethrough.enabled=true adapters.sharethrough.endpoint=http://localhost:8090/sharethrough-exchange +adapters.showheroes.enabled=true +adapters.showheroes.endpoint=http://localhost:8090/showheroes-exchange +adapters.showheroes.aliases.showheroesBs.enabled=true +adapters.showheroes.aliases.showheroes-bs.enabled=true adapters.silvermob.enabled=true adapters.silvermob.endpoint=http://localhost:8090/silvermob-exchange adapters.silverpush.enabled=true