-
Notifications
You must be signed in to change notification settings - Fork 190
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Basic integration tests for hooks framework (#1250)
* Sample module for integration testing * Integration test specifically for hooks invocation * Add sample raw auction request hook to integration test * Add sample processed auction request hook to integration test * Add sample bidder request hook to integration test * Add sample raw bidder response hook to integration test * Add sample processed bidder response hook to integration test * Add sample auction response hook to integration test * Simplify integration test for hooks framework by using a separate account * Add tests for rejection scenarios at different stages
- Loading branch information
Showing
37 changed files
with
1,578 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
src/test/java/org/prebid/server/hooks/execution/InvocationResultImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package org.prebid.server.hooks.execution; | ||
|
||
import lombok.Builder; | ||
import lombok.Value; | ||
import lombok.experimental.Accessors; | ||
import org.prebid.server.hooks.v1.InvocationAction; | ||
import org.prebid.server.hooks.v1.InvocationResult; | ||
import org.prebid.server.hooks.v1.InvocationStatus; | ||
import org.prebid.server.hooks.v1.PayloadUpdate; | ||
|
||
import java.util.List; | ||
|
||
@Accessors(fluent = true) | ||
@Builder | ||
@Value | ||
public class InvocationResultImpl<PAYLOAD> implements InvocationResult<PAYLOAD> { | ||
|
||
InvocationStatus status; | ||
|
||
String message; | ||
|
||
InvocationAction action; | ||
|
||
PayloadUpdate<PAYLOAD> payloadUpdate; | ||
|
||
List<String> errors; | ||
|
||
List<String> warnings; | ||
|
||
List<String> debugMessages; | ||
|
||
Object moduleContext; | ||
|
||
public static <PAYLOAD> InvocationResult<PAYLOAD> succeeded(PayloadUpdate<PAYLOAD> payloadUpdate) { | ||
return InvocationResultImpl.<PAYLOAD>builder() | ||
.status(InvocationStatus.success) | ||
.action(InvocationAction.update) | ||
.payloadUpdate(payloadUpdate) | ||
.build(); | ||
} | ||
|
||
public static <PAYLOAD> InvocationResult<PAYLOAD> failed(String message) { | ||
return InvocationResultImpl.<PAYLOAD>builder() | ||
.status(InvocationStatus.failure) | ||
.message(message) | ||
.build(); | ||
} | ||
|
||
public static <PAYLOAD> InvocationResult<PAYLOAD> noAction() { | ||
return InvocationResultImpl.<PAYLOAD>builder() | ||
.status(InvocationStatus.success) | ||
.action(InvocationAction.no_action) | ||
.build(); | ||
} | ||
|
||
public static <PAYLOAD> InvocationResult<PAYLOAD> rejected(String message) { | ||
return InvocationResultImpl.<PAYLOAD>builder() | ||
.status(InvocationStatus.success) | ||
.action(InvocationAction.reject) | ||
.message(message) | ||
.build(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
147 changes: 147 additions & 0 deletions
147
src/test/java/org/prebid/server/it/hooks/HooksTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,147 @@ | ||
package org.prebid.server.it.hooks; | ||
|
||
import io.restassured.response.Response; | ||
import org.json.JSONException; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.prebid.server.it.IntegrationTest; | ||
import org.skyscreamer.jsonassert.JSONAssert; | ||
import org.skyscreamer.jsonassert.JSONCompareMode; | ||
import org.springframework.test.context.junit4.SpringRunner; | ||
|
||
import java.io.IOException; | ||
|
||
import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; | ||
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.postRequestedFor; | ||
import static com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo; | ||
import static io.restassured.RestAssured.given; | ||
import static java.util.Collections.singletonList; | ||
import static org.hamcrest.Matchers.empty; | ||
|
||
@RunWith(SpringRunner.class) | ||
public class HooksTest extends IntegrationTest { | ||
|
||
private static final String RUBICON = "rubicon"; | ||
|
||
@Test | ||
public void openrtb2AuctionShouldRunHooksAtEachStage() throws IOException, JSONException { | ||
// given | ||
WIRE_MOCK_RULE.stubFor(post(urlPathEqualTo("/rubicon-exchange")) | ||
.withRequestBody(equalToJson(jsonFrom("hooks/sample-module/test-rubicon-bid-request-1.json"))) | ||
.willReturn(aResponse().withBody(jsonFrom("hooks/sample-module/test-rubicon-bid-response-1.json")))); | ||
|
||
// when | ||
final Response response = given(SPEC) | ||
.queryParam("sample-it-module-update", "headers,body") | ||
.header("User-Agent", "userAgent") | ||
.body(jsonFrom("hooks/sample-module/test-auction-sample-module-request.json")) | ||
.post("/openrtb2/auction"); | ||
|
||
// then | ||
final String expectedAuctionResponse = openrtbAuctionResponseFrom( | ||
"hooks/sample-module/test-auction-sample-module-response.json", response, singletonList(RUBICON)); | ||
|
||
JSONAssert.assertEquals(expectedAuctionResponse, response.asString(), JSONCompareMode.LENIENT); | ||
} | ||
|
||
@Test | ||
public void openrtb2AuctionShouldBeRejectedByEntrypointHook() throws IOException { | ||
given(SPEC) | ||
.queryParam("sample-it-module-reject", "true") | ||
.header("User-Agent", "userAgent") | ||
.body(jsonFrom("hooks/sample-module/test-auction-sample-module-request.json")) | ||
.post("/openrtb2/auction") | ||
.then() | ||
.statusCode(200) | ||
.body("seatbid", empty()); | ||
} | ||
|
||
@Test | ||
public void openrtb2AuctionShouldBeRejectedByRawAuctionRequestHook() throws IOException { | ||
given(SPEC) | ||
.header("User-Agent", "userAgent") | ||
.body(jsonFrom("hooks/reject/test-auction-raw-auction-request-reject-request.json")) | ||
.post("/openrtb2/auction") | ||
.then() | ||
.statusCode(200) | ||
.body("seatbid", empty()); | ||
} | ||
|
||
@Test | ||
public void openrtb2AuctionShouldBeRejectedByProcessedAuctionRequestHook() throws IOException { | ||
given(SPEC) | ||
.header("User-Agent", "userAgent") | ||
.body(jsonFrom("hooks/reject/test-auction-processed-auction-request-reject-request.json")) | ||
.post("/openrtb2/auction") | ||
.then() | ||
.statusCode(200) | ||
.body("seatbid", empty()); | ||
} | ||
|
||
@Test | ||
public void openrtb2AuctionShouldRejectRubiconBidderByBidderRequestHook() throws IOException, JSONException { | ||
// when | ||
final Response response = given(SPEC) | ||
.header("User-Agent", "userAgent") | ||
.body(jsonFrom("hooks/reject/test-auction-bidder-request-reject-request.json")) | ||
.post("/openrtb2/auction"); | ||
|
||
// then | ||
final String expectedAuctionResponse = openrtbAuctionResponseFrom( | ||
"hooks/reject/test-auction-bidder-request-reject-response.json", response, singletonList(RUBICON)); | ||
|
||
JSONAssert.assertEquals(expectedAuctionResponse, response.asString(), JSONCompareMode.LENIENT); | ||
|
||
WIRE_MOCK_RULE.verify(0, postRequestedFor(urlPathEqualTo("/rubicon-exchange"))); | ||
} | ||
|
||
@Test | ||
public void openrtb2AuctionShouldRejectRubiconBidderByRawBidderResponseHook() throws IOException, JSONException { | ||
// given | ||
WIRE_MOCK_RULE.stubFor(post(urlPathEqualTo("/rubicon-exchange")) | ||
.willReturn(aResponse().withBody(jsonFrom("hooks/reject/test-rubicon-bid-response-1.json")))); | ||
|
||
// when | ||
final Response response = given(SPEC) | ||
.header("User-Agent", "userAgent") | ||
.body(jsonFrom("hooks/reject/test-auction-raw-bidder-response-reject-request.json")) | ||
.post("/openrtb2/auction"); | ||
|
||
// then | ||
final String expectedAuctionResponse = openrtbAuctionResponseFrom( | ||
"hooks/reject/test-auction-raw-bidder-response-reject-response.json", response, singletonList(RUBICON)); | ||
|
||
JSONAssert.assertEquals(expectedAuctionResponse, response.asString(), JSONCompareMode.LENIENT); | ||
|
||
WIRE_MOCK_RULE.verify(1, postRequestedFor(urlPathEqualTo("/rubicon-exchange")) | ||
.withRequestBody(equalToJson(jsonFrom("hooks/reject/test-rubicon-bid-request-1.json")))); | ||
} | ||
|
||
@Test | ||
public void openrtb2AuctionShouldRejectRubiconBidderByProcessedBidderResponseHook() | ||
throws IOException, JSONException { | ||
|
||
// given | ||
WIRE_MOCK_RULE.stubFor(post(urlPathEqualTo("/rubicon-exchange")) | ||
.willReturn(aResponse().withBody(jsonFrom("hooks/reject/test-rubicon-bid-response-1.json")))); | ||
|
||
// when | ||
final Response response = given(SPEC) | ||
.header("User-Agent", "userAgent") | ||
.body(jsonFrom("hooks/reject/test-auction-processed-bidder-response-reject-request.json")) | ||
.post("/openrtb2/auction"); | ||
|
||
// then | ||
final String expectedAuctionResponse = openrtbAuctionResponseFrom( | ||
"hooks/reject/test-auction-processed-bidder-response-reject-response.json", | ||
response, | ||
singletonList(RUBICON)); | ||
|
||
JSONAssert.assertEquals(expectedAuctionResponse, response.asString(), JSONCompareMode.LENIENT); | ||
|
||
WIRE_MOCK_RULE.verify(1, postRequestedFor(urlPathEqualTo("/rubicon-exchange")) | ||
.withRequestBody(equalToJson(jsonFrom("hooks/reject/test-rubicon-bid-request-1.json")))); | ||
} | ||
} |
Oops, something went wrong.