From 18575157ee874db9182548566d6261e434315d40 Mon Sep 17 00:00:00 2001 From: Serhii Nahornyi Date: Tue, 27 Apr 2021 14:02:46 +0300 Subject: [PATCH] Beachfront update (#1177) --- .../bidder/beachfront/BeachfrontBidder.java | 52 ++++++++++--------- .../beachfront/BeachfrontBidderTest.java | 42 +++++++++++---- .../test-beachfront-bid-request-3.json | 4 +- 3 files changed, 61 insertions(+), 37 deletions(-) diff --git a/src/main/java/org/prebid/server/bidder/beachfront/BeachfrontBidder.java b/src/main/java/org/prebid/server/bidder/beachfront/BeachfrontBidder.java index f37945066a6..0896136e9d6 100644 --- a/src/main/java/org/prebid/server/bidder/beachfront/BeachfrontBidder.java +++ b/src/main/java/org/prebid/server/bidder/beachfront/BeachfrontBidder.java @@ -54,9 +54,9 @@ public class BeachfrontBidder implements Bidder { private static final String NURL_VIDEO_TYPE = "nurl"; private static final String ADM_VIDEO_TYPE = "adm"; private static final String BEACHFRONT_NAME = "BF_PREBID_S2S"; - private static final String BEACHFRONT_VERSION = "0.9.1"; + private static final String BEACHFRONT_VERSION = "0.9.2"; private static final String NURL_VIDEO_ENDPOINT_SUFFIX = "&prebidserver"; - private static final String TEST_IP = "192.168.255.255"; + private static final String FAKE_IP = "255.255.255.255"; private static final BigDecimal MIN_BID_FLOOR = BigDecimal.valueOf(0.01); private static final int DEFAULT_VIDEO_WIDTH = 300; @@ -236,7 +236,7 @@ private static String getAppId(ExtImpBeachfront extImpBeachfront, boolean isBann } private static BigDecimal checkBidFloor(BigDecimal bidFloor) { - return bidFloor.compareTo(MIN_BID_FLOOR) > 0 ? bidFloor : BigDecimal.ZERO; + return bidFloor != null && bidFloor.compareTo(MIN_BID_FLOOR) > 0 ? bidFloor : BigDecimal.ZERO; } /** @@ -273,7 +273,7 @@ private static User makeUser(User user) { */ private static void populateDeviceFields(BeachfrontBannerRequest.BeachfrontBannerRequestBuilder builder, Device device) { - builder.ip(getIP(device.getIp())); + builder.ip(device.getIp()); builder.deviceModel(device.getModel()); builder.deviceOs(device.getOs()); if (device.getDnt() != null) { @@ -284,10 +284,6 @@ private static void populateDeviceFields(BeachfrontBannerRequest.BeachfrontBanne } } - private static String getIP(String ip) { - return StringUtils.isBlank(ip) || ip.equals("::1") || ip.equals("127.0.0.1") ? TEST_IP : ip; - } - private static int getSecure(String page) { return StringUtils.contains(page, "https") ? 1 : 0; } @@ -308,15 +304,19 @@ private List getVideoRequests(BidRequest bidRequest, Lis } final String videoResponseType = extImpBeachfront.getVideoResponseType(); - final String responseType = StringUtils.isBlank(videoResponseType) ? ADM_VIDEO_TYPE : videoResponseType; final BeachfrontVideoRequest.BeachfrontVideoRequestBuilder requestBuilder = BeachfrontVideoRequest.builder() - .appId(appId) - .videoResponseType(responseType); + .appId(appId); + final String responseType; - if (responseType.equals(NURL_VIDEO_TYPE)) { + if (videoResponseType != null && videoResponseType.equals(NURL_VIDEO_TYPE)) { requestBuilder.isPrebid(true); + responseType = NURL_VIDEO_TYPE; + } else { + responseType = ADM_VIDEO_TYPE; } + requestBuilder.videoResponseType(responseType); + final BidRequest.BidRequestBuilder bidRequestBuilder = bidRequest.toBuilder(); int secure = 0; final Site site = bidRequest.getSite(); @@ -326,16 +326,6 @@ private List getVideoRequests(BidRequest bidRequest, Lis secure = getSecure(site.getPage()); } - final App app = bidRequest.getApp(); - if (app != null && StringUtils.isBlank(app.getDomain()) && StringUtils.isNotBlank(app.getBundle())) { - final String trimmedBundle = StringUtils.removeStart(app.getBundle(), "_"); - final String[] split = StringUtils.removeEnd(trimmedBundle, "_").split("\\."); - - if (split.length > 1) { - bidRequestBuilder.app(app.toBuilder().domain(String.format("%s.%s", split[1], split[0])).build()); - } - } - final Device device = bidRequest.getDevice(); if (device != null) { final Device.DeviceBuilder deviceBuilder = device.toBuilder(); @@ -343,12 +333,23 @@ private List getVideoRequests(BidRequest bidRequest, Lis if (devicetype == null || devicetype == 0) { deviceBuilder.devicetype(bidRequest.getSite() != null ? 2 : 1); } - if (StringUtils.isNotBlank(device.getIp())) { - deviceBuilder.ip(getIP(device.getIp())); + if (StringUtils.isBlank(device.getIp()) && responseType.equals(ADM_VIDEO_TYPE)) { + deviceBuilder.ip(FAKE_IP); } + bidRequestBuilder.device(deviceBuilder.build()); } + final App app = bidRequest.getApp(); + if (app != null && StringUtils.isBlank(app.getDomain()) && StringUtils.isNotBlank(app.getBundle())) { + final String trimmedBundle = StringUtils.removeStart(app.getBundle(), "_"); + final String[] split = StringUtils.removeEnd(trimmedBundle, "_").split("\\."); + + if (split.length > 1) { + bidRequestBuilder.app(app.toBuilder().domain(String.format("%s.%s", split[1], split[0])).build()); + } + } + final Imp.ImpBuilder impBuilder = imp.toBuilder() .banner(null) .ext(null) @@ -421,7 +422,8 @@ private List makeBeachfrontResponseSlots(String response responseBody, mapper.mapper().getTypeFactory().constructCollectionType(List.class, BeachfrontResponseSlot.class)); } catch (IOException ex) { - throw new PreBidException(ex.getMessage()); + throw new PreBidException("server response failed to unmarshal " + + "as valid rtb. Run with request.debug = 1 for more info"); } } diff --git a/src/test/java/org/prebid/server/bidder/beachfront/BeachfrontBidderTest.java b/src/test/java/org/prebid/server/bidder/beachfront/BeachfrontBidderTest.java index 23c75bc15ae..89c93b38c4f 100644 --- a/src/test/java/org/prebid/server/bidder/beachfront/BeachfrontBidderTest.java +++ b/src/test/java/org/prebid/server/bidder/beachfront/BeachfrontBidderTest.java @@ -268,9 +268,8 @@ public void makeHttpRequestsShouldReturnExpectedBannerRequest() { .deviceOs("nokia") .isMobile(1) .user(User.builder().id("userId").buyeruid("buid").build()) - .adapterVersion("0.9.1") + .adapterVersion("0.9.2") .adapterName("BF_PREBID_S2S") - .ip("192.168.255.255") .requestId("153") .real204(true) .build()); @@ -281,7 +280,7 @@ public void makeHttpRequestsShouldReturnExpectedAdmAndNurlVideoRequests() { // given final BidRequest bidRequest = BidRequest.builder() .app(App.builder().bundle("prefix_test1.test2.test3_suffix").build()) - .device(Device.builder().ip("127.0.0.1").build()) + .device(Device.builder().build()) .imp(asList( givenImp(impBuilder -> impBuilder.ext(mapper.valueToTree(ExtPrebid.of(null, mapper.valueToTree(ExtImpBeachfront.of("appId2", null, BigDecimal.TEN, "nurl")))))), @@ -294,10 +293,6 @@ public void makeHttpRequestsShouldReturnExpectedAdmAndNurlVideoRequests() { // then assertThat(result.getErrors()).isEmpty(); - final BidRequest.BidRequestBuilder expectedRequestBuilder = BidRequest.builder() - .device(Device.builder().ip("192.168.255.255").devicetype(1).build()) - .cur(singletonList("USD")); - final Imp.ImpBuilder expectedImpBuilder = Imp.builder() .video(Video.builder().w(300).h(250).build()) .secure(0); @@ -308,25 +303,50 @@ public void makeHttpRequestsShouldReturnExpectedAdmAndNurlVideoRequests() { .isPrebid(true) .appId("appId2") .videoResponseType("nurl") - .request(expectedRequestBuilder + .request(BidRequest.builder() + .device(Device.builder().devicetype(1).build()) .app(App.builder().bundle("prefix_test1.test2.test3_suffix") .domain("test2.prefix_test1").build()) .imp(singletonList(expectedImpBuilder.id("123") .bidfloor(BigDecimal.TEN).build())) + .cur(singletonList("USD")) .build()) .build(), BeachfrontVideoRequest.builder() .appId("appId") .videoResponseType("adm") - .request(expectedRequestBuilder + .request(BidRequest.builder() + .device(Device.builder().ip("255.255.255.255").devicetype(1).build()) .app(App.builder().bundle("prefix_test1.test2.test3_suffix") .domain("test2.prefix_test1").build()) .imp(singletonList(expectedImpBuilder.id("234") .bidfloor(BigDecimal.ONE).build())) + .cur(singletonList("USD")) .build()) .build()); } + @Test + public void makeHttpRequestsShouldCreateAdmRequestForEveryUnknownResponseType() { + // given + final BidRequest bidRequest = BidRequest.builder() + .imp(singletonList( + givenImp(impBuilder -> impBuilder.ext(mapper.valueToTree(ExtPrebid.of(null, + mapper.valueToTree(ExtImpBeachfront.of("appId2", null, null, "unknownType")))))) + )) + .build(); + + // when + final Result>> result = beachfrontBidder.makeHttpRequests(bidRequest); + + // then + assertThat(result.getErrors()).isEmpty(); + assertThat(result.getValue()) + .extracting(httpRequest -> mapper.readValue(httpRequest.getBody(), BeachfrontVideoRequest.class)) + .extracting(BeachfrontVideoRequest::getVideoResponseType) + .containsExactly("adm"); + } + @Test public void makeBidsShouldReturnEmptyResultWhenResponseBodyHasEmptyArray() { // given @@ -351,7 +371,9 @@ public void makeBidsShouldReturnErrorWhenResponseBodyIsInvalid() { // then assertThat(result.getValue()).isEmpty(); assertThat(result.getErrors()).hasSize(1); - assertThat(result.getErrors().get(0).getMessage()).startsWith("Unrecognized token"); + assertThat(result.getErrors().get(0).getMessage()) + .isEqualTo("server response failed to unmarshal as valid rtb. " + + "Run with request.debug = 1 for more info"); } @Test diff --git a/src/test/resources/org/prebid/server/it/openrtb2/beachfront/test-beachfront-bid-request-3.json b/src/test/resources/org/prebid/server/it/openrtb2/beachfront/test-beachfront-bid-request-3.json index d67ef472966..7c101b7433c 100644 --- a/src/test/resources/org/prebid/server/it/openrtb2/beachfront/test-beachfront-bid-request-3.json +++ b/src/test/resources/org/prebid/server/it/openrtb2/beachfront/test-beachfront-bid-request-3.json @@ -22,8 +22,8 @@ "buyeruid": "BF-UID" }, "adapterName": "BF_PREBID_S2S", - "adapterVersion": "0.9.1", + "adapterVersion": "0.9.2", "ip": "193.168.244.1", "requestId": "tid", "real204": true -} \ No newline at end of file +}