Skip to content

Commit

Permalink
Remove redundant code
Browse files Browse the repository at this point in the history
  • Loading branch information
Serhii Nahornyi committed Jul 6, 2021
1 parent f3222de commit 820da64
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 17 deletions.
11 changes: 3 additions & 8 deletions src/test/java/org/prebid/server/it/EmxdigitalTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import org.json.JSONException;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.prebid.server.model.Endpoint;
import org.springframework.test.context.junit4.SpringRunner;

import java.io.IOException;
Expand All @@ -15,7 +16,6 @@
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;

@RunWith(SpringRunner.class)
public class EmxdigitalTest extends IntegrationTest {
Expand All @@ -36,13 +36,8 @@ public void openrtb2AuctionShouldRespondWithBidsFromEmxdigital() throws IOExcept
.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")
.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
assertJSONEquals("openrtb2/emxdigital/test-auction-emxdigital-response.json",
Expand Down
14 changes: 13 additions & 1 deletion src/test/java/org/prebid/server/it/IntegrationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
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;
Expand All @@ -43,6 +44,7 @@
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)
Expand Down Expand Up @@ -83,6 +85,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)));
Expand Down Expand Up @@ -189,7 +201,7 @@ static CustomComparator openrtbCacheDebugComparator() {
new Customization("ext.debug.httpcalls.cache", arrayValueMatcher));
}

static void assertJSONEquals(String file, String bidder, String response, Customization... customizations)
protected static void assertJSONEquals(String file, String bidder, String response, Customization... customizations)
throws IOException, JSONException {
final List<Customization> fullCustomizations = new ArrayList<>(Arrays.asList(customizations));
fullCustomizations.add(new Customization("ext.prebid.auctiontimestamp", (o1, o2) -> true));
Expand Down
11 changes: 3 additions & 8 deletions src/test/java/org/prebid/server/it/LoopmeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import org.json.JSONException;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.prebid.server.model.Endpoint;
import org.springframework.test.context.junit4.SpringRunner;

import java.io.IOException;
Expand All @@ -12,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;

@RunWith(SpringRunner.class)
public class LoopmeTest extends IntegrationTest {
Expand All @@ -25,13 +25,8 @@ 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")
.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
assertJSONEquals("openrtb2/loopme/test-auction-loopme-response.json", "loopme", response.asString());
Expand Down

0 comments on commit 820da64

Please sign in to comment.