This repository contains a sample project that demonstrates the integration of Keploy with JWT (JSON Web Token) authentication in a Spring Boot application.
Before getting started, ensure you have the following installed:
- Latest version of JDK
- Keploy
- Docker (if you want to run the application in Docker)
- Postman for testing APIs
To get started, clone the repository:
git clone https://github.com/jaiakash/samples-java.git
cd samples-java/spring-boot-jwtTo run the application locally, follow these steps:
- Build the application:
mvn clean install- Run the application:
java -jar target/spring-boot-jwt.jarTo run the application with Docker, follow these steps:
- Build the Docker image:
docker build -t spring-boot-jwt .- Run the Docker container:
docker run -p 8080:8080 spring-boot-jwtThe application will be accessible at http://localhost:8080.
- To run the application, use:
keploy record -c "java -jar target/spring-boot-jwt.jar"keploy record -c "docker run -p 8080:8080 spring-boot-jwt"- To generate test cases, make API calls using Postman or
curl:
-
Login
curl --location --request POST 'http://localhost:8080/users/login' \ --header 'Content-Type: application/json' \ --data-raw '{ "username": "akash@example.com", "password": "password" }'
-
Verify
curl --location --request POST 'http://localhost:8080/users/tokenVerification' \ --header 'Authorization: Bearer <your_jwt_token_here>'
To test the application, start Keploy in test mode. In the root directory, run the following command:
keploy test -c "java -jar target/spring-boot-jwt.jar" --delay 30keploy test -c "docker run -p 8080:8080 spring-boot-jwt" --delay 30This command will run the tests and generate the report in the Keploy/reports directory in the current working directory.