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

Keploy Integration - Added sample Java application using JWT Token #76

Open
wants to merge 9 commits into
base: main
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
33 changes: 33 additions & 0 deletions spring-boot-jwt/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
HELP.md
target/
!.mvn/wrapper/maven-wrapper.jar
!**/src/main/**/target/
!**/src/test/**/target/

### STS ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache

### IntelliJ IDEA ###
.idea
*.iws
*.iml
*.ipr

### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
build/
!**/src/main/**/build/
!**/src/test/**/build/

### VS Code ###
.vscode/
19 changes: 19 additions & 0 deletions spring-boot-jwt/.mvn/wrapper/maven-wrapper.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
wrapperVersion=3.3.2
distributionType=only-script
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.7/apache-maven-3.9.7-bin.zip
20 changes: 20 additions & 0 deletions spring-boot-jwt/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Use an official OpenJDK runtime as a parent image
FROM openjdk:22-bookworm

# Set the working directory to /app
WORKDIR /app

# Install Maven
RUN apt-get update && apt-get install -y maven

# Copy the current directory contents into the container at /app
jaiakash marked this conversation as resolved.
Show resolved Hide resolved
COPY . /app/

# Run mvn clean install
RUN mvn clean install

# Expose the port the app runs on
EXPOSE 8080

# Run the application when the container launches
CMD ["/usr/share/maven/bin/mvn", "spring-boot:run"]
112 changes: 112 additions & 0 deletions spring-boot-jwt/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
# Keploy Sample Java - JWT Token Verification and Spring Boot

This repository contains a sample project that demonstrates the integration of Keploy with JWT (JSON Web Token) authentication in a Spring Boot application.

## Prerequisites

Before getting started, ensure you have the following installed:

- Latest version of JDK
- [Keploy](https://keploy.io/docs/server/installation/)
- [Docker](https://docs.docker.com/engine/install/) (if you want to run the application in Docker)
- Postman for testing APIs

## Getting Started

To get started, clone the repository:

```bash
git clone https://github.com/jaiakash/samples-java.git
cd samples-java/spring-boot-jwt
```

## Native Usage

To run the application locally, follow these steps:

1. Build the application:

```bash
mvn clean install
```

2. Run the application:

```bash
java -jar target/spring-boot-jwt.jar
```

## Running with Docker

To run the application with Docker, follow these steps:

1. Build the Docker image:

```bash
docker build -t spring-boot-jwt .
```

2. Run the Docker container:

```bash
docker run -p 8080:8080 spring-boot-jwt
```

The application will be accessible at `http://localhost:8080`.

## Integration with Keploy
jaiakash marked this conversation as resolved.
Show resolved Hide resolved

### RECORD Mode

1. To run the application, use:

#### Native Usage

```bash
keploy record -c "java -jar target/spring-boot-jwt.jar"
```

#### Docker Usage

```bash
keploy record -c "docker run -p 8080:8080 spring-boot-jwt"
```

2. To generate test cases, make API calls using Postman or `curl`:

- Login

```bash
curl --location --request POST 'http://localhost:8080/users/login' \
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is the native case removed ..?

These should be the headings

Prerequisites
Getting Started
Native Usage
Docker Usage

  • here only you can write the command to build application image etc.

we dont need API Endpoints/ Running with Docker section

--header 'Content-Type: application/json' \
--data-raw '{
"username": "[email protected]",
"password": "password"
}'
```

- Verify

```bash
curl --location --request POST 'http://localhost:8080/users/tokenVerification' \
jaiakash marked this conversation as resolved.
Show resolved Hide resolved
--header 'Authorization: Bearer <your_jwt_token_here>'
```

### TEST Mode

To test the application, start Keploy in test mode. In the root directory, run the following command:

#### Native Usage

```bash
keploy test -c "java -jar target/spring-boot-jwt.jar" --delay 30
```

#### Docker Usage

```bash
keploy test -c "docker run -p 8080:8080 spring-boot-jwt" --delay 30
```

This command will run the tests and generate the report in the `Keploy/reports` directory in the current working directory.

44 changes: 44 additions & 0 deletions spring-boot-jwt/keploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
path: ""
appId: 0
appName: ""
command: ./mvnw spring-boot:run
port: 0
dnsPort: 26789
proxyPort: 16789
debug: false
disableTele: false
jaiakash marked this conversation as resolved.
Show resolved Hide resolved
disableANSI: false
containerName: ""
networkName: ""
buildDelay: 30
test:
selectedTests: {}
globalNoise:
global:
body: {"token": ["*"]}
test-sets: {}
delay: 5
apiTimeout: 5
skipCoverage: false
coverageReportPath: ""
ignoreOrdering: true
mongoPassword: default@123
language: ""
removeUnusedMocks: false
fallBackOnMiss: false
jacocoAgentPath: ""
basePath: ""
mocking: true
ignoredTests: {}
record:
filters: []
recordTimer: 0s
configPath: ""
bypassRules: []
generateGithubActions: true
keployContainer: keploy-v2
keployNetwork: keploy-network
cmdType: native
inCi: false

# Visit [https://keploy.io/docs/running-keploy/configuration-file/] to learn about using keploy through configration file.
Loading