Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
5 changes: 1 addition & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,7 @@
<profile>
<id>surefire-java16</id>
<activation>
<property>
<name>java.version</name>
<value>16.0.1</value>
</property>
<jdk>[16,)</jdk>
</activation>
<build>
<plugins>
Expand Down
9 changes: 5 additions & 4 deletions src/test/java/com/datadog/api/ClientSteps.java
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ public void newRequest(String methodName)
java.lang.IllegalAccessException,
java.lang.NoSuchMethodException,
java.lang.reflect.InvocationTargetException {
world.newRequest(methodName);
if (!TestRunner.runnerEnabled()) world.newRequest(methodName);
}

@Given("request contains {string} parameter from {string}")
Expand All @@ -172,7 +172,7 @@ public void requestContainsParameterFrom(String parameterName, String fixturePat
java.lang.ClassNotFoundException,
java.lang.NoSuchMethodException,
java.lang.reflect.InvocationTargetException {
world.addRequestParameterFixture(parameterName, fixturePath);
if (!TestRunner.runnerEnabled()) world.addRequestParameterFixture(parameterName, fixturePath);
}

@Given("request contains {string} parameter with value {}")
Expand All @@ -183,7 +183,7 @@ public void requestContainsParameterWithValue(String parameterName, String value
java.lang.NoSuchMethodException,
java.lang.reflect.InvocationTargetException,
com.fasterxml.jackson.core.JsonProcessingException {
world.addRequestParameter(parameterName, value);
if (!TestRunner.runnerEnabled()) world.addRequestParameter(parameterName, value);
}

@Given("body with value {}")
Expand All @@ -194,7 +194,7 @@ public void setBody(String data)
java.lang.NoSuchMethodException,
java.lang.reflect.InvocationTargetException,
com.fasterxml.jackson.core.JsonProcessingException {
world.addRequestParameter("body", data);
if (!TestRunner.runnerEnabled()) world.addRequestParameter("body", data);
}

@Given("body from file {string}")
Expand All @@ -205,6 +205,7 @@ public void setBodyFromFile(String filename)
java.lang.NoSuchMethodException,
java.lang.reflect.InvocationTargetException,
IOException {
if (TestRunner.runnerEnabled()) return;
Path bodyPath =
Paths.get("src/test/resources/com/datadog/api/client/" + apiVersion + "/api/" + filename);
String data = new String(Files.readAllBytes(bodyPath));
Expand Down
8 changes: 2 additions & 6 deletions src/test/java/com/datadog/api/Given.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,8 @@ public <T> T resolve(Class<T> clazz, Object context, ObjectMapper mapper, String
if (value != null) {
if (clazz == File.class) {
// trim leading and trailing quotes from the value variable
String filePath =
"src/test/resources/com/datadog/api/client/"
+ version
+ "/api/"
+ value.replaceAll("^\"|\"$", "");
return (T) new File(filePath);
return (T)
TestRunner.featureDataPath(version, value.replaceAll("^\"|\"$", "")).toFile();
}
return World.fromJSON(mapper, clazz, World.templated(value, context));
}
Expand Down
3 changes: 1 addition & 2 deletions src/test/java/com/datadog/api/GivenAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ private GivenAction() {

private static List<Given> loadGiven(String apiVersion) {
try {
File file =
new File("src/test/resources/com/datadog/api/client/" + apiVersion + "/api/given.json");
File file = TestRunner.featureDataPath(apiVersion, "given.json").toFile();
return Given.load(file);
} catch (Exception e) {
throw new RuntimeException(e);
Expand Down
35 changes: 34 additions & 1 deletion src/test/java/com/datadog/api/RecorderSteps.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package com.datadog.api;

import io.cucumber.java.After;
import io.cucumber.java.AfterAll;
import io.cucumber.java.Before;
import io.cucumber.java.BeforeAll;
import io.cucumber.java.Scenario;
import io.cucumber.java.Status;
import io.cucumber.java.en.When;
Expand Down Expand Up @@ -43,6 +45,19 @@ public RecorderSteps(World world) {
this.world = world;
}

@BeforeAll
public static void startGeneratedTestServer() throws Exception {
TestRunner.startServer();
if (TestRunner.serverEnabled()) {
System.out.println("=== Using Generated Test Runner ===");
}
}

@AfterAll
public static void stopGeneratedTestServer() throws Exception {
TestRunner.stopServer();
}

@Before(value = "@integration-only", order = 0)
public void skipIntegrationOnly() {
if (!TestUtils.getRecordingMode().equals(RecordingMode.MODE_IGNORE)) {
Expand All @@ -61,6 +76,14 @@ public void skipReplayOnly() {

@Before(order = 1)
public void setupClock(Scenario scenario) throws java.io.IOException {
if (TestRunner.serverEnabled()) {
try {
TestRunner.startSession(world, scenario);
} catch (Exception error) {
throw new IOException(error);
}
return;
}
if (TestUtils.getRecordingMode().equals(RecordingMode.MODE_IGNORE)
|| scenario.getSourceTagNames().contains("@integration-only")) {
world.now = OffsetDateTime.now();
Expand Down Expand Up @@ -108,8 +131,16 @@ public void setupClock(Scenario scenario) throws java.io.IOException {
}
}

@After
@After(order = 0)
public void cleanAndSendExpectations(Scenario scenario) throws IOException {
if (TestRunner.serverEnabled()) {
try {
TestRunner.stopSession(world);
} catch (Exception error) {
throw new IOException(error);
}
return;
}
// Cleanup the recorded requests from sensitive information (API keys in headers and query
// params),
// create the associated expectations and save them to disk in the `cassettes/**/*.json` files
Expand Down Expand Up @@ -168,11 +199,13 @@ public String getCassetteName() {

@When("the request is sent")
public void theRequestIsSent() throws Exception {
TestRunner.applyPlan(world, false);
world.sendRequest();
}

@When("the request with pagination is sent")
public void theRequestSentWithPagination() throws Exception {
TestRunner.applyPlan(world, true);
world.sendPaginatedRequest();
}
}
Loading
Loading