diff --git a/src/main/java/org/prebid/server/bidder/yeahmobi/YeahmobiBidder.java b/src/main/java/org/prebid/server/bidder/yeahmobi/YeahmobiBidder.java new file mode 100644 index 00000000000..2705b1f7c6e --- /dev/null +++ b/src/main/java/org/prebid/server/bidder/yeahmobi/YeahmobiBidder.java @@ -0,0 +1,150 @@ +package org.prebid.server.bidder.yeahmobi; + +import com.fasterxml.jackson.core.JsonProcessingException; +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.BidRequest; +import com.iab.openrtb.request.Imp; +import com.iab.openrtb.request.Native; +import com.iab.openrtb.response.BidResponse; +import com.iab.openrtb.response.SeatBid; +import io.vertx.core.http.HttpMethod; +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.yeahmobi.ExtImpYeahmobi; +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.Map; +import java.util.Objects; +import java.util.Optional; +import java.util.function.Function; +import java.util.stream.Collectors; + +public class YeahmobiBidder implements Bidder { + + private static final TypeReference> EXT_TYPE_REFERENCE = new TypeReference<>() { + }; + private static final String HOST_MACRO = "{{Host}}"; + private static final String HOST_PATTERN = "gw-%s-bid.yeahtargeter.com"; + + private final String endpointUrl; + private final JacksonMapper mapper; + + public YeahmobiBidder(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 modifiedImps = new ArrayList<>(); + + ExtImpYeahmobi extImp = null; + for (Imp imp : request.getImp()) { + try { + extImp = parseImpExt(imp); + modifiedImps.add(modifyImp(imp)); + } catch (PreBidException e) { + errors.add(BidderError.badInput(e.getMessage())); + } + } + + if (extImp == null) { + return Result.withError(BidderError.badInput("Invalid ExtImpYeahmobi value")); + } + + final BidRequest modifiedRequest = request.toBuilder().imp(modifiedImps).build(); + + final HttpRequest httpRequest = makeHttpRequest(modifiedRequest, extImp.getZoneId()); + return Result.of(Collections.singletonList(httpRequest), errors); + } + + private HttpRequest makeHttpRequest(BidRequest request, String zoneId) { + final String host = HOST_PATTERN.formatted(zoneId); + final String uri = endpointUrl.replace(HOST_MACRO, host); + + return HttpRequest.builder() + .method(HttpMethod.POST) + .uri(uri) + .impIds(BidderUtil.impIds(request)) + .headers(HttpUtil.headers()) + .payload(request) + .body(mapper.encodeToBytes(request)) + .build(); + } + + private ExtImpYeahmobi parseImpExt(Imp imp) { + try { + return mapper.mapper().convertValue(imp.getExt(), EXT_TYPE_REFERENCE).getBidder(); + } catch (IllegalArgumentException e) { + throw new PreBidException(String.format("Impression id=%s, has invalid Ext", imp.getId())); + } + } + + private Imp modifyImp(Imp imp) { + final Native impNative = imp.getXNative(); + return Optional.ofNullable(impNative) + .map(xNative -> resolveNativeRequest(xNative.getRequest())) + .map(nativeRequest -> imp.toBuilder().xNative( + impNative.toBuilder().request(nativeRequest).build()) + .build()) + .orElse(imp); + } + + private String resolveNativeRequest(String nativeRequest) { + try { + final JsonNode nativePayload = nativeRequest != null + ? mapper.mapper().readValue(nativeRequest, JsonNode.class) + : mapper.mapper().createObjectNode(); + final ObjectNode objectNode = mapper.mapper().createObjectNode().set("native", nativePayload); + return mapper.mapper().writeValueAsString(objectNode); + } catch (JsonProcessingException e) { + throw new PreBidException(e.getMessage()); + } + } + + @Override + public Result> makeBids(BidderCall httpCall, BidRequest bidRequest) { + try { + final BidResponse bidResponse = mapper.decodeValue(httpCall.getResponse().getBody(), BidResponse.class); + return Result.withValues(extractBids(httpCall.getRequest().getPayload(), bidResponse)); + } catch (DecodeException | PreBidException e) { + return Result.withError(BidderError.badServerResponse(e.getMessage())); + } + } + + private List extractBids(BidRequest bidRequest, BidResponse bidResponse) { + if (bidResponse == null || bidResponse.getSeatbid() == null) { + return Collections.emptyList(); + } + return bidsFromResponse(bidRequest, bidResponse); + } + + private List bidsFromResponse(BidRequest bidRequest, BidResponse bidResponse) { + final Map impMap = bidRequest.getImp().stream() + .collect(Collectors.toMap(Imp::getId, Function.identity())); + return bidResponse.getSeatbid().stream() + .filter(Objects::nonNull) + .map(SeatBid::getBid) + .filter(Objects::nonNull) + .flatMap(Collection::stream) + .map(bid -> BidderBid.of(bid, BidderUtil.getBidType(bid, impMap), bidResponse.getCur())) + .toList(); + } + +} diff --git a/src/main/java/org/prebid/server/proto/openrtb/ext/request/yeahmobi/ExtImpYeahmobi.java b/src/main/java/org/prebid/server/proto/openrtb/ext/request/yeahmobi/ExtImpYeahmobi.java new file mode 100644 index 00000000000..65b9da862c7 --- /dev/null +++ b/src/main/java/org/prebid/server/proto/openrtb/ext/request/yeahmobi/ExtImpYeahmobi.java @@ -0,0 +1,15 @@ +package org.prebid.server.proto.openrtb.ext.request.yeahmobi; + +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.Value; + +@Value(staticConstructor = "of") +public class ExtImpYeahmobi { + + @JsonProperty("pubId") + String pubId; + + @JsonProperty("zoneId") + String zoneId; + +} diff --git a/src/main/java/org/prebid/server/spring/config/bidder/YeahmobiConfiguration.java b/src/main/java/org/prebid/server/spring/config/bidder/YeahmobiConfiguration.java new file mode 100644 index 00000000000..8dc6c20d857 --- /dev/null +++ b/src/main/java/org/prebid/server/spring/config/bidder/YeahmobiConfiguration.java @@ -0,0 +1,41 @@ +package org.prebid.server.spring.config.bidder; + +import org.prebid.server.bidder.BidderDeps; +import org.prebid.server.bidder.yeahmobi.YeahmobiBidder; +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 javax.validation.constraints.NotBlank; + +@Configuration +@PropertySource(value = "classpath:/bidder-config/yeahmobi.yaml", factory = YamlPropertySourceFactory.class) +public class YeahmobiConfiguration { + + private static final String BIDDER_NAME = "yeahmobi"; + + @Bean("yeahmobiConfigurationProperties") + @ConfigurationProperties("adapters.yeahmobi") + BidderConfigurationProperties configurationProperties() { + return new BidderConfigurationProperties(); + } + + @Bean + BidderDeps yeahmobiBidderDeps(BidderConfigurationProperties yeahmobiConfigurationProperties, + @NotBlank @Value("${external-url}") String externalUrl, + JacksonMapper mapper) { + + return BidderDepsAssembler.forBidder(BIDDER_NAME) + .withConfig(yeahmobiConfigurationProperties) + .usersyncerCreator(UsersyncerCreator.create(externalUrl)) + .bidderCreator(config -> new YeahmobiBidder(config.getEndpoint(), mapper)) + .assemble(); + } +} diff --git a/src/main/java/org/prebid/server/util/BidderUtil.java b/src/main/java/org/prebid/server/util/BidderUtil.java index 62cc4913cca..f156628caae 100644 --- a/src/main/java/org/prebid/server/util/BidderUtil.java +++ b/src/main/java/org/prebid/server/util/BidderUtil.java @@ -11,11 +11,14 @@ import org.prebid.server.bidder.model.Price; import org.prebid.server.bidder.model.PriceFloorInfo; import org.prebid.server.json.JacksonMapper; +import org.prebid.server.proto.openrtb.ext.response.BidType; import java.math.BigDecimal; import java.math.RoundingMode; import java.util.List; +import java.util.Map; import java.util.Objects; +import java.util.Optional; import java.util.Set; import java.util.stream.Collectors; @@ -106,4 +109,22 @@ public static BigDecimal roundFloor(BigDecimal floor) { public static boolean isNullOrZero(Integer value) { return value == null || value == 0; } + + public static BidType getBidType(Bid bid, Map impIdToImpMap) { + return Optional.ofNullable(impIdToImpMap.get(bid.getImpid())) + .map(imp -> { + if (imp.getBanner() != null) { + return BidType.banner; + } else if (imp.getVideo() != null) { + return BidType.video; + } else if (imp.getXNative() != null) { + return BidType.xNative; + } else if (imp.getAudio() != null) { + return BidType.audio; + } else { + return BidType.banner; + } + }) + .orElse(BidType.banner); + } } diff --git a/src/main/resources/bidder-config/yeahmobi.yaml b/src/main/resources/bidder-config/yeahmobi.yaml new file mode 100644 index 00000000000..a36bc7406c4 --- /dev/null +++ b/src/main/resources/bidder-config/yeahmobi.yaml @@ -0,0 +1,15 @@ +adapters: + yeahmobi: + endpoint: https://{{.Host}}/prebid/bid + meta-info: + maintainer-email: developer@yeahmobi.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/yeahmobi.json b/src/main/resources/static/bidder-params/yeahmobi.json new file mode 100644 index 00000000000..07bf751e17f --- /dev/null +++ b/src/main/resources/static/bidder-params/yeahmobi.json @@ -0,0 +1,19 @@ +{ + "$schema": "http://json-schema.org/draft-04/schema#", + "title": "Yeahmobi Adapter Params", + "description": "A schema which validates params accepted by the Yeahmobi adapter", + "type": "object", + "properties": { + "pubId": { + "type": "string", + "description": "Publisher ID", + "minLength": 1 + }, + "zoneId": { + "type": "string", + "description": "Zone Id", + "minLength": 1 + } + }, + "required": ["pubId", "zoneId"] +} diff --git a/src/test/java/org/prebid/server/bidder/yeahmobi/YeahmobiBidderTest.java b/src/test/java/org/prebid/server/bidder/yeahmobi/YeahmobiBidderTest.java new file mode 100644 index 00000000000..016592dac17 --- /dev/null +++ b/src/test/java/org/prebid/server/bidder/yeahmobi/YeahmobiBidderTest.java @@ -0,0 +1,305 @@ +package org.prebid.server.bidder.yeahmobi; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.iab.openrtb.request.Banner; +import com.iab.openrtb.request.BidRequest; +import com.iab.openrtb.request.Format; +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.yeahmobi.ExtImpYeahmobi; + +import java.util.List; +import java.util.function.Function; + +import static java.util.Arrays.asList; +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.prebid.server.proto.openrtb.ext.response.BidType.banner; +import static org.prebid.server.proto.openrtb.ext.response.BidType.video; +import static org.prebid.server.proto.openrtb.ext.response.BidType.xNative; + +public class YeahmobiBidderTest extends VertxTest { + + private static final String ENDPOINT_URL = "https://{{Host}}/prebid/bid"; + + private final YeahmobiBidder target = new YeahmobiBidder(ENDPOINT_URL, jacksonMapper); + + @Test + public void creationShouldFailOnInvalidEndpointUrl() { + assertThatIllegalArgumentException().isThrownBy(() -> new YeahmobiBidder("invalid_url", jacksonMapper)); + } + + @Test + public void makeHttpRequestsShouldReturnErrorIfImpExtCouldNotBeParsed() { + // given + final BidRequest bidRequest = givenBidRequest( + impBuilder -> impBuilder + .id("123") + .ext(mapper.valueToTree(ExtPrebid.of(null, mapper.createArrayNode())))); + // when + final Result>> result = target.makeHttpRequests(bidRequest); + + // then + assertThat(result.getErrors()).containsExactly(BidderError.badInput("Invalid ExtImpYeahmobi value")); + } + + @Test + public void makeHttpRequestsShouldReturnErrorOfEveryNotValidImp() { + // given + final BidRequest bidRequest = BidRequest.builder() + .imp(asList(givenImp(impBuilder -> impBuilder + .id("123") + .ext(mapper.valueToTree(ExtPrebid.of(null, mapper.createArrayNode())))), + givenImp(identity()))) + .build(); + + // when + final Result>> result = target.makeHttpRequests(bidRequest); + + // then + assertThat(result.getErrors()).containsExactly(BidderError.badInput("Impression id=123, has invalid Ext")); + } + + @Test + public void makeHttpRequestsShouldCreateCorrectURL() { + // given + final BidRequest bidRequest = givenBidRequest( + impBuilder -> impBuilder + .banner(Banner.builder() + .format(singletonList(Format.builder().w(300).h(500).build())) + .build())); + + // when + final Result>> result = target.makeHttpRequests(bidRequest); + + // then + assertThat(result.getErrors()).isEmpty(); + assertThat(result.getValue()) + .extracting(HttpRequest::getUri) + .containsExactly("https://gw-zoneId-bid.yeahtargeter.com/prebid/bid"); + } + + @Test + public void makeHttpRequestsShouldAddNativeRequest() { + // given + final String nativeRequest = "{\"ver\":\"1.2\",\"context\":1,\"plcmttype\":4,\"plcmtcnt\":1," + + "\"assets\":[{\"id\":2," + + "\"required\":1,\"title\":{\"len\":90}},{\"id\":6,\"required\":1,\"img\":{\"type\":3,\"wmin\"" + + ":128,\"hmin\":128,\"mimes\":[\"image/jpg\",\"image/jpeg\",\"image/png\"]}},{\"id\":7," + + "\"required\":1,\"data\":{\"type\":2,\"len\":120}}]}"; + + final BidRequest bidRequest = givenBidRequest( + impBuilder -> impBuilder + .banner(Banner.builder().build()) + .xNative(Native.builder().request(nativeRequest).build())); + + // when + final Result>> result = target.makeHttpRequests(bidRequest); + + // then + final String expectedNativeRequest = "{\"native\":" + + "{\"ver\":\"1.2\",\"context\":1,\"plcmttype\":4,\"plcmtcnt\":1," + + "\"assets\":[{\"id\":2,\"required\":1,\"title\":{\"len\":90}},{\"id\":6,\"required\":1,\"img\":" + + "{\"type\":3,\"wmin\":128,\"hmin\":128,\"mimes\":[\"image/jpg\",\"image/jpeg\",\"image/png\"]}}," + + "{\"id\":7,\"required\":1,\"data\":{\"type\":2,\"len\":120}}]}}"; + + assertThat(result.getErrors()).isEmpty(); + assertThat(result.getValue()) + .extracting(HttpRequest::getPayload) + .flatExtracting(BidRequest::getImp) + .extracting(Imp::getXNative) + .extracting(Native::getRequest) + .containsExactly(expectedNativeRequest); + } + + @Test + public void makeHttpRequestsShouldAddEmptyNativeRequestIfRequestNotPresent() { + // given + final BidRequest bidRequest = givenBidRequest( + impBuilder -> impBuilder + .banner(Banner.builder().build()) + .xNative(Native.builder().build())); + + // when + final Result>> result = target.makeHttpRequests(bidRequest); + + // then + assertThat(result.getErrors()).isEmpty(); + assertThat(result.getValue()) + .extracting(HttpRequest::getPayload) + .flatExtracting(BidRequest::getImp) + .extracting(Imp::getXNative) + .extracting(Native::getRequest) + .containsExactly("{\"native\":{}}"); + } + + @Test + public void makeBidsShouldReturnErrorIfResponseBodyCouldNotBeParsed() { + // given + final BidderCall httpCall = givenHttpCall(null, "invalid"); + + // when + final Result> result = target.makeBids(httpCall, null); + + // then + assertThat(result.getErrors()).hasSize(1) + .allSatisfy(error -> { + assertThat(error.getType()).isEqualTo(BidderError.Type.bad_server_response); + assertThat(error.getMessage()).startsWith("Failed to decode: Unrecognized token"); + }); + assertThat(result.getValue()).isEmpty(); + } + + @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 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 makeBidsShouldReturnBannerBidIfBannerIsPresentInRequestImp() throws JsonProcessingException { + // given + final BidderCall httpCall = givenHttpCall( + BidRequest.builder() + .imp(singletonList(Imp.builder().id("123").banner(Banner.builder().build()).build())) + .build(), + mapper.writeValueAsString( + givenBidResponse(bidBuilder -> bidBuilder.impid("123")))); + + // when + final Result> result = target.makeBids(httpCall, null); + + // then + assertThat(result.getErrors()).isEmpty(); + assertThat(result.getValue()) + .containsExactly(BidderBid.of(Bid.builder().impid("123").build(), banner, "EUR")); + } + + @Test + public void makeBidsShouldReturnBannerBidByDefault() throws JsonProcessingException { + // given + final BidderCall httpCall = givenHttpCall( + BidRequest.builder() + .imp(singletonList(Imp.builder().id("123").build())) + .build(), + mapper.writeValueAsString( + givenBidResponse(bidBuilder -> bidBuilder.impid("123")))); + + // when + final Result> result = target.makeBids(httpCall, null); + + // then + assertThat(result.getErrors()).isEmpty(); + assertThat(result.getValue()) + .containsExactly(BidderBid.of(Bid.builder().impid("123").build(), banner, "EUR")); + } + + @Test + public void makeBidsShouldReturnVideoBidIfVideoIsPresentInRequestImp() throws JsonProcessingException { + // given + final BidderCall httpCall = givenHttpCall(BidRequest.builder() + .imp(singletonList(Imp.builder().id("123").video(Video.builder().build()).build())) + .build(), + mapper.writeValueAsString( + givenBidResponse(bidBuilder -> bidBuilder.impid("123")))); + + // when + final Result> result = target.makeBids(httpCall, null); + + // then + assertThat(result.getErrors()).isEmpty(); + assertThat(result.getValue()) + .containsExactly(BidderBid.of(Bid.builder().impid("123").build(), video, "EUR")); + } + + @Test + public void makeBidsShouldReturnNativeBidIfNativeIsPresentInRequestImp() throws JsonProcessingException { + // given + final BidderCall httpCall = givenHttpCall( + BidRequest.builder() + .imp(singletonList(Imp.builder().id("123").xNative(Native.builder().build()).build())) + .build(), + mapper.writeValueAsString( + givenBidResponse(bidBuilder -> bidBuilder.impid("123")))); + + // when + final Result> result = target.makeBids(httpCall, null); + + // then + assertThat(result.getErrors()).isEmpty(); + assertThat(result.getValue()) + .containsExactly(BidderBid.of(Bid.builder().impid("123").build(), xNative, "EUR")); + } + + private static BidRequest givenBidRequest( + Function bidRequestCustomizer, + Function impCustomizer) { + + return bidRequestCustomizer.apply(BidRequest.builder() + .imp(singletonList(givenImp(impCustomizer)))) + .build(); + } + + private static BidRequest givenBidRequest(Function impCustomizer) { + return givenBidRequest(identity(), impCustomizer); + } + + private static Imp givenImp(Function impCustomizer) { + return impCustomizer.apply(Imp.builder() + .id("123") + .banner(Banner.builder().id("banner_id").build()) + .ext(mapper.valueToTree(ExtPrebid.of(null, ExtImpYeahmobi.of("pubId", "zoneId"))))) + .build(); + } + + private static BidResponse givenBidResponse(Function bidCustomizer) { + return BidResponse.builder() + .cur("EUR") + .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); + } +} diff --git a/src/test/java/org/prebid/server/it/YeahmobiTest.java b/src/test/java/org/prebid/server/it/YeahmobiTest.java new file mode 100644 index 00000000000..8a20bf308fb --- /dev/null +++ b/src/test/java/org/prebid/server/it/YeahmobiTest.java @@ -0,0 +1,34 @@ +package org.prebid.server.it; + +import com.github.tomakehurst.wiremock.client.WireMock; +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 java.util.List; + +import static com.github.tomakehurst.wiremock.client.WireMock.equalToJson; + +@RunWith(SpringRunner.class) +public class YeahmobiTest extends IntegrationTest { + + @Test + public void openrtb2AuctionShouldRespondWithBidsFromYeahmobi() throws IOException, JSONException { + // given + WIRE_MOCK_RULE.stubFor(WireMock.post(WireMock.urlPathEqualTo("/yeahmobi-exchange")) + .withRequestBody(equalToJson(jsonFrom("openrtb2/yeahmobi/test-yeahmobi-bid-request.json"))) + .willReturn(WireMock.aResponse().withBody( + jsonFrom("openrtb2/yeahmobi/test-yeahmobi-bid-response.json")))); + + // when + final Response response = responseFor("openrtb2/yeahmobi/test-auction-yeahmobi-request.json", + Endpoint.openrtb2_auction); + + // then + assertJsonEquals("openrtb2/yeahmobi/test-auction-yeahmobi-response.json", response, List.of("yeahmobi")); + } +} diff --git a/src/test/java/org/prebid/server/util/BidderUtilTest.java b/src/test/java/org/prebid/server/util/BidderUtilTest.java index 2379419f831..c17ac9861d0 100644 --- a/src/test/java/org/prebid/server/util/BidderUtilTest.java +++ b/src/test/java/org/prebid/server/util/BidderUtilTest.java @@ -1,13 +1,19 @@ package org.prebid.server.util; +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 org.junit.Test; import org.prebid.server.bidder.model.PriceFloorInfo; +import org.prebid.server.proto.openrtb.ext.response.BidType; import java.math.BigDecimal; import java.util.List; +import java.util.Map; import java.util.function.UnaryOperator; import static java.util.Collections.emptyList; @@ -160,6 +166,74 @@ public void resolvePriceFloorShouldReturnPriceFloorInfoIfBothImpFloorAndCurrency assertThat(result).isEqualTo(PriceFloorInfo.of(BigDecimal.ONE, "USD")); } + @Test + public void getBidTypeShouldReturnBannerBidTypeWhenBannerImpIsPresent() { + // given + final Bid bannerBid = givenBid(bidBuilder -> bidBuilder.impid("imp_banner")); + final Imp bannerImp = givenImp(impBuilder -> impBuilder.id("imp_banner").banner(Banner.builder().build())); + final Map impMap = Map.of("imp_banner", bannerImp); + + // when + final BidType actual = BidderUtil.getBidType(bannerBid, impMap); + + // then + assertThat(actual).isEqualTo(BidType.banner); + } + + @Test + public void getBidTypeShouldReturnBannerBidTypeWhenVideoImpIsPresent() { + // given + final Bid videoBid = givenBid(bidBuilder -> bidBuilder.impid("imp_video")); + final Imp videoImp = givenImp(impBuilder -> impBuilder.id("imp_video").video(Video.builder().build())); + final Map impMap = Map.of("imp_video", videoImp); + + // when + final BidType actual = BidderUtil.getBidType(videoBid, impMap); + + // then + assertThat(actual).isEqualTo(BidType.video); + } + + @Test + public void getBidTypeShouldReturnBannerBidTypeWhenAudioImpIsPresent() { + // given + final Bid audioBid = givenBid(bidBuilder -> bidBuilder.impid("imp_audio")); + final Imp audioImp = givenImp(impBuilder -> impBuilder.id("imp_audio").audio(Audio.builder().build())); + final Map impMap = Map.of("imp_audio", audioImp); + + // when + final BidType actual = BidderUtil.getBidType(audioBid, impMap); + + // then + assertThat(actual).isEqualTo(BidType.audio); + } + + @Test + public void getBidTypeShouldReturnBannerBidTypeWhenNativeImpIsPresent() { + // given + final Bid nativeBid = givenBid(bidBuilder -> bidBuilder.impid("imp_native")); + final Imp nativeImp = givenImp(impBuilder -> impBuilder.id("imp_native").xNative(Native.builder().build())); + final Map impMap = Map.of("imp_native", nativeImp); + + // when + final BidType actual = BidderUtil.getBidType(nativeBid, impMap); + + // then + assertThat(actual).isEqualTo(BidType.xNative); + } + + @Test + public void getBidTypeShouldReturnBannerBidTypeWhenImpForBidIsAbsent() { + // given + final Bid unknownBid = givenBid(bidBuilder -> bidBuilder.impid("imp_unknown")); + + // when + final BidType actual = BidderUtil.getBidType(unknownBid, Map.of()); + + // then + assertThat(actual).isEqualTo(BidType.banner); + } + private static BidRequest givenBidRequest(UnaryOperator bidRequestCustomizer) { return bidRequestCustomizer.apply(BidRequest.builder() .imp(givenImps(identity()))) @@ -167,7 +241,11 @@ private static BidRequest givenBidRequest(UnaryOperator givenImps(UnaryOperator impCustomizer) { - return singletonList(impCustomizer.apply(Imp.builder().id("impId")).build()); + return singletonList(givenImp(impCustomizer)); + } + + private static Imp givenImp(UnaryOperator impCustomizer) { + return impCustomizer.apply(Imp.builder().id("impId")).build(); } private static Bid givenBid(UnaryOperator bidCustomizer) { diff --git a/src/test/resources/org/prebid/server/it/openrtb2/yeahmobi/test-auction-yeahmobi-request.json b/src/test/resources/org/prebid/server/it/openrtb2/yeahmobi/test-auction-yeahmobi-request.json new file mode 100644 index 00000000000..00da073c998 --- /dev/null +++ b/src/test/resources/org/prebid/server/it/openrtb2/yeahmobi/test-auction-yeahmobi-request.json @@ -0,0 +1,24 @@ +{ + "id": "test-request-id", + "imp": [ + { + "id": "test-imp-id", + "native": { + "request": "{\"ver\":\"1.2\",\"context\":1,\"plcmttype\":4,\"plcmtcnt\":1,\"assets\":[{\"id\":2,\"required\":1,\"title\":{\"len\":90}},{\"id\":6,\"required\":1,\"img\":{\"type\":3,\"wmin\":128,\"hmin\":128,\"mimes\":[\"image/jpg\",\"image/jpeg\",\"image/png\"]}},{\"id\":7,\"required\":1,\"data\":{\"type\":2,\"len\":120}}]}", + "ver": "1.2" + }, + "ext": { + "yeahmobi": { + "pubId": "fake-pub-id", + "zoneId": "sin" + } + } + } + ], + "tmax": 5000, + "regs": { + "ext": { + "gdpr": 0 + } + } +} diff --git a/src/test/resources/org/prebid/server/it/openrtb2/yeahmobi/test-auction-yeahmobi-response.json b/src/test/resources/org/prebid/server/it/openrtb2/yeahmobi/test-auction-yeahmobi-response.json new file mode 100644 index 00000000000..4b393d47bff --- /dev/null +++ b/src/test/resources/org/prebid/server/it/openrtb2/yeahmobi/test-auction-yeahmobi-response.json @@ -0,0 +1,35 @@ +{ + "id": "test-request-id", + "seatbid": [ + { + "bid": [ + { + "id": "8400d766-58b3-47d4-80d7-6658b337d403", + "impid": "test-imp-id", + "adm": "{\"ver\":\"1.2\"}", + "price": 1.2, + "cid": "1", + "crid": "1", + "ext": { + "prebid": { + "type": "native" + }, + "origbidcpm": 1.2 + } + } + ], + "group": 0, + "seat": "yeahmobi" + } + ], + "cur": "USD", + "ext": { + "responsetimemillis": { + "yeahmobi": "{{ yeahmobi.response_time_ms }}" + }, + "prebid": { + "auctiontimestamp": 1000 + }, + "tmaxrequest": 5000 + } +} diff --git a/src/test/resources/org/prebid/server/it/openrtb2/yeahmobi/test-yeahmobi-bid-request.json b/src/test/resources/org/prebid/server/it/openrtb2/yeahmobi/test-yeahmobi-bid-request.json new file mode 100644 index 00000000000..db90fc7efb9 --- /dev/null +++ b/src/test/resources/org/prebid/server/it/openrtb2/yeahmobi/test-yeahmobi-bid-request.json @@ -0,0 +1,57 @@ +{ + "id": "test-request-id", + "imp": [ + { + "id": "test-imp-id", + "secure": 1, + "native": { + "request": "{\"native\":{\"ver\":\"1.2\",\"context\":1,\"plcmttype\":4,\"plcmtcnt\":1,\"assets\":[{\"id\":2,\"required\":1,\"title\":{\"len\":90}},{\"id\":6,\"required\":1,\"img\":{\"type\":3,\"wmin\":128,\"hmin\":128,\"mimes\":[\"image/jpg\",\"image/jpeg\",\"image/png\"]}},{\"id\":7,\"required\":1,\"data\":{\"type\":2,\"len\":120}}]}}", + "ver": "1.2" + }, + "ext": { + "tid": "${json-unit.any-string}", + "bidder": { + "pubId": "fake-pub-id", + "zoneId": "sin" + } + } + } + ], + "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/yeahmobi/test-yeahmobi-bid-response.json b/src/test/resources/org/prebid/server/it/openrtb2/yeahmobi/test-yeahmobi-bid-response.json new file mode 100644 index 00000000000..292f3adca7c --- /dev/null +++ b/src/test/resources/org/prebid/server/it/openrtb2/yeahmobi/test-yeahmobi-bid-response.json @@ -0,0 +1,17 @@ +{ + "id": "test-request-id", + "seatbid": [ + { + "bid": [ + { + "id": "8400d766-58b3-47d4-80d7-6658b337d403", + "impid": "test-imp-id", + "adm": "{\"ver\":\"1.2\"}", + "price": 1.2, + "cid": "1", + "crid": "1" + } + ] + } + ] +} 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 b2fd7be14dd..2ca4d48981f 100644 --- a/src/test/resources/org/prebid/server/it/test-application.properties +++ b/src/test/resources/org/prebid/server/it/test-application.properties @@ -388,6 +388,8 @@ adapters.invibes.enabled=true adapters.invibes.endpoint=http://localhost:8090/invibes-exchange adapters.yandex.enabled=true adapters.yandex.endpoint=http://localhost:8090/yandex-exchange +adapters.yeahmobi.enabled=true +adapters.yeahmobi.endpoint=http://localhost:8090/yeahmobi-exchange adapters.yieldlab.enabled=true adapters.yieldlab.endpoint=http://localhost:8090/yieldlab-exchange adapters.yieldmo.enabled=true