Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Challenge solution #162

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
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
Binary file added .DS_Store
Binary file not shown.
26 changes: 26 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,29 @@ This tells you that the server is up and ready to demonstrate Swagger.

### Using the UI
There is an HTML5-based API tool bundled in this sample--you can view it it at [http://localhost:8080](http://localhost:8080). This lets you inspect the API using an interactive UI. You can access the source of this code from [here](https://github.com/swagger-api/swagger-ui)

### To run API tests
```
mvn test
```

### To run performance tests (JMeter)
#### Step 1: Download and install JMeter
1. Visit the [Apache JMeter download page](https://jmeter.apache.org/download_jmeter.cgi)
2. Download the latest binary distribution (usually in .tgz format)
3. Extract the downloaded file to a desired location:
```
tar -xvzf apache-jmeter-<version>.tgz
```
#### Step 2: Open JMeter
```
cd apache-jmeter-<version>/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. 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.
14 changes: 14 additions & 0 deletions node_modules/.package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions node_modules/k6/package.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
13 changes: 13 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,19 @@
<artifactId>jackson-databind</artifactId>
<version>${jackson-version}</version>
</dependency>
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>rest-assured</artifactId>
<version>5.4.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>5.7.0</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
Expand Down
Binary file added src/.DS_Store
Binary file not shown.
65 changes: 65 additions & 0 deletions src/main/resources/openapi-inflector.yaml
Original file line number Diff line number Diff line change
@@ -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

Binary file added src/test/.DS_Store
Binary file not shown.
145 changes: 145 additions & 0 deletions src/test/PetstoreAPITestDocument.md
Original file line number Diff line number Diff line change
@@ -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`
Binary file added src/test/java/.DS_Store
Binary file not shown.
5 changes: 0 additions & 5 deletions src/test/java/ip/swagger/petstore/PetStoreTest.java

This file was deleted.

Loading