Skip to content

Commit 28e129c

Browse files
feat: adding new spring-boot mongodb sample app (#56)
Signed-off-by: Shashwat79802 <[email protected]>
1 parent 65feb0b commit 28e129c

File tree

26 files changed

+2362
-0
lines changed

26 files changed

+2362
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ This repo contains the sample for [Keploy's](https://keploy.io) Java Application
1919
## Sample Apps with Keploy
2020

2121
1. [employee-manager](https://github.com/keploy/samples-java/tree/main/employee-manager)
22+
2. [spring-boot-mongo](https://github.com/keploy/samples-java/tree/main/spring-boot-mongo)
2223

2324
## Community Support ❤️
2425

spring-boot-mongo/.gitignore

Lines changed: 217 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,217 @@
1+
2+
# Created by https://www.toptal.com/developers/gitignore/api/macos,linux,jetbrains,visualstudiocode
3+
# Edit at https://www.toptal.com/developers/gitignore?templates=macos,linux,jetbrains,visualstudiocode
4+
5+
### JetBrains ###
6+
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider
7+
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
8+
9+
# User-specific stuff
10+
.idea/
11+
.idea/**/workspace.xml
12+
.idea/**/tasks.xml
13+
.idea/**/usage.statistics.xml
14+
.idea/**/dictionaries
15+
.idea/**/shelf
16+
17+
# AWS User-specific
18+
.idea/**/aws.xml
19+
20+
# Generated files
21+
.idea/**/contentModel.xml
22+
23+
# Sensitive or high-churn files
24+
.idea/**/dataSources/
25+
.idea/**/dataSources.ids
26+
.idea/**/dataSources.local.xml
27+
.idea/**/sqlDataSources.xml
28+
.idea/**/dynamic.xml
29+
.idea/**/uiDesigner.xml
30+
.idea/**/dbnavigator.xml
31+
32+
# Gradle
33+
.idea/**/gradle.xml
34+
.idea/**/libraries
35+
36+
# Gradle and Maven with auto-import
37+
# When using Gradle or Maven with auto-import, you should exclude module files,
38+
# since they will be recreated, and may cause churn. Uncomment if using
39+
auto-import.
40+
.idea/artifacts
41+
.idea/compiler.xml
42+
.idea/jarRepositories.xml
43+
.idea/modules.xml
44+
.idea/*.iml
45+
.idea/modules
46+
*.iml
47+
*.ipr
48+
49+
# CMake
50+
cmake-build-*/
51+
52+
# Mongo Explorer plugin
53+
.idea/**/mongoSettings.xml
54+
55+
# File-based project format
56+
*.iws
57+
58+
# IntelliJ
59+
out/
60+
61+
# mpeltonen/sbt-idea plugin
62+
.idea_modules/
63+
64+
# JIRA plugin
65+
atlassian-ide-plugin.xml
66+
67+
# Cursive Clojure plugin
68+
.idea/replstate.xml
69+
70+
# SonarLint plugin
71+
.idea/sonarlint/
72+
73+
# Crashlytics plugin (for Android Studio and IntelliJ)
74+
com_crashlytics_export_strings.xml
75+
crashlytics.properties
76+
crashlytics-build.properties
77+
fabric.properties
78+
79+
# Editor-based Rest Client
80+
.idea/httpRequests
81+
82+
# Android studio 3.1+ serialized cache file
83+
.idea/caches/build_file_checksums.ser
84+
85+
### JetBrains Patch ###
86+
# Comment Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-215987721
87+
88+
# *.iml
89+
# modules.xml
90+
# .idea/misc.xml
91+
# *.ipr
92+
93+
# Sonarlint plugin
94+
# https://plugins.jetbrains.com/plugin/7973-sonarlint
95+
.idea/**/sonarlint/
96+
97+
# SonarQube Plugin
98+
# https://plugins.jetbrains.com/plugin/7238-sonarqube-community-plugin
99+
.idea/**/sonarIssues.xml
100+
101+
# Markdown Navigator plugin
102+
# https://plugins.jetbrains.com/plugin/7896-markdown-navigator-enhanced
103+
.idea/**/markdown-navigator.xml
104+
.idea/**/markdown-navigator-enh.xml
105+
.idea/**/markdown-navigator/
106+
107+
# Cache file creation bug
108+
# See https://youtrack.jetbrains.com/issue/JBR-2257
109+
.idea/$CACHE_FILE$
110+
111+
# CodeStream plugin
112+
# https://plugins.jetbrains.com/plugin/12206-codestream
113+
.idea/codestream.xml
114+
115+
### Linux ###
116+
*~
117+
118+
# temporary files which can be created if a process still has a handle open of a deleted file
119+
.fuse_hidden*
120+
121+
# KDE directory preferences
122+
.directory
123+
124+
# Linux trash folder which might appear on any partition or disk
125+
.Trash-*
126+
127+
# .nfs files are created when an open file is removed but is still being accessed
128+
.nfs*
129+
130+
### macOS ###
131+
# General
132+
.DS_Store
133+
.AppleDouble
134+
.LSOverride
135+
136+
# Icon must end with two \r
137+
Icon
138+
139+
140+
# Thumbnails
141+
._*
142+
143+
# Files that might appear in the root of a volume
144+
.DocumentRevisions-V100
145+
.fseventsd
146+
.Spotlight-V100
147+
.TemporaryItems
148+
.Trashes
149+
.VolumeIcon.icns
150+
.com.apple.timemachine.donotpresent
151+
152+
# Directories potentially created on remote AFP share
153+
.AppleDB
154+
.AppleDesktop
155+
Network Trash Folder
156+
Temporary Items
157+
.apdisk
158+
159+
### VisualStudioCode ###
160+
.vscode/*
161+
!.vscode/settings.json
162+
!.vscode/tasks.json
163+
!.vscode/launch.json
164+
!.vscode/extensions.json
165+
!.vscode/*.code-snippets
166+
167+
# Local History for Visual Studio Code
168+
.history/
169+
170+
# Built Visual Studio Code Extensions
171+
*.vsix
172+
173+
### VisualStudioCode Patch ###
174+
# Ignore all local history of files
175+
.history
176+
.ionide
177+
.env
178+
target/springbootapp-0.0.1-SNAPSHOT.jar
179+
target/springbootapp-0.0.1-SNAPSHOT.jar.original
180+
.jar
181+
# Support for Project snippet scope
182+
183+
# End of https://www.toptal.com/developers/gitignore/api/macos,linux,jetbrains,visualstudiocode
184+
185+
HELP.md
186+
target/
187+
!.mvn/wrapper/maven-wrapper.jar
188+
!**/src/main/**/target/
189+
!**/src/test/**/target/
190+
191+
### STS ###
192+
.apt_generated
193+
.classpath
194+
.factorypath
195+
.project
196+
.settings
197+
.springBeans
198+
.sts4-cache
199+
200+
### IntelliJ IDEA ###
201+
.idea
202+
*.iws
203+
*.iml
204+
*.ipr
205+
206+
### NetBeans ###
207+
/nbproject/private/
208+
/nbbuild/
209+
/dist/
210+
/nbdist/
211+
/.nb-gradle/
212+
build/
213+
!**/src/main/**/build/
214+
!**/src/test/**/build/
215+
216+
### VS Code ###
217+
.vscode/

spring-boot-mongo/Dockerfile

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Use an official OpenJDK runtime as a parent image
2+
FROM openjdk:22-bookworm
3+
4+
# Set the working directory to /app
5+
WORKDIR /app
6+
7+
# Install Maven
8+
RUN apt-get update && apt-get install -y maven
9+
10+
# Copy the current directory contents into the container at /app
11+
COPY . /app/
12+
13+
# Expose the port the app runs on
14+
EXPOSE 8080
15+
16+
# Define environment variables
17+
ENV MONGODB_URI=mongodb://localhost:27017/Keploy
18+
19+
# Run the application when the container launches
20+
# CMD ["java", "-jar", "PotionsAPI-0.0.1-SNAPSHOT.jar"]
21+
CMD ["/usr/share/maven/bin/mvn", "spring-boot:run"]

spring-boot-mongo/README.md

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
## REST API with Spring-Boot + MongoDB
2+
3+
The application is built purely with Java Spring-Boot that does the complete CRUD in the MongoDB database. This CRUD Application is about managing the data of Magical Potions in the Keploy inventory.
4+
5+
### Pre-Requisites
6+
7+
Make sure you have the following -
8+
9+
1. Latest version of JDK
10+
2. MongoDB Container
11+
3. Postman
12+
13+
14+
### About the API
15+
16+
The API has 5 endpoints - <br>
17+
a. Get `/potions` - Gets the data of all the potions stored in the bank. <br>
18+
b. Get `/potions/{id}` - Gets the data of the potion by its Id. <br>
19+
c. Post `/potions` - Posts the data of the potion to the DB. <br>
20+
d. Put `/potions/{id}` - Updates the data of the potion specified by its id. <br>
21+
e. Delete `/potions/{id}` - Deletes the data of the potion specified by its id. <br>
22+
<br><br>
23+
The potions data should have the following attributes - <br>
24+
a. name - Holds the name of the potion. `String` <br>
25+
b. description - Holds the details of what the potions does. `String` <br>
26+
c. bottle - Specify the number of bottles. `Int` <br>
27+
d. quantity - Holds the total amount of potion the bank has in total. `Int` <br>
28+
29+
30+
### Getting Started
31+
32+
Follow the steps to start the application -
33+
34+
1. Clone the repository:
35+
36+
```bash
37+
git clone https://github.com/keploy/samples-java
38+
```
39+
40+
2. Start the MongoDB instance:
41+
42+
```bash
43+
docker run -p 27017:27017 --name spring-boot-mongo --network backend mongo
44+
```
45+
46+
3. Your application is ready to be executed!!
47+
To start Keploy in record mode, in the root directory, run:
48+
49+
```bash
50+
keploy record -c "./mvnw spring-boot:run"
51+
```
52+
53+
a. Make a `POST` Request:
54+
55+
```bash
56+
curl --location 'http://localhost:8080/potions' \
57+
--header 'Content-Type: application/json' \
58+
--data ' {
59+
"name": "Strength Potion v2",
60+
"description": "Enhances the drinker'\''s physical strength temporarily.",
61+
"bottle": 3,
62+
"quantity": 150
63+
}'
64+
```
65+
66+
b. Make a `GET` Request:
67+
68+
```bash
69+
curl --location --request GET 'http://localhost:8080/potions'
70+
```
71+
72+
c. Make a `PUT` Request:
73+
74+
```bash
75+
curl --location --request PUT 'http://localhost:8080/potions/UUID_OF_POTION' \
76+
--header 'Content-Type: application/json' \
77+
--data ' {
78+
"name": "Strength Potion",
79+
"description": "Enhances the drinker'\''s physical strength temporarily.",
80+
"bottle": 5,
81+
"quantity": 200
82+
}'
83+
```
84+
85+
Replace the placeholder `UUID_OF_POTION` with the UUID of the potion you want to update.
86+
87+
d. Make a `GET` Request using ID:
88+
89+
```bash
90+
curl --location --request GET 'http://localhost:8080/potions/UUID_OF_POTION'
91+
```
92+
93+
Replace the placeholder `UUID_OF_POTION` with the UUID of the potion you want to get.
94+
95+
e. Make a `DELETE` Request:
96+
97+
```bash
98+
curl --location --request DELETE 'http://localhost:8080/potions/UUID_OF_POTION'
99+
```
100+
101+
Replace the placeholder `UUID_OF_POTION` with the UUID of the potion you want to delete.
102+
103+
You can try experimenting with the data given in `potions.json` file by taking the data of each potion individually.
104+
105+
The generated tests and mocks are stored in the `Keploy` directory in the CWD.
106+
107+
4. To test the app, start Keploy in test mode. In the root directory, run:
108+
109+
```bash
110+
keploy test -c "./mvnw spring-boot:run" --delay 15
111+
```
112+
113+
This will run the tests and generate the report in the `Keploy/reports` directory in the CWD.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
version: '3'
2+
3+
services:
4+
spring-boot-mongo:
5+
image: mongo:latest
6+
container_name: spring-boot-mongo
7+
ports:
8+
- "27017:27017"
9+
networks:
10+
- backend
11+
12+
networks:
13+
backend:
14+
driver: bridge

0 commit comments

Comments
 (0)