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