Skip to content

Commit 25f3e2e

Browse files
Rajat SharmaRajat Sharma
authored andcommitted
Zip file incorporate
1 parent ed492bb commit 25f3e2e

6 files changed

Lines changed: 56 additions & 555 deletions

File tree

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030
*.tar.gz
3131
*.rar
3232

33+
!memex/src/test/resources/test-data/*.zip
34+
3335
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
3436
hs_err_pid*
3537
replay_pid*

memex/src/test/java/com/johnlpage/memex/cucumber/steps/BulkInspectionApiSteps.java

Lines changed: 0 additions & 97 deletions
This file was deleted.

memex/src/test/java/com/johnlpage/memex/cucumber/steps/RestApiSteps.java

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,23 @@
88

99
import com.johnlpage.memex.cucumber.service.MacrosRegister;
1010
import io.cucumber.java.ParameterType;
11+
import io.cucumber.java.en.And;
1112
import io.cucumber.java.en.When;
1213
import io.cucumber.java.en.Then;
1314
import io.restassured.http.ContentType;
1415
import io.restassured.path.json.JsonPath;
1516
import io.restassured.response.Response;
1617

18+
import java.io.IOException;
19+
import java.io.InputStream;
1720
import java.util.List;
1821
import java.util.Map;
22+
import java.util.zip.ZipEntry;
23+
import java.util.zip.ZipInputStream;
1924

2025
import org.springframework.beans.factory.annotation.Autowired;
2126
import org.springframework.beans.factory.annotation.Value;
27+
import org.springframework.core.io.ClassPathResource;
2228

2329
public class RestApiSteps {
2430

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

3137
private Response response;
3238

39+
private long durationMs;
40+
3341
@ParameterType("true|false")
3442
public Boolean bool(String bool) {
3543
return Boolean.parseBoolean(bool);
@@ -160,4 +168,47 @@ public void theResponseShouldBeAStreamOfValidJsonObjectsEachOnANewLine() {
160168
}
161169
}
162170
}
171+
172+
@When("I send a POST request to {string} with the payload from {string}")
173+
public void sendPostRequestWithPayloadFromZip(String endpoint, String zipFilePath) throws IOException {
174+
ClassPathResource zipResource = new ClassPathResource(zipFilePath);
175+
if (!zipResource.exists()) {
176+
throw new AssertionError("ZIP file not found: " + zipFilePath);
177+
}
178+
179+
byte[] payload = extractJsonFromZip(zipResource);
180+
181+
long startTime = System.nanoTime();
182+
183+
response = given()
184+
.baseUri(baseUrl)
185+
.contentType(ContentType.JSON)
186+
.body(payload)
187+
.post(endpoint);
188+
189+
long endTime = System.nanoTime();
190+
durationMs = (endTime - startTime) / 1_000_000;
191+
}
192+
193+
194+
@And("the response time should be under {int} milliseconds")
195+
public void responseTimeShouldBeUnderLimit(int maxAllowedMs) {
196+
197+
assertTrue(durationMs <= maxAllowedMs,
198+
"API call took too long: " + durationMs + "ms (limit: " + maxAllowedMs + "ms)");
199+
}
200+
201+
private byte[] extractJsonFromZip(ClassPathResource zipResource) throws IOException {
202+
try (InputStream zipInputStream = zipResource.getInputStream();
203+
ZipInputStream zis = new ZipInputStream(zipInputStream)) {
204+
205+
ZipEntry entry;
206+
while ((entry = zis.getNextEntry()) != null) {
207+
if (entry.getName().endsWith(".json")) {
208+
return zis.readAllBytes();
209+
}
210+
}
211+
}
212+
throw new AssertionError("No .json file found in zip: " + zipResource.getPath());
213+
}
163214
}

memex/src/test/resources/features/inspections.rest.bulk_api_response_time.feature

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ Feature: Bulk Vehicle Inspection API
66

77
@sunny_day @fast_response
88
Scenario: Successfully submit vehicle inspections in bulk within time limit
9-
Given I load vehicle inspections from file "test-data/vehicle-inspections.json"
10-
And I validate all inspection test IDs
11-
When I send inspections to the bulk API: "/api/inspections?updateStrategy=INSERT&futz=true"
12-
Then the response status should be 2xx
13-
And the response time should be under 4 seconds
9+
When I send a POST request to "/api/inspections?updateStrategy=INSERT&futz=true" with the payload from "test-data/vehicle-inspections.zip"
10+
Then the response status code should be 200
11+
And the response time should be under 3000 milliseconds

0 commit comments

Comments
 (0)