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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 24 additions & 3 deletions src/test/java/com/datadog/api/ClientSteps.java
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public void anInstanceOfAPI(String apiName)
java.lang.NoSuchMethodException,
java.lang.reflect.InvocationTargetException {
apiName = apiName.replace("-", "");
world.setupAPI(apiVersion, World.toClassName(apiName));
world.setupAPI(world.getOperationVersion(), World.toClassName(apiName));
}

@Given("operation {string} enabled")
Expand Down Expand Up @@ -165,6 +165,20 @@ public void newRequest(String methodName)
if (!TestRunner.runnerEnabled()) world.newRequest(methodName);
}

@Given("new {string} with version {string} request")
public void newVersionedRequest(String methodName, String version)
throws java.lang.ClassNotFoundException,
java.lang.InstantiationException,
java.lang.IllegalAccessException,
java.lang.NoSuchMethodException,
java.lang.reflect.InvocationTargetException {
world.setOperationVersion(version);
if (!TestRunner.runnerEnabled()) {
world.setupAPI(world.getOperationVersion(), world.apiName);
world.newRequest(methodName);
}
}

@Given("request contains {string} parameter from {string}")
public void requestContainsParameterFrom(String parameterName, String fixturePath)
throws java.lang.IllegalAccessException,
Expand Down Expand Up @@ -306,8 +320,15 @@ public void theResponseHasTheSameValueAs(String responsePath, String fixturePath
java.lang.ClassNotFoundException,
java.lang.NoSuchFieldException {
Object responseData = world.responseClass.getMethod("getData").invoke(world.response);
assertEquals(
World.lookup(world.context, fixturePath), World.lookup(responseData, responsePath));
Object expected = World.lookup(world.context, fixturePath);
Object actual = World.lookup(responseData, responsePath);
if (expected instanceof AbstractOpenApiSchema) {
expected = ((AbstractOpenApiSchema) expected).getActualInstanceRecursively();
}
if (actual instanceof AbstractOpenApiSchema) {
actual = ((AbstractOpenApiSchema) actual).getActualInstanceRecursively();
}
assertEquals(expected, actual);
}

@Then("the response {string} has length {long}")
Expand Down
7 changes: 6 additions & 1 deletion src/test/java/com/datadog/api/TestRunner.java
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,13 @@ public static void applyPlan(World world, boolean pagination) throws Exception {
throw new IllegalStateException("Generated request plan pagination mismatch");
}

if (plan.get("operation_version") != null) {
world.setOperationVersion(plan.get("operation_version").toString());
}

world.setupAPI(
world.getVersion(), World.toClassName(plan.get("api").toString().replace("-", "")));
world.getOperationVersion(),
World.toClassName(plan.get("api").toString().replace("-", "")));
world.newRequest(plan.get("operation_id").toString());

List<Map<String, Object>> parameters = (List<Map<String, Object>>) request.get("parameters");
Expand Down
11 changes: 11 additions & 0 deletions src/test/java/com/datadog/api/World.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ public class World {
// Specific API information
Class<?> apiClass;
public Object api;
String apiName;
String operationVersion;

// Templating context
public Map<String, Object> context;
Expand Down Expand Up @@ -143,6 +145,14 @@ public String getVersion() {
throw new IllegalStateException("API version not found in " + scenario.getUri());
}

public void setOperationVersion(String version) {
operationVersion = getVersion() + "_" + version.replace("-", "");
}

public String getOperationVersion() {
return operationVersion == null ? getVersion() : operationVersion;
}

private void configureClient(Class<?> clientClass, Object client)
throws java.lang.reflect.InvocationTargetException,
java.lang.IllegalAccessException,
Expand Down Expand Up @@ -236,6 +246,7 @@ public void setupAPI(String apiVersion, String apiName)
java.lang.NoSuchMethodException,
java.lang.reflect.InvocationTargetException {
// import com.datadog.api.{{ apiVersion }}.client.api.{{ apiName }}Api
this.apiName = apiName;
apiClass = Class.forName("com.datadog.api.client." + apiVersion + ".api." + apiName + "Api");
// api = new {{ apiName }}Api(client)
api = apiClass.getConstructor(clientClass).newInstance(client);
Expand Down
Loading