Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Colossus: Add new param #1818

Merged
merged 6 commits into from
May 5, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,13 @@ private static BidderBid makeBidderBid(Bid bid, List<Imp> imps, String currency,
private static BidType resolveBidType(String impId, List<Imp> imps) {
marki1an marked this conversation as resolved.
Show resolved Hide resolved
for (Imp imp : imps) {
if (Objects.equals(impId, imp.getId())) {
if (imp.getBanner() == null && imp.getVideo() != null) {
if (imp.getBanner() != null) {
return BidType.banner;
} else if (imp.getVideo() != null) {
return BidType.video;
} else if (imp.getXNative() != null) {
return BidType.xNative;
}
return BidType.banner;
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
package org.prebid.server.proto.openrtb.ext.request.colossus;

import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.AllArgsConstructor;
import lombok.Value;

/**
* Defines the contract for bidRequest.imp[i].ext.colossus
*/
@AllArgsConstructor(staticName = "of")
@Value
@Value(staticConstructor = "of")
public class ExtImpColossus {

@JsonProperty("TagID")
String tagId;

String groupId;
marki1an marked this conversation as resolved.
Show resolved Hide resolved
}
18 changes: 16 additions & 2 deletions src/main/resources/static/bidder-params/colossus.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,27 @@
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "Colossus Adapter Params",
"description": "A schema which validates params accepted by the Colossus adapter",

"type": "object",
"properties": {
"TagID": {
"type": "string",
"description": "An ID which identifies the colossus ad tag"
},
"groupId": {
"type": "string",
"description": "An ID which identifies the colossus group"
}
},
"required" : [ "TagID" ]
"oneOf": [
{
"required": [
"TagID"
]
},
{
"required": [
"groupId"
]
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.iab.openrtb.request.Banner;
import com.iab.openrtb.request.BidRequest;
import com.iab.openrtb.request.Imp;
import com.iab.openrtb.request.Native;
import com.iab.openrtb.request.Video;
import com.iab.openrtb.response.Bid;
import com.iab.openrtb.response.BidResponse;
Expand All @@ -22,14 +23,15 @@

import java.util.Arrays;
import java.util.List;
import java.util.function.Function;
import java.util.function.UnaryOperator;

import static java.util.Collections.singletonList;
import static java.util.function.Function.identity;
import static java.util.function.UnaryOperator.identity;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
import static org.prebid.server.proto.openrtb.ext.response.BidType.banner;
import static org.prebid.server.proto.openrtb.ext.response.BidType.video;
import static org.prebid.server.proto.openrtb.ext.response.BidType.xNative;

public class ColossusBidderTest extends VertxTest {

Expand All @@ -51,9 +53,8 @@ public void creationShouldFailOnInvalidEndpointUrl() {
public void makeHttpRequestsShouldReturnErrorIfImpExtCouldNotBeParsed() {
// given
final BidRequest bidRequest = BidRequest.builder()
.imp(singletonList(Imp.builder()
.ext(mapper.valueToTree(ExtPrebid.of(null, mapper.createArrayNode())))
.build()))
.imp(singletonList(givenImp(impBuilder -> impBuilder
marki1an marked this conversation as resolved.
Show resolved Hide resolved
.ext(mapper.valueToTree(ExtPrebid.of(null, mapper.createArrayNode()))))))
.build();

// when
Expand All @@ -79,8 +80,8 @@ public void makeHttpRequestsShouldReturnExpectedBidRequest() {
.build();
assertThat(result.getErrors()).isEmpty();
assertThat(result.getValue()).hasSize(1)
.extracting(httpRequest -> mapper.readValue(httpRequest.getBody(), BidRequest.class))
.containsOnly(expectedRequest);
.extracting(HttpRequest::getPayload)
.containsExactly(expectedRequest);
}

@Test
Expand All @@ -90,20 +91,19 @@ public void makeHttpRequestsShouldMakeOneRequestPerImp() {
identity(),
requestBuilder -> requestBuilder.imp(Arrays.asList(
givenImp(identity()),
Imp.builder()
.ext(mapper.valueToTree(ExtPrebid.of(null, ExtImpColossus.of("otherTagId"))))
.build())));
givenImp(impBuilder -> impBuilder.ext(mapper.valueToTree(
ExtPrebid.of(null, ExtImpColossus.of("otherTagId", null))))))));

// when
final Result<List<HttpRequest<BidRequest>>> result = colossusBidder.makeHttpRequests(bidRequest);

// then
assertThat(result.getErrors()).isEmpty();
assertThat(result.getValue()).hasSize(2)
.extracting(httpRequest -> mapper.readValue(httpRequest.getBody(), BidRequest.class))
.flatExtracting(BidRequest::getImp).hasSize(2)
assertThat(result.getValue())
.extracting(HttpRequest::getPayload)
.flatExtracting(BidRequest::getImp)
.extracting(Imp::getTagid)
.containsOnly("tagidString", "otherTagId");
.containsExactly("tagidString", "otherTagId");
}

@Test
Expand Down Expand Up @@ -149,78 +149,94 @@ public void makeBidsShouldReturnEmptyListIfBidResponseSeatBidIsNull() throws Jso
}

@Test
public void makeBidsShouldReturnBannerBidByDefault() throws JsonProcessingException {
public void makeBidsShouldReturnBannerBid() throws JsonProcessingException {
// given
final HttpCall<BidRequest> httpCall = givenHttpCall(givenBidRequest(identity()),
mapper.writeValueAsString(givenBidResponse(bidBuilder -> bidBuilder.impid("123"))));

// when
final Result<List<BidderBid>> result = colossusBidder.makeBids(httpCall, null);

// then
assertThat(result.getErrors()).isEmpty();
assertThat(result.getValue())
.containsExactly(BidderBid.of(Bid.builder().impid("123").build(), banner, "USD"));
}

@Test
public void makeBidsShouldReturnxNativerBid() throws JsonProcessingException {
// given
final HttpCall<BidRequest> httpCall = givenHttpCall(
BidRequest.builder().imp(singletonList(Imp.builder().id("123").build())).build(),
BidRequest.builder().imp(singletonList(givenImp(impBuilder -> impBuilder.banner(null).video(null)
marki1an marked this conversation as resolved.
Show resolved Hide resolved
.xNative(Native.builder().build()))))
.build(),
mapper.writeValueAsString(givenBidResponse(bidBuilder -> bidBuilder.impid("123"))));

// when
final Result<List<BidderBid>> result = colossusBidder.makeBids(httpCall, null);

// then
assertThat(result.getErrors()).isEmpty();
assertThat(result.getValue()).containsOnly(BidderBid.of(Bid.builder().impid("123").build(), banner, "USD"));
assertThat(result.getValue())
.containsExactly(BidderBid.of(Bid.builder().impid("123").build(), xNative, "USD"));
}

@Test
public void makeBidsShouldReturnVideoBidIfNoBannerAndHasVideo() throws JsonProcessingException {
public void makeBidsShouldReturnVideoBid() throws JsonProcessingException {
// given
final HttpCall<BidRequest> httpCall = givenHttpCall(
marki1an marked this conversation as resolved.
Show resolved Hide resolved
BidRequest.builder()
.imp(singletonList(Imp.builder().video(Video.builder().build()).id("123").build()))
.build(),
.imp(singletonList(givenImp(impBuilder -> impBuilder.banner(null)))).build(),
mapper.writeValueAsString(givenBidResponse(bidBuilder -> bidBuilder.impid("123"))));

// when
final Result<List<BidderBid>> result = colossusBidder.makeBids(httpCall, null);

// then
assertThat(result.getErrors()).isEmpty();
assertThat(result.getValue()).containsOnly(BidderBid.of(Bid.builder().impid("123").build(), video, "USD"));
assertThat(result.getValue())
.containsExactly(BidderBid.of(Bid.builder().impid("123").build(), video, "USD"));
}

@Test
public void makeBidsShouldReturnBannerBidIfHasBothBannerAndVideo() throws JsonProcessingException {
public void makeBidsShouldReturnErrorIfDoesHaveAnyBidType() throws JsonProcessingException {
// given
final HttpCall<BidRequest> httpCall = givenHttpCall(
marki1an marked this conversation as resolved.
Show resolved Hide resolved
BidRequest.builder()
.imp(singletonList(givenImp(identity())))
.imp(singletonList(givenImp(impBuilder -> impBuilder.banner(null).video(null))))
.build(),
mapper.writeValueAsString(givenBidResponse(bidBuilder -> bidBuilder.impid("123"))));

// when
final Result<List<BidderBid>> result = colossusBidder.makeBids(httpCall, null);

// then
assertThat(result.getErrors()).isEmpty();
assertThat(result.getValue()).containsOnly(BidderBid.of(Bid.builder().impid("123").build(), banner, "USD"));
assertThat(result.getValue()).isEmpty();
assertThat(result.getErrors())
.containsExactly(BidderError.badServerResponse("Failed to find impression for ID: 123"));
}

private static BidRequest givenBidRequest(
Function<Imp.ImpBuilder, Imp.ImpBuilder> impCustomizer,
Function<BidRequest.BidRequestBuilder, BidRequest.BidRequestBuilder> requestCustomizer) {
return requestCustomizer.apply(BidRequest.builder()
.imp(singletonList(givenImp(impCustomizer))))
.build();
private static BidRequest givenBidRequest(UnaryOperator<Imp.ImpBuilder> impCustomizer,
UnaryOperator<BidRequest.BidRequestBuilder> requestCustomizer) {
return requestCustomizer.apply(BidRequest.builder().imp(singletonList(givenImp(impCustomizer)))).build();
}

private static BidRequest givenBidRequest(
Function<Imp.ImpBuilder, Imp.ImpBuilder> impCustomizer) {
private static BidRequest givenBidRequest(UnaryOperator<Imp.ImpBuilder> impCustomizer) {
return givenBidRequest(impCustomizer, identity());
}

private static Imp givenImp(Function<Imp.ImpBuilder, Imp.ImpBuilder> impCustomizer) {
private static Imp givenImp(UnaryOperator<Imp.ImpBuilder> impCustomizer) {

return impCustomizer.apply(Imp.builder()
.id("123"))
.banner(Banner.builder().build())
.video(Video.builder().build())
.ext(mapper.valueToTree(ExtPrebid.of(null, ExtImpColossus.of("tagidString"))))
.id("123")
.banner(Banner.builder().build())
.video(Video.builder().build())
.ext(mapper.valueToTree(
ExtPrebid.of(null, ExtImpColossus.of("tagidString", "groupIdStr")))))
.build();
}

private static BidResponse givenBidResponse(
Function<Bid.BidBuilder, Bid.BidBuilder> bidCustomizer) {
private static BidResponse givenBidResponse(UnaryOperator<Bid.BidBuilder> bidCustomizer) {
return BidResponse.builder()
.cur("USD")
.seatbid(singletonList(SeatBid.builder()
Expand Down