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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
*.tar.gz
*.rar

!memex/src/test/resources/test-data/*.zip

# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*
replay_pid*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,23 @@

import com.johnlpage.memex.cucumber.service.MacrosRegister;
import io.cucumber.java.ParameterType;
import io.cucumber.java.en.And;
import io.cucumber.java.en.When;
import io.cucumber.java.en.Then;
import io.restassured.http.ContentType;
import io.restassured.path.json.JsonPath;
import io.restassured.response.Response;

import java.io.IOException;
import java.io.InputStream;
import java.util.List;
import java.util.Map;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.io.ClassPathResource;

public class RestApiSteps {

Expand All @@ -30,6 +36,8 @@ public class RestApiSteps {

private Response response;

private long durationMs;

@ParameterType("true|false")
public Boolean bool(String bool) {
return Boolean.parseBoolean(bool);
Expand Down Expand Up @@ -160,4 +168,47 @@ public void theResponseShouldBeAStreamOfValidJsonObjectsEachOnANewLine() {
}
}
}

@When("I send a POST request to {string} with the payload from {string}")
public void sendPostRequestWithPayloadFromZip(String endpoint, String zipFilePath) throws IOException {
ClassPathResource zipResource = new ClassPathResource(zipFilePath);
if (!zipResource.exists()) {
throw new AssertionError("ZIP file not found: " + zipFilePath);
}

byte[] payload = extractJsonFromZip(zipResource);

long startTime = System.nanoTime();

response = given()
.baseUri(baseUrl)
.contentType(ContentType.JSON)
.body(payload)
.post(endpoint);

long endTime = System.nanoTime();
durationMs = (endTime - startTime) / 1_000_000;
}


@And("the response time should be under {int} milliseconds")
public void responseTimeShouldBeUnderLimit(int maxAllowedMs) {

assertTrue(durationMs <= maxAllowedMs,
"API call took too long: " + durationMs + "ms (limit: " + maxAllowedMs + "ms)");
}

private byte[] extractJsonFromZip(ClassPathResource zipResource) throws IOException {
try (InputStream zipInputStream = zipResource.getInputStream();
ZipInputStream zis = new ZipInputStream(zipInputStream)) {

ZipEntry entry;
while ((entry = zis.getNextEntry()) != null) {
if (entry.getName().endsWith(".json")) {
return zis.readAllBytes();
}
}
}
throw new AssertionError("No .json file found in zip: " + zipResource.getPath());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
@bulk_api @vehicle_inspection @performance
Feature: Bulk Vehicle Inspection API
This feature tests the bulk vehicle inspection API endpoint.
It ensures that a batch of vehicle inspections can be submitted successfully,
all required IDs are valid, and the API responds within an acceptable time frame.

@sunny_day @fast_response
Scenario: Successfully submit vehicle inspections in bulk within time limit
When I send a POST request to "/api/inspections?updateStrategy=INSERT&futz=true" with the payload from "test-data/vehicle-inspections.zip"
Then the response status code should be 200
And the response time should be under 5000 milliseconds
Binary file not shown.
Loading