From 7d3f6d420f44c4bbbb3703c29a4aca4c5e25361f Mon Sep 17 00:00:00 2001 From: Serhii Nahornyi Date: Mon, 12 Jul 2021 12:48:27 +0300 Subject: [PATCH] Simplify integration tests (#1356) --- pom.xml | 2 +- .../bidder/emxdigital/EmxDigitalBidder.java | 20 --- .../emxdigital/EmxDigitalBidderTest.java | 37 ----- .../org/prebid/server/it/ApplicationTest.java | 19 +-- .../java/org/prebid/server/it/AvocetTest.java | 6 +- .../org/prebid/server/it/BeintooTest.java | 7 +- .../org/prebid/server/it/DatablocksTest.java | 6 +- .../org/prebid/server/it/EmxdigitalTest.java | 30 ++-- .../org/prebid/server/it/IntegrationTest.java | 75 +++++++--- .../org/prebid/server/it/KubientTest.java | 7 +- .../java/org/prebid/server/it/LoopmeTest.java | 21 +-- .../prebid/server/it/SharethroughTest.java | 31 ++-- .../prebid/server/it/SmartadserverTest.java | 6 +- .../server/it/TripleliftNativeTest.java | 6 +- .../org/prebid/server/it/TripleliftTest.java | 6 +- .../org/prebid/server/it/YieldlabTest.java | 6 +- .../prebid/server/it/ZeroclickfraudTest.java | 6 +- .../test-auction-emxdigital-request.json | 59 +------- .../test-auction-emxdigital-response.json | 117 +--------------- .../test-emxdigital-bid-request.json | 54 ++----- .../test-emxdigital-bid-response.json | 4 +- .../loopme/test-auction-loopme-request.json | 31 +--- .../loopme/test-auction-loopme-response.json | 24 ++-- .../loopme/test-loopme-bid-request.json | 35 +---- .../loopme/test-loopme-bid-response.json | 8 +- .../test-auction-sharethrough-request.json | 18 --- .../test-auction-sharethrough-response.json | 132 +----------------- .../test-sharethrough-request.json | 2 +- 28 files changed, 149 insertions(+), 626 deletions(-) diff --git a/pom.xml b/pom.xml index d77d7dfaa05..abd86f146e8 100644 --- a/pom.xml +++ b/pom.xml @@ -317,7 +317,7 @@ com.github.tomakehurst - wiremock + wiremock-jre8 ${wiremock.version} test diff --git a/src/main/java/org/prebid/server/bidder/emxdigital/EmxDigitalBidder.java b/src/main/java/org/prebid/server/bidder/emxdigital/EmxDigitalBidder.java index f9f2bcc8a9a..bf07d29ecf9 100644 --- a/src/main/java/org/prebid/server/bidder/emxdigital/EmxDigitalBidder.java +++ b/src/main/java/org/prebid/server/bidder/emxdigital/EmxDigitalBidder.java @@ -27,8 +27,6 @@ import org.prebid.server.json.DecodeException; import org.prebid.server.json.JacksonMapper; import org.prebid.server.proto.openrtb.ext.ExtPrebid; -import org.prebid.server.proto.openrtb.ext.request.ExtRequest; -import org.prebid.server.proto.openrtb.ext.request.ExtRequestPrebid; import org.prebid.server.proto.openrtb.ext.request.emxdigital.ExtImpEmxDigital; import org.prebid.server.proto.openrtb.ext.response.BidType; import org.prebid.server.util.HttpUtil; @@ -241,28 +239,10 @@ private String makeUrl(BidRequest bidRequest) { final Long tmax = bidRequest.getTmax(); final int urlTimeout = tmax == 0 ? 1000 : tmax.intValue(); - if (isDebugEnabled(bidRequest)) { - // for passing validation tests - return String.format("%s?t=1000&ts=2060541160", endpointUrl); - } - return String.format("%s?t=%s&ts=%s&src=pbserver", endpointUrl, urlTimeout, (int) Instant.now().getEpochSecond()); } - /** - * Determines debug flag from {@link BidRequest} or {@link ExtRequest}. - */ - private boolean isDebugEnabled(BidRequest bidRequest) { - if (Objects.equals(bidRequest.getTest(), 1)) { - return true; - } - - final ExtRequest extRequest = bidRequest.getExt(); - final ExtRequestPrebid extRequestPrebid = extRequest != null ? extRequest.getPrebid() : null; - return extRequestPrebid != null && Objects.equals(extRequestPrebid.getDebug(), 1); - } - @Override public Result> makeBids(HttpCall httpCall, BidRequest bidRequest) { try { diff --git a/src/test/java/org/prebid/server/bidder/emxdigital/EmxDigitalBidderTest.java b/src/test/java/org/prebid/server/bidder/emxdigital/EmxDigitalBidderTest.java index b522c3228f8..3d2a3120a73 100644 --- a/src/test/java/org/prebid/server/bidder/emxdigital/EmxDigitalBidderTest.java +++ b/src/test/java/org/prebid/server/bidder/emxdigital/EmxDigitalBidderTest.java @@ -496,43 +496,6 @@ public void makeHttpRequestsShouldSendRequestToModifiedUrlWithHeaders() { tuple("Accept-Language", "fr")); } - @Test - public void makeHttpRequestsShouldSendRequestToTestUrlWithHeadersWhenTestIsOne() { - // given - final BidRequest bidRequest = BidRequest.builder() - .imp(singletonList(Imp.builder() - .banner(Banner.builder().w(1).h(1).build()) - .ext(mapper.valueToTree(ExtPrebid.of(null, ExtImpEmxDigital.of("1", "asd")))) - .build())) - .device(Device.builder().ip("ip").ua("Agent").language("fr").dnt(1).build()) - .site(Site.builder().page("myPage").build()) - .test(1) - .tmax(1000L) - .build(); - - // when - final Result>> result = emxDigitalBidder - .makeHttpRequests(bidRequest); - - // then - assertThat(result.getErrors()).isEmpty(); - assertThat(result.getValue()).hasSize(1) - .extracting(HttpRequest::getUri) - .allSatisfy(uri -> assertThat(uri).isEqualTo("https://test.endpoint.com?t=1000&ts=2060541160")); - - assertThat(result.getValue()).hasSize(1) - .flatExtracting(r -> r.getHeaders().entries()) - .extracting(Map.Entry::getKey, Map.Entry::getValue) - .containsOnly( - tuple("Content-Type", "application/json;charset=utf-8"), - tuple("Accept", "application/json"), - tuple("User-Agent", "Agent"), - tuple("X-Forwarded-For", "ip"), - tuple("Referer", "myPage"), - tuple("DNT", "1"), - tuple("Accept-Language", "fr")); - } - @Test public void makeBidsShouldReturnErrorWhenResponseBodyCouldNotBeParsed() { // given diff --git a/src/test/java/org/prebid/server/it/ApplicationTest.java b/src/test/java/org/prebid/server/it/ApplicationTest.java index 96aa4712a8b..cc2e5362932 100644 --- a/src/test/java/org/prebid/server/it/ApplicationTest.java +++ b/src/test/java/org/prebid/server/it/ApplicationTest.java @@ -129,11 +129,8 @@ public void openrtb2AuctionShouldRespondWithBidsFromRubiconAndAppnexus() throws .post("/openrtb2/auction"); // then - final String expectedAuctionResponse = openrtbAuctionResponseFrom( - "openrtb2/rubicon_appnexus/test-auction-rubicon-appnexus-response.json", - response, asList(RUBICON, APPNEXUS, APPNEXUS_ALIAS)); - - JSONAssert.assertEquals(expectedAuctionResponse, response.asString(), openrtbCacheDebugComparator()); + assertJsonEquals("openrtb2/rubicon_appnexus/test-auction-rubicon-appnexus-response.json", + response, asList(RUBICON, APPNEXUS, APPNEXUS_ALIAS), openrtbCacheDebugCustomization()); } @Test @@ -214,11 +211,8 @@ public void openrtb2MultiBidAuctionShouldRespondWithBidsFromRubiconAndAppnexus() .post("/openrtb2/auction"); // then - final String expectedAuctionResponse = openrtbAuctionResponseFrom( - "openrtb2/rubicon_appnexus_multi_bid/test-auction-rubicon-appnexus-response.json", + assertJsonEquals("openrtb2/rubicon_appnexus_multi_bid/test-auction-rubicon-appnexus-response.json", response, asList(RUBICON, APPNEXUS, APPNEXUS_ALIAS)); - - JSONAssert.assertEquals(expectedAuctionResponse, response.asString(), openrtbCacheDebugComparator()); } @Test @@ -240,11 +234,8 @@ public void openrtb2AuctionShouldRespondWithStoredBidResponse() throws IOExcepti .post("/openrtb2/auction"); // then - final String expectedAuctionResponse = openrtbAuctionResponseFrom( - "openrtb2/storedresponse/test-auction-response.json", - response, singletonList(RUBICON)); - - JSONAssert.assertEquals(expectedAuctionResponse, response.asString(), openrtbCacheDebugComparator()); + assertJsonEquals("openrtb2/storedresponse/test-auction-response.json", + response, singletonList(RUBICON), openrtbCacheDebugCustomization()); } @Test diff --git a/src/test/java/org/prebid/server/it/AvocetTest.java b/src/test/java/org/prebid/server/it/AvocetTest.java index 3f640d1fa99..9e62ca731c1 100644 --- a/src/test/java/org/prebid/server/it/AvocetTest.java +++ b/src/test/java/org/prebid/server/it/AvocetTest.java @@ -4,7 +4,6 @@ import org.json.JSONException; import org.junit.Test; import org.junit.runner.RunWith; -import org.skyscreamer.jsonassert.JSONAssert; import org.springframework.test.context.junit4.SpringRunner; import java.io.IOException; @@ -38,9 +37,6 @@ public void openrtb2AuctionShouldRespondWithBidsFromAvocet() throws IOException, .post("/openrtb2/auction"); // then - final String expectedAuctionResponse = openrtbAuctionResponseFrom( - "openrtb2/avocet/test-auction-avocet-response.json", response, singletonList("avocet")); - - JSONAssert.assertEquals(expectedAuctionResponse, response.asString(), openrtbCacheDebugComparator()); + assertJsonEquals("openrtb2/avocet/test-auction-avocet-response.json", response, singletonList("avocet")); } } diff --git a/src/test/java/org/prebid/server/it/BeintooTest.java b/src/test/java/org/prebid/server/it/BeintooTest.java index e8e393359a2..ab11d8eb04e 100644 --- a/src/test/java/org/prebid/server/it/BeintooTest.java +++ b/src/test/java/org/prebid/server/it/BeintooTest.java @@ -4,7 +4,6 @@ import org.json.JSONException; import org.junit.Test; import org.junit.runner.RunWith; -import org.skyscreamer.jsonassert.JSONAssert; import org.springframework.test.context.junit4.SpringRunner; import java.io.IOException; @@ -48,10 +47,6 @@ public void openrtb2AuctionShouldRespondWithBidsFromBeintoo() throws IOException .post("/openrtb2/auction"); // then - final String expectedAuctionResponse = openrtbAuctionResponseFrom( - "openrtb2/beintoo/test-auction-beintoo-response.json", - response, singletonList("beintoo")); - - JSONAssert.assertEquals(expectedAuctionResponse, response.asString(), openrtbCacheDebugComparator()); + assertJsonEquals("openrtb2/beintoo/test-auction-beintoo-response.json", response, singletonList("beintoo")); } } diff --git a/src/test/java/org/prebid/server/it/DatablocksTest.java b/src/test/java/org/prebid/server/it/DatablocksTest.java index 1ffb94ed630..b4624c038eb 100644 --- a/src/test/java/org/prebid/server/it/DatablocksTest.java +++ b/src/test/java/org/prebid/server/it/DatablocksTest.java @@ -4,7 +4,6 @@ import org.json.JSONException; import org.junit.Test; import org.junit.runner.RunWith; -import org.skyscreamer.jsonassert.JSONAssert; import org.springframework.test.context.junit4.SpringRunner; import java.io.IOException; @@ -45,10 +44,7 @@ public void openrtb2AuctionShouldRespondWithBidsFromDatablocks() throws IOExcept .post("/openrtb2/auction"); // then - final String expectedAuctionResponse = openrtbAuctionResponseFrom( - "openrtb2/datablocks/test-auction-datablocks-response.json", + assertJsonEquals("openrtb2/datablocks/test-auction-datablocks-response.json", response, singletonList("datablocks")); - - JSONAssert.assertEquals(expectedAuctionResponse, response.asString(), openrtbCacheDebugComparator()); } } diff --git a/src/test/java/org/prebid/server/it/EmxdigitalTest.java b/src/test/java/org/prebid/server/it/EmxdigitalTest.java index 1e05f5f3ca9..a7dad8fec69 100644 --- a/src/test/java/org/prebid/server/it/EmxdigitalTest.java +++ b/src/test/java/org/prebid/server/it/EmxdigitalTest.java @@ -4,7 +4,7 @@ import org.json.JSONException; import org.junit.Test; import org.junit.runner.RunWith; -import org.skyscreamer.jsonassert.JSONAssert; +import org.prebid.server.model.Endpoint; import org.springframework.test.context.junit4.SpringRunner; import java.io.IOException; @@ -13,9 +13,9 @@ import static com.github.tomakehurst.wiremock.client.WireMock.equalTo; import static com.github.tomakehurst.wiremock.client.WireMock.equalToIgnoreCase; import static com.github.tomakehurst.wiremock.client.WireMock.equalToJson; +import static com.github.tomakehurst.wiremock.client.WireMock.matching; import static com.github.tomakehurst.wiremock.client.WireMock.post; import static com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo; -import static io.restassured.RestAssured.given; import static java.util.Collections.singletonList; @RunWith(SpringRunner.class) @@ -25,36 +25,24 @@ public class EmxdigitalTest extends IntegrationTest { public void openrtb2AuctionShouldRespondWithBidsFromEmxdigital() throws IOException, JSONException { // given WIRE_MOCK_RULE.stubFor(post(urlPathEqualTo("/emx_digital-exchange")) - .withQueryParam("t", equalTo("1000")) - .withQueryParam("ts", equalTo("2060541160")) + .withQueryParam("t", matching("^[0-9]*$")) + .withQueryParam("ts", matching("^[0-9]*$")) .withHeader("Accept", equalTo("application/json")) .withHeader("Content-Type", equalToIgnoreCase("application/json;charset=utf-8")) - .withHeader("User-Agent", equalTo("Android Chrome/60")) + .withHeader("User-Agent", equalTo("userAgent")) .withHeader("X-Forwarded-For", equalTo("193.168.244.1")) .withHeader("Referer", equalTo("http://www.example.com")) - .withHeader("DNT", equalTo("2")) - .withHeader("Accept-Language", equalTo("en")) .withRequestBody(equalToJson(jsonFrom("openrtb2/emxdigital/test-emxdigital-bid-request.json"), - true, true)) + true, false)) .willReturn(aResponse().withBody(jsonFrom("openrtb2/emxdigital/test-emxdigital-bid-response.json")))); // when - final Response response = given(SPEC) - .header("Referer", "http://www.example.com") - .header("X-Forwarded-For", "193.168.244.1") - .header("User-Agent", "userAgent") - .header("Origin", "http://www.example.com") - // this uids cookie value stands for {"uids":{"emxdigital":"STR-UID"}} - .cookie("uids", "eyJ1aWRzIjp7ImVteGRpZ2l0YWwiOiJTVFItVUlEIn19") - .body(jsonFrom("openrtb2/emxdigital/test-auction-emxdigital-request.json")) - .post("/openrtb2/auction"); + final Response response = + responseFor("openrtb2/emxdigital/test-auction-emxdigital-request.json", Endpoint.openrtb2_auction); // then - final String expectedAuctionResponse = openrtbAuctionResponseFrom( - "openrtb2/emxdigital/test-auction-emxdigital-response.json", + assertJsonEquals("openrtb2/emxdigital/test-auction-emxdigital-response.json", response, singletonList("emx_digital")); - - JSONAssert.assertEquals(expectedAuctionResponse, response.asString(), openrtbCacheDebugComparator()); } } diff --git a/src/test/java/org/prebid/server/it/IntegrationTest.java b/src/test/java/org/prebid/server/it/IntegrationTest.java index d39f569dd3e..1d5f78d91c5 100644 --- a/src/test/java/org/prebid/server/it/IntegrationTest.java +++ b/src/test/java/org/prebid/server/it/IntegrationTest.java @@ -23,8 +23,10 @@ import org.prebid.server.cache.proto.response.CacheObject; import org.prebid.server.it.hooks.TestHooksConfiguration; import org.prebid.server.it.util.BidCacheRequestPattern; +import org.prebid.server.model.Endpoint; import org.skyscreamer.jsonassert.ArrayValueMatcher; import org.skyscreamer.jsonassert.Customization; +import org.skyscreamer.jsonassert.JSONAssert; import org.skyscreamer.jsonassert.JSONCompare; import org.skyscreamer.jsonassert.JSONCompareMode; import org.skyscreamer.jsonassert.ValueMatcher; @@ -35,12 +37,14 @@ import java.io.IOException; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; import static com.github.tomakehurst.wiremock.client.WireMock.get; import static com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo; import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.options; +import static io.restassured.RestAssured.given; import static java.lang.String.format; @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.NONE) @@ -63,6 +67,9 @@ public abstract class IntegrationTest extends VertxTest { public WireMockClassRule instanceRule = WIRE_MOCK_RULE; protected static final RequestSpecification SPEC = spec(APP_PORT); + private static final String HOST_AND_PORT = "localhost:" + WIREMOCK_PORT; + private static final String CACHE_PATH = "/cache"; + private static final String CACHE_ENDPOINT = "http://" + HOST_AND_PORT + CACHE_PATH; @BeforeClass public static void setUp() throws IOException { @@ -81,6 +88,16 @@ static RequestSpecification spec(int port) { .build(); } + protected static Response responseFor(String file, Endpoint endpoint) throws IOException { + return given(SPEC) + .header("Referer", "http://www.example.com") + .header("X-Forwarded-For", "193.168.244.1") + .header("User-Agent", "userAgent") + .header("Origin", "http://www.example.com") + .body(jsonFrom(file)) + .post(endpoint.value()); + } + protected static String jsonFrom(String file) throws IOException { // workaround to clear formatting return mapper.writeValueAsString(mapper.readTree(IntegrationTest.class.getResourceAsStream(file))); @@ -94,20 +111,12 @@ protected static String openrtbAuctionResponseFrom(String templatePath, Response private static String auctionResponseFrom(String templatePath, Response response, String responseTimePath, List bidders) throws IOException { - final String hostAndPort = "localhost:" + WIREMOCK_PORT; - final String cachePath = "/cache"; - final String cacheEndpoint = "http://" + hostAndPort + cachePath; - - String result = jsonFrom(templatePath) - .replaceAll("\\{\\{ cache.endpoint }}", cacheEndpoint) - .replaceAll("\\{\\{ cache.resource_url }}", cacheEndpoint + "?uuid=") - .replaceAll("\\{\\{ cache.host }}", hostAndPort) - .replaceAll("\\{\\{ cache.path }}", cachePath) - .replaceAll("\\{\\{ event.url }}", "http://localhost:8080/event?"); + + String result = replaceStaticInfo(jsonFrom(templatePath)); for (final String bidder : bidders) { result = result.replaceAll("\\{\\{ " + bidder + "\\.exchange_uri }}", - "http://" + hostAndPort + "/" + bidder + "-exchange"); + "http://" + HOST_AND_PORT + "/" + bidder + "-exchange"); result = setResponseTime(response, result, bidder, responseTimePath); } @@ -124,7 +133,7 @@ private static String setResponseTime(Response response, String expectedResponse } final Object cacheVal = response.path("ext.responsetimemillis.cache"); - final Integer cacheResponseTime = val instanceof Integer ? (Integer) cacheVal : null; + final Integer cacheResponseTime = cacheVal instanceof Integer ? (Integer) cacheVal : null; if (cacheResponseTime != null) { expectedResponseJson = expectedResponseJson.replaceAll("\"\\{\\{ cache\\.response_time_ms }}\"", cacheResponseTime.toString()); @@ -165,9 +174,9 @@ private static String resolvePriceForJsonMediaType(PutObject putItem) { /** * Cache debug fields "requestbody" and "responsebody" are escaped JSON strings. - * This comparator allows to compare them with actual values as usual JSON objects. + * This customization allows to compare them with actual values as usual JSON objects. */ - static CustomComparator openrtbCacheDebugComparator() { + static Customization openrtbCacheDebugCustomization() { final ValueMatcher jsonStringValueMatcher = (actual, expected) -> { try { return !JSONCompare.compareJSON(actual.toString(), expected.toString(), JSONCompareMode.NON_EXTENSIBLE) @@ -182,9 +191,41 @@ static CustomComparator openrtbCacheDebugComparator() { new Customization("ext.debug.httpcalls.cache[*].requestbody", jsonStringValueMatcher), new Customization("ext.debug.httpcalls.cache[*].responsebody", jsonStringValueMatcher))); - return new CustomComparator( - JSONCompareMode.NON_EXTENSIBLE, - new Customization("ext.debug.httpcalls.cache", arrayValueMatcher)); + return new Customization("ext.debug.httpcalls.cache", arrayValueMatcher); + } + + protected static void assertJsonEquals(String file, + Response response, + List bidders, + Customization... customizations) throws IOException, JSONException { + final List fullCustomizations = new ArrayList<>(Arrays.asList(customizations)); + fullCustomizations.add(new Customization("ext.prebid.auctiontimestamp", (o1, o2) -> true)); + fullCustomizations.add(new Customization("ext.responsetimemillis.cache", (o1, o2) -> true)); + String expectedRequest = replaceStaticInfo(jsonFrom(file)); + for (String bidder : bidders) { + expectedRequest = replaceBidderRelatedStaticInfo(expectedRequest, bidder); + fullCustomizations.add(new Customization( + String.format("ext.responsetimemillis.%s", bidder), (o1, o2) -> true)); + } + + JSONAssert.assertEquals(expectedRequest, response.asString(), + new CustomComparator(JSONCompareMode.NON_EXTENSIBLE, + fullCustomizations.stream().toArray(Customization[]::new))); + } + + private static String replaceStaticInfo(String json) { + + return json.replaceAll("\\{\\{ cache.endpoint }}", CACHE_ENDPOINT) + .replaceAll("\\{\\{ cache.resource_url }}", CACHE_ENDPOINT + "?uuid=") + .replaceAll("\\{\\{ cache.host }}", HOST_AND_PORT) + .replaceAll("\\{\\{ cache.path }}", CACHE_PATH) + .replaceAll("\\{\\{ event.url }}", "http://localhost:8080/event?"); + } + + private static String replaceBidderRelatedStaticInfo(String json, String bidder) { + + return json.replaceAll("\\{\\{ " + bidder + "\\.exchange_uri }}", + "http://" + HOST_AND_PORT + "/" + bidder + "-exchange"); } static BidCacheRequestPattern equalToBidCacheRequest(String json) { diff --git a/src/test/java/org/prebid/server/it/KubientTest.java b/src/test/java/org/prebid/server/it/KubientTest.java index 095373ae785..95006bbbb81 100644 --- a/src/test/java/org/prebid/server/it/KubientTest.java +++ b/src/test/java/org/prebid/server/it/KubientTest.java @@ -4,7 +4,6 @@ import org.json.JSONException; import org.junit.Test; import org.junit.runner.RunWith; -import org.skyscreamer.jsonassert.JSONAssert; import org.springframework.test.context.junit4.SpringRunner; import java.io.IOException; @@ -38,11 +37,7 @@ public void openrtb2AuctionShouldRespondWithBidsFromKubient() throws IOException .post("/openrtb2/auction"); // then - final String expectedAuctionResponse = openrtbAuctionResponseFrom( - "openrtb2/kubient/test-auction-kubient-response.json", - response, singletonList("kubient")); - - JSONAssert.assertEquals(expectedAuctionResponse, response.asString(), openrtbCacheDebugComparator()); + assertJsonEquals("openrtb2/kubient/test-auction-kubient-response.json", response, singletonList("kubient")); } } diff --git a/src/test/java/org/prebid/server/it/LoopmeTest.java b/src/test/java/org/prebid/server/it/LoopmeTest.java index fe8fe1f8a03..b54561c6e47 100644 --- a/src/test/java/org/prebid/server/it/LoopmeTest.java +++ b/src/test/java/org/prebid/server/it/LoopmeTest.java @@ -4,8 +4,7 @@ import org.json.JSONException; import org.junit.Test; import org.junit.runner.RunWith; -import org.skyscreamer.jsonassert.JSONAssert; -import org.skyscreamer.jsonassert.JSONCompareMode; +import org.prebid.server.model.Endpoint; import org.springframework.test.context.junit4.SpringRunner; import java.io.IOException; @@ -14,7 +13,6 @@ import static com.github.tomakehurst.wiremock.client.WireMock.equalToJson; import static com.github.tomakehurst.wiremock.client.WireMock.post; import static com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo; -import static io.restassured.RestAssured.given; import static java.util.Collections.singletonList; @RunWith(SpringRunner.class) @@ -28,21 +26,10 @@ public void openrtb2AuctionShouldRespondWithBidsFromLoopme() throws IOException, .willReturn(aResponse().withBody(jsonFrom("openrtb2/loopme/test-loopme-bid-response.json")))); // when - final Response response = given(SPEC) - .header("Referer", "http://www.example.com") - .header("X-Forwarded-For", "193.168.244.1") - .header("User-Agent", "userAgent") - .header("Origin", "http://www.example.com") - // this uids cookie value stands for {"uids":{"loopme":"LPM-UID"}} - .cookie("uids", "eyJ1aWRzIjp7Imxvb3BtZSI6IkxQTS1VSUQifX0=") - .body(jsonFrom("openrtb2/loopme/test-auction-loopme-request.json")) - .post("/openrtb2/auction"); + final Response response = + responseFor("openrtb2/loopme/test-auction-loopme-request.json", Endpoint.openrtb2_auction); // then - final String expectedAuctionResponse = openrtbAuctionResponseFrom( - "openrtb2/loopme/test-auction-loopme-response.json", - response, singletonList("loopme")); - - JSONAssert.assertEquals(expectedAuctionResponse, response.asString(), JSONCompareMode.NON_EXTENSIBLE); + assertJsonEquals("openrtb2/loopme/test-auction-loopme-response.json", response, singletonList("loopme")); } } diff --git a/src/test/java/org/prebid/server/it/SharethroughTest.java b/src/test/java/org/prebid/server/it/SharethroughTest.java index e293043a958..0f50102a8c0 100644 --- a/src/test/java/org/prebid/server/it/SharethroughTest.java +++ b/src/test/java/org/prebid/server/it/SharethroughTest.java @@ -4,17 +4,16 @@ import org.json.JSONException; import org.junit.Test; import org.junit.runner.RunWith; -import org.prebid.server.util.HttpUtil; -import org.skyscreamer.jsonassert.JSONAssert; +import org.skyscreamer.jsonassert.Customization; import org.springframework.test.context.junit4.SpringRunner; import java.io.IOException; -import java.text.SimpleDateFormat; -import java.util.Date; import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; import static com.github.tomakehurst.wiremock.client.WireMock.equalTo; import static com.github.tomakehurst.wiremock.client.WireMock.equalToIgnoreCase; +import static com.github.tomakehurst.wiremock.client.WireMock.equalToJson; +import static com.github.tomakehurst.wiremock.client.WireMock.matching; import static com.github.tomakehurst.wiremock.client.WireMock.post; import static com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo; import static io.restassured.RestAssured.given; @@ -23,10 +22,7 @@ @RunWith(SpringRunner.class) public class SharethroughTest extends IntegrationTest { - private static final Date TEST_TIME = new Date(1604455678999L); // hardcoded value in bidder - private static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssXXX"); - private static final String TEST_FORMATTED_TIME = DATE_FORMAT.format(TEST_TIME); - private static final String DEADLINE_FORMATTED_TIME = DATE_FORMAT.format(new Date(TEST_TIME.getTime() + 3000L)); + private static final String DATE_REGEX = "^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}\\+\\d{2}:\\d{2}$"; @Test public void openrtb2AuctionShouldRespondWithBidsFromSharethrough() throws IOException, JSONException { @@ -42,9 +38,8 @@ public void openrtb2AuctionShouldRespondWithBidsFromSharethrough() throws IOExce .withQueryParam("height", equalTo("50")) .withQueryParam("width", equalTo("50")) .withQueryParam("supplyId", equalTo("FGMrCMMc")) - .withQueryParam("adRequestAt", equalTo(TEST_FORMATTED_TIME)) + .withQueryParam("adRequestAt", matching(DATE_REGEX)) .withQueryParam("ttduid", equalTo("id")) - .withQueryParam("stxuid", equalTo("STR-UID")) .withQueryParam("strVersion", equalTo("8")) .withHeader("Accept", equalTo("application/json")) .withHeader("Content-Type", equalToIgnoreCase("application/json;charset=utf-8")) @@ -52,8 +47,7 @@ public void openrtb2AuctionShouldRespondWithBidsFromSharethrough() throws IOExce .withHeader("X-Forwarded-For", equalTo("193.168.244.1")) .withHeader("Origin", equalTo("http://www.example.com")) .withHeader("Referer", equalTo("http://www.example.com")) - .withRequestBody(equalTo(jsonFrom("openrtb2/sharethrough/test-sharethrough-request.json") - .replace("{{ DEADLINE_FORMATTED_TIME }}", DEADLINE_FORMATTED_TIME))) + .withRequestBody(equalToJson(jsonFrom("openrtb2/sharethrough/test-sharethrough-request.json"))) .willReturn( aResponse().withBody(jsonFrom("openrtb2/sharethrough/test-sharethrough-bid-response-1.json")))); @@ -63,18 +57,13 @@ public void openrtb2AuctionShouldRespondWithBidsFromSharethrough() throws IOExce .header("X-Forwarded-For", "193.168.244.1") .header("User-Agent", "userAgent") .header("Origin", "http://www.example.com") - // this uids cookie value stands for {"uids":{"sharethrough":"STR-UID"}} - .cookie("uids", "eyJ1aWRzIjp7InNoYXJldGhyb3VnaCI6IlNUUi1VSUQifX0=") .body(jsonFrom("openrtb2/sharethrough/test-auction-sharethrough-request.json")) .post("/openrtb2/auction"); // then - final String expectedAuctionResponse = openrtbAuctionResponseFrom( - "openrtb2/sharethrough/test-auction-sharethrough-response.json", - response, singletonList("sharethrough")) - .replace("{{ TEST_FORMATTED_TIME }}", HttpUtil.encodeUrl(TEST_FORMATTED_TIME)) - .replace("{{ DEADLINE_FORMATTED_TIME }}", DEADLINE_FORMATTED_TIME); - - JSONAssert.assertEquals(expectedAuctionResponse, response.asString(), openrtbCacheDebugComparator()); + assertJsonEquals("openrtb2/sharethrough/test-auction-sharethrough-response.json", + response, + singletonList("sharethrough"), + new Customization("seatbid[*].bid[*].adm", (o1, o2) -> true)); } } diff --git a/src/test/java/org/prebid/server/it/SmartadserverTest.java b/src/test/java/org/prebid/server/it/SmartadserverTest.java index 6a0fc9a3be0..b25d52f0708 100644 --- a/src/test/java/org/prebid/server/it/SmartadserverTest.java +++ b/src/test/java/org/prebid/server/it/SmartadserverTest.java @@ -4,7 +4,6 @@ import org.json.JSONException; import org.junit.Test; import org.junit.runner.RunWith; -import org.skyscreamer.jsonassert.JSONAssert; import org.springframework.test.context.junit4.SpringRunner; import java.io.IOException; @@ -41,10 +40,7 @@ public void openrtb2AuctionShouldRespondWithBidsFromSmartadserver() throws IOExc .post("/openrtb2/auction"); // then - final String expectedAuctionResponse = openrtbAuctionResponseFrom( - "openrtb2/smartadserver/test-auction-smartadserver-response.json", + assertJsonEquals("openrtb2/smartadserver/test-auction-smartadserver-response.json", response, singletonList("smartadserver")); - - JSONAssert.assertEquals(expectedAuctionResponse, response.asString(), openrtbCacheDebugComparator()); } } diff --git a/src/test/java/org/prebid/server/it/TripleliftNativeTest.java b/src/test/java/org/prebid/server/it/TripleliftNativeTest.java index 8ade2a181ac..18027ae7096 100644 --- a/src/test/java/org/prebid/server/it/TripleliftNativeTest.java +++ b/src/test/java/org/prebid/server/it/TripleliftNativeTest.java @@ -4,7 +4,6 @@ import org.json.JSONException; import org.junit.Test; import org.junit.runner.RunWith; -import org.skyscreamer.jsonassert.JSONAssert; import org.springframework.test.context.junit4.SpringRunner; import java.io.IOException; @@ -40,11 +39,8 @@ public void openrtb2AuctionShouldRespondWithBidsFromTriplelift() throws IOExcept .post("/openrtb2/auction"); // then - final String expectedAuctionResponse = openrtbAuctionResponseFrom( - "openrtb2/tripleliftnative/test-auction-triplelift-native-response.json", + assertJsonEquals("openrtb2/tripleliftnative/test-auction-triplelift-native-response.json", response, singletonList("triplelift_native")); - - JSONAssert.assertEquals(expectedAuctionResponse, response.asString(), openrtbCacheDebugComparator()); } } diff --git a/src/test/java/org/prebid/server/it/TripleliftTest.java b/src/test/java/org/prebid/server/it/TripleliftTest.java index 093416ef8b8..8f6b199247c 100644 --- a/src/test/java/org/prebid/server/it/TripleliftTest.java +++ b/src/test/java/org/prebid/server/it/TripleliftTest.java @@ -4,7 +4,6 @@ import org.json.JSONException; import org.junit.Test; import org.junit.runner.RunWith; -import org.skyscreamer.jsonassert.JSONAssert; import org.springframework.test.context.junit4.SpringRunner; import java.io.IOException; @@ -41,11 +40,8 @@ public void openrtb2AuctionShouldRespondWithBidsFromTriplelift() throws IOExcept .post("/openrtb2/auction"); // then - final String expectedAuctionResponse = openrtbAuctionResponseFrom( - "openrtb2/triplelift/test-auction-triplelift-response.json", + assertJsonEquals("openrtb2/triplelift/test-auction-triplelift-response.json", response, singletonList("triplelift")); - - JSONAssert.assertEquals(expectedAuctionResponse, response.asString(), openrtbCacheDebugComparator()); } } diff --git a/src/test/java/org/prebid/server/it/YieldlabTest.java b/src/test/java/org/prebid/server/it/YieldlabTest.java index 2573adfdfa5..205c2076ff9 100644 --- a/src/test/java/org/prebid/server/it/YieldlabTest.java +++ b/src/test/java/org/prebid/server/it/YieldlabTest.java @@ -5,7 +5,6 @@ import org.json.JSONException; import org.junit.Test; import org.junit.runner.RunWith; -import org.skyscreamer.jsonassert.JSONAssert; import org.springframework.test.context.junit4.SpringRunner; import java.io.IOException; @@ -52,10 +51,7 @@ public void openrtb2AuctionShouldRespondWithBidsFromYieldlab() throws IOExceptio .post("/openrtb2/auction"); // then - final String expectedAuctionResponse = openrtbAuctionResponseFrom( - "openrtb2/yieldlab/test-auction-yieldlab-response.json", + assertJsonEquals("openrtb2/yieldlab/test-auction-yieldlab-response.json", response, singletonList("yieldlab")); - - JSONAssert.assertEquals(expectedAuctionResponse, response.asString(), openrtbCacheDebugComparator()); } } diff --git a/src/test/java/org/prebid/server/it/ZeroclickfraudTest.java b/src/test/java/org/prebid/server/it/ZeroclickfraudTest.java index 4e5fd65e28f..1551a2d10e5 100644 --- a/src/test/java/org/prebid/server/it/ZeroclickfraudTest.java +++ b/src/test/java/org/prebid/server/it/ZeroclickfraudTest.java @@ -4,7 +4,6 @@ import org.json.JSONException; import org.junit.Test; import org.junit.runner.RunWith; -import org.skyscreamer.jsonassert.JSONAssert; import org.springframework.test.context.junit4.SpringRunner; import java.io.IOException; @@ -49,10 +48,7 @@ public void openrtb2AuctionShouldRespondWithBidsFromZeroclickfraud() throws IOEx .post("/openrtb2/auction"); // then - final String expectedAuctionResponse = openrtbAuctionResponseFrom( - "openrtb2/zeroclickfraud/test-auction-zeroclickfraud-response.json", + assertJsonEquals("openrtb2/zeroclickfraud/test-auction-zeroclickfraud-response.json", response, singletonList("zeroclickfraud")); - - JSONAssert.assertEquals(expectedAuctionResponse, response.asString(), openrtbCacheDebugComparator()); } } diff --git a/src/test/resources/org/prebid/server/it/openrtb2/emxdigital/test-auction-emxdigital-request.json b/src/test/resources/org/prebid/server/it/openrtb2/emxdigital/test-auction-emxdigital-request.json index 5a2519b4668..916e721b29c 100644 --- a/src/test/resources/org/prebid/server/it/openrtb2/emxdigital/test-auction-emxdigital-request.json +++ b/src/test/resources/org/prebid/server/it/openrtb2/emxdigital/test-auction-emxdigital-request.json @@ -1,15 +1,11 @@ { - "id": "tid", + "id": "request_id", "imp": [ { - "id": "uuid", + "id": "imp_id", "banner": { - "format": [ - { - "w": 300, - "h": 250 - } - ] + "w": 300, + "h": 250 }, "ext": { "prebid": { @@ -22,54 +18,7 @@ } } ], - "device": { - "pxratio": 4.2, - "dnt": 2, - "language": "en", - "ifa": "ifaId", - "ua": "Android Chrome/60", - "ip": "127.0.0.1" - }, - "site": { - "page": "http://www.example.com", - "publisher": { - "id": "publisherId" - }, - "ext": { - "amp": 0 - } - }, - "at": 1, "tmax": 5000, - "cur": [ - "USD" - ], - "source": { - "fd": 1, - "tid": "tid" - }, - "ext": { - "prebid": { - "debug": 1, - "targeting": { - "pricegranularity": { - "precision": 2, - "ranges": [ - { - "max": 20, - "increment": 0.1 - } - ] - } - }, - "auctiontimestamp": 1000 - } - }, - "user": { - "ext": { - "consent": "consentValue" - } - }, "regs": { "ext": { "gdpr": 0 diff --git a/src/test/resources/org/prebid/server/it/openrtb2/emxdigital/test-auction-emxdigital-response.json b/src/test/resources/org/prebid/server/it/openrtb2/emxdigital/test-auction-emxdigital-response.json index 1078a7fc830..6d2e3cf823c 100644 --- a/src/test/resources/org/prebid/server/it/openrtb2/emxdigital/test-auction-emxdigital-response.json +++ b/src/test/resources/org/prebid/server/it/openrtb2/emxdigital/test-auction-emxdigital-response.json @@ -1,11 +1,11 @@ { - "id": "tid", + "id": "request_id", "seatbid": [ { "bid": [ { - "id": "uuid", - "impid": "uuid", + "id": "imp_id", + "impid": "imp_id", "price": 2.942808, "adm": "
", "adid": "94395500", @@ -14,15 +14,7 @@ "h": 250, "ext": { "prebid": { - "type": "banner", - "targeting": { - "hb_pb": "2.90", - "hb_size": "300x250", - "hb_bidder": "emx_digital", - "hb_bidder_emx_digital": "emx_digital", - "hb_size_emx_digital": "300x250", - "hb_pb_emx_digital": "2.90" - } + "type": "banner" }, "origbidcpm": 2.942808, "origbidcur": "USD" @@ -35,108 +27,11 @@ ], "cur": "USD", "ext": { - "debug": { - "httpcalls": { - "emx_digital": [ - { - "uri": "{{ emx_digital.exchange_uri }}?t=1000&ts=2060541160", - "requestbody": "{\"id\":\"tid\",\"imp\":[{\"id\":\"uuid\",\"banner\":{\"format\":[],\"w\":300,\"h\":250},\"tagid\":\"25251\",\"secure\":0,\"ext\":{\"bidder\":{\"tagid\":\"25251\"}}}],\"site\":{\"domain\":\"www.example.com\",\"page\":\"http://www.example.com\",\"publisher\":{\"id\":\"publisherId\",\"domain\":\"example.com\"},\"ext\":{\"amp\":0}},\"device\":{\"ua\":\"Android Chrome/60\",\"dnt\":2,\"ip\":\"193.168.244.1\",\"pxratio\":4.2,\"language\":\"en\",\"ifa\":\"ifaId\"},\"user\":{\"ext\":{\"consent\":\"consentValue\"}},\"at\":1,\"tmax\":5000,\"cur\":[\"USD\"],\"source\":{\"fd\":1,\"tid\":\"tid\"},\"regs\":{\"ext\":{\"gdpr\":0}},\"ext\":{\"prebid\":{\"debug\":1,\"targeting\":{\"pricegranularity\":{\"precision\":2,\"ranges\":[{\"max\":20,\"increment\":0.1}]},\"includewinners\":true,\"includebidderkeys\":true},\"auctiontimestamp\":1000,\"channel\":{\"name\":\"web\"}}}}", - "responsebody": "{\"id\":\"some_test_auction\",\"seatbid\":[{\"seat\":\"12356\",\"bid\":[{\"id\":\"uuid\",\"adm\":\"
\",\"impid\":\"uuid\",\"ttl\":300,\"crid\":\"94395500\",\"w\":300,\"price\":2.942808,\"adid\":\"94395500\",\"h\":250}]}],\"cur\":\"USD\"}", - "status": 200 - } - ] - }, - "resolvedrequest": { - "id": "tid", - "imp": [ - { - "id": "uuid", - "banner": { - "format": [ - { - "w": 300, - "h": 250 - } - ] - }, - "ext": { - "prebid": { - "bidder": { - "emx_digital": { - "tagid": "25251" - } - } - } - } - } - ], - "site": { - "domain": "www.example.com", - "page": "http://www.example.com", - "publisher": { - "id": "publisherId", - "domain": "example.com" - }, - "ext": { - "amp": 0 - } - }, - "device": { - "ua": "Android Chrome/60", - "dnt": 2, - "ip": "193.168.244.1", - "pxratio": 4.2, - "language": "en", - "ifa": "ifaId" - }, - "user": { - "ext": { - "consent": "consentValue" - } - }, - "at": 1, - "tmax": 5000, - "cur": [ - "USD" - ], - "source": { - "fd": 1, - "tid": "tid" - }, - "regs": { - "ext": { - "gdpr": 0 - } - }, - "ext": { - "prebid": { - "debug": 1, - "targeting": { - "pricegranularity": { - "precision": 2, - "ranges": [ - { - "max": 20, - "increment": 0.1 - } - ] - }, - "includewinners": true, - "includebidderkeys": true - }, - "auctiontimestamp": 1000, - "channel": { - "name": "web" - } - } - } - } - }, "responsetimemillis": { - "emx_digital": "{{ emx_digital.response_time_ms }}" + "emx_digital": 0 }, "prebid": { - "auctiontimestamp": 1000 + "auctiontimestamp": 0 }, "tmaxrequest": 5000 } diff --git a/src/test/resources/org/prebid/server/it/openrtb2/emxdigital/test-emxdigital-bid-request.json b/src/test/resources/org/prebid/server/it/openrtb2/emxdigital/test-emxdigital-bid-request.json index a1fb612b7cc..5e890065fbd 100644 --- a/src/test/resources/org/prebid/server/it/openrtb2/emxdigital/test-emxdigital-bid-request.json +++ b/src/test/resources/org/prebid/server/it/openrtb2/emxdigital/test-emxdigital-bid-request.json @@ -1,69 +1,43 @@ { - "id": "tid", + "id": "request_id", "imp": [ { - "id": "uuid", + "id": "imp_id", "banner": { - "format": [], "w": 300, "h": 250 }, "tagid": "25251", - "secure": 0 + "secure": 0, + "ext": { + "bidder": { + "tagid": "25251" + } + } } ], "site": { "domain": "www.example.com", "page": "http://www.example.com", "publisher": { - "id": "publisherId", "domain": "example.com" + }, + "ext": { + "amp": 0 } }, "device": { - "ua": "Android Chrome/60", - "dnt": 2, - "ip": "193.168.244.1", - "pxratio": 4.2, - "language": "en", - "ifa": "ifaId" - }, - "user": { + "ua": "userAgent", + "ip": "193.168.244.1" }, "at": 1, "tmax": 5000, "cur": [ "USD" ], - "source": { - "fd": 1, - "tid": "tid" - }, "regs": { "ext": { "gdpr": 0 } - }, - "ext": { - "prebid": { - "debug": 1, - "targeting": { - "pricegranularity": { - "precision": 2, - "ranges": [ - { - "max": 20, - "increment": 0.1 - } - ] - }, - "includewinners": true, - "includebidderkeys": true - }, - "auctiontimestamp": 1000, - "channel": { - "name": "web" - } - } } -} \ No newline at end of file +} diff --git a/src/test/resources/org/prebid/server/it/openrtb2/emxdigital/test-emxdigital-bid-response.json b/src/test/resources/org/prebid/server/it/openrtb2/emxdigital/test-emxdigital-bid-response.json index e1df1077904..c40dd3e89f8 100644 --- a/src/test/resources/org/prebid/server/it/openrtb2/emxdigital/test-emxdigital-bid-response.json +++ b/src/test/resources/org/prebid/server/it/openrtb2/emxdigital/test-emxdigital-bid-response.json @@ -5,9 +5,9 @@ "seat": "12356", "bid": [ { - "id": "uuid", + "id": "imp_id", "adm": "