|
1 | 1 | package org.prebid.server.bidder.seedtag; |
2 | 2 |
|
3 | 3 | import com.fasterxml.jackson.core.JsonProcessingException; |
| 4 | +import com.fasterxml.jackson.databind.node.ObjectNode; |
4 | 5 | import com.iab.openrtb.request.BidRequest; |
5 | 6 | import com.iab.openrtb.request.Imp; |
6 | 7 | import com.iab.openrtb.response.Bid; |
|
20 | 21 | import org.prebid.server.bidder.model.Result; |
21 | 22 | import org.prebid.server.currency.CurrencyConversionService; |
22 | 23 | import org.prebid.server.exception.PreBidException; |
| 24 | +import org.prebid.server.proto.openrtb.ext.request.seedtag.ExtImpSeedtag; |
23 | 25 |
|
24 | 26 | import java.math.BigDecimal; |
25 | 27 | import java.util.List; |
@@ -127,6 +129,115 @@ public void makeHttpRequestsShouldSkipImpsWithCurrencyThatCanNotBeConverted() { |
127 | 129 | .hasSize(1); |
128 | 130 | } |
129 | 131 |
|
| 132 | + @Test |
| 133 | + public void makeHttpRequestsShouldSucceedWithPublisherIdAndRonIdIntegrationType() { |
| 134 | + // given |
| 135 | + final BidRequest bidRequest = givenBidRequest( |
| 136 | + identity(), |
| 137 | + requestBuilder -> requestBuilder.imp(singletonList( |
| 138 | + givenImp(identity(), ExtImpSeedtag.of(null, "somePubId", "ronId"))))); |
| 139 | + |
| 140 | + // when |
| 141 | + final Result<List<HttpRequest<BidRequest>>> result = target.makeHttpRequests(bidRequest); |
| 142 | + |
| 143 | + // then |
| 144 | + assertThat(result.getErrors()).isEmpty(); |
| 145 | + assertThat(result.getValue()).hasSize(1); |
| 146 | + assertThat(result.getValue().get(0).getPayload().getImp()).hasSize(1); |
| 147 | + } |
| 148 | + |
| 149 | + @Test |
| 150 | + public void makeHttpRequestsShouldSucceedWithAdUnitIdAndPublisherIdWhenIntegrationTypeIsRonId() { |
| 151 | + // given: adUnitId is irrelevant when integrationType is ronId — publisherId is what matters |
| 152 | + final BidRequest bidRequest = givenBidRequest( |
| 153 | + identity(), |
| 154 | + requestBuilder -> requestBuilder.imp(singletonList( |
| 155 | + givenImp(identity(), ExtImpSeedtag.of("someAdUnitId", "somePubId", "ronId"))))); |
| 156 | + |
| 157 | + // when |
| 158 | + final Result<List<HttpRequest<BidRequest>>> result = target.makeHttpRequests(bidRequest); |
| 159 | + |
| 160 | + // then |
| 161 | + assertThat(result.getErrors()).isEmpty(); |
| 162 | + assertThat(result.getValue()).hasSize(1); |
| 163 | + } |
| 164 | + |
| 165 | + @Test |
| 166 | + public void makeHttpRequestsShouldSucceedWithAdUnitIdWhenIntegrationTypeIsAbsent() { |
| 167 | + // given |
| 168 | + final BidRequest bidRequest = givenBidRequest( |
| 169 | + identity(), |
| 170 | + requestBuilder -> requestBuilder.imp(singletonList( |
| 171 | + givenImp(identity(), ExtImpSeedtag.of("someAdUnitId", null, null))))); |
| 172 | + |
| 173 | + // when |
| 174 | + final Result<List<HttpRequest<BidRequest>>> result = target.makeHttpRequests(bidRequest); |
| 175 | + |
| 176 | + // then |
| 177 | + assertThat(result.getErrors()).isEmpty(); |
| 178 | + assertThat(result.getValue()).hasSize(1); |
| 179 | + } |
| 180 | + |
| 181 | + @Test |
| 182 | + public void makeHttpRequestsShouldSkipImpWithRonIdIntegrationTypeButMissingPublisherId() { |
| 183 | + // given |
| 184 | + final BidRequest bidRequest = givenBidRequest( |
| 185 | + identity(), |
| 186 | + requestBuilder -> requestBuilder.imp(singletonList( |
| 187 | + givenImp(identity(), ExtImpSeedtag.of("someAdUnitId", null, "ronId"))))); |
| 188 | + |
| 189 | + // when |
| 190 | + final Result<List<HttpRequest<BidRequest>>> result = target.makeHttpRequests(bidRequest); |
| 191 | + |
| 192 | + // then |
| 193 | + assertThat(result.getValue()).isEmpty(); |
| 194 | + assertThat(result.getErrors()).hasSize(1) |
| 195 | + .allSatisfy(error -> { |
| 196 | + assertThat(error.getType()).isEqualTo(BidderError.Type.bad_input); |
| 197 | + assertThat(error.getMessage()).contains("publisherId is required when integrationType is 'ronId'"); |
| 198 | + }); |
| 199 | + } |
| 200 | + |
| 201 | + @Test |
| 202 | + public void makeHttpRequestsShouldSkipImpWithNoAdUnitIdAndNoRonIdIntegrationType() { |
| 203 | + // given: no adUnitId and integrationType is not ronId → adUnitId is required |
| 204 | + final BidRequest bidRequest = givenBidRequest( |
| 205 | + identity(), |
| 206 | + requestBuilder -> requestBuilder.imp(singletonList( |
| 207 | + givenImp(identity(), ExtImpSeedtag.of(null, "somePubId", null))))); |
| 208 | + |
| 209 | + // when |
| 210 | + final Result<List<HttpRequest<BidRequest>>> result = target.makeHttpRequests(bidRequest); |
| 211 | + |
| 212 | + // then |
| 213 | + assertThat(result.getValue()).isEmpty(); |
| 214 | + assertThat(result.getErrors()).hasSize(1) |
| 215 | + .allSatisfy(error -> { |
| 216 | + assertThat(error.getType()).isEqualTo(BidderError.Type.bad_input); |
| 217 | + assertThat(error.getMessage()).contains("adUnitId is required when integrationType is not 'ronId'"); |
| 218 | + }); |
| 219 | + } |
| 220 | + |
| 221 | + @Test |
| 222 | + public void makeHttpRequestsShouldSkipImpWithNoAdUnitIdAndNoParams() { |
| 223 | + // given |
| 224 | + final BidRequest bidRequest = givenBidRequest( |
| 225 | + identity(), |
| 226 | + requestBuilder -> requestBuilder.imp(singletonList( |
| 227 | + givenImp(identity(), ExtImpSeedtag.of(null, null, null))))); |
| 228 | + |
| 229 | + // when |
| 230 | + final Result<List<HttpRequest<BidRequest>>> result = target.makeHttpRequests(bidRequest); |
| 231 | + |
| 232 | + // then |
| 233 | + assertThat(result.getValue()).isEmpty(); |
| 234 | + assertThat(result.getErrors()).hasSize(1) |
| 235 | + .allSatisfy(error -> { |
| 236 | + assertThat(error.getType()).isEqualTo(BidderError.Type.bad_input); |
| 237 | + assertThat(error.getMessage()).contains("adUnitId is required when integrationType is not 'ronId'"); |
| 238 | + }); |
| 239 | + } |
| 240 | + |
130 | 241 | @Test |
131 | 242 | public void makeBidsShouldReturnEmptyListIfBidResponseIsNull() throws JsonProcessingException { |
132 | 243 | // given |
@@ -231,7 +342,13 @@ private static BidRequest givenBidRequest(UnaryOperator<Imp.ImpBuilder> impCusto |
231 | 342 | } |
232 | 343 |
|
233 | 344 | private static Imp givenImp(UnaryOperator<Imp.ImpBuilder> impCustomizer) { |
234 | | - return impCustomizer.apply(Imp.builder().id("123")).build(); |
| 345 | + return givenImp(impCustomizer, ExtImpSeedtag.of("someAdUnitId", null, null)); |
| 346 | + } |
| 347 | + |
| 348 | + private static Imp givenImp(UnaryOperator<Imp.ImpBuilder> impCustomizer, ExtImpSeedtag extImpSeedtag) { |
| 349 | + final ObjectNode bidderExt = mapper.createObjectNode(); |
| 350 | + bidderExt.set("bidder", mapper.valueToTree(extImpSeedtag)); |
| 351 | + return impCustomizer.apply(Imp.builder().id("123").ext(bidderExt)).build(); |
235 | 352 | } |
236 | 353 |
|
237 | 354 | private static BidResponse givenBidResponse(UnaryOperator<Bid.BidBuilder> bidCustomizer) { |
|
0 commit comments