Skip to content

Commit

Permalink
Small refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
Serhii Nahornyi committed Feb 11, 2022
1 parent 471a025 commit c5d9f48
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 30 deletions.
33 changes: 11 additions & 22 deletions src/main/java/org/prebid/server/bidder/vidoomy/VidoomyBidder.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,13 @@ private static Imp modifyImp(Imp imp) {
}

private static void validateBannerSizes(Integer width, Integer height, List<Format> formats) {
final boolean isMeasuresNotNull = width != null && height != null;
if (isMeasuresNotNull && (width == 0 || height == 0)) {
final boolean sizePresent = width != null && height != null;
if (sizePresent && (width == 0 || height == 0)) {
throw new PreBidException(String.format("invalid sizes provided for Banner %s x %s", width, height));
}

if (!isMeasuresNotNull && CollectionUtils.isEmpty(formats)) {
throw new PreBidException(String.format("no sizes provided for Banner %s", formats));
if (!sizePresent && CollectionUtils.isEmpty(formats)) {
throw new PreBidException("no sizes provided for Banner []");
}
}

Expand All @@ -115,18 +115,11 @@ private static MultiMap headers(Device device) {
final MultiMap headers = HttpUtil.headers()
.add(HttpUtil.X_OPENRTB_VERSION_HEADER, OPENRTB_VERSION);

HttpUtil.addHeaderIfValueIsNotEmpty(
headers,
HttpUtil.USER_AGENT_HEADER,
ObjectUtil.getIfNotNull(device, Device::getUa));
HttpUtil.addHeaderIfValueIsNotEmpty(
headers,
HttpUtil.X_FORWARDED_FOR_HEADER,
ObjectUtil.getIfNotNull(device, Device::getIpv6));
HttpUtil.addHeaderIfValueIsNotEmpty(
headers,
HttpUtil.X_FORWARDED_FOR_HEADER,
ObjectUtil.getIfNotNull(device, Device::getIp));
if (device != null) {
HttpUtil.addHeaderIfValueIsNotEmpty(headers, HttpUtil.USER_AGENT_HEADER, device.getUa());
HttpUtil.addHeaderIfValueIsNotEmpty(headers, HttpUtil.X_FORWARDED_FOR_HEADER, device.getIpv6());
HttpUtil.addHeaderIfValueIsNotEmpty(headers, HttpUtil.X_FORWARDED_FOR_HEADER, device.getIp());
}

return headers;
}
Expand All @@ -152,15 +145,11 @@ private static List<BidderBid> extractBids(BidResponse bidResponse, BidRequest b
.filter(Objects::nonNull)
.flatMap(Collection::stream)
.filter(Objects::nonNull)
.map(bid -> BidderBid.of(
bid,
resolveBidType(bid.getImpid(), bidRequest.getImp()),
bidResponse.getCur()))
.filter(Objects::nonNull)
.map(bid -> BidderBid.of(bid, getBidType(bid.getImpid(), bidRequest.getImp()), bidResponse.getCur()))
.collect(Collectors.toList());
}

private static BidType resolveBidType(String impId, List<Imp> imps) {
private static BidType getBidType(String impId, List<Imp> imps) {
for (Imp imp : imps) {
if (Objects.equals(impId, imp.getId())) {
if (imp.getVideo() != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import org.junit.Before;
import org.junit.Test;
import org.prebid.server.VertxTest;
import org.prebid.server.bidder.between.BetweenBidder;
import org.prebid.server.bidder.model.BidderBid;
import org.prebid.server.bidder.model.BidderError;
import org.prebid.server.bidder.model.HttpCall;
Expand Down Expand Up @@ -48,7 +47,7 @@ public void setUp() {

@Test
public void creationShouldFailOnInvalidEndpointUrl() {
assertThatIllegalArgumentException().isThrownBy(() -> new BetweenBidder("invalid_url", jacksonMapper));
assertThatIllegalArgumentException().isThrownBy(() -> new AxonixBidder("invalid_url", jacksonMapper));
}

@Test
Expand Down Expand Up @@ -209,7 +208,7 @@ private static BidRequest givenBidRequest(
Function<Imp.ImpBuilder, Imp.ImpBuilder> impCustomizer) {

return bidRequestCustomizer.apply(BidRequest.builder()
.imp(singletonList(givenImp(impCustomizer))))
.imp(singletonList(givenImp(impCustomizer))))
.build();
}

Expand All @@ -219,9 +218,9 @@ private static BidRequest givenBidRequest(Function<Imp.ImpBuilder, Imp.ImpBuilde

private static Imp givenImp(Function<Imp.ImpBuilder, Imp.ImpBuilder> impCustomizer) {
return impCustomizer.apply(Imp.builder()
.id("123")
.banner(Banner.builder().w(23).h(25).build())
.ext(mapper.valueToTree(ExtPrebid.of(null, ExtImpBetween.of("127.0.0.1", "pubId")))))
.id("123")
.banner(Banner.builder().w(23).h(25).build())
.ext(mapper.valueToTree(ExtPrebid.of(null, ExtImpBetween.of("127.0.0.1", "pubId")))))
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import org.junit.Before;
import org.junit.Test;
import org.prebid.server.VertxTest;
import org.prebid.server.bidder.between.BetweenBidder;
import org.prebid.server.bidder.model.BidderBid;
import org.prebid.server.bidder.model.BidderError;
import org.prebid.server.bidder.model.HttpCall;
Expand Down Expand Up @@ -51,7 +50,7 @@ public void setUp() {

@Test
public void creationShouldFailOnInvalidEndpointUrl() {
assertThatIllegalArgumentException().isThrownBy(() -> new BetweenBidder("invalid_url", jacksonMapper));
assertThatIllegalArgumentException().isThrownBy(() -> new VidoomyBidder("invalid_url", jacksonMapper));
}

@Test
Expand Down Expand Up @@ -122,6 +121,21 @@ public void makeHttpRequestsShouldReturnErrorIfAllSizesIsInvalid() {
.containsExactly(BidderError.badInput("no sizes provided for Banner []"));
}

@Test
public void makeHttpRequestsShouldReturnErrorIfAllSizesIsInvalidAndFormatIsNotPresent() {
// given
final BidRequest bidRequest = givenBidRequest(impBuilder -> impBuilder
.banner(Banner.builder().w(5).h(null).format(null).build()));

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

// then
assertThat(result.getValue()).isEmpty();
assertThat(result.getErrors())
.containsExactly(BidderError.badInput("no sizes provided for Banner []"));
}

@Test
public void makeHttpRequestsShouldUseBannerFormatIfBannerSizeIsInvalid() {
// given
Expand Down

0 comments on commit c5d9f48

Please sign in to comment.