From 50ee3fa7b637b5c0bacabb9029b414b723a107f3 Mon Sep 17 00:00:00 2001 From: apavlyuk Date: Mon, 13 Jul 2020 13:03:24 +0300 Subject: [PATCH 1/2] Add OrbidderBidder and tests --- .../bidder/orbidder/OrbidderBidder.java | 131 ++++++++++++ .../ext/request/orbidder/ExtImpOrbidder.java | 21 ++ .../config/bidder/OrbidderConfiguration.java | 56 ++++++ .../resources/bidder-config/orbidder.yaml | 23 +++ .../static/bidder-params/orbidder.json | 24 +++ .../server/bidder/orbidder/OrbidderTest.java | 189 ++++++++++++++++++ .../org/prebid/server/it/OrbidderTest.java | 57 ++++++ .../test-auction-orbidder-request.json | 100 +++++++++ .../test-auction-orbidder-response.json | 56 ++++++ .../orbidder/test-cache-orbidder-request.json | 18 ++ .../test-cache-orbidder-response.json | 7 + .../orbidder/test-orbidder-bid-request.json | 101 ++++++++++ .../orbidder/test-orbidder-bid-response.json | 20 ++ .../server/it/test-application.properties | 4 + 14 files changed, 807 insertions(+) create mode 100644 src/main/java/org/prebid/server/bidder/orbidder/OrbidderBidder.java create mode 100644 src/main/java/org/prebid/server/proto/openrtb/ext/request/orbidder/ExtImpOrbidder.java create mode 100644 src/main/java/org/prebid/server/spring/config/bidder/OrbidderConfiguration.java create mode 100644 src/main/resources/bidder-config/orbidder.yaml create mode 100644 src/main/resources/static/bidder-params/orbidder.json create mode 100644 src/test/java/org/prebid/server/bidder/orbidder/OrbidderTest.java create mode 100644 src/test/java/org/prebid/server/it/OrbidderTest.java create mode 100644 src/test/resources/org/prebid/server/it/openrtb2/orbidder/test-auction-orbidder-request.json create mode 100644 src/test/resources/org/prebid/server/it/openrtb2/orbidder/test-auction-orbidder-response.json create mode 100644 src/test/resources/org/prebid/server/it/openrtb2/orbidder/test-cache-orbidder-request.json create mode 100644 src/test/resources/org/prebid/server/it/openrtb2/orbidder/test-cache-orbidder-response.json create mode 100644 src/test/resources/org/prebid/server/it/openrtb2/orbidder/test-orbidder-bid-request.json create mode 100644 src/test/resources/org/prebid/server/it/openrtb2/orbidder/test-orbidder-bid-response.json diff --git a/src/main/java/org/prebid/server/bidder/orbidder/OrbidderBidder.java b/src/main/java/org/prebid/server/bidder/orbidder/OrbidderBidder.java new file mode 100644 index 00000000000..7ea11c4ce3d --- /dev/null +++ b/src/main/java/org/prebid/server/bidder/orbidder/OrbidderBidder.java @@ -0,0 +1,131 @@ +package org.prebid.server.bidder.orbidder; + +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.BidResponse; +import com.iab.openrtb.response.SeatBid; +import io.netty.handler.codec.http.HttpResponseStatus; +import io.vertx.core.http.HttpMethod; +import org.apache.commons.collections4.CollectionUtils; +import org.prebid.server.bidder.Bidder; +import org.prebid.server.bidder.model.BidderBid; +import org.prebid.server.bidder.model.BidderError; +import org.prebid.server.bidder.model.HttpCall; +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.orbidder.ExtImpOrbidder; +import org.prebid.server.proto.openrtb.ext.response.BidType; +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.stream.Collectors; + +public class OrbidderBidder implements Bidder { + + private static final TypeReference> ORBIDDER_EXT_TYPE_REFERENCE = + new TypeReference>() { + }; + + private static final String DEFAULT_BID_CURRENCY = "USD"; + + private final String endpointUrl; + private final JacksonMapper mapper; + + public OrbidderBidder(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 validImps = new ArrayList<>(); + + if (CollectionUtils.isEmpty(request.getImp())) { + errors.add(BidderError.badInput("No valid impressions in the bid request")); + return Result.of(Collections.emptyList(), errors); + } + + for (Imp imp : request.getImp()) { + try { + parseImpExt(imp); + validImps.add(imp); + } catch (PreBidException e) { + errors.add(BidderError.badInput(e.getMessage())); + } + } + final BidRequest outgoingRequest = request.toBuilder().imp(validImps).build(); + final String body = mapper.encode(outgoingRequest); + + return Result.of(Collections.singletonList( + HttpRequest.builder() + .method(HttpMethod.POST) + .uri(endpointUrl) + .headers(HttpUtil.headers()) + .payload(outgoingRequest) + .body(body) + .build()), + errors); + } + + private void parseImpExt(Imp imp) { + try { + mapper.mapper().convertValue(imp.getExt(), ORBIDDER_EXT_TYPE_REFERENCE); + } catch (IllegalArgumentException e) { + throw new PreBidException(e.getMessage(), e); + } + } + + @Override + public Result> makeBids(HttpCall httpCall, BidRequest bidRequest) { + final int statusCode = httpCall.getResponse().getStatusCode(); + if (statusCode == HttpResponseStatus.NO_CONTENT.code()) { + return Result.of(Collections.emptyList(), Collections.emptyList()); + } else if (statusCode == HttpResponseStatus.BAD_REQUEST.code()) { + return Result.emptyWithError(BidderError.badInput("Invalid request.")); + } else if (statusCode == HttpResponseStatus.INTERNAL_SERVER_ERROR.code()) { + return Result.emptyWithError(BidderError.badInput("Server internal error.")); + } else if (statusCode != HttpResponseStatus.OK.code()) { + return Result.emptyWithError(BidderError.badServerResponse(String.format("Unexpected HTTP status %s.", + statusCode))); + } + + final BidResponse bidResponse; + try { + bidResponse = decodeBodyToBidResponse(httpCall); + } catch (PreBidException e) { + return Result.emptyWithError(BidderError.badServerResponse(e.getMessage())); + } + + final List bidderBids = bidResponse.getSeatbid().stream() + .map(SeatBid::getBid) + .flatMap(Collection::stream) + .map(bid -> BidderBid.of(bid, BidType.banner, DEFAULT_BID_CURRENCY)) + .collect(Collectors.toList()); + return Result.of(bidderBids, Collections.emptyList()); + } + + private BidResponse decodeBodyToBidResponse(HttpCall httpCall) { + try { + return mapper.decodeValue(httpCall.getResponse().getBody(), BidResponse.class); + } catch (DecodeException e) { + throw new PreBidException(e.getMessage(), e); + } + } + + @Override + public Map extractTargeting(ObjectNode ext) { + return Collections.emptyMap(); + } +} diff --git a/src/main/java/org/prebid/server/proto/openrtb/ext/request/orbidder/ExtImpOrbidder.java b/src/main/java/org/prebid/server/proto/openrtb/ext/request/orbidder/ExtImpOrbidder.java new file mode 100644 index 00000000000..c8bb28d2dd9 --- /dev/null +++ b/src/main/java/org/prebid/server/proto/openrtb/ext/request/orbidder/ExtImpOrbidder.java @@ -0,0 +1,21 @@ +package org.prebid.server.proto.openrtb.ext.request.orbidder; + +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.AllArgsConstructor; +import lombok.Value; + +import java.math.BigDecimal; + +@Value +@AllArgsConstructor(staticName = "of") +public class ExtImpOrbidder { + + @JsonProperty("accountId") + String accountId; + + @JsonProperty("placementId") + String placementId; + + @JsonProperty("bidfloor") + BigDecimal bidFloor; +} diff --git a/src/main/java/org/prebid/server/spring/config/bidder/OrbidderConfiguration.java b/src/main/java/org/prebid/server/spring/config/bidder/OrbidderConfiguration.java new file mode 100644 index 00000000000..9436c25bd8d --- /dev/null +++ b/src/main/java/org/prebid/server/spring/config/bidder/OrbidderConfiguration.java @@ -0,0 +1,56 @@ +package org.prebid.server.spring.config.bidder; + +import org.prebid.server.bidder.BidderDeps; +import org.prebid.server.bidder.orbidder.OrbidderBidder; +import org.prebid.server.json.JacksonMapper; +import org.prebid.server.spring.config.bidder.model.BidderConfigurationProperties; +import org.prebid.server.spring.config.bidder.model.UsersyncConfigurationProperties; +import org.prebid.server.spring.config.bidder.util.BidderDepsAssembler; +import org.prebid.server.spring.config.bidder.util.BidderInfoCreator; +import org.prebid.server.spring.config.bidder.util.UsersyncerCreator; +import org.prebid.server.spring.env.YamlPropertySourceFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +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/orbidder.yaml", factory = YamlPropertySourceFactory.class) +public class OrbidderConfiguration { + + private static final String BIDDER_NAME = "orbidder"; + + @Value("${external-url}") + @NotBlank + private String externalUrl; + + @Autowired + private JacksonMapper mapper; + + @Autowired + @Qualifier("orbidderConfigurationProperties") + private BidderConfigurationProperties configProperties; + + @Bean("orbidderConfigurationProperties") + @ConfigurationProperties("adapters.orbidder") + BidderConfigurationProperties configurationProperties() { + return new BidderConfigurationProperties(); + } + + @Bean + BidderDeps orbidderBidderDeps() { + final UsersyncConfigurationProperties usersync = configProperties.getUsersync(); + + return BidderDepsAssembler.forBidder(BIDDER_NAME) + .withConfig(configProperties) + .bidderInfo(BidderInfoCreator.create(configProperties)) + .usersyncerCreator(UsersyncerCreator.create(usersync, externalUrl)) + .bidderCreator(() -> new OrbidderBidder(configProperties.getEndpoint(), mapper)) + .assemble(); + } +} diff --git a/src/main/resources/bidder-config/orbidder.yaml b/src/main/resources/bidder-config/orbidder.yaml new file mode 100644 index 00000000000..846ecd38f6e --- /dev/null +++ b/src/main/resources/bidder-config/orbidder.yaml @@ -0,0 +1,23 @@ +adapters: + orbidder: + enabled: false + endpoint: https://orbidder.otto.de/openrtb2 + pbs-enforces-gdpr: true + pbs-enforces-ccpa: true + modifying-vast-xml-allowed: true + deprecated-names: + aliases: + meta-info: + maintainer-email: realtime-siggi@otto.de + app-media-types: + - banner + site-media-types: + - banner + supported-vendors: + vendor-id: 0 + usersync: + url: + redirect-url: + cookie-family-name: orbidder + type: redirect + support-cors: false diff --git a/src/main/resources/static/bidder-params/orbidder.json b/src/main/resources/static/bidder-params/orbidder.json new file mode 100644 index 00000000000..d986b23284e --- /dev/null +++ b/src/main/resources/static/bidder-params/orbidder.json @@ -0,0 +1,24 @@ +{ + "$schema": "http://json-schema.org/draft-04/schema#", + "title": "Orbidder Adapter Params", + "description": "A schema which validates params accepted by the Orbidder adapter", + + "type": "object", + "properties": { + "accountId": { + "type": "string", + "description": "The marketer's accountId." + }, + "placementId": { + "type": "string", + "description": "The placementId of the ad unit." + }, + "bidfloor": { + "type": "number", + "description": "The minimum CPM price in EUR.", + "minimum": 0 + } + }, + + "required": ["accountId", "placementId"] +} \ No newline at end of file diff --git a/src/test/java/org/prebid/server/bidder/orbidder/OrbidderTest.java b/src/test/java/org/prebid/server/bidder/orbidder/OrbidderTest.java new file mode 100644 index 00000000000..435ac0b8fac --- /dev/null +++ b/src/test/java/org/prebid/server/bidder/orbidder/OrbidderTest.java @@ -0,0 +1,189 @@ +package org.prebid.server.bidder.orbidder; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonNode; +import com.iab.openrtb.request.BidRequest; +import com.iab.openrtb.response.Bid; +import com.iab.openrtb.response.BidResponse; +import com.iab.openrtb.response.SeatBid; +import org.junit.Before; +import org.junit.Test; +import org.prebid.server.VertxTest; +import org.prebid.server.bidder.model.BidderBid; +import org.prebid.server.bidder.model.BidderError; +import org.prebid.server.bidder.model.HttpCall; +import org.prebid.server.bidder.model.HttpRequest; +import org.prebid.server.bidder.model.HttpResponse; +import org.prebid.server.bidder.model.Result; + +import java.util.Collections; +import java.util.List; +import java.util.Map; +import java.util.function.Function; + +import static java.util.Collections.emptyList; +import static java.util.Collections.emptyMap; +import static java.util.Collections.singletonList; +import static java.util.Collections.singletonMap; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException; + +public class OrbidderTest extends VertxTest { + + private static final String ENDPOINT_URL = "https://test.endpoint.com/"; + + private OrbidderBidder orbidderBidder; + + @Before + public void setUp() { + orbidderBidder = new OrbidderBidder(ENDPOINT_URL, jacksonMapper); + } + + @Test + public void creationShouldFailOnInvalidEndpointUrl() { + assertThatIllegalArgumentException().isThrownBy(() -> new OrbidderBidder("invalid_url", jacksonMapper)); + } + + @Test + public void makeHttpRequestsShouldReturnErrorIfImpressionListSizeIsZero() { + // given + final BidRequest bidRequest = BidRequest.builder() + .imp(emptyList()) + .build(); + + // when + final Result>> result = orbidderBidder.makeHttpRequests(bidRequest); + + // then + assertThat(result.getErrors()).hasSize(1) + .containsOnly(BidderError.badInput("No valid impressions in the bid request")); + } + + @Test + public void makeBidsShouldReturnEmptyResultWhenResponseWithNoContent() { + // given + final HttpCall httpCall = HttpCall + .success(null, HttpResponse.of(204, null, null), null); + + // when + final Result> result = orbidderBidder.makeBids(httpCall, null); + + // then + assertThat(result.getErrors()).isEmpty(); + assertThat(result.getValue()).isEmpty(); + } + + @Test + public void makeBidsShouldReturnEmptyResultWhenResponseStatusIsNotOk() { + // given + final HttpCall httpCall = HttpCall + .success(null, HttpResponse.of(404, null, null), null); + + // when + final Result> result = orbidderBidder.makeBids(httpCall, null); + + // then + assertThat(result.getErrors().get(0).getMessage()).startsWith("Unexpected HTTP status 404."); + assertThat(result.getErrors().get(0).getType()).isEqualTo(BidderError.Type.bad_server_response); + } + + @Test + public void makeBidsShouldReturnEmptyResultWhenBadRequest() { + // given + final HttpCall httpCall = HttpCall + .success(null, HttpResponse.of(400, null, null), null); + + // when + final Result> result = orbidderBidder.makeBids(httpCall, null); + + // then + assertThat(result.getErrors().get(0).getMessage()).startsWith("Invalid request."); + assertThat(result.getErrors().get(0).getType()).isEqualTo(BidderError.Type.bad_input); + } + + @Test + public void makeBidsShouldReturnEmptyResultWhenBadServerResponse() { + // given + final HttpCall httpCall = HttpCall + .success(null, HttpResponse.of(500, null, null), null); + + // when + final Result> result = orbidderBidder.makeBids(httpCall, null); + + // then + assertThat(result.getErrors().get(0).getMessage()).startsWith("Server internal error."); + assertThat(result.getErrors().get(0).getType()).isEqualTo(BidderError.Type.bad_input); + } + + @Test + public void makeBidsShouldReturnErrorIfResponseBodyCouldNotBeParsed() { + // given + final HttpCall httpCall = givenHttpCall("false"); + + // when + final Result> result = orbidderBidder.makeBids(httpCall, null); + + // then + assertThat(result.getErrors().get(0).getType()).isEqualTo(BidderError.Type.bad_server_response); + assertThat(result.getValue()).isEmpty(); + } + + @Test + public void makeBidsShouldReturnErrorsWhenSeatBidIsEmptyList() throws JsonProcessingException { + // given + final HttpCall httpCall = + givenHttpCall(mapper.writeValueAsString(BidResponse.builder().seatbid(emptyList()).build())); + + // when + final Result> result = orbidderBidder.makeBids(httpCall, BidRequest.builder().build()); + + // then + assertThat(result.getErrors()).isEmpty(); + assertThat(result).isNotNull() + .extracting(Result::getValue, Result::getErrors) + .containsOnly(Collections.emptyList(), Collections.emptyList()); + } + + @Test + public void makeBidsShouldReturnErrorsWhenBidsEmptyList() + throws JsonProcessingException { + // given + final HttpCall httpCall = + givenHttpCall(mapper.writeValueAsString( + BidResponse.builder() + .seatbid(singletonList(SeatBid.builder().bid(emptyList()).build())) + .build())); + + // when + final Result> result = orbidderBidder.makeBids(httpCall, BidRequest.builder().build()); + + // then + assertThat(result.getErrors()).isEmpty(); + assertThat(result).isNotNull() + .extracting(Result::getValue, Result::getErrors) + .containsOnly(Collections.emptyList(), Collections.emptyList()); + } + + @Test + public void extractTargetingShouldReturnEmptyMap() { + assertThat(orbidderBidder.extractTargeting(mapper.createObjectNode())).isEqualTo(emptyMap()); + } + + private static BidResponse givenBidResponse(Function bidCustomizer) { + return BidResponse.builder() + .seatbid(singletonList(SeatBid.builder().bid(singletonList(bidCustomizer.apply(Bid.builder()).build())) + .build())) + .build(); + } + + private static HttpCall givenHttpCall(String body) { + return HttpCall.success( + HttpRequest.builder().payload(null).build(), + HttpResponse.of(200, null, body), + null); + } + + private static Map givenCustomParams(String key, Object values) { + return singletonMap(key, mapper.valueToTree(values)); + } +} diff --git a/src/test/java/org/prebid/server/it/OrbidderTest.java b/src/test/java/org/prebid/server/it/OrbidderTest.java new file mode 100644 index 00000000000..638078fdeb7 --- /dev/null +++ b/src/test/java/org/prebid/server/it/OrbidderTest.java @@ -0,0 +1,57 @@ +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.skyscreamer.jsonassert.JSONAssert; +import org.skyscreamer.jsonassert.JSONCompareMode; +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.equalTo; +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 io.restassured.RestAssured.given; +import static java.util.Collections.singletonList; + +@RunWith(SpringRunner.class) +public class OrbidderTest extends IntegrationTest { + + @Test + public void openrtb2AuctionShouldRespondWithBidsFromOrbidder() throws IOException, JSONException { + // given + // OrbidderBidder bid response for imp 001 + WIRE_MOCK_RULE.stubFor(post(urlPathEqualTo("/orbidder-exchange")) + .withHeader("Accept", equalTo("application/json")) + .withHeader("Content-Type", equalTo("application/json;charset=UTF-8")) + .withRequestBody(equalToJson(jsonFrom("openrtb2/orbidder/test-orbidder-bid-request.json"))) + .willReturn(aResponse().withBody(jsonFrom("openrtb2/orbidder/test-orbidder-bid-response.json")))); + + // pre-bid cache + WIRE_MOCK_RULE.stubFor(post(urlPathEqualTo("/cache")) + .withRequestBody(equalToJson(jsonFrom("openrtb2/orbidder/test-cache-orbidder-request.json"))) + .willReturn(aResponse().withBody(jsonFrom("openrtb2/orbidder/test-cache-orbidder-response.json")))); + + // when + final Response response = given(SPEC) + .header("Referer", "http://www.example.com") + .header("X-Forwarded-For", "193.168.244.1") + .header("User-Agent", "userAgent") + .header("Origin", "http://www.example.com") + //this uids cookie value stands for {"uids":{"orbidder":"OB-UID"}} + .cookie("uids", "eyJ1aWRzIjp7Im9yYmlkZGVyIjoiT0ItVUlEIn19") + .body(jsonFrom("openrtb2/orbidder/test-auction-orbidder-request.json")) + .post("/openrtb2/auction"); + + // then + final String expectedAuctionResponse = openrtbAuctionResponseFrom( + "openrtb2/orbidder/test-auction-orbidder-response.json", + response, singletonList("orbidder")); + + JSONAssert.assertEquals(expectedAuctionResponse, response.asString(), JSONCompareMode.NON_EXTENSIBLE); + } +} diff --git a/src/test/resources/org/prebid/server/it/openrtb2/orbidder/test-auction-orbidder-request.json b/src/test/resources/org/prebid/server/it/openrtb2/orbidder/test-auction-orbidder-request.json new file mode 100644 index 00000000000..e745675331a --- /dev/null +++ b/src/test/resources/org/prebid/server/it/openrtb2/orbidder/test-auction-orbidder-request.json @@ -0,0 +1,100 @@ +{ + "id": "tid", + "imp": [ + { + "id": "impId001", + "tagid": "2eb6bd58-865c-47ce-af7f-a918108c3fd2", + "banner": { + "format": [ + { + "w": 300, + "h": 250 + } + ] + }, + "ext": { + "orbidder": { + "accountId": "orbidder-test", + "placementId": "test-placement", + "bidfloor": 0.1 + } + } + } + ], + "device": { + "pxratio": 4.2, + "dnt": 2, + "ip": "193.168.244.1", + "language": "en", + "ifa": "ifaId", + "ua": "userAgent" + }, + "site": { + "domain": "example.com", + "ext": { + "amp": 0 + }, + "page": "http://www.example.com", + "publisher": { + "id": "publisherId" + } + }, + "at": 1, + "tmax": 3000, + "cur": [ + "USD" + ], + "source": { + "fd": 1, + "tid": "tid" + }, + "user": { + "ext": { + "consent": "consentValue", + "digitrust": { + "id": "id", + "keyv": 123, + "pref": 0 + } + } + }, + "regs": { + "ext": { + "gdpr": 0 + } + }, + "ext": { + "prebid": { + "currency": { + "rates": { + "EUR": { + "USD": 1.2406 + }, + "USD": { + "EUR": 0.8110 + } + } + }, + "targeting": { + "includebidderkeys": true, + "includewinners": true, + "pricegranularity": { + "precision": 2, + "ranges": [ + { + "max": 20, + "increment": 0.1 + } + ] + } + }, + "cache": { + "bids": {}, + "vastxml": { + "ttlseconds": 120 + } + }, + "auctiontimestamp": 1000 + } + } +} \ No newline at end of file diff --git a/src/test/resources/org/prebid/server/it/openrtb2/orbidder/test-auction-orbidder-response.json b/src/test/resources/org/prebid/server/it/openrtb2/orbidder/test-auction-orbidder-response.json new file mode 100644 index 00000000000..78d19b742f4 --- /dev/null +++ b/src/test/resources/org/prebid/server/it/openrtb2/orbidder/test-auction-orbidder-response.json @@ -0,0 +1,56 @@ +{ + "id": "tid", + "seatbid": [ + { + "bid": [ + { + "adm": "hi", + "cid": "test_cid", + "crid": "test_banner_crid", + "ext": { + "bidder": { + "format": "BANNER" + }, + "prebid": { + "type": "banner", + "targeting": { + "hb_bidder": "orbidder", + "hb_bidder_orbidder": "orbidder", + "hb_cache_host": "{{ cache.host }}", + "hb_cache_host_orbidder": "{{ cache.host }}", + "hb_cache_id": "f0ab9105-cb21-4e59-b433-70f5ad6671cb", + "hb_cache_id_orbidder": "f0ab9105-cb21-4e59-b433-70f5ad6671cb", + "hb_cache_path": "{{ cache.path }}", + "hb_cache_path_orbidder": "{{ cache.path }}", + "hb_pb": "0.00", + "hb_pb_orbidder": "0.00" + }, + "cache": { + "bids": { + "cacheId": "f0ab9105-cb21-4e59-b433-70f5ad6671cb", + "url": "{{ cache.resource_url }}f0ab9105-cb21-4e59-b433-70f5ad6671cb" + } + } + } + }, + "id": "1", + "impid": "imp123", + "price": 0.01 + } + ], + "group": 0, + "seat": "orbidder" + } + ], + "cur": "USD", + "ext": { + "responsetimemillis": { + "cache": "{{ cache.response_time_ms }}", + "orbidder": "{{ orbidder.response_time_ms }}" + }, + "prebid": { + "auctiontimestamp": 1000 + }, + "tmaxrequest": 3000 + } +} \ No newline at end of file diff --git a/src/test/resources/org/prebid/server/it/openrtb2/orbidder/test-cache-orbidder-request.json b/src/test/resources/org/prebid/server/it/openrtb2/orbidder/test-cache-orbidder-request.json new file mode 100644 index 00000000000..5b04ae31763 --- /dev/null +++ b/src/test/resources/org/prebid/server/it/openrtb2/orbidder/test-cache-orbidder-request.json @@ -0,0 +1,18 @@ +{ + "puts": [ + { + "type": "json", + "value": { + "id": "1", + "impid": "imp123", + "price": 0.01, + "adm": "hi", + "cid": "test_cid", + "crid": "test_banner_crid", + "ext": { + "format": "BANNER" + } + } + } + ] +} \ No newline at end of file diff --git a/src/test/resources/org/prebid/server/it/openrtb2/orbidder/test-cache-orbidder-response.json b/src/test/resources/org/prebid/server/it/openrtb2/orbidder/test-cache-orbidder-response.json new file mode 100644 index 00000000000..93d0b8de2cd --- /dev/null +++ b/src/test/resources/org/prebid/server/it/openrtb2/orbidder/test-cache-orbidder-response.json @@ -0,0 +1,7 @@ +{ + "responses": [ + { + "uuid": "f0ab9105-cb21-4e59-b433-70f5ad6671cb" + } + ] +} \ No newline at end of file diff --git a/src/test/resources/org/prebid/server/it/openrtb2/orbidder/test-orbidder-bid-request.json b/src/test/resources/org/prebid/server/it/openrtb2/orbidder/test-orbidder-bid-request.json new file mode 100644 index 00000000000..598294ca01b --- /dev/null +++ b/src/test/resources/org/prebid/server/it/openrtb2/orbidder/test-orbidder-bid-request.json @@ -0,0 +1,101 @@ +{ + "id": "tid", + "imp": [ + { + "id": "impId001", + "banner": { + "format": [ + { + "w": 300, + "h": 250 + } + ] + }, + "tagid" : "2eb6bd58-865c-47ce-af7f-a918108c3fd2", + "ext": { + "bidder": { + "accountId": "orbidder-test", + "placementId": "test-placement", + "bidfloor": 0.1 + } + } + } + ], + "site": { + "domain": "example.com", + "page": "http://www.example.com", + "publisher": { + "id": "publisherId" + }, + "ext": { + "amp": 0 + } + }, + "device": { + "ua": "userAgent", + "dnt": 2, + "ip": "193.168.244.1", + "pxratio": 4.2, + "language": "en", + "ifa": "ifaId" + }, + "user": { + "buyeruid": "OB-UID", + "ext": { + "consent": "consentValue", + "digitrust": { + "id": "id", + "keyv": 123, + "pref": 0 + } + } + }, + "at": 1, + "tmax": 3000, + "cur": [ + "USD" + ], + "source": { + "fd": 1, + "tid": "tid" + }, + "regs": { + "ext": { + "gdpr": 0 + } + }, + "ext": { + "prebid": { + "currency": { + "rates": { + "EUR": { + "USD": 1.2406 + }, + "USD": { + "EUR": 0.811 + } + } + }, + "targeting": { + "includebidderkeys": true, + "includewinners": true, + "pricegranularity": { + "precision": 2, + "ranges": [ + { + "max": 20, + "increment": 0.1 + } + ] + } + }, + "cache": { + "bids": {}, + "vastxml": { + "ttlseconds": 120 + } + }, + "auctiontimestamp": 1000 + } + } +} \ No newline at end of file diff --git a/src/test/resources/org/prebid/server/it/openrtb2/orbidder/test-orbidder-bid-response.json b/src/test/resources/org/prebid/server/it/openrtb2/orbidder/test-orbidder-bid-response.json new file mode 100644 index 00000000000..f8f642f77ed --- /dev/null +++ b/src/test/resources/org/prebid/server/it/openrtb2/orbidder/test-orbidder-bid-response.json @@ -0,0 +1,20 @@ +{ + "id": "tid", + "seatbid": [ + { + "bid": [ + { + "adm": "hi", + "crid": "test_banner_crid", + "cid": "test_cid", + "impid": "imp123", + "id": "1", + "price": 0.01, + "ext": { + "format": "BANNER" + } + } + ] + } + ] +} \ No newline at end of file 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 7f1eeecef18..5ecbc541205 100644 --- a/src/test/resources/org/prebid/server/it/test-application.properties +++ b/src/test/resources/org/prebid/server/it/test-application.properties @@ -142,6 +142,10 @@ adapters.openx.enabled=true adapters.openx.endpoint=http://localhost:8090/openx-exchange adapters.openx.pbs-enforces-gdpr=true adapters.openx.usersync.url=//openx-usersync +adapters.orbidder.enabled=true +adapters.orbidder.endpoint=http://localhost:8090/orbidder-exchange +adapters.orbidder.pbs-enforces-gdpr=true +adapters.orbidder.usersync.url=//orbidder-usersync adapters.pubmatic.enabled=true adapters.pubmatic.endpoint=http://localhost:8090/pubmatic-exchange adapters.pubmatic.pbs-enforces-gdpr=true From 6d0460c051f1a3773e381cd561f8e200ad307b5d Mon Sep 17 00:00:00 2001 From: apavlyuk Date: Fri, 11 Sep 2020 12:43:33 +0300 Subject: [PATCH 2/2] Small refactoring of code --- .../server/bidder/orbidder/OrbidderBidder.java | 6 ------ .../ext/request/orbidder/ExtImpOrbidder.java | 6 +----- .../server/bidder/orbidder/OrbidderTest.java | 15 --------------- .../orbidder/test-auction-orbidder-request.json | 10 ---------- .../orbidder/test-orbidder-bid-request.json | 10 ---------- 5 files changed, 1 insertion(+), 46 deletions(-) diff --git a/src/main/java/org/prebid/server/bidder/orbidder/OrbidderBidder.java b/src/main/java/org/prebid/server/bidder/orbidder/OrbidderBidder.java index 7ea11c4ce3d..fa3fb027bdb 100644 --- a/src/main/java/org/prebid/server/bidder/orbidder/OrbidderBidder.java +++ b/src/main/java/org/prebid/server/bidder/orbidder/OrbidderBidder.java @@ -8,7 +8,6 @@ import com.iab.openrtb.response.SeatBid; import io.netty.handler.codec.http.HttpResponseStatus; import io.vertx.core.http.HttpMethod; -import org.apache.commons.collections4.CollectionUtils; import org.prebid.server.bidder.Bidder; import org.prebid.server.bidder.model.BidderBid; import org.prebid.server.bidder.model.BidderError; @@ -52,11 +51,6 @@ public Result>> makeHttpRequests(BidRequest request final List errors = new ArrayList<>(); final List validImps = new ArrayList<>(); - if (CollectionUtils.isEmpty(request.getImp())) { - errors.add(BidderError.badInput("No valid impressions in the bid request")); - return Result.of(Collections.emptyList(), errors); - } - for (Imp imp : request.getImp()) { try { parseImpExt(imp); diff --git a/src/main/java/org/prebid/server/proto/openrtb/ext/request/orbidder/ExtImpOrbidder.java b/src/main/java/org/prebid/server/proto/openrtb/ext/request/orbidder/ExtImpOrbidder.java index c8bb28d2dd9..a22df1038c0 100644 --- a/src/main/java/org/prebid/server/proto/openrtb/ext/request/orbidder/ExtImpOrbidder.java +++ b/src/main/java/org/prebid/server/proto/openrtb/ext/request/orbidder/ExtImpOrbidder.java @@ -1,6 +1,5 @@ package org.prebid.server.proto.openrtb.ext.request.orbidder; -import com.fasterxml.jackson.annotation.JsonProperty; import lombok.AllArgsConstructor; import lombok.Value; @@ -10,12 +9,9 @@ @AllArgsConstructor(staticName = "of") public class ExtImpOrbidder { - @JsonProperty("accountId") String accountId; - @JsonProperty("placementId") String placementId; - @JsonProperty("bidfloor") - BigDecimal bidFloor; + BigDecimal bidfloor; } diff --git a/src/test/java/org/prebid/server/bidder/orbidder/OrbidderTest.java b/src/test/java/org/prebid/server/bidder/orbidder/OrbidderTest.java index 435ac0b8fac..ae106f20dfd 100644 --- a/src/test/java/org/prebid/server/bidder/orbidder/OrbidderTest.java +++ b/src/test/java/org/prebid/server/bidder/orbidder/OrbidderTest.java @@ -44,21 +44,6 @@ public void creationShouldFailOnInvalidEndpointUrl() { assertThatIllegalArgumentException().isThrownBy(() -> new OrbidderBidder("invalid_url", jacksonMapper)); } - @Test - public void makeHttpRequestsShouldReturnErrorIfImpressionListSizeIsZero() { - // given - final BidRequest bidRequest = BidRequest.builder() - .imp(emptyList()) - .build(); - - // when - final Result>> result = orbidderBidder.makeHttpRequests(bidRequest); - - // then - assertThat(result.getErrors()).hasSize(1) - .containsOnly(BidderError.badInput("No valid impressions in the bid request")); - } - @Test public void makeBidsShouldReturnEmptyResultWhenResponseWithNoContent() { // given diff --git a/src/test/resources/org/prebid/server/it/openrtb2/orbidder/test-auction-orbidder-request.json b/src/test/resources/org/prebid/server/it/openrtb2/orbidder/test-auction-orbidder-request.json index e745675331a..ae6c601f277 100644 --- a/src/test/resources/org/prebid/server/it/openrtb2/orbidder/test-auction-orbidder-request.json +++ b/src/test/resources/org/prebid/server/it/openrtb2/orbidder/test-auction-orbidder-request.json @@ -65,16 +65,6 @@ }, "ext": { "prebid": { - "currency": { - "rates": { - "EUR": { - "USD": 1.2406 - }, - "USD": { - "EUR": 0.8110 - } - } - }, "targeting": { "includebidderkeys": true, "includewinners": true, diff --git a/src/test/resources/org/prebid/server/it/openrtb2/orbidder/test-orbidder-bid-request.json b/src/test/resources/org/prebid/server/it/openrtb2/orbidder/test-orbidder-bid-request.json index 598294ca01b..22e4b1b13d7 100644 --- a/src/test/resources/org/prebid/server/it/openrtb2/orbidder/test-orbidder-bid-request.json +++ b/src/test/resources/org/prebid/server/it/openrtb2/orbidder/test-orbidder-bid-request.json @@ -66,16 +66,6 @@ }, "ext": { "prebid": { - "currency": { - "rates": { - "EUR": { - "USD": 1.2406 - }, - "USD": { - "EUR": 0.811 - } - } - }, "targeting": { "includebidderkeys": true, "includewinners": true,