Skip to content

Commit

Permalink
pre-commit fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
ci.datadog-api-spec committed Mar 6, 2023
1 parent 2aa7187 commit 58a1c16
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 110 deletions.
117 changes: 39 additions & 78 deletions src/test/java/com/datadog/api/ClientSteps.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,9 @@ public void setupVersion(Scenario scenario) {

@Before(order = 10)
public void setupClient()
throws java.lang.reflect.InvocationTargetException,
java.lang.IllegalAccessException,
java.lang.InstantiationException,
java.lang.NoSuchMethodException,
java.lang.ClassNotFoundException,
java.lang.NoSuchFieldException {
throws java.lang.reflect.InvocationTargetException, java.lang.IllegalAccessException,
java.lang.InstantiationException, java.lang.NoSuchMethodException,
java.lang.ClassNotFoundException, java.lang.NoSuchFieldException {
world.setupClient(apiVersion);
}

Expand Down Expand Up @@ -100,31 +97,24 @@ public void undo() {

@Given("an instance of {string} API")
public void anInstanceOfAPI(String apiName)
throws java.lang.ClassNotFoundException,
java.lang.NoSuchFieldException,
java.lang.InstantiationException,
java.lang.IllegalAccessException,
java.lang.NoSuchMethodException,
java.lang.reflect.InvocationTargetException {
throws java.lang.ClassNotFoundException, java.lang.NoSuchFieldException,
java.lang.InstantiationException, java.lang.IllegalAccessException,
java.lang.NoSuchMethodException, java.lang.reflect.InvocationTargetException {
world.setupAPI(apiVersion, World.toClassName(apiName));
}

@Given("operation {string} enabled")
public void operationEnabled(String operationId)
throws java.lang.reflect.InvocationTargetException,
java.lang.IllegalAccessException,
java.lang.InstantiationException,
java.lang.NoSuchMethodException,
throws java.lang.reflect.InvocationTargetException, java.lang.IllegalAccessException,
java.lang.InstantiationException, java.lang.NoSuchMethodException,
java.lang.ClassNotFoundException {
world.setUnstableOperationEnabled(apiVersion + "." + World.toMethodName(operationId));
}

@Given("a valid \"apiKeyAuth\" key in the system")
public void aValidApiKeyInTheSystem()
throws java.lang.reflect.InvocationTargetException,
java.lang.IllegalAccessException,
java.lang.InstantiationException,
java.lang.NoSuchMethodException,
throws java.lang.reflect.InvocationTargetException, java.lang.IllegalAccessException,
java.lang.InstantiationException, java.lang.NoSuchMethodException,
java.lang.ClassNotFoundException {
HashMap<String, String> secrets = new HashMap<String, String>();
secrets.put("apiKeyAuth", System.getenv(TEST_API_KEY_NAME));
Expand All @@ -133,10 +123,8 @@ public void aValidApiKeyInTheSystem()

@Given("a valid \"appKeyAuth\" key in the system")
public void aValidAppKeyInTheSystem()
throws java.lang.reflect.InvocationTargetException,
java.lang.IllegalAccessException,
java.lang.InstantiationException,
java.lang.NoSuchMethodException,
throws java.lang.reflect.InvocationTargetException, java.lang.IllegalAccessException,
java.lang.InstantiationException, java.lang.NoSuchMethodException,
java.lang.ClassNotFoundException {
HashMap<String, String> secrets = new HashMap<String, String>();
secrets.put("appKeyAuth", System.getenv(TEST_APP_KEY_NAME));
Expand All @@ -145,53 +133,42 @@ public void aValidAppKeyInTheSystem()

@Given("new {string} request")
public void newRequest(String methodName)
throws java.lang.IllegalAccessException,
java.lang.IllegalAccessException,
java.lang.NoSuchMethodException,
java.lang.reflect.InvocationTargetException {
throws java.lang.IllegalAccessException, java.lang.IllegalAccessException,
java.lang.NoSuchMethodException, java.lang.reflect.InvocationTargetException {
world.newRequest(methodName);
}

@Given("request contains {string} parameter from {string}")
public void requestContainsParameterFrom(String parameterName, String fixturePath)
throws java.lang.IllegalAccessException,
java.lang.NoSuchFieldException,
java.lang.ClassNotFoundException,
java.lang.NoSuchMethodException,
throws java.lang.IllegalAccessException, java.lang.NoSuchFieldException,
java.lang.ClassNotFoundException, java.lang.NoSuchMethodException,
java.lang.reflect.InvocationTargetException {
world.addRequestParameterFixture(parameterName, fixturePath);
}

@Given("request contains {string} parameter with value {}")
public void requestContainsParameterWithValue(String parameterName, String value)
throws java.lang.IllegalAccessException,
java.lang.NoSuchFieldException,
java.lang.ClassNotFoundException,
java.lang.NoSuchMethodException,
throws java.lang.IllegalAccessException, java.lang.NoSuchFieldException,
java.lang.ClassNotFoundException, java.lang.NoSuchMethodException,
java.lang.reflect.InvocationTargetException,
com.fasterxml.jackson.core.JsonProcessingException {
world.addRequestParameter(parameterName, value);
}

@Given("body with value {}")
public void setBody(String data)
throws java.lang.IllegalAccessException,
java.lang.NoSuchFieldException,
java.lang.ClassNotFoundException,
java.lang.NoSuchMethodException,
throws java.lang.IllegalAccessException, java.lang.NoSuchFieldException,
java.lang.ClassNotFoundException, java.lang.NoSuchMethodException,
java.lang.reflect.InvocationTargetException,
com.fasterxml.jackson.core.JsonProcessingException {
world.addRequestParameter("body", data);
}

@Given("body from file {string}")
public void setBodyFromFile(String filename)
throws java.lang.IllegalAccessException,
java.lang.NoSuchFieldException,
java.lang.ClassNotFoundException,
java.lang.NoSuchMethodException,
java.lang.reflect.InvocationTargetException,
IOException {
throws java.lang.IllegalAccessException, java.lang.NoSuchFieldException,
java.lang.ClassNotFoundException, java.lang.NoSuchMethodException,
java.lang.reflect.InvocationTargetException, IOException {
Path bodyPath =
Paths.get("src/test/resources/com/datadog/api/client/" + apiVersion + "/api/" + filename);
String data = new String(Files.readAllBytes(bodyPath));
Expand All @@ -200,10 +177,8 @@ public void setBodyFromFile(String filename)

@Then("the response status is {int} {}")
public void theResponseStatusIs(Integer statusCode, String unused)
throws java.lang.reflect.InvocationTargetException,
java.lang.IllegalAccessException,
java.lang.InstantiationException,
java.lang.NoSuchMethodException,
throws java.lang.reflect.InvocationTargetException, java.lang.IllegalAccessException,
java.lang.InstantiationException, java.lang.NoSuchMethodException,
java.lang.ClassNotFoundException {
Integer responseStatusCode = (Integer) 0;

Expand All @@ -220,14 +195,10 @@ public void theResponseStatusIs(Integer statusCode, String unused)

@Then("the response {string} is equal to {}")
public void theResponseIsEqualTo(String responsePath, String value)
throws java.lang.IllegalAccessException,
java.lang.NoSuchFieldException,
java.lang.reflect.InvocationTargetException,
java.lang.IllegalAccessException,
java.lang.InstantiationException,
java.lang.NoSuchMethodException,
java.lang.ClassNotFoundException,
com.fasterxml.jackson.core.JsonProcessingException {
throws java.lang.IllegalAccessException, java.lang.NoSuchFieldException,
java.lang.reflect.InvocationTargetException, java.lang.IllegalAccessException,
java.lang.InstantiationException, java.lang.NoSuchMethodException,
java.lang.ClassNotFoundException, com.fasterxml.jackson.core.JsonProcessingException {
Object responseData = world.responseClass.getMethod("getData").invoke(world.response);
Object responseValue = World.lookup(responseData, responsePath);
if (responseValue != null) {
Expand All @@ -244,46 +215,36 @@ public void theResponseIsEqualTo(String responsePath, String value)

@Then("the response {string} is false")
public void theResponseIsFalse(String responsePath)
throws java.lang.reflect.InvocationTargetException,
java.lang.IllegalAccessException,
java.lang.InstantiationException,
java.lang.NoSuchMethodException,
java.lang.ClassNotFoundException,
java.lang.NoSuchFieldException {
throws java.lang.reflect.InvocationTargetException, java.lang.IllegalAccessException,
java.lang.InstantiationException, java.lang.NoSuchMethodException,
java.lang.ClassNotFoundException, java.lang.NoSuchFieldException {
Object responseData = world.responseClass.getMethod("getData").invoke(world.response);
assertFalse((Boolean) World.lookup(responseData, responsePath));
}

@Then("the response {string} has the same value as {string}")
public void theResponseHasTheSameValueAs(String responsePath, String fixturePath)
throws java.lang.reflect.InvocationTargetException,
java.lang.IllegalAccessException,
java.lang.InstantiationException,
java.lang.NoSuchMethodException,
java.lang.ClassNotFoundException,
java.lang.NoSuchFieldException {
throws java.lang.reflect.InvocationTargetException, java.lang.IllegalAccessException,
java.lang.InstantiationException, java.lang.NoSuchMethodException,
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));
}

@Then("the response {string} has length {long}")
public void theResponseHasLength(String responsePath, Long size)
throws java.lang.reflect.InvocationTargetException,
java.lang.IllegalAccessException,
java.lang.InstantiationException,
java.lang.NoSuchMethodException,
java.lang.ClassNotFoundException,
java.lang.NoSuchFieldException {
throws java.lang.reflect.InvocationTargetException, java.lang.IllegalAccessException,
java.lang.InstantiationException, java.lang.NoSuchMethodException,
java.lang.ClassNotFoundException, java.lang.NoSuchFieldException {
Object responseData = world.responseClass.getMethod("getData").invoke(world.response);
List value = (List) World.lookup(responseData, responsePath);
assertEquals(size, Long.valueOf(value.size()));
}

@Then("the response has {int} items")
public void theResponseHasItems(Integer size)
throws java.lang.reflect.InvocationTargetException,
java.lang.IllegalAccessException,
throws java.lang.reflect.InvocationTargetException, java.lang.IllegalAccessException,
java.lang.NoSuchMethodException {
if (world.response.getClass().getSimpleName().equals("PaginationIterable")) {
assertEquals(size, ((Object) world.paginatedItems.size()));
Expand Down
48 changes: 16 additions & 32 deletions src/test/java/com/datadog/api/World.java
Original file line number Diff line number Diff line change
Expand Up @@ -133,12 +133,9 @@ public String getVersion() {
}

private void configureClient(Class<?> clientClass, Object client)
throws java.lang.reflect.InvocationTargetException,
java.lang.IllegalAccessException,
java.lang.InstantiationException,
java.lang.NoSuchMethodException,
java.lang.ClassNotFoundException,
java.lang.NoSuchFieldException {
throws java.lang.reflect.InvocationTargetException, java.lang.IllegalAccessException,
java.lang.InstantiationException, java.lang.NoSuchMethodException,
java.lang.ClassNotFoundException, java.lang.NoSuchFieldException {
// client.setServerIndex(0);
clientClass.getMethod("setServerIndex", Integer.class).invoke(client, 0);

Expand Down Expand Up @@ -192,12 +189,9 @@ private void configureClient(Class<?> clientClass, Object client)
}

public void setupClient(String apiVersion)
throws java.lang.reflect.InvocationTargetException,
java.lang.IllegalAccessException,
java.lang.InstantiationException,
java.lang.NoSuchMethodException,
java.lang.ClassNotFoundException,
java.lang.NoSuchFieldException {
throws java.lang.reflect.InvocationTargetException, java.lang.IllegalAccessException,
java.lang.InstantiationException, java.lang.NoSuchMethodException,
java.lang.ClassNotFoundException, java.lang.NoSuchFieldException {
// import com.datadog.api.client.ApiClient
clientClass = Class.forName("com.datadog.api.client.ApiClient");
// client = new ApiClient()
Expand All @@ -206,10 +200,8 @@ public void setupClient(String apiVersion)
}

public void setupAPI(String apiVersion, String apiName)
throws java.lang.ClassNotFoundException,
java.lang.InstantiationException,
java.lang.IllegalAccessException,
java.lang.NoSuchMethodException,
throws java.lang.ClassNotFoundException, java.lang.InstantiationException,
java.lang.IllegalAccessException, java.lang.NoSuchMethodException,
java.lang.reflect.InvocationTargetException {
// import com.datadog.api.{{ apiVersion }}.client.api.{{ apiName }}Api
apiClass = Class.forName("com.datadog.api.client." + apiVersion + ".api." + apiName + "Api");
Expand All @@ -218,8 +210,7 @@ public void setupAPI(String apiVersion, String apiName)
}

public void setUnstableOperationEnabled(String operationId)
throws java.lang.reflect.InvocationTargetException,
java.lang.IllegalAccessException,
throws java.lang.reflect.InvocationTargetException, java.lang.IllegalAccessException,
java.lang.NoSuchMethodException {
// client.setUnstableOperationEnabled(operationId, true)
clientClass
Expand All @@ -228,16 +219,14 @@ public void setUnstableOperationEnabled(String operationId)
}

public void configureApiKeys(Map<String, String> secrets)
throws java.lang.reflect.InvocationTargetException,
java.lang.IllegalAccessException,
throws java.lang.reflect.InvocationTargetException, java.lang.IllegalAccessException,
java.lang.NoSuchMethodException {
// client.configureApiKeys(secrets)
clientClass.getMethod("configureApiKeys", Map.class).invoke(client, secrets);
}

public void authenticateClient(Class<?> clientClass, Object client)
throws java.lang.reflect.InvocationTargetException,
java.lang.IllegalAccessException,
throws java.lang.reflect.InvocationTargetException, java.lang.IllegalAccessException,
java.lang.NoSuchMethodException {

HashMap<String, String> secrets = new HashMap<String, String>();
Expand Down Expand Up @@ -269,10 +258,8 @@ public void newRequest(String name) {
}

public void addRequestParameter(String parameterName, String value)
throws java.lang.IllegalAccessException,
java.lang.NoSuchFieldException,
java.lang.NoSuchMethodException,
java.lang.reflect.InvocationTargetException,
throws java.lang.IllegalAccessException, java.lang.NoSuchFieldException,
java.lang.NoSuchMethodException, java.lang.reflect.InvocationTargetException,
com.fasterxml.jackson.core.JsonProcessingException {
String propertyName = toPropertyName(parameterName);
Class fieldType = null;
Expand Down Expand Up @@ -307,10 +294,8 @@ public void addRequestParameter(String parameterName, String value)
}

public void addRequestParameterFixture(String parameterName, String fixturePath)
throws java.lang.IllegalAccessException,
java.lang.NoSuchFieldException,
java.lang.NoSuchMethodException,
java.lang.reflect.InvocationTargetException {
throws java.lang.IllegalAccessException, java.lang.NoSuchFieldException,
java.lang.NoSuchMethodException, java.lang.reflect.InvocationTargetException {
String propertyName = toPropertyName(parameterName);
Class fieldType = null;
boolean isOptional = false;
Expand Down Expand Up @@ -586,8 +571,7 @@ public void sendPaginatedRequest() throws Exception {
}

public ObjectMapper getObjectMapper()
throws java.lang.IllegalAccessException,
java.lang.NoSuchMethodException,
throws java.lang.IllegalAccessException, java.lang.NoSuchMethodException,
java.lang.reflect.InvocationTargetException {
Method getJSON = clientClass.getMethod("getJSON");
Object json = getJSON.invoke(client);
Expand Down

0 comments on commit 58a1c16

Please sign in to comment.