Skip to content

Commit ae6260f

Browse files
add tests for 2nd alias and resolve comments
1 parent 4ee05b4 commit ae6260f

15 files changed

Lines changed: 223 additions & 76 deletions

File tree

src/main/java/org/prebid/server/bidder/showheroes/ShowheroesBidder.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -184,15 +184,13 @@ private Source modifySource(BidRequest bidRequest) {
184184

185185
@Override
186186
public Result<List<BidderBid>> makeBids(BidderCall<BidRequest> httpCall, BidRequest bidRequest) {
187-
final BidResponse bidResponse;
188-
189187
try {
190-
bidResponse = mapper.decodeValue(httpCall.getResponse().getBody(), BidResponse.class);
188+
final BidResponse bidResponse = mapper.decodeValue(httpCall.getResponse().getBody(), BidResponse.class);
189+
return Result.of(extractBids(bidResponse), Collections.emptyList());
191190
} catch (DecodeException | PreBidException e) {
192191
return Result.withError(BidderError.badServerResponse(e.getMessage()));
193192
}
194193

195-
return Result.of(extractBids(bidResponse), Collections.emptyList());
196194
}
197195

198196
private List<BidderBid> extractBids(BidResponse bidResponse) {

src/main/java/org/prebid/server/proto/openrtb/ext/request/showheroes/ExtImpShowheroes.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@
33
import com.fasterxml.jackson.annotation.JsonProperty;
44
import lombok.Value;
55

6-
/**
7-
* Defines the contract for bidRequest.imp[i].ext.showheroes
8-
*/
96
@Value(staticConstructor = "of")
107
public class ExtImpShowheroes {
118

src/main/resources/static/bidder-params/showheroes.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
"properties": {
77
"unitId": {
88
"type": "string",
9-
"description": "Unit ID"
9+
"description": "Unit ID",
10+
"minLength": 8
1011
}
1112
},
1213
"required": ["unitId"]

src/test/java/org/prebid/server/bidder/showheroes/ShowheroesBidderTest.java

Lines changed: 19 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828

2929
import java.math.BigDecimal;
3030
import java.util.List;
31-
import java.util.Map;
31+
import java.util.Set;
3232
import java.util.function.Function;
3333

3434
import static org.mockito.ArgumentMatchers.any;
@@ -45,23 +45,26 @@
4545
import static org.assertj.core.api.Assertions.tuple;
4646
import static org.prebid.server.proto.openrtb.ext.response.BidType.banner;
4747
import static org.prebid.server.proto.openrtb.ext.response.BidType.video;
48+
import static org.prebid.server.util.HttpUtil.ACCEPT_HEADER;
49+
import static org.prebid.server.util.HttpUtil.APPLICATION_JSON_CONTENT_TYPE;
50+
import static org.prebid.server.util.HttpUtil.CONTENT_TYPE_HEADER;
51+
import static org.springframework.util.MimeTypeUtils.APPLICATION_JSON_VALUE;
4852

4953
@ExtendWith(MockitoExtension.class)
5054
public class ShowheroesBidderTest extends VertxTest {
5155

5256
private static final String ENDPOINT_URL = "https://ads.showheroes.com/";
5357

54-
private ShowheroesBidder target;
55-
5658
@Mock(strictness = LENIENT)
5759
private CurrencyConversionService currencyConversionService;
5860

5961
@Mock(strictness = LENIENT)
6062
private PrebidVersionProvider prebidVersionProvider;
6163

64+
private ShowheroesBidder target;
65+
6266
@BeforeEach
6367
public void setUp() {
64-
// set always 'test_version' as Prebid version for testing
6568
given(prebidVersionProvider.getNameVersionRecord()).willReturn("test_version");
6669
target = new ShowheroesBidder(ENDPOINT_URL, currencyConversionService, prebidVersionProvider, jacksonMapper);
6770
}
@@ -136,6 +139,7 @@ public void makeHttpRequestsShouldCreateCorrectURL() {
136139

137140
@Test
138141
public void makeHttpRequestsShouldReturnPbsVersion() {
142+
// given
139143
final BidRequest bidRequest = givenBidRequest(identity());
140144

141145
// when
@@ -155,6 +159,7 @@ public void makeHttpRequestsShouldReturnPbsVersion() {
155159

156160
@Test
157161
public void makeHttpRequestsShouldConvertCurrencyFromUsdToEur() {
162+
// given
158163
final BidRequest bidRequest = BidRequest.builder()
159164
.imp(List.of(givenImp(impBuilder -> impBuilder.bidfloor(BigDecimal.ONE).bidfloorcur("USD"))))
160165
.app(App.builder().bundle("test_bundle").build())
@@ -178,6 +183,7 @@ public void makeHttpRequestsShouldConvertCurrencyFromUsdToEur() {
178183

179184
@Test
180185
public void makeHttpRequestsShouldNotConvertCurrencyEur() {
186+
// given
181187
final BidRequest bidRequest = BidRequest.builder()
182188
.imp(List.of(givenImp(impBuilder -> impBuilder.bidfloor(BigDecimal.ONE).bidfloorcur("EUR"))))
183189
.app(App.builder().bundle("test_bundle").build())
@@ -214,7 +220,9 @@ public void makeHttpRequestsShouldCreateSingleRequestForAllImps() {
214220

215221
// then
216222
assertThat(result.getErrors()).isEmpty();
217-
assertThat(result.getValue()).hasSize(1);
223+
assertThat(result.getValue()).hasSize(1)
224+
.extracting(HttpRequest::getImpIds)
225+
.containsOnly(Set.of("imp1", "imp2"));
218226

219227
final BidRequest outgoingRequest = result.getValue().get(0).getPayload();
220228
assertThat(outgoingRequest.getImp()).hasSize(2)
@@ -232,12 +240,12 @@ public void makeHttpRequestsShouldSetCorrectHeaders() {
232240

233241
// then
234242
assertThat(result.getErrors()).isEmpty();
235-
assertThat(result.getValue()).hasSize(1);
236-
237-
final Map<String, String> headers = result.getValue().get(0).getHeaders().entries().stream()
238-
.collect(java.util.stream.Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
239-
assertThat(headers).containsEntry("Content-Type", "application/json;charset=utf-8")
240-
.containsEntry("Accept", "application/json");
243+
assertThat(result.getValue()).hasSize(1).first()
244+
.extracting(HttpRequest::getHeaders)
245+
.satisfies(headers -> assertThat(headers.get(CONTENT_TYPE_HEADER))
246+
.isEqualTo(APPLICATION_JSON_CONTENT_TYPE))
247+
.satisfies(headers -> assertThat(headers.get(ACCEPT_HEADER))
248+
.isEqualTo(APPLICATION_JSON_VALUE));
241249
}
242250

243251
@Test
@@ -279,38 +287,6 @@ public void makeBidsShouldReturnEmptyListIfBidResponseSeatBidIsEmpty() throws Js
279287
assertThat(result.getValue()).isEmpty();
280288
}
281289

282-
@Test
283-
public void makeBidsShouldReturnBannerBidIfBannerIsPresentInImp() throws JsonProcessingException {
284-
// given
285-
final BidderCall<BidRequest> httpCall = givenHttpCall(
286-
givenBidResponse(bidBuilder -> bidBuilder.impid("123").mtype(1)));
287-
288-
// when
289-
final Result<List<BidderBid>> result = target.makeBids(httpCall, null);
290-
291-
// then
292-
assertThat(result.getErrors()).isEmpty();
293-
assertThat(result.getValue())
294-
.extracting(BidderBid::getBid, BidderBid::getType)
295-
.containsExactly(tuple(Bid.builder().impid("123").mtype(1).build(), banner));
296-
}
297-
298-
@Test
299-
public void makeBidsShouldReturnVideoBidIfVideoIsPresentInImp() throws JsonProcessingException {
300-
// given
301-
final BidderCall<BidRequest> httpCall = givenHttpCall(
302-
givenBidResponse(bidBuilder -> bidBuilder.impid("123").mtype(2)));
303-
304-
// when
305-
final Result<List<BidderBid>> result = target.makeBids(httpCall, null);
306-
307-
// then
308-
assertThat(result.getErrors()).isEmpty();
309-
assertThat(result.getValue())
310-
.extracting(BidderBid::getBid, BidderBid::getType)
311-
.containsExactly(tuple(Bid.builder().impid("123").mtype(2).build(), video));
312-
}
313-
314290
@Test
315291
public void makeBidsShouldReturnVideoBidByDefaultWhenMtypeIsUnknown() throws JsonProcessingException {
316292
// given
@@ -327,23 +303,6 @@ public void makeBidsShouldReturnVideoBidByDefaultWhenMtypeIsUnknown() throws Jso
327303
.containsExactly(tuple(Bid.builder().impid("123").mtype(99).build(), video));
328304
}
329305

330-
@Test
331-
public void makeBidsShouldReturnCorrectBidderBid() throws JsonProcessingException {
332-
// given
333-
final BidderCall<BidRequest> httpCall = givenHttpCall(
334-
givenBidResponse(bidBuilder -> bidBuilder.impid("123").price(BigDecimal.ONE)));
335-
336-
// when
337-
final Result<List<BidderBid>> result = target.makeBids(httpCall, null);
338-
339-
// then
340-
assertThat(result.getErrors()).isEmpty();
341-
assertThat(result.getValue())
342-
.extracting(BidderBid::getBid)
343-
.extracting(Bid::getPrice)
344-
.containsExactly(BigDecimal.ONE);
345-
}
346-
347306
@Test
348307
public void makeBidsShouldReturnMultipleBids() throws JsonProcessingException {
349308
// given

src/test/java/org/prebid/server/it/ShowheroesBSTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public class ShowheroesBSTest extends IntegrationTest {
2323
@Test
2424
public void openrtb2AuctionShouldRespondWithBidsFromShowheroesBS() throws IOException, JSONException {
2525
// given
26-
WIRE_MOCK_RULE.stubFor(post(urlPathEqualTo("/showheroesbs-exchange"))
26+
WIRE_MOCK_RULE.stubFor(post(urlPathEqualTo("/showheroes-exchange"))
2727
.withRequestBody(equalToJson(jsonFrom("openrtb2/showheroesBs/test-showheroes-bid-request.json",
2828
prebidVersionProvider)))
2929
.willReturn(
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package org.prebid.server.it;
2+
3+
import io.restassured.response.Response;
4+
import org.json.JSONException;
5+
import org.junit.jupiter.api.Test;
6+
import org.prebid.server.model.Endpoint;
7+
import org.prebid.server.version.PrebidVersionProvider;
8+
import org.springframework.beans.factory.annotation.Autowired;
9+
10+
import java.io.IOException;
11+
12+
import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
13+
import static com.github.tomakehurst.wiremock.client.WireMock.equalToJson;
14+
import static com.github.tomakehurst.wiremock.client.WireMock.post;
15+
import static com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo;
16+
import static java.util.Collections.singletonList;
17+
18+
public class ShowheroesbsTest extends IntegrationTest {
19+
20+
@Autowired
21+
private PrebidVersionProvider prebidVersionProvider;
22+
23+
@Test
24+
public void openrtb2AuctionShouldRespondWithBidsFromShowheroesbs() throws IOException, JSONException {
25+
// given
26+
WIRE_MOCK_RULE.stubFor(post(urlPathEqualTo("/showheroes-exchange"))
27+
.withRequestBody(equalToJson(jsonFrom("openrtb2/showheroes_bs/test-showheroes-bid-request.json",
28+
prebidVersionProvider)))
29+
.willReturn(
30+
aResponse().withBody(jsonFrom("openrtb2/showheroes_bs/test-showheroes-bid-response.json"))));
31+
32+
// when
33+
final Response response = responseFor("openrtb2/showheroes_bs/test-auction-showheroes-request.json",
34+
Endpoint.openrtb2_auction);
35+
36+
// then
37+
assertJsonEquals("openrtb2/showheroes_bs/test-auction-showheroes-response.json", response,
38+
singletonList("showheroes-bs"));
39+
}
40+
}

src/test/resources/org/prebid/server/it/openrtb2/showheroes/test-auction-showheroes-request.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
},
1010
"ext": {
1111
"showheroes": {
12-
"unitId": "12345"
12+
"unitId": "12345678"
1313
}
1414
},
1515
"tagid": "tag_id"

src/test/resources/org/prebid/server/it/openrtb2/showheroes/test-showheroes-bid-request.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@
1212
"ext": {
1313
"tid": "${json-unit.any-string}",
1414
"bidder": {
15-
"unitId": "12345"
15+
"unitId": "12345678"
1616
},
1717
"params": {
18-
"unitId": "12345"
18+
"unitId": "12345678"
1919
}
2020
}
2121
}

src/test/resources/org/prebid/server/it/openrtb2/showheroesBs/test-auction-showheroes-request.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
},
1010
"ext": {
1111
"showheroesBs": {
12-
"unitId": "12345"
12+
"unitId": "12345678"
1313
}
1414
},
1515
"tagid": "tag_id"

src/test/resources/org/prebid/server/it/openrtb2/showheroesBs/test-showheroes-bid-request.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@
1212
"ext": {
1313
"tid": "${json-unit.any-string}",
1414
"bidder": {
15-
"unitId": "12345"
15+
"unitId": "12345678"
1616
},
1717
"params": {
18-
"unitId": "12345"
18+
"unitId": "12345678"
1919
}
2020
}
2121
}

0 commit comments

Comments
 (0)