From 73fd87a2c8c30b14bfc3f22733cac44d32a80306 Mon Sep 17 00:00:00 2001 From: Sarthak Shyngle <50234097+Sarthak160@users.noreply.github.com> Date: Tue, 11 Mar 2025 00:42:21 +0530 Subject: [PATCH 1/3] docs: add support for xml Signed-off-by: Sarthak Shyngle <50234097+Sarthak160@users.noreply.github.com> --- .../quickstart/java-spring-boot-xml.md | 142 ++++++++++++++++++ 1 file changed, 142 insertions(+) create mode 100644 versioned_docs/version-2.0.0/quickstart/java-spring-boot-xml.md diff --git a/versioned_docs/version-2.0.0/quickstart/java-spring-boot-xml.md b/versioned_docs/version-2.0.0/quickstart/java-spring-boot-xml.md new file mode 100644 index 000000000..6a449a41b --- /dev/null +++ b/versioned_docs/version-2.0.0/quickstart/java-spring-boot-xml.md @@ -0,0 +1,142 @@ +--- +id: java-spring-boot-xml +title: Sample REST API with Spring-Boot and XML +sidebar_label: XML API App +description: This CRUD Application demonstrates REST API endpoints that serve XML responses using Spring Boot. +tags: + - java + - spring-boot + - xml + - quickstart + - samples + - examples + - tutorial + - restful-api +keyword: + - XML + - Maven + - Springboot Framework + - REST API + - Java + - API Test generator + - Auto Testcase generation + - JAXB +--- + +## Introduction + +🌟 Explore creating REST APIs with XML responses using [Spring-Boot](https://github.com/spring-projects/spring-boot). Discover the ease of integrating XML serialization through JAXB. Let's dive right in! 🚀 + +## Pre-Requisite 🛠️ + +- Install [Java 17](https://www.oracle.com/java/technologies/downloads/) and set JAVA_HOME environment variable. +- Install [Maven](https://maven.apache.org/install.html) +- Install [Docker](https://docs.docker.com/engine/install/) (optional) + +## Get Started! 🎬 + +### Clone and Build the Application + +```bash +git clone https://github.com/your-repository/spring-boot-xml-app.git +cd spring-boot-xml-app +mvn clean install +``` + +### Run the Application + +Start the Spring Boot application with: + +```bash +mvn spring-boot:run +``` + +> **Note**: For Windows users, commands remain the same. + +## API Endpoints 📡 + +### Get User Data (XML) + +- **Endpoint**: `GET /api/user` + +Make a request using `curl`: + +```bash +curl -X GET -H \"Accept: application/xml\" http://localhost:8080/api/user +``` + +### Example XML Response + +```xml + + John Doe + 30 + 0101233333 + +``` + +## Integrating with Keploy 📥 + +Harness Keploy's test generation capabilities easily: + +### Install Keploy + +```bash +curl --silent --location \"https://github.com/keploy/keploy/releases/latest/download/keploy_linux_amd64.tar.gz\" | tar xz -C /tmp +sudo mkdir -p /usr/local/bin && sudo mv /tmp/keploy /usr/local/bin && keploy +``` + +### Record Test Cases + +Start recording interactions by running: + +```bash +keploy record -c \"mvn spring-boot:run\" +``` + +Then, invoke the API using `curl` or your favorite API testing tool. + +### Run Generated Tests + +Execute recorded tests: + +```bash +keploy test -c \"mvn spring-boot:run\" --delay 10 +``` + +Review generated test reports in `Keploy/reports`. + +## Handling Failing Tests ⚠️ + +If you encounter failing tests due to variable or irrelevant data, like timestamps or dynamically generated fields, you can add them to the global noise configuration in your `keploy.yml`: + +**Example:** + +```yaml +globalNoise: + global: + header.Date: [] + body: + # To ignore some values for a field, pass regex patterns to the corresponding array value + UserList: [] +``` + +Here is a screenshot of a failing test example (replace this with your actual screenshot): + +![Failing Test Example](paste-your-screenshot-here.png) + +After updating `keploy.yml` with the above configuration, rerun your tests, and the issue should be resolved. + +## Dependencies 📚 + +- Spring Boot +- Spring Web +- JAXB (XML serialization) + +## Wrapping Up 🎉 + +Fantastic! You've successfully navigated creating and testing XML APIs with Spring Boot and Keploy. Keep exploring, experimenting, and innovating! If you have any queries, we're here to help! + +import GetSupport from '../concepts/support.md' + + From 56e91b051a4e9842a46272f8da0971f487318311 Mon Sep 17 00:00:00 2001 From: Sarthak Shyngle <50234097+Sarthak160@users.noreply.github.com> Date: Tue, 11 Mar 2025 00:57:49 +0530 Subject: [PATCH 2/3] Update java-spring-boot-xml.md Signed-off-by: Sarthak Shyngle <50234097+Sarthak160@users.noreply.github.com> --- .../quickstart/java-spring-boot-xml.md | 31 +++++++++++++------ 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/versioned_docs/version-2.0.0/quickstart/java-spring-boot-xml.md b/versioned_docs/version-2.0.0/quickstart/java-spring-boot-xml.md index 6a449a41b..5a22f6cf7 100644 --- a/versioned_docs/version-2.0.0/quickstart/java-spring-boot-xml.md +++ b/versioned_docs/version-2.0.0/quickstart/java-spring-boot-xml.md @@ -38,8 +38,8 @@ keyword: ### Clone and Build the Application ```bash -git clone https://github.com/your-repository/spring-boot-xml-app.git -cd spring-boot-xml-app +git clone https://github.com/keploy/samples-java.git +cd spring-boot-xml/naive-spring-boot mvn clean install ``` @@ -82,16 +82,27 @@ Harness Keploy's test generation capabilities easily: ### Install Keploy ```bash -curl --silent --location \"https://github.com/keploy/keploy/releases/latest/download/keploy_linux_amd64.tar.gz\" | tar xz -C /tmp -sudo mkdir -p /usr/local/bin && sudo mv /tmp/keploy /usr/local/bin && keploy + curl --silent -O -L https://keploy.io/install.sh && source install.sh +``` + +or + +### Install the cloud version - + +```bash + curl --silent -O -L https://keploy.io/ent/install.sh && source install.sh ``` ### Record Test Cases +```bash +keploy record -c "java -jar target/XML-0.0.1-SNAPSHOT.jar" +``` + Start recording interactions by running: ```bash -keploy record -c \"mvn spring-boot:run\" +keploy record -c "java -jar target/XML-0.0.1-SNAPSHOT.jar" ``` Then, invoke the API using `curl` or your favorite API testing tool. @@ -101,7 +112,7 @@ Then, invoke the API using `curl` or your favorite API testing tool. Execute recorded tests: ```bash -keploy test -c \"mvn spring-boot:run\" --delay 10 +keploy test -c "java -jar target/XML-0.0.1-SNAPSHOT.jar" --delay 10 ``` Review generated test reports in `Keploy/reports`. @@ -112,6 +123,8 @@ If you encounter failing tests due to variable or irrelevant data, like timestam **Example:** +Screenshot 2025-03-11 at 12 07 04 AM + ```yaml globalNoise: global: @@ -121,12 +134,10 @@ globalNoise: UserList: [] ``` -Here is a screenshot of a failing test example (replace this with your actual screenshot): - -![Failing Test Example](paste-your-screenshot-here.png) - After updating `keploy.yml` with the above configuration, rerun your tests, and the issue should be resolved. +Screenshot 2025-03-11 at 12 07 19 AM + ## Dependencies 📚 - Spring Boot From 96176a1c8e55ce7bb2a8b8eecbad7548a2f01b41 Mon Sep 17 00:00:00 2001 From: Sarthak Shyngle <50234097+Sarthak160@users.noreply.github.com> Date: Tue, 11 Mar 2025 01:11:39 +0530 Subject: [PATCH 3/3] docs: add support for xml Signed-off-by: Sarthak Shyngle <50234097+Sarthak160@users.noreply.github.com> --- .../quickstart/java-spring-boot-xml.md | 16 ++++++++++++++++ .../running-keploy/configuration-file.md | 2 ++ 2 files changed, 18 insertions(+) diff --git a/versioned_docs/version-2.0.0/quickstart/java-spring-boot-xml.md b/versioned_docs/version-2.0.0/quickstart/java-spring-boot-xml.md index 5a22f6cf7..f7780cb54 100644 --- a/versioned_docs/version-2.0.0/quickstart/java-spring-boot-xml.md +++ b/versioned_docs/version-2.0.0/quickstart/java-spring-boot-xml.md @@ -65,6 +65,22 @@ Make a request using `curl`: curl -X GET -H \"Accept: application/xml\" http://localhost:8080/api/user ``` +- **Endpoint**: `GET /api/users` + +Make a request using `curl`: + +```bash +curl -X GET http://localhost:8080/api/users -H "Accept: application/xml" +``` + +- **Endpoint**: `GET /api/people` + +Make a request using `curl`: + +```bash +curl -X GET http://localhost:8080/api/people -H "Accept: application/xml" +``` + ### Example XML Response ```xml diff --git a/versioned_docs/version-2.0.0/running-keploy/configuration-file.md b/versioned_docs/version-2.0.0/running-keploy/configuration-file.md index 6e70a788e..ee6860b10 100644 --- a/versioned_docs/version-2.0.0/running-keploy/configuration-file.md +++ b/versioned_docs/version-2.0.0/running-keploy/configuration-file.md @@ -270,6 +270,8 @@ Earlier the only way to add the [noisy fields](http://keploy.io/docs/concepts/ge The `global subsection` of `globalNoise` is used to define parameters that are globally ignored for all API calls during testing. It enables you to filter out consistent noise, ensuring a cleaner evaluation of responses. +**Note** - The examples below support both the xml as well as the json type responses. + ```yml globalNoise: global: {body: {