From 6f29ea096bbbbb38f1c48d9f562cc2e5b2152d2f Mon Sep 17 00:00:00 2001 From: Matheus Marques Colares Date: Thu, 17 Oct 2024 18:17:18 -0300 Subject: [PATCH 1/5] add api and performance tests --- .DS_Store | Bin 0 -> 6148 bytes README.md | 25 ++ node_modules/.package-lock.json | 14 + node_modules/k6/package.json | 16 + package-lock.json | 21 ++ package.json | 17 + pom.xml | 13 + src/.DS_Store | Bin 0 -> 6148 bytes src/main/resources/openapi-inflector.yaml | 65 ++++ src/test/.DS_Store | Bin 0 -> 6148 bytes src/test/java/.DS_Store | Bin 0 -> 6148 bytes .../ip/swagger/petstore/PetStoreTest.java | 5 - .../ip/swagger/petstore/PetstoreApiTests.java | 291 ++++++++++++++++++ .../java/performance/petStore_Test Plan.jmx | 227 ++++++++++++++ .../java/performance/place_order_load_test.js | 37 +++ .../performance/place_order_stress_test.js | 43 +++ 16 files changed, 769 insertions(+), 5 deletions(-) create mode 100644 .DS_Store create mode 100644 node_modules/.package-lock.json create mode 100644 node_modules/k6/package.json create mode 100644 package-lock.json create mode 100644 package.json create mode 100644 src/.DS_Store create mode 100644 src/main/resources/openapi-inflector.yaml create mode 100644 src/test/.DS_Store create mode 100644 src/test/java/.DS_Store delete mode 100644 src/test/java/ip/swagger/petstore/PetStoreTest.java create mode 100644 src/test/java/ip/swagger/petstore/PetstoreApiTests.java create mode 100644 src/test/java/performance/petStore_Test Plan.jmx create mode 100644 src/test/java/performance/place_order_load_test.js create mode 100644 src/test/java/performance/place_order_stress_test.js diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..d687949dc61049b60515512cde5d528b86880dc8 GIT binary patch literal 6148 zcmeHK%}T>S5Z<-brW7Fug&r5YR%}bff|n5M3mDOZN=;1BV9b^zHHT8jSzpK}@p+ut z-GIfMMeGdhe)GGV{UH0p7~}3D957}x#w=)v9F-bDcWr3PBqMShBbx`Y48Zyb<|g*n z0l&S$GM2K3p!oj%ag^o#{wLpRG`DwJR?F&GcixjMyxh+hnd_%FXkAJf2bJyzSJAAP z+Iwd*$^9sqrK%tbXOMDx9VMYGT)9ZXOx1ciV70CG)b1{qhr@AC91mALu^jYAqnEyt+l3jxpyn|v^^XjEZER#p@RM}M)Au&J<5Cg=(W;0;U z1*@~!G|=ja0b-zr0o)%1G(^W>sZnhm(BbtN<4r^q(D5ySC=5CVON|f#;kp!1mvZyO z;JO_A!sIyyOO3jmaWylHV`i=%FI>$IexcGCcQjH@3=jkB3^cT9#GAOVD08;{SRS6W0@^(^6wE780ResO5&#D7BV85Lae+GIIR;COI12hz QIUrpG6d}|R1HZt)7kZFMeE.tgz +``` +#### Step 2: Open JMeter +``` +cd apache-jmeter-/bin +``` +Start JMeter +``` +./jmeter +``` +#### 3. Open the test plan and run the test +1. In JMeter click on the open iIcon and select the test plan file for Pet Store performance test "petStore_Test Plan.jmx"(src/test/java/performance) +2. Click on the green **Start** button in the toolbar to run the test. diff --git a/node_modules/.package-lock.json b/node_modules/.package-lock.json new file mode 100644 index 00000000..60f4cb99 --- /dev/null +++ b/node_modules/.package-lock.json @@ -0,0 +1,14 @@ +{ + "name": "swagger-petstore", + "version": "1.0.0", + "lockfileVersion": 3, + "requires": true, + "packages": { + "node_modules/k6": { + "version": "0.0.0", + "resolved": "https://registry.npmjs.org/k6/-/k6-0.0.0.tgz", + "integrity": "sha512-GAQSWayS2+LjbH5bkRi+pMPYyP1JSp7o+4j58ANZ762N/RH/SdlAT3CHHztnn8s/xgg8kYNM24Gd2IPo9b5W+g==", + "license": "AGPL-3.0" + } + } +} diff --git a/node_modules/k6/package.json b/node_modules/k6/package.json new file mode 100644 index 00000000..c4c83d56 --- /dev/null +++ b/node_modules/k6/package.json @@ -0,0 +1,16 @@ +{ + "name": "k6", + "version": "0.0.0", + "description": "Dummy package for autocompleting k6 scripts.", + "main": "index.js", + "repository": { + "type": "git", + "url": "git+https://github.com/loadimpact/k6.git" + }, + "author": "Emily Ekberg ", + "license": "AGPL-3.0", + "bugs": { + "url": "https://github.com/loadimpact/k6/issues" + }, + "homepage": "https://github.com/loadimpact/k6#readme" +} diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 00000000..41060074 --- /dev/null +++ b/package-lock.json @@ -0,0 +1,21 @@ +{ + "name": "swagger-petstore", + "version": "1.0.0", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "name": "swagger-petstore", + "version": "1.0.0", + "dependencies": { + "k6": "^0.0.0" + } + }, + "node_modules/k6": { + "version": "0.0.0", + "resolved": "https://registry.npmjs.org/k6/-/k6-0.0.0.tgz", + "integrity": "sha512-GAQSWayS2+LjbH5bkRi+pMPYyP1JSp7o+4j58ANZ762N/RH/SdlAT3CHHztnn8s/xgg8kYNM24Gd2IPo9b5W+g==", + "license": "AGPL-3.0" + } + } +} diff --git a/package.json b/package.json new file mode 100644 index 00000000..8db8308b --- /dev/null +++ b/package.json @@ -0,0 +1,17 @@ +{ + "name": "swagger-petstore", + "version": "1.0.0", + "description": "", + "main": "index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "repository": { + "type": "git", + "url": "https://github.com/swagger-api/swagger-petstore.git" + }, + "private": true, + "dependencies": { + "k6": "^0.0.0" + } +} diff --git a/pom.xml b/pom.xml index 9e5b30ec..1d138428 100644 --- a/pom.xml +++ b/pom.xml @@ -162,6 +162,19 @@ jackson-databind ${jackson-version} + + io.rest-assured + rest-assured + 5.4.0 + test + + + org.junit.jupiter + junit-jupiter + 5.7.0 + test + + com.fasterxml.jackson.core jackson-annotations diff --git a/src/.DS_Store b/src/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..7ea0f692ab55cc20d3551ff067601475b2c36ef0 GIT binary patch literal 6148 zcmeHK%}T>S5Z-O0O({YS3Oz1(t=N`|1ur4i7cim+m70*C!I&*gY7eE5v%Zi|;`2DO zyAg}^Dq?3~_nY6{><8H&#u)czQI9c)F=j(UbgvE7Ofn+JF~WI12~!z@{bpi+ z9q`*NRT<@_%rK6bxq7^CH9Po)N@v{FNIfw?46HIx*QSH#{~7!;YajWm zC1eo;#K1pefLkMfX7FeEH&aN S=vU={bP-U5P)7{>0s|lNj!Jd_ literal 0 HcmV?d00001 diff --git a/src/main/resources/openapi-inflector.yaml b/src/main/resources/openapi-inflector.yaml new file mode 100644 index 00000000..48dcc42a --- /dev/null +++ b/src/main/resources/openapi-inflector.yaml @@ -0,0 +1,65 @@ +openapi: 3.0.0 +info: + title: Swagger Petstore API + description: API for managing a pet store + version: 1.0.0 +servers: + - url: http://localhost:8080/v2 +paths: + /pet: + post: + summary: Add a new pet to the store + requestBody: + required: true + content: + application/json: + schema: + type: object + properties: + id: + type: integer + name: + type: string + status: + type: string + responses: + '200': + description: Pet added successfully + content: + application/json: + schema: + type: object + properties: + id: + type: integer + name: + type: string + status: + type: string + /pet/{petId}: + get: + summary: Find pet by ID + parameters: + - name: petId + in: path + required: true + description: ID of pet to return + schema: + type: integer + responses: + '200': + description: Successful operation + content: + application/json: + schema: + type: object + properties: + id: + type: integer + name: + type: string + status: + type: string + '404': + description: Pet not found + diff --git a/src/test/.DS_Store b/src/test/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..55c1fcbeb4ba2bef02771ea2748f3e4b0ea5c07d GIT binary patch literal 6148 zcmeH~J&wXa427SU6iC~oq@0EW>)m< zk%er^j=Knh3!DIf); zz>E~gV|@8Jqi52iNC7D@4+Z@DQ0UH@Y@PAxV2BZb99RzHI%Wy7c!8|R*2xOZa(b|A zwHQOZ9_?hw>uR!f_I6kfAC`AEpJHg%+hK(X&1yhF3P^#80*juHe*W+1ujcQ^n8@Auu4PPqH)~DC=`aY|^Zges(XZZ6Iz{HQ@6+Mjm#TR5vwoX=P`Vj~j6r{kv GD)0dNyb`AX literal 0 HcmV?d00001 diff --git a/src/test/java/.DS_Store b/src/test/java/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..24d39a3b4824f29462b54220f2cc5bb8383375fd GIT binary patch literal 6148 zcmeHK!Ab)$5S_HuZYe?!3VI88E!ZtZ1usjjKj4ZURO+r>b#c2X+twaRVek4w{)pe> zOp=PF_TWXN%)sPLCNmrIvSbnf5bbf#1*idlgGyMaVDp2}IO&oUtcOtOZz#y14*{fb zzZA`m|HuICT@?lp;m$q4_x+2)$#4)RD#VEQaFE2qQKRu83dPdKX4xq_Rp-`!QWJj^ zjK;%ukX=*nLa8L2+d+64N0V-C`&6Z)AWox9C&ax7LvF6(w5KL*HBNg&o$H$cr{Yw) zwY}-oZ64O8+j3`hIdvPYR$U$)H)peov$KD2a^8JT`l)&~oC^H?v}{?N!y6hamiOXk zX`<3cjF@N7vly8HW`G%3a|Z0O=Tz5xoxD6|fEoBb19Uz}R6@^UZcrZ`*wFQn#!G}G zXwzGQP+IgX<_2*DMVM4XlPc^JLzr~*OB?4|%nh1!5PD|(j-6T97mCocqhIQ95S~G9 znE_^Ck%6M=)~NoUt$zP6CUK7$U&3mmB;_K|_~f fjHOb%i>d|vk_<%8Vr~#UD0~snG;qTV{3!#U7E(^l literal 0 HcmV?d00001 diff --git a/src/test/java/ip/swagger/petstore/PetStoreTest.java b/src/test/java/ip/swagger/petstore/PetStoreTest.java deleted file mode 100644 index 260ba2e6..00000000 --- a/src/test/java/ip/swagger/petstore/PetStoreTest.java +++ /dev/null @@ -1,5 +0,0 @@ -package ip.swagger.petstore; - -public class PetStoreTest { - -} diff --git a/src/test/java/ip/swagger/petstore/PetstoreApiTests.java b/src/test/java/ip/swagger/petstore/PetstoreApiTests.java new file mode 100644 index 00000000..d778f246 --- /dev/null +++ b/src/test/java/ip/swagger/petstore/PetstoreApiTests.java @@ -0,0 +1,291 @@ +package ip.swagger.petstore; + +import io.restassured.RestAssured; +import io.restassured.http.ContentType; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.Order; +import org.junit.jupiter.api.TestMethodOrder; +import org.junit.jupiter.api.MethodOrderer.OrderAnnotation; + +import static io.restassured.RestAssured.given; +import static org.hamcrest.Matchers.*; + +@TestMethodOrder(OrderAnnotation.class) +public class PetstoreApiTests { + + @BeforeAll + public static void setup() { + RestAssured.baseURI = "http://localhost:8080/api/v3"; + } + + // Pets API tests + + @Test + @Order(1) + public void testAddPet() { + String newPetJson = "{ \"id\": 1, \"name\": \"Doggie\", \"status\": \"available\" }"; + given() + .contentType(ContentType.JSON) + .body(newPetJson) + .when() + .post("/pet") + .then() + .statusCode(200) + .body("name", equalTo("Doggie")) + .body("status", equalTo("available")); + } + + @Test + @Order(2) + public void testGetPetById() { + int petId = 1; // Existing pet ID + given() + .pathParam("petId", petId) + .when() + .get("/pet/{petId}") + .then() + .statusCode(200) + .body("id", equalTo(petId)); + } + + @Test + @Order(3) + public void testUpdatePet() { + String updatedPetJson = "{ \"id\": 1, \"name\": \"Doggie\", \"status\": \"sold\" }"; + given() + .contentType(ContentType.JSON) + .body(updatedPetJson) + .when() + .put("/pet") + .then() + .statusCode(200) + .body("status", equalTo("sold")); + } + + @Test + @Order(4) + public void testDeletePet() { + int petId = 1; // Existing pet ID to delete + given() + .pathParam("petId", petId) + .when() + .delete("/pet/{petId}") + .then() + .statusCode(200); + //.body("message", equalTo(String.valueOf(petId))); + } + + @Test + @Order(5) + public void testFindPetsByStatus() { + String status = "available"; + given() + .queryParam("status", status) + .when() + .get("/pet/findByStatus") + .then() + .statusCode(200) + .body("size()", greaterThan(0)); + } + + @Test + @Order(6) + public void test_06_FindPetsByTags() { + String tag = "dog"; // Example tag + given() + .queryParam("tags", tag) + .when() + .get("/pet/findByTags") + .then() + .statusCode(200) + .body("size()", greaterThanOrEqualTo(0)); + } + + // Store API tests + + @Test + @Order(7) + public void testGetInventory() { + given() + .when() + .get("/store/inventory") + .then() + .statusCode(200); + } + + @Test + @Order(8) + public void testPlaceOrder() { + String orderJson = "{ \"id\": 1, \"petId\": 1, \"quantity\": 1, \"shipDate\": \"2024-10-10T00:00:00Z\", \"status\": \"placed\", \"complete\": false }"; + given() + .contentType(ContentType.JSON) + .body(orderJson) + .when() + .post("/store/order") + .then() + .statusCode(200) + .body("status", equalTo("placed")); + } + + @Test + @Order(9) + public void testGetOrderById() { + int orderId = 1; // Example order ID + given() + .pathParam("orderId", orderId) + .when() + .get("/store/order/{orderId}") + .then() + .statusCode(200) + .body("id", equalTo(orderId)); + } + + @Test + @Order(10) + public void testDeleteOrder() { + int orderId = 1; // Example order ID to delete + given() + .pathParam("orderId", orderId) + .when() + .delete("/store/order/{orderId}") + .then() + .statusCode(200); + } + + // User API tests + + @Test + @Order(11) + public void testCreateUser() { + String userJson = "{ \"id\": 0, \"username\": \"johndoe\", \"firstName\": \"John\", \"lastName\": \"Doe\", \"email\": \"john@example.com\", \"password\": \"password\", \"phone\": \"123-456-7890\", \"userStatus\": 1 }"; + given() + .contentType(ContentType.JSON) + .body(userJson) + .when() + .post("/user") + .then() + .statusCode(200); + } + + @Test + @Order(12) + public void testGetUserByUsername() { + String username = "johndoe"; // Existing username + given() + .pathParam("username", username) + .when() + .get("/user/{username}") + .then() + .statusCode(200) + .body("username", equalTo(username)); + } + + @Test + @Order(13) + public void testUpdateUser() { + String updatedUserJson = "{ \"id\": 0, \"username\": \"johndoe\", \"firstName\": \"Johnny\", \"lastName\": \"Doe\", \"email\": \"johnny@example.com\", \"password\": \"newpassword\", \"phone\": \"123-456-7890\", \"userStatus\": 1 }"; + given() + .contentType(ContentType.JSON) + .body(updatedUserJson) + .when() + .put("/user/johndoe") + .then() + .statusCode(200); + } + + @Test + @Order(14) + public void testDeleteUser() { + String username = "johndoe"; // Existing username to delete + given() + .pathParam("username", username) + .when() + .delete("/user/{username}") + .then() + .statusCode(200); + } + + @Test + @Order(15) + public void testLoginUser() { + String username = "johndoe"; + String password = "password"; + given() + .queryParam("username", username) + .queryParam("password", password) + .when() + .get("/user/login") + .then() + .statusCode(200); + } + + @Test + @Order(16) + public void testLogoutUser() { + given() + .when() + .get("/user/logout") + .then() + .statusCode(200); + } + + //BUG #001 + // Api is returning 200 when we send a request without user and password parameters. It should return 400 + @Test + @Order(17) + public void testLogin_MissingUserAndPassword() { + given() + .when() + .get("/user/login") + .then() + .statusCode(400); + } + + //BUG #002 + // Api is returning 200 when we send a request with an empty user and password parameters. It should return 400 + @Test + @Order(18) + public void testLogin_InvalidUserAndPassword() { + String username = " "; + String password = " "; + given() + .queryParam("username", username) + .queryParam("password", password) + .when() + .get("/user/login") + .then() + .statusCode(400); + } + + //#BUG #003 + // Api is returning 200 when we send a request without an username. It should return 400 + @Test + @Order(19) + public void testCreateUser_missingUsername() { + String userJson = "{ \"id\": 0, \"firstName\": \"John\", \"lastName\": \"Doe\", \"email\": \"john@example.com\", \"password\": \"password\", \"phone\": \"123-456-7890\", \"userStatus\": 1 }"; + given() + .contentType(ContentType.JSON) + .body(userJson) + .when() + .post("/user") + .then() + .statusCode(400); + } + + //BUG #004 + // Api is crashing after returning 500 when we send a request without providing a password. It should return 400 + @Test + @Order(20) + public void testCreateUser_missingPassword() { + String userJson = "{ \"id\": 0, \"username\": \"johndoe\", \"firstName\": \"John\", \"lastName\": \"Doe\", \"email\": \"john@example.com\", \"phone\": \"123-456-7890\", \"userStatus\": 1 }"; + given() + .contentType(ContentType.JSON) + .body(userJson) + .when() + .post("/user") + .then() + .statusCode(400); + } + +} diff --git a/src/test/java/performance/petStore_Test Plan.jmx b/src/test/java/performance/petStore_Test Plan.jmx new file mode 100644 index 00000000..ee4f8228 --- /dev/null +++ b/src/test/java/performance/petStore_Test Plan.jmx @@ -0,0 +1,227 @@ + + + + + + + + + + + 500 + 120 + true + continue + + 5 + false + + + + + localhost + 8080 + /api/v3/store/order + true + POST + true + true + + + + false + { + "id": ${__Random(1,1000)}, + "petId": ${__Random(198772, 198999)}, + "quantity": ${__Random(1,10)}, + "shipDate": "${__time(yyyy-MM-dd'T'HH:mm:ss.SSS'Z')}", + "status": "approved", + "complete": true +} + = + + + + + + + + + accept + application/json + + + Content-Type + application/json + + + + + + + + + randomId + ${__Random(1,1000)} + = + + + randomPetId + ${__Random(198772, 198999)} + = + + + + + + false + + saveConfig + + + true + true + true + + true + true + true + true + false + true + true + false + false + false + true + false + false + false + true + 0 + true + true + true + true + true + true + + + + + + + false + + saveConfig + + + true + true + true + + true + true + true + true + false + true + true + false + false + false + true + false + false + false + true + 0 + true + true + true + true + true + true + + + + + + + false + + saveConfig + + + true + true + true + + true + true + true + true + false + true + true + false + false + false + true + false + false + false + true + 0 + true + true + true + true + true + true + + + + + + + false + + saveConfig + + + true + true + true + + true + true + true + true + false + true + true + false + false + false + true + false + false + false + true + 0 + true + true + true + true + true + true + + + + + + + + + diff --git a/src/test/java/performance/place_order_load_test.js b/src/test/java/performance/place_order_load_test.js new file mode 100644 index 00000000..51e832dd --- /dev/null +++ b/src/test/java/performance/place_order_load_test.js @@ -0,0 +1,37 @@ +import http from 'k6/http'; +import { check, sleep } from 'k6'; + +const BASE_URL = 'http://localhost:8080/api/v3/store'; // Adjust the base URL if necessary + +export let options = { + vus: 100, // Number of virtual users + duration: '1m', // Test duration +}; + +export default function () { + // Define the order payload + const order = { + id: 1, + petId: 198772, + quantity: 7, + shipDate: new Date().toISOString(), // Use the current date and time + status: "approved", + complete: true + }; + + // Make the POST request + let response = http.post(`${BASE_URL}/order`, JSON.stringify(order), { + headers: { + 'Accept': 'application/json', + 'Content-Type': 'application/json', + }, + }); + + // Check response + check(response, { + 'status is 200': (r) => r.status === 200, + 'response is not empty': (r) => r.body.length > 0, + }); + + sleep(1); // Wait for 1 second before the next iteration +} \ No newline at end of file diff --git a/src/test/java/performance/place_order_stress_test.js b/src/test/java/performance/place_order_stress_test.js new file mode 100644 index 00000000..e5e8c3a0 --- /dev/null +++ b/src/test/java/performance/place_order_stress_test.js @@ -0,0 +1,43 @@ +import http from 'k6/http'; +import { check, sleep } from 'k6'; + +const BASE_URL = 'http://localhost:8080/v3/store'; // Adjust the base URL as needed + +export let options = { + stages: [ + { duration: '30s', target: 50 }, // Ramp-up to 50 users over 30 seconds + { duration: '1m', target: 50 }, // Stay at 50 users for 1 minute + { duration: '30s', target: 0 }, // Ramp-down to 0 users + ], +}; + +export default function () { + // Create a new order + let orderId = Math.floor(Math.random() * 1000); // Random ID for the order + const order = { + id: orderId, + petId: Math.floor(Math.random() * 1000), // Random pet ID + quantity: Math.floor(Math.random() * 10) + 1, // Random quantity + shipDate: new Date().toISOString(), + status: "placed", + complete: true + }; + + let createOrderResponse = http.post(`${BASE_URL}/order`, JSON.stringify(order), { + headers: { 'Content-Type': 'application/json' }, + }); + + // Check response + check(createOrderResponse, { + 'create order status is 200': (r) => r.status === 200, + 'response is not empty': (r) => r.body.length > 0, + }); + + // Optionally retrieve the created order + let getOrderResponse = http.get(`${BASE_URL}/order/${orderId}`); + check(getOrderResponse, { + 'get order status is 200': (r) => r.status === 200, + }); + + sleep(1); // Wait for 1 second before the next iteration +} From 428e256c8c8c05118a633bf227a129007157dc02 Mon Sep 17 00:00:00 2001 From: Matheus Marques Colares Date: Fri, 18 Oct 2024 10:13:42 -0300 Subject: [PATCH 2/5] add jmeter test plan --- src/test/java/performance/petStore_Test Plan.jmx | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/test/java/performance/petStore_Test Plan.jmx b/src/test/java/performance/petStore_Test Plan.jmx index ee4f8228..a0734717 100644 --- a/src/test/java/performance/petStore_Test Plan.jmx +++ b/src/test/java/performance/petStore_Test Plan.jmx @@ -5,6 +5,8 @@ + false + false @@ -13,7 +15,7 @@ true continue - 5 + 1 false @@ -44,7 +46,7 @@ - + accept From 19fb5a552a35b19c5311e0d0f5e7754241ad19f3 Mon Sep 17 00:00:00 2001 From: Matheus Marques Colares Date: Fri, 18 Oct 2024 18:19:06 -0300 Subject: [PATCH 3/5] add api testing document --- src/test/PetstoreAPITestDocument.md | 145 ++++++++++++++++++++++++++++ src/test/java/.DS_Store | Bin 6148 -> 6148 bytes 2 files changed, 145 insertions(+) create mode 100644 src/test/PetstoreAPITestDocument.md diff --git a/src/test/PetstoreAPITestDocument.md b/src/test/PetstoreAPITestDocument.md new file mode 100644 index 00000000..795b224e --- /dev/null +++ b/src/test/PetstoreAPITestDocument.md @@ -0,0 +1,145 @@ +# Petstore API Tests + +This document describes the test cases for the Petstore API. Each test case is classified by **criticality** and **severity**. + +## Table of Contents +- [Pets API Tests](#pets-api-tests) +- [Store API Tests](#store-api-tests) +- [User API Tests](#user-api-tests) +- [Bug Tests](#bug-tests) + +--- + +## Pets API Tests + +### 1. **Test: Add Pet** + - **Description**: Tests the addition of a new pet. + - **Criticality**: High - Essential functionality of adding pets. + - **Severity**: Critical - Failure results in inability to add pets. + - **Test Method**: `testAddPet` + +### 2. **Test: Get Pet by ID** + - **Description**: Retrieves a pet by its ID. + - **Criticality**: High - A primary feature for fetching pet details. + - **Severity**: Major - Failure blocks the retrieval of specific pets. + - **Test Method**: `testGetPetById` + +### 3. **Test: Update Pet** + - **Description**: Updates the details of an existing pet. + - **Criticality**: High - Users must be able to update pet details. + - **Severity**: Critical - Failure results in incorrect or missing pet data. + - **Test Method**: `testUpdatePet` + +### 4. **Test: Delete Pet** + - **Description**: Deletes a pet by its ID. + - **Criticality**: Medium - Required for removing pets from the store. + - **Severity**: Major - Failure results in the inability to delete pets. + - **Test Method**: `testDeletePet` + +### 5. **Test: Find Pets by Status** + - **Description**: Finds pets by their status (e.g., available, sold). + - **Criticality**: Medium - Helps filter pets for customers. + - **Severity**: Moderate - Failure impacts search functionality but has workarounds. + - **Test Method**: `testFindPetsByStatus` + +### 6. **Test: Find Pets by Tags** + - **Description**: Finds pets by tags. + - **Criticality**: Low - An auxiliary feature to filter pets. + - **Severity**: Minor - Failure would affect convenience but not core functionality. + - **Test Method**: `test_06_FindPetsByTags` + +--- + +## Store API Tests + +### 7. **Test: Get Inventory** + - **Description**: Retrieves the store's inventory. + - **Criticality**: Medium - Essential for tracking available pets. + - **Severity**: Major - Failure impacts stock management and business operations. + - **Test Method**: `testGetInventory` + +### 8. **Test: Place Order** + - **Description**: Places an order for a pet. + - **Criticality**: High - A primary business operation. + - **Severity**: Critical - Failure prevents customers from purchasing pets. + - **Test Method**: `testPlaceOrder` + +### 9. **Test: Get Order by ID** + - **Description**: Retrieves an order by its ID. + - **Criticality**: Medium - Important for tracking orders. + - **Severity**: Major - Failure makes it difficult to monitor specific orders. + - **Test Method**: `testGetOrderById` + +### 10. **Test: Delete Order** + - **Description**: Deletes an order by its ID. + - **Criticality**: Medium - Needed for order cancellations. + - **Severity**: Major - Failure causes order retention issues. + - **Test Method**: `testDeleteOrder` + +--- + +## User API Tests + +### 11. **Test: Create User** + - **Description**: Creates a new user. + - **Criticality**: High - Crucial for customer management. + - **Severity**: Critical - Failure stops user creation and system usability. + - **Test Method**: `testCreateUser` + +### 12. **Test: Get User by Username** + - **Description**: Retrieves user details by username. + - **Criticality**: High - Essential for retrieving user information. + - **Severity**: Major - Failure results in inability to fetch user data. + - **Test Method**: `testGetUserByUsername` + +### 13. **Test: Update User** + - **Description**: Updates an existing user's details. + - **Criticality**: Medium - Important for keeping user information up to date. + - **Severity**: Major - Failure causes incorrect user data in the system. + - **Test Method**: `testUpdateUser` + +### 14. **Test: Delete User** + - **Description**: Deletes a user by username. + - **Criticality**: Medium - Needed for account management. + - **Severity**: Major - Failure results in retained user accounts. + - **Test Method**: `testDeleteUser` + +### 15. **Test: Login User** + - **Description**: Logs in a user using username and password. + - **Criticality**: High - Required for user authentication. + - **Severity**: Critical - Failure results in inability to access user accounts. + - **Test Method**: `testLoginUser` + +### 16. **Test: Logout User** + - **Description**: Logs out the current user. + - **Criticality**: Medium - A security feature for account sessions. + - **Severity**: Minor - Failure impacts session management but not core functionality. + - **Test Method**: `testLogoutUser` + +--- + +## Bug Tests + +### 17. **Test: Login Missing User and Password** + - **Description**: Tests login when username and password are missing. + - **Criticality**: High - Bug test for correct error handling. + - **Severity**: Critical - Failure means insecure login behavior. + - **Test Method**: `testLogin_MissingUserAndPassword` + +### 18. **Test: Login Invalid User and Password** + - **Description**: Tests login with empty username and password. + - **Criticality**: High - Ensures validation for login credentials. + - **Severity**: Critical - Failure results in insecure login behavior. + - **Test Method**: `testLogin_InvalidUserAndPassword` + +### 19. **Test: Create User Missing Username** + - **Description**: Tests user creation without a username. + - **Criticality**: High - Validates the requirement for usernames. + - **Severity**: Critical - Failure leads to invalid user creation. + - **Test Method**: `testCreateUser_missingUsername` + +### 20. **Test: Create User Missing Password** + - **Description**: Tests user creation without a password. + - **Criticality**: High - Ensures password validation. + - **Severity**: Critical - Failure leads to invalid user creation and security issues. + - **Test Method**: `testCreateUser_missingPassword` diff --git a/src/test/java/.DS_Store b/src/test/java/.DS_Store index 24d39a3b4824f29462b54220f2cc5bb8383375fd..1ecacf0c9984744180b70873db0a9fcd58fd7854 100644 GIT binary patch delta 21 ccmZoMXffEZjETd@%tA-O(A<3UI;JpD07w=FA^-pY delta 21 ccmZoMXffEZjETe0$V^AU(8O@_I;JpD07r@j5&!@I From e8770bab2b2f4b65d1cbadb4b5694cff862742e7 Mon Sep 17 00:00:00 2001 From: Matheus Marques Colares Date: Mon, 21 Oct 2024 14:00:24 -0300 Subject: [PATCH 4/5] add test results file --- src/test/java/performance/petStore_Test Plan.jmx | 16 ++++++++-------- .../java/performance/results/test_results.xml | 11 +++++++++++ 2 files changed, 19 insertions(+), 8 deletions(-) create mode 100644 src/test/java/performance/results/test_results.xml diff --git a/src/test/java/performance/petStore_Test Plan.jmx b/src/test/java/performance/petStore_Test Plan.jmx index a0734717..81e34909 100644 --- a/src/test/java/performance/petStore_Test Plan.jmx +++ b/src/test/java/performance/petStore_Test Plan.jmx @@ -10,8 +10,8 @@ - 500 - 120 + 10 + 30 true continue @@ -20,7 +20,7 @@ - + localhost 8080 /api/v3/store/order @@ -60,7 +60,7 @@ - + randomId @@ -109,7 +109,7 @@ true - + /Users/matheusmarquescolares/IdeaProjects/swagger-petstore/src/test/java/performance/results/test_results.xml @@ -146,7 +146,7 @@ true - + /Users/matheusmarquescolares/IdeaProjects/swagger-petstore/src/test/java/performance/results/test_results.xml @@ -183,7 +183,7 @@ true - + /Users/matheusmarquescolares/IdeaProjects/swagger-petstore/src/test/java/performance/results/test_results.xml @@ -220,7 +220,7 @@ true - + /Users/matheusmarquescolares/IdeaProjects/swagger-petstore/src/test/java/performance/results/test_results.xml diff --git a/src/test/java/performance/results/test_results.xml b/src/test/java/performance/results/test_results.xml new file mode 100644 index 00000000..c4229921 --- /dev/null +++ b/src/test/java/performance/results/test_results.xml @@ -0,0 +1,11 @@ +timeStamp,elapsed,label,responseCode,responseMessage,threadName,dataType,success,failureMessage,bytes,sentBytes,grpThreads,allThreads,URL,Latency,IdleTime,Connect +1729529898462,230,HTTP Request,200,OK,Thread Group 1-1,text,true,,465,358,1,1,http://localhost:8080/api/v3/store/order,224,0,69 +1729529901354,8,HTTP Request,200,OK,Thread Group 1-2,text,true,,465,358,1,1,http://localhost:8080/api/v3/store/order,8,0,2 +1729529904358,7,HTTP Request,200,OK,Thread Group 1-3,text,true,,465,358,1,1,http://localhost:8080/api/v3/store/order,7,0,1 +1729529907357,8,HTTP Request,200,OK,Thread Group 1-4,text,true,,465,358,1,1,http://localhost:8080/api/v3/store/order,8,0,1 +1729529910358,6,HTTP Request,200,OK,Thread Group 1-5,text,true,,465,358,1,1,http://localhost:8080/api/v3/store/order,6,0,1 +1729529913356,7,HTTP Request,200,OK,Thread Group 1-6,text,true,,464,357,1,1,http://localhost:8080/api/v3/store/order,7,0,1 +1729529916355,7,HTTP Request,200,OK,Thread Group 1-7,text,true,,465,358,1,1,http://localhost:8080/api/v3/store/order,7,0,1 +1729529919357,6,HTTP Request,200,OK,Thread Group 1-8,text,true,,464,357,1,1,http://localhost:8080/api/v3/store/order,6,0,1 +1729529922356,6,HTTP Request,200,OK,Thread Group 1-9,text,true,,465,358,1,1,http://localhost:8080/api/v3/store/order,6,0,1 +1729529925356,6,HTTP Request,200,OK,Thread Group 1-10,text,true,,465,358,1,1,http://localhost:8080/api/v3/store/order,6,0,1 From 8d53e8c9eb8ce774e1ec529c48b05d87e81ed05b Mon Sep 17 00:00:00 2001 From: Matheus Marques Colares Date: Mon, 21 Oct 2024 14:19:10 -0300 Subject: [PATCH 5/5] add instructions for reporting file in README file --- .DS_Store | Bin 6148 -> 6148 bytes README.md | 3 ++- src/.DS_Store | Bin 6148 -> 6148 bytes 3 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.DS_Store b/.DS_Store index d687949dc61049b60515512cde5d528b86880dc8..e484d93bd3cb6c5d829a481bea878d11ced20c84 100644 GIT binary patch delta 62 zcmV-E0Kxx+FoZCWVFS5haFg)?r;{)g1d|T|5&^lBA^~v=8GCy&HaILGF*i4podFyH Ui<7zm9|4TB+5s#Evj+(M4}QuMivR!s delta 61 zcmV-D0K)%-FoZCWVFS2gaFg)?r;{)g1d|T|5&^iAA^~v<7<+pyGB_+CH8PW)0UQB} Tle+;Q0gJQS0W1cy1_=HSY(x`B diff --git a/README.md b/README.md index a48af86f..1d794a37 100644 --- a/README.md +++ b/README.md @@ -66,4 +66,5 @@ Start JMeter ``` #### 3. Open the test plan and run the test 1. In JMeter click on the open iIcon and select the test plan file for Pet Store performance test "petStore_Test Plan.jmx"(src/test/java/performance) -2. Click on the green **Start** button in the toolbar to run the test. +2. After opening the test plan you will see four listeners (View Results Tree, Summary Report, Aggregate Report and Response Time Graph). Make sure the "Write results to file" path is pointing to the results file available on the projects performance folder (src/test/java/performance/results/test_results.xml) +32. Click on the green **Start** button in the toolbar to run the test. diff --git a/src/.DS_Store b/src/.DS_Store index 7ea0f692ab55cc20d3551ff067601475b2c36ef0..c3efaeb19d7ebf4ee72c95f88def47176a67b740 100644 GIT binary patch delta 60 zcmZoMXfc?O%(!zhBh&K91|lqz`58rkJQc=5ZprFuBQpyf1w(W5$@3Xy7`rF$VU%a= P*?fmli)}MI$6tN`9u5)G delta 59 zcmZoMXfc?O%(!DRBh&K91|lqz`58rkJQc=5E{W=DT_Xz}1yiHR3m9b>yC&~tlxOVT Oe3wy+Z8ICkKYjoWM-h$y