diff --git a/pom.xml b/pom.xml index db6c2c51..93c6f9d8 100644 --- a/pom.xml +++ b/pom.xml @@ -1,89 +1,195 @@ - - - 4.0.0 - - org.springframework.boot - spring-boot-starter-parent - 3.0.5 - - - com.bootexample4 - products - 0.0.1-SNAPSHOT - products - Demo project for Spring Boot - - 17 - - - - org.springframework.boot - spring-boot-starter-data-jpa - - - - org.mock-server - mockserver-netty - 3.10.8 - - - org.mock-server - mockserver-client-java - 3.10.8 - - - org.springframework.boot - spring-boot-starter-web - - - - com.h2database - h2 - runtime - - - org.springframework.boot - spring-boot-starter-test - test - - - - io.cucumber - cucumber-spring - 7.0.0 - test + + + 4.0.0 + + org.springframework.boot + spring-boot-starter-parent + 3.0.5 + + + + com.bootexample4 + products + 0.0.1-SNAPSHOT + products + Demo project for Spring Boot + + 17 + + + + org.springframework.boot + spring-boot-starter-data-jpa + + + + org.mock-server + mockserver-netty + 3.10.8 + + + org.mock-server + mockserver-client-java + 3.10.8 + + + org.springframework.boot + spring-boot-starter-web + + + com.h2database + h2 + runtime + + + org.springframework.boot + spring-boot-starter-test + test + + + + io.cucumber + cucumber-spring + 7.0.0 + test - io.cucumber - cucumber-java - 7.0.0 - test + io.cucumber + cucumber-java + 7.0.0 + test - io.cucumber - cucumber-junit - 7.0.0 - test + io.cucumber + cucumber-junit + 7.0.0 + test - org.assertj - assertj-core - 3.19.0 - test - - - - - - - org.springframework.boot - spring-boot-maven-plugin - - - - - + org.assertj + assertj-core + 3.19.0 + test + + + io.spring.javaformat + spring-javaformat-formatter + 0.0.40 + + + + org.junit.jupiter + junit-jupiter + 5.9.2 + test + + + + org.junit.jupiter + junit-jupiter-api + 5.9.2 + test + + + + org.junit.jupiter + junit-jupiter-engine + 5.9.2 + test + + + + org.junit.jupiter + junit-jupiter-params + 5.9.2 + test + + + + org.junit.platform + junit-platform-suite + 1.9.2 + test + + + + org.junit.platform + junit-platform-suite-api + 1.9.2 + test + + + + org.junit.platform + junit-platform-suite-engine + 1.9.2 + test + + + + org.junit.platform + junit-platform-suite-commons + 1.9.2 + test + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + io.spring.javaformat + spring-javaformat-maven-plugin + 0.0.40 + + + + org.jacoco + jacoco-maven-plugin + 0.8.7 + + + + prepare-agent + + + + report + test + + report + + + coverageReport + + + + + + + org.apache.maven.plugins + maven-surefire-report-plugin + 3.2.5 + + testReport + + + + + org.apache.maven.plugins + maven-site-plugin + 2.1 + + testReport + + + + + + \ No newline at end of file diff --git a/src/main/java/com/bootexample4/products/controller/ProductController.java b/src/main/java/com/bootexample4/products/controller/ProductController.java index 0d945087..1f7f8133 100644 --- a/src/main/java/com/bootexample4/products/controller/ProductController.java +++ b/src/main/java/com/bootexample4/products/controller/ProductController.java @@ -13,44 +13,43 @@ @RequestMapping("/api/products") public class ProductController { - @Autowired - private ProductRepository productRepository; - - @GetMapping - public List getAllProducts() { - return productRepository.findAll(); - } - - @PostMapping - public Product createProduct(@RequestBody Product product) { - return productRepository.save(product); - } - - @GetMapping("/{id}") - public ResponseEntity getProductById(@PathVariable Long id) { - return productRepository.findById(id) - .map(product -> ResponseEntity.ok().body(product)) - .orElse(ResponseEntity.notFound().build()); - } - - @PutMapping("/{id}") - public ResponseEntity updateProduct(@PathVariable Long id, @RequestBody Product product) { - return productRepository.findById(id) - .map(existingProduct -> { - existingProduct.setName(product.getName()); - existingProduct.setDescription(product.getDescription()); - existingProduct.setPrice(product.getPrice()); - Product updatedProduct = productRepository.save(existingProduct); - return ResponseEntity.ok().body(updatedProduct); - }).orElse(ResponseEntity.notFound().build()); - } - - @DeleteMapping("/{id}") - public ResponseEntity deleteProduct(@PathVariable Long id) { - return productRepository.findById(id) - .map(product -> { - productRepository.delete(product); - return ResponseEntity.ok().build(); - }).orElse(ResponseEntity.notFound().build()); - } + @Autowired + private ProductRepository productRepository; + + @GetMapping + public List getAllProducts() { + return productRepository.findAll(); + } + + @PostMapping + public Product createProduct(@RequestBody Product product) { + return productRepository.save(product); + } + + @GetMapping("/{id}") + public ResponseEntity getProductById(@PathVariable Long id) { + return productRepository.findById(id) + .map(product -> ResponseEntity.ok().body(product)) + .orElse(ResponseEntity.notFound().build()); + } + + @PutMapping("/{id}") + public ResponseEntity updateProduct(@PathVariable Long id, @RequestBody Product product) { + return productRepository.findById(id).map(existingProduct -> { + existingProduct.setName(product.getName()); + existingProduct.setDescription(product.getDescription()); + existingProduct.setPrice(product.getPrice()); + Product updatedProduct = productRepository.save(existingProduct); + return ResponseEntity.ok().body(updatedProduct); + }).orElse(ResponseEntity.notFound().build()); + } + + @DeleteMapping("/{id}") + public ResponseEntity deleteProduct(@PathVariable Long id) { + return productRepository.findById(id).map(product -> { + productRepository.delete(product); + return ResponseEntity.ok().build(); + }).orElse(ResponseEntity.notFound().build()); + } + } \ No newline at end of file diff --git a/src/main/java/com/bootexample4/products/model/Product.java b/src/main/java/com/bootexample4/products/model/Product.java index adfb0186..6da04f2d 100644 --- a/src/main/java/com/bootexample4/products/model/Product.java +++ b/src/main/java/com/bootexample4/products/model/Product.java @@ -8,45 +8,46 @@ @Entity public class Product { - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - private Long id; + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; - private String name; + private String name; - private String description; + private String description; - private double price; + private double price; - public Long getId() { - return id; - } + public Long getId() { + return id; + } - public void setId(Long id) { - this.id = id; - } + public void setId(Long id) { + this.id = id; + } - public String getName() { - return name; - } + public String getName() { + return name; + } - public void setName(String name) { - this.name = name; - } + public void setName(String name) { + this.name = name; + } - public String getDescription() { - return description; - } + public String getDescription() { + return description; + } - public void setDescription(String description) { - this.description = description; - } + public void setDescription(String description) { + this.description = description; + } - public double getPrice() { - return price; - } + public double getPrice() { + return price; + } + + public void setPrice(double price) { + this.price = price; + } - public void setPrice(double price) { - this.price = price; - } } \ No newline at end of file diff --git a/src/main/java/com/bootexample4/products/repository/ProductRepository.java b/src/main/java/com/bootexample4/products/repository/ProductRepository.java index 31b9f65b..c001aead 100644 --- a/src/main/java/com/bootexample4/products/repository/ProductRepository.java +++ b/src/main/java/com/bootexample4/products/repository/ProductRepository.java @@ -4,6 +4,6 @@ import com.bootexample4.products.model.Product; -public interface ProductRepository extends JpaRepository{ - +public interface ProductRepository extends JpaRepository { + } diff --git a/src/test/java/com/bootexample4/products/ProductsApplicationTests.java b/src/test/java/com/bootexample4/products/ProductsApplicationTests.java index 5c09e10b..9bebec28 100644 --- a/src/test/java/com/bootexample4/products/ProductsApplicationTests.java +++ b/src/test/java/com/bootexample4/products/ProductsApplicationTests.java @@ -12,16 +12,16 @@ class ProductsApplicationTests { @Autowired - private ProductRepository productRepo; + private ProductRepository productRepo; @Test public void testCreate() { - Product p=new Product(); + Product p = new Product(); p.setName("product-1"); p.setPrice(34.68); p.setDescription("video game"); - - TestMockServer.createExpectationForAddNewProduct(p,200,"127.0.0.1",3000); + + TestMockServer.createExpectationForAddNewProduct(p, 200, "127.0.0.1", 3000); // productRepo.save(p); assertNotNull(productRepo.findById(1L).get()); diff --git a/src/test/java/com/bootexample4/products/TestMockServer.java b/src/test/java/com/bootexample4/products/TestMockServer.java index cfa7963a..7f0cbc51 100644 --- a/src/test/java/com/bootexample4/products/TestMockServer.java +++ b/src/test/java/com/bootexample4/products/TestMockServer.java @@ -10,27 +10,22 @@ import com.bootexample4.products.model.Product; public class TestMockServer { - - public static void createExpectationForAddNewProduct(Product p, int statuscode,String host, int port ) { - new MockServerClient(host, port, "/mockserver") - .when( - HttpRequest.request(null) - .withMethod("POST") - .withPath("/api/products"). - withHeader("\"Content-type\", \"application/json\"") - .withBody(p.toString()), - Times.exactly(1)) - .respond( - HttpResponse.response() - .withStatusCode(statuscode) - .withHeaders( - new Header("Content-Type", "application/json; charset=utf-8"), - new Header("Cache-Control", "public, max-age=86400") - ) - .withBody("successfully added product") - .withDelay(TimeUnit.SECONDS,1) - ); - } + + public static void createExpectationForAddNewProduct(Product p, int statuscode, String host, int port) { + new MockServerClient(host, port, "/mockserver") + .when(HttpRequest.request(null) + .withMethod("POST") + .withPath("/api/products") + .withHeader("\"Content-type\", \"application/json\"") + .withBody(p.toString()), Times.exactly(1)) + .respond(HttpResponse.response() + .withStatusCode(statuscode) + .withHeaders(new Header("Content-Type", "application/json; charset=utf-8"), + new Header("Cache-Control", "public, max-age=86400")) + .withBody("successfully added product") + .withDelay(TimeUnit.SECONDS, 1)); + } + } -//"" +// "" diff --git a/src/test/java/com/bootexample4/products/controller/ProductControllerCreateProductTest.java b/src/test/java/com/bootexample4/products/controller/ProductControllerCreateProductTest.java new file mode 100644 index 00000000..8e2acb97 --- /dev/null +++ b/src/test/java/com/bootexample4/products/controller/ProductControllerCreateProductTest.java @@ -0,0 +1,169 @@ +// ********RoostGPT******** +/* +Test generated by RoostGPT for test java-springboot using AI Type Claude AI and AI Model claude-3-opus-20240229 + +ROOST_METHOD_HASH=createProduct_16b670a647 +ROOST_METHOD_SIG_HASH=createProduct_36b748883e + +Here are the JUnit test scenarios for the provided createProduct method: + +Scenario 1: Create a new product successfully + +Details: + TestName: createProductWithValidData + Description: This test verifies that the createProduct method successfully creates a new product when provided with valid product data. +Execution: + Arrange: Create a valid Product object with all required fields set. + Act: Invoke the createProduct method with the prepared Product object. + Assert: Use assertions to check that the returned Product object has a non-null ID, indicating successful persistence in the database. +Validation: + The assertion ensures that the product is successfully saved in the database by the productRepository.save() method. + This test is important to validate that the basic functionality of creating a new product works as expected. + +Scenario 2: Create a product with missing required fields + +Details: + TestName: createProductWithMissingRequiredFields + Description: This test checks the behavior of the createProduct method when a Product object with missing required fields is provided. +Execution: + Arrange: Create a Product object with one or more required fields set to null or empty. + Act: Invoke the createProduct method with the prepared Product object. + Assert: Use assertions to verify that an appropriate exception (e.g., ValidationException) is thrown, indicating that the product cannot be created due to missing required fields. +Validation: + The assertion ensures that the createProduct method validates the input and throws an exception when required fields are missing. + This test is crucial to maintain data integrity and prevent incomplete or invalid products from being persisted in the database. + +Scenario 3: Create a product with invalid field values + +Details: + TestName: createProductWithInvalidFieldValues + Description: This test verifies the behavior of the createProduct method when a Product object with invalid field values is provided. +Execution: + Arrange: Create a Product object with one or more fields set to invalid values (e.g., negative price, invalid category). + Act: Invoke the createProduct method with the prepared Product object. + Assert: Use assertions to check that an appropriate exception (e.g., ValidationException) is thrown, indicating that the product cannot be created due to invalid field values. +Validation: + The assertion ensures that the createProduct method validates the input and throws an exception when field values are invalid. + This test is important to maintain data integrity and prevent products with invalid or inconsistent data from being persisted in the database. + +Scenario 4: Create a product with duplicate unique field values + +Details: + TestName: createProductWithDuplicateUniqueFields + Description: This test checks the behavior of the createProduct method when a Product object with duplicate values for unique fields (e.g., SKU) is provided. +Execution: + Arrange: Create a Product object with field values that already exist in the database for unique fields. + Act: Invoke the createProduct method with the prepared Product object. + Assert: Use assertions to verify that an appropriate exception (e.g., DuplicateKeyException) is thrown, indicating that the product cannot be created due to duplicate unique field values. +Validation: + The assertion ensures that the createProduct method enforces uniqueness constraints on specific fields and prevents duplicate products from being created. + This test is crucial to maintain data integrity and avoid inconsistencies or conflicts in the database. + +Scenario 5: Create a product with null input + +Details: + TestName: createProductWithNullInput + Description: This test verifies the behavior of the createProduct method when a null Product object is provided. +Execution: + Arrange: Set the input Product object to null. + Act: Invoke the createProduct method with the null Product object. + Assert: Use assertions to check that an appropriate exception (e.g., IllegalArgumentException) is thrown, indicating that the product cannot be created with a null input. +Validation: + The assertion ensures that the createProduct method handles null input gracefully and throws an exception to prevent unexpected behavior or null pointer exceptions. + This test is important to validate the robustness and defensive programming practices of the createProduct method. + +These test scenarios cover various aspects of the createProduct method, including successful creation, missing required fields, invalid field values, duplicate unique fields, and null input handling. They help ensure the correctness and reliability of the product creation functionality in the application. +*/ + +// ********RoostGPT******** +package com.bootexample4.products.controller; + +import com.bootexample4.products.model.Product; +import com.bootexample4.products.repository.ProductRepository; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.when; + +@ExtendWith(MockitoExtension.class) +class ProductControllerCreateProductTest { + + @Mock + private ProductRepository productRepository; + + @InjectMocks + private ProductController productController; + + @Test + void createProductWithValidData() { + // Arrange + Product product = new Product(); + product.setName("Test Product"); + product.setDescription("Test Description"); + product.setPrice(9.99); + when(productRepository.save(any(Product.class))).thenReturn(product); + // Act + Product createdProduct = productController.createProduct(product); + // Assert + assertThat(createdProduct).isNotNull(); + assertThat(createdProduct.getName()).isEqualTo(product.getName()); + assertThat(createdProduct.getDescription()).isEqualTo(product.getDescription()); + assertThat(createdProduct.getPrice()).isEqualTo(product.getPrice()); + } + + @Test + void createProductWithMissingRequiredFields() { + // Arrange + Product product = new Product(); + product.setName(null); + product.setDescription("Test Description"); + product.setPrice(9.99); + // Act & Assert + // TODO: Update the createProduct method to handle missing required fields and + // throw appropriate exception + assertThrows(IllegalArgumentException.class, () -> productController.createProduct(product)); + } + + @Test + void createProductWithInvalidFieldValues() { + // Arrange + Product product = new Product(); + product.setName("Test Product"); + product.setDescription("Test Description"); + product.setPrice(-9.99); + // Act & Assert + // TODO: Update the createProduct method to handle invalid field values and throw + // appropriate exception + assertThrows(IllegalArgumentException.class, () -> productController.createProduct(product)); + } + + @Test + void createProductWithDuplicateUniqueFields() { + // Arrange + Product existingProduct = new Product(); + existingProduct.setName("Existing Product"); + existingProduct.setDescription("Existing Description"); + existingProduct.setPrice(9.99); + when(productRepository.save(any(Product.class))).thenThrow(new RuntimeException("Duplicate entry")); + Product duplicateProduct = new Product(); + duplicateProduct.setName("Existing Product"); + duplicateProduct.setDescription("Duplicate Description"); + duplicateProduct.setPrice(19.99); + // Act & Assert + assertThrows(RuntimeException.class, () -> productController.createProduct(duplicateProduct)); + } + + @Test + void createProductWithNullInput() { + // Act & Assert + // TODO: Update the createProduct method to handle null input and throw + // appropriate exception + assertThrows(IllegalArgumentException.class, () -> productController.createProduct(null)); + } + +} diff --git a/src/test/java/com/bootexample4/products/controller/ProductControllerDeleteProductTest.java b/src/test/java/com/bootexample4/products/controller/ProductControllerDeleteProductTest.java new file mode 100644 index 00000000..afd628f1 --- /dev/null +++ b/src/test/java/com/bootexample4/products/controller/ProductControllerDeleteProductTest.java @@ -0,0 +1,158 @@ +// ********RoostGPT******** +/* +Test generated by RoostGPT for test java-springboot using AI Type Claude AI and AI Model claude-3-opus-20240229 + +ROOST_METHOD_HASH=deleteProduct_5ea3a876a4 +ROOST_METHOD_SIG_HASH=deleteProduct_dcaff736d4 + +Scenario 1: Successful Product Deletion + +Details: + TestName: deleteExistingProduct(). + Description: This test verifies that the deleteProduct() method successfully deletes a product when a valid product ID is provided. +Execution: + Arrange: Create a sample product and save it to the database using the ProductRepository. + Act: Invoke the deleteProduct() method with the ID of the saved product. + Assert: Assert that the response status code is 200 (OK) and the product is no longer present in the database. +Validation: + The assertion checks that the product is successfully deleted when a valid ID is provided. + This test ensures that the deleteProduct() method correctly removes the product from the database and returns an appropriate response. + +Scenario 2: Attempt to Delete Non-Existent Product + +Details: + TestName: deleteNonExistentProduct(). + Description: This test verifies that the deleteProduct() method handles the scenario when an attempt is made to delete a product with an ID that does not exist in the database. +Execution: + Arrange: Ensure that the provided product ID does not exist in the database. + Act: Invoke the deleteProduct() method with the non-existent product ID. + Assert: Assert that the response status code is 404 (Not Found). +Validation: + The assertion checks that the deleteProduct() method correctly handles the case when a non-existent product ID is provided. + This test ensures that the method returns an appropriate response indicating that the product was not found. + +Scenario 3: Delete Product with Null ID + +Details: + TestName: deleteProductWithNullId(). + Description: This test verifies that the deleteProduct() method handles the scenario when a null value is passed as the product ID. +Execution: + Arrange: No specific arrangement is required. + Act: Invoke the deleteProduct() method with a null value as the ID. + Assert: Assert that the response status code is 400 (Bad Request) or an appropriate error response is returned. +Validation: + The assertion checks that the deleteProduct() method correctly handles the case when a null ID is provided. + This test ensures that the method validates the input and returns an appropriate error response for an invalid ID. + +Scenario 4: Delete Product with Invalid ID Format + +Details: + TestName: deleteProductWithInvalidIdFormat(). + Description: This test verifies that the deleteProduct() method handles the scenario when an ID with an invalid format (e.g., non-numeric) is provided. +Execution: + Arrange: No specific arrangement is required. + Act: Invoke the deleteProduct() method with an ID that has an invalid format. + Assert: Assert that the response status code is 400 (Bad Request) or an appropriate error response is returned. +Validation: + The assertion checks that the deleteProduct() method correctly handles the case when an ID with an invalid format is provided. + This test ensures that the method validates the input and returns an appropriate error response for an invalid ID format. + +Scenario 5: Delete Product with Large ID Value + +Details: + TestName: deleteProductWithLargeIdValue(). + Description: This test verifies that the deleteProduct() method handles the scenario when an extremely large ID value is provided. +Execution: + Arrange: No specific arrangement is required. + Act: Invoke the deleteProduct() method with an extremely large ID value. + Assert: Assert that the response status code is either 404 (Not Found) or an appropriate error response is returned. +Validation: + The assertion checks that the deleteProduct() method correctly handles the case when an extremely large ID value is provided. + This test ensures that the method does not encounter any issues or exceptions when dealing with large ID values and returns an appropriate response. +*/ + +// ********RoostGPT******** +package com.bootexample4.products.controller; + +import com.bootexample4.products.model.Product; +import com.bootexample4.products.repository.ProductRepository; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import java.util.Optional; +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.Mockito.*; +import java.util.List; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; + +@ExtendWith(MockitoExtension.class) +class ProductControllerDeleteProductTest { + + @Mock + private ProductRepository productRepository; + + @InjectMocks + private ProductController productController; + + @Test + void deleteExistingProduct() { + // Arrange + Long productId = 1L; + Product product = new Product(); + product.setId(productId); + when(productRepository.findById(productId)).thenReturn(Optional.of(product)); + // Act + ResponseEntity response = productController.deleteProduct(productId); + // Assert + assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK); + verify(productRepository, times(1)).delete(product); + } + + @Test + void deleteNonExistentProduct() { + // Arrange + Long productId = 1L; + when(productRepository.findById(productId)).thenReturn(Optional.empty()); + // Act + ResponseEntity response = productController.deleteProduct(productId); + // Assert + assertThat(response.getStatusCode()).isEqualTo(HttpStatus.NOT_FOUND); + verify(productRepository, never()).delete(any(Product.class)); + } + + @Test + void deleteProductWithNullId() { + // Arrange + Long productId = null; + // Act + ResponseEntity response = productController.deleteProduct(productId); + // Assert + assertThat(response.getStatusCode()).isEqualTo(HttpStatus.BAD_REQUEST); + verify(productRepository, never()).findById(any()); + verify(productRepository, never()).delete(any(Product.class)); + } + + // Comment: The deleteProductWithInvalidIdFormat test case should be removed as it is + // not applicable + // since the id parameter is of type Long and cannot be assigned an invalid string + // value. + + @Test + void deleteProductWithLargeIdValue() { + // Arrange + Long largeId = Long.MAX_VALUE; + when(productRepository.findById(largeId)).thenReturn(Optional.empty()); + // Act + ResponseEntity response = productController.deleteProduct(largeId); + // Assert + assertThat(response.getStatusCode()).isEqualTo(HttpStatus.NOT_FOUND); + verify(productRepository, times(1)).findById(largeId); + verify(productRepository, never()).delete(any(Product.class)); + } + +} diff --git a/src/test/java/com/bootexample4/products/controller/ProductControllerGetAllProductsTest.java b/src/test/java/com/bootexample4/products/controller/ProductControllerGetAllProductsTest.java new file mode 100644 index 00000000..d06c3031 --- /dev/null +++ b/src/test/java/com/bootexample4/products/controller/ProductControllerGetAllProductsTest.java @@ -0,0 +1,151 @@ +// ********RoostGPT******** +/* +Test generated by RoostGPT for test java-springboot using AI Type Claude AI and AI Model claude-3-opus-20240229 + +ROOST_METHOD_HASH=getAllProducts_fef141838b +ROOST_METHOD_SIG_HASH=getAllProducts_7e38cc05f6 + +Here are the JUnit test scenarios for the provided `getAllProducts` method: + +Scenario 1: Retrieve All Products Successfully + +Details: + TestName: getAllProductsReturnsListOfProducts + Description: This test verifies that the `getAllProducts` method retrieves all products from the database and returns them as a list. +Execution: + Arrange: Set up the `ProductRepository` mock to return a predefined list of products when `findAll` is called. + Act: Invoke the `getAllProducts` method. + Assert: Use JUnit assertions to check that the returned list matches the predefined list of products. +Validation: + The assertion verifies that the method correctly retrieves all products from the repository. + This test ensures that the application can fetch and display all available products to the users. + +Scenario 2: Empty Product List + +Details: + TestName: getAllProductsReturnsEmptyList + Description: This test checks the behavior of the `getAllProducts` method when there are no products in the database. +Execution: + Arrange: Set up the `ProductRepository` mock to return an empty list when `findAll` is called. + Act: Invoke the `getAllProducts` method. + Assert: Use JUnit assertions to verify that the returned list is empty. +Validation: + The assertion confirms that the method handles the case of an empty product list gracefully. + This test ensures that the application doesn't break or display incorrect information when no products are available. + +Scenario 3: Repository Throws Exception + +Details: + TestName: getAllProductsHandlesRepositoryException + Description: This test verifies that the `getAllProducts` method handles exceptions thrown by the `ProductRepository` appropriately. +Execution: + Arrange: Set up the `ProductRepository` mock to throw an exception when `findAll` is called. + Act: Invoke the `getAllProducts` method. + Assert: Use JUnit assertions to check that the method catches the exception and returns an empty list or throws a specific exception. +Validation: + The assertion ensures that the method has proper error handling and doesn't propagate exceptions to the caller. + This test helps maintain the stability and reliability of the application in case of database or repository issues. + +Scenario 4: Performance Test + +Details: + TestName: getAllProductsPerformance + Description: This test measures the performance of the `getAllProducts` method when retrieving a large number of products. +Execution: + Arrange: Set up the `ProductRepository` mock to return a large list of products (e.g., thousands of products) when `findAll` is called. + Act: Invoke the `getAllProducts` method and measure the execution time. + Assert: Use JUnit assertions to verify that the execution time is within an acceptable range. +Validation: + The assertion checks that the method performs efficiently and doesn't introduce significant delays, even with a large dataset. + This test helps identify potential performance bottlenecks and ensures a smooth user experience. + +Note: The actual implementation of these test scenarios would require the use of a mocking framework like Mockito to create mock objects for the `ProductRepository` and set up the desired behavior for each test case. +*/ + +// ********RoostGPT******** +package com.bootexample4.products.controller; + +import java.util.ArrayList; +import java.util.List; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; +import static org.junit.jupiter.api.Assertions.*; +import static org.mockito.Mockito.*; +import com.bootexample4.products.model.Product; +import com.bootexample4.products.repository.ProductRepository; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.*; + +@ExtendWith(MockitoExtension.class) +class ProductControllerGetAllProductsTest { + + @Mock + private ProductRepository productRepository; + + @InjectMocks + private ProductController productController; + + @Test + void getAllProductsReturnsListOfProducts() { + // Arrange + List expectedProducts = new ArrayList<>(); + // TODO: Update the constructor based on the actual Product class constructor + expectedProducts.add(new Product()); + expectedProducts.add(new Product()); + when(productRepository.findAll()).thenReturn(expectedProducts); + // Act + List actualProducts = productController.getAllProducts(); + // Assert + assertEquals(expectedProducts, actualProducts); + verify(productRepository, times(1)).findAll(); + } + + @Test + void getAllProductsReturnsEmptyList() { + // Arrange + when(productRepository.findAll()).thenReturn(new ArrayList<>()); + // Act + List actualProducts = productController.getAllProducts(); + // Assert + assertTrue(actualProducts.isEmpty()); + verify(productRepository, times(1)).findAll(); + } + + @Test + void getAllProductsHandlesRepositoryException() { + // Arrange + when(productRepository.findAll()).thenThrow(new RuntimeException("Repository Exception")); + // Act & Assert + assertThrows(RuntimeException.class, () -> productController.getAllProducts()); + verify(productRepository, times(1)).findAll(); + } + + @Test + void getAllProductsPerformance() { + // Arrange + List largeProductList = generateLargeProductList(10000); + when(productRepository.findAll()).thenReturn(largeProductList); + // Act + long startTime = System.currentTimeMillis(); + List actualProducts = productController.getAllProducts(); + long endTime = System.currentTimeMillis(); + // Assert + assertEquals(largeProductList, actualProducts); + assertTrue(endTime - startTime < 1000, "Execution time should be less than 1 second"); + verify(productRepository, times(1)).findAll(); + } + + private List generateLargeProductList(int count) { + List products = new ArrayList<>(); + for (int i = 1; i <= count; i++) { + // TODO: Update the constructor based on the actual Product class constructor + products.add(new Product()); + } + return products; + } + +} diff --git a/src/test/java/com/bootexample4/products/controller/ProductControllerGetProductByIdTest.java b/src/test/java/com/bootexample4/products/controller/ProductControllerGetProductByIdTest.java new file mode 100644 index 00000000..319270f7 --- /dev/null +++ b/src/test/java/com/bootexample4/products/controller/ProductControllerGetProductByIdTest.java @@ -0,0 +1,153 @@ + +// ********RoostGPT******** +/* +Test generated by RoostGPT for test java-springboot using AI Type Claude AI and AI Model claude-3-opus-20240229 + +ROOST_METHOD_HASH=getProductById_a31a3ac160 +ROOST_METHOD_SIG_HASH=getProductById_d22f3ea272 + +Here are the JUnit test scenarios for the provided getProductById method: + +Scenario 1: Successfully retrieve a product by ID + +Details: + TestName: getProductByIdReturnsProduct + Description: This test verifies that the getProductById method returns the correct product when a valid ID is provided. +Execution: + Arrange: Create a mock ProductRepository and configure it to return a specific Product when findById is called with a specific ID. + Act: Call the getProductById method with the same ID used in the mock setup. + Assert: Assert that the returned ResponseEntity has a status code of 200 (OK) and its body contains the expected Product. +Validation: + The assertion ensures that the method retrieves the correct product from the repository based on the provided ID. + This test is important to validate that the endpoint returns the expected product details when a valid ID is supplied. + +Scenario 2: Handle non-existent product ID + +Details: + TestName: getProductByIdReturnsNotFound + Description: This test checks that the getProductById method returns a 404 (Not Found) response when a non-existent product ID is provided. +Execution: + Arrange: Create a mock ProductRepository and configure it to return an empty Optional when findById is called with a non-existent ID. + Act: Call the getProductById method with the non-existent ID. + Assert: Assert that the returned ResponseEntity has a status code of 404 (Not Found) and its body is empty. +Validation: + The assertion verifies that the method handles the case when a product with the given ID does not exist in the repository. + This test ensures that the endpoint correctly responds with a 404 status code, indicating that the requested resource was not found. + +Scenario 3: Handle null product ID + +Details: + TestName: getProductByIdWithNullId + Description: This test verifies that the getProductById method handles a null product ID gracefully and returns an appropriate response. +Execution: + Arrange: No specific arrangement is needed for this test. + Act: Call the getProductById method with a null ID. + Assert: Assert that the returned ResponseEntity has a status code of 400 (Bad Request) or any other appropriate error status code. +Validation: + The assertion checks that the method handles a null ID input and returns an error response, indicating that the request was invalid. + This test ensures that the endpoint validates the input and provides meaningful feedback to the client when an invalid ID is supplied. + +Scenario 4: Handle repository exception + +Details: + TestName: getProductByIdHandlesRepositoryException + Description: This test verifies that the getProductById method handles exceptions thrown by the ProductRepository gracefully and returns an appropriate error response. +Execution: + Arrange: Create a mock ProductRepository and configure it to throw an exception when findById is called. + Act: Call the getProductById method with any valid ID. + Assert: Assert that the returned ResponseEntity has a status code of 500 (Internal Server Error) or any other appropriate error status code. +Validation: + The assertion ensures that the method catches and handles exceptions thrown by the repository, preventing them from propagating to the client. + This test validates that the endpoint provides a consistent error response in case of internal server errors, maintaining a stable API contract. + +These test scenarios cover the main functionality of the getProductById method, including successful retrieval, handling of non-existent product IDs, null input validation, and exception handling. They ensure that the method behaves as expected under different conditions and provides appropriate responses to the client. + +roost_feedback [5/7/2024, 6:38:13 AM]:comment out the test getProductByIdHandlesRepositoryException() +*/ + +// ********RoostGPT******** + +package com.bootexample4.products.controller; + +import com.bootexample4.products.model.Product; +import com.bootexample4.products.repository.ProductRepository; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import java.util.Optional; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.mockito.ArgumentMatchers.anyLong; +import static org.mockito.Mockito.when; +import java.util.List; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; + +class ProductControllerGetProductByIdTest { + + @Mock + private ProductRepository productRepository; + + @InjectMocks + private ProductController productController; + + @BeforeEach + void setUp() { + MockitoAnnotations.openMocks(this); + } + + @Test + void getProductByIdReturnsProduct() { + // Arrange + Long productId = 1L; + Product product = new Product(); + product.setId(productId); + product.setName("Test Product"); + product.setDescription("Test Description"); + product.setPrice(9.99); + when(productRepository.findById(productId)).thenReturn(Optional.of(product)); + // Act + ResponseEntity response = productController.getProductById(productId); + // Assert + assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK); + assertThat(response.getBody()).isEqualTo(product); + } + + @Test + void getProductByIdReturnsNotFound() { + // Arrange + Long nonExistentProductId = 100L; + when(productRepository.findById(nonExistentProductId)).thenReturn(Optional.empty()); + // Act + ResponseEntity response = productController.getProductById(nonExistentProductId); + // Assert + assertThat(response.getStatusCode()).isEqualTo(HttpStatus.NOT_FOUND); + assertThat(response.getBody()).isNull(); + } + + @Test + void getProductByIdWithNullId() { + // Arrange + Long nullProductId = null; + // Act + ResponseEntity response = productController.getProductById(nullProductId); + // Assert + assertThat(response.getStatusCode()).isEqualTo(HttpStatus.BAD_REQUEST); + } + + // @Test + // void getProductByIdHandlesRepositoryException() { + // // Arrange + // Long productId = 1L; + // when(productRepository.findById(anyLong())).thenThrow(new RuntimeException("Repository Exception")); + // // Act & Assert + // assertThatThrownBy(() -> productController.getProductById(productId)) + // .isInstanceOf(RuntimeException.class) + // .hasMessage("Repository Exception"); + // } + +} diff --git a/src/test/java/com/bootexample4/products/controller/ProductControllerUpdateProductTest.java b/src/test/java/com/bootexample4/products/controller/ProductControllerUpdateProductTest.java new file mode 100644 index 00000000..1e873b97 --- /dev/null +++ b/src/test/java/com/bootexample4/products/controller/ProductControllerUpdateProductTest.java @@ -0,0 +1,262 @@ +// ********RoostGPT******** +/* +Test generated by RoostGPT for test java-springboot using AI Type Claude AI and AI Model claude-3-opus-20240229 + +ROOST_METHOD_HASH=updateProduct_e220585694 +ROOST_METHOD_SIG_HASH=updateProduct_9454a9af90 + +Here are the JUnit test scenarios for the `updateProduct` method: + +Scenario 1: Update an existing product with valid data + +Details: + TestName: updateExistingProductWithValidData + Description: This test verifies that the `updateProduct` method successfully updates an existing product when provided with valid data. It checks if the product details are correctly updated in the database and the updated product is returned in the response. +Execution: + Arrange: + - Create a mock product with a specific ID and set its initial properties. + - Save the mock product in the `ProductRepository`. + Act: + - Create a new `Product` object with updated properties. + - Invoke the `updateProduct` method with the mock product ID and the updated `Product` object. + Assert: + - Verify that the response status code is 200 (OK). + - Verify that the response body contains the updated `Product` object. + - Verify that the updated product properties match the expected values. +Validation: + The assertion ensures that the `updateProduct` method correctly updates the existing product in the database when provided with valid data. It validates that the response contains the updated product details, confirming that the update operation was successful. + +Scenario 2: Update a non-existing product + +Details: + TestName: updateNonExistingProduct + Description: This test verifies that the `updateProduct` method handles the scenario when an attempt is made to update a non-existing product. It checks if the method returns a 404 (Not Found) response when the specified product ID does not exist in the database. +Execution: + Arrange: + - Ensure that the `ProductRepository` is empty or does not contain a product with the specified ID. + Act: + - Create a new `Product` object with any valid properties. + - Invoke the `updateProduct` method with a non-existing product ID and the `Product` object. + Assert: + - Verify that the response status code is 404 (Not Found). +Validation: + The assertion confirms that the `updateProduct` method correctly handles the case when a non-existing product ID is provided. It ensures that the method returns a 404 response, indicating that the specified product does not exist in the database. + +Scenario 3: Update a product with null name + +Details: + TestName: updateProductWithNullName + Description: This test verifies that the `updateProduct` method handles the scenario when an attempt is made to update a product with a null name. It checks if the method throws an appropriate exception or returns an error response. +Execution: + Arrange: + - Create a mock product with a specific ID and set its initial properties. + - Save the mock product in the `ProductRepository`. + Act: + - Create a new `Product` object with a null name and other valid properties. + - Invoke the `updateProduct` method with the mock product ID and the `Product` object with a null name. + Assert: + - Verify that the method throws an appropriate exception or returns an error response. +Validation: + The assertion ensures that the `updateProduct` method correctly handles the case when a null name is provided during the update operation. It validates that the method either throws an exception or returns an error response, preventing the update of a product with an invalid name. + +Scenario 4: Update a product with negative price + +Details: + TestName: updateProductWithNegativePrice + Description: This test verifies that the `updateProduct` method handles the scenario when an attempt is made to update a product with a negative price. It checks if the method throws an appropriate exception or returns an error response. +Execution: + Arrange: + - Create a mock product with a specific ID and set its initial properties. + - Save the mock product in the `ProductRepository`. + Act: + - Create a new `Product` object with a negative price and other valid properties. + - Invoke the `updateProduct` method with the mock product ID and the `Product` object with a negative price. + Assert: + - Verify that the method throws an appropriate exception or returns an error response. +Validation: + The assertion ensures that the `updateProduct` method correctly handles the case when a negative price is provided during the update operation. It validates that the method either throws an exception or returns an error response, preventing the update of a product with an invalid price. + +Scenario 5: Update a product with empty description + +Details: + TestName: updateProductWithEmptyDescription + Description: This test verifies that the `updateProduct` method allows updating a product with an empty description. It checks if the method successfully updates the product and returns the updated product in the response. +Execution: + Arrange: + - Create a mock product with a specific ID and set its initial properties. + - Save the mock product in the `ProductRepository`. + Act: + - Create a new `Product` object with an empty description and other valid properties. + - Invoke the `updateProduct` method with the mock product ID and the `Product` object with an empty description. + Assert: + - Verify that the response status code is 200 (OK). + - Verify that the response body contains the updated `Product` object. + - Verify that the updated product properties match the expected values, including the empty description. +Validation: + The assertion ensures that the `updateProduct` method allows updating a product with an empty description. It validates that the response contains the updated product details, confirming that the update operation was successful, even with an empty description. + +These test scenarios cover various aspects of the `updateProduct` method, including updating an existing product with valid data, handling non-existing products, and handling edge cases such as null name, negative price, and empty description. They aim to ensure the correctness and robustness of the method under different scenarios. +*/ + +// ********RoostGPT******** +package com.bootexample4.products.controller; + +import com.bootexample4.products.model.Product; +import com.bootexample4.products.repository.ProductRepository; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import java.util.Optional; +import static org.junit.jupiter.api.Assertions.*; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.*; +import java.util.List; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; + +class ProductControllerUpdateProductTest { + + @Mock + private ProductRepository productRepository; + + @InjectMocks + private ProductController productController; + + @BeforeEach + void setUp() { + MockitoAnnotations.openMocks(this); + } + + @Test + void updateExistingProductWithValidData() { + // Arrange + Long productId = 1L; + Product existingProduct = new Product(); + existingProduct.setId(productId); + existingProduct.setName("Product 1"); + existingProduct.setDescription("Description 1"); + existingProduct.setPrice(10.0); + + Product updatedProduct = new Product(); + updatedProduct.setId(productId); + updatedProduct.setName("Updated Product"); + updatedProduct.setDescription("Updated Description"); + updatedProduct.setPrice(20.0); + + when(productRepository.findById(productId)).thenReturn(Optional.of(existingProduct)); + when(productRepository.save(any(Product.class))).thenReturn(updatedProduct); + + // Act + ResponseEntity response = productController.updateProduct(productId, updatedProduct); + + // Assert + assertEquals(HttpStatus.OK, response.getStatusCode()); + assertEquals(updatedProduct, response.getBody()); + verify(productRepository, times(1)).findById(productId); + verify(productRepository, times(1)).save(existingProduct); + } + + @Test + void updateNonExistingProduct() { + // Arrange + Long productId = 1L; + Product updatedProduct = new Product(); + updatedProduct.setId(productId); + updatedProduct.setName("Updated Product"); + updatedProduct.setDescription("Updated Description"); + updatedProduct.setPrice(20.0); + + when(productRepository.findById(productId)).thenReturn(Optional.empty()); + + // Act + ResponseEntity response = productController.updateProduct(productId, updatedProduct); + + // Assert + assertEquals(HttpStatus.NOT_FOUND, response.getStatusCode()); + assertNull(response.getBody()); + verify(productRepository, times(1)).findById(productId); + verify(productRepository, never()).save(any(Product.class)); + } + + @Test + void updateProductWithNullName() { + // Arrange + Long productId = 1L; + Product existingProduct = new Product(); + existingProduct.setId(productId); + existingProduct.setName("Product 1"); + existingProduct.setDescription("Description 1"); + existingProduct.setPrice(10.0); + + Product updatedProduct = new Product(); + updatedProduct.setId(productId); + updatedProduct.setName(null); + updatedProduct.setDescription("Updated Description"); + updatedProduct.setPrice(20.0); + + when(productRepository.findById(productId)).thenReturn(Optional.of(existingProduct)); + + // Act & Assert + assertThrows(IllegalArgumentException.class, () -> productController.updateProduct(productId, updatedProduct)); + verify(productRepository, times(1)).findById(productId); + verify(productRepository, never()).save(any(Product.class)); + } + + @Test + void updateProductWithNegativePrice() { + // Arrange + Long productId = 1L; + Product existingProduct = new Product(); + existingProduct.setId(productId); + existingProduct.setName("Product 1"); + existingProduct.setDescription("Description 1"); + existingProduct.setPrice(10.0); + + Product updatedProduct = new Product(); + updatedProduct.setId(productId); + updatedProduct.setName("Updated Product"); + updatedProduct.setDescription("Updated Description"); + updatedProduct.setPrice(-20.0); + + when(productRepository.findById(productId)).thenReturn(Optional.of(existingProduct)); + + // Act & Assert + assertThrows(IllegalArgumentException.class, () -> productController.updateProduct(productId, updatedProduct)); + verify(productRepository, times(1)).findById(productId); + verify(productRepository, never()).save(any(Product.class)); + } + + @Test + void updateProductWithEmptyDescription() { + // Arrange + Long productId = 1L; + Product existingProduct = new Product(); + existingProduct.setId(productId); + existingProduct.setName("Product 1"); + existingProduct.setDescription("Description 1"); + existingProduct.setPrice(10.0); + + Product updatedProduct = new Product(); + updatedProduct.setId(productId); + updatedProduct.setName("Updated Product"); + updatedProduct.setDescription(""); + updatedProduct.setPrice(20.0); + + when(productRepository.findById(productId)).thenReturn(Optional.of(existingProduct)); + when(productRepository.save(any(Product.class))).thenReturn(updatedProduct); + + // Act + ResponseEntity response = productController.updateProduct(productId, updatedProduct); + + // Assert + assertEquals(HttpStatus.OK, response.getStatusCode()); + assertEquals(updatedProduct, response.getBody()); + verify(productRepository, times(1)).findById(productId); + verify(productRepository, times(1)).save(existingProduct); + } + +} diff --git a/src/test/java/com/bootexample4/products/cucumber/CucumberTestRunner.java b/src/test/java/com/bootexample4/products/cucumber/CucumberTestRunner.java index 36174380..6b7cdd14 100644 --- a/src/test/java/com/bootexample4/products/cucumber/CucumberTestRunner.java +++ b/src/test/java/com/bootexample4/products/cucumber/CucumberTestRunner.java @@ -6,9 +6,8 @@ import io.cucumber.junit.CucumberOptions; @RunWith(Cucumber.class) -@CucumberOptions( - features = {"src/test/resources/features"}, - plugin = {"pretty"}, - glue = {"com.bootexample4.products.cucumber"}) +@CucumberOptions(features = { "src/test/resources/features" }, plugin = { "pretty" }, + glue = { "com.bootexample4.products.cucumber" }) public class CucumberTestRunner { + } \ No newline at end of file diff --git a/src/test/java/com/bootexample4/products/cucumber/ProductStepDefinitions.java b/src/test/java/com/bootexample4/products/cucumber/ProductStepDefinitions.java index 0e8387b7..d6762054 100644 --- a/src/test/java/com/bootexample4/products/cucumber/ProductStepDefinitions.java +++ b/src/test/java/com/bootexample4/products/cucumber/ProductStepDefinitions.java @@ -18,159 +18,171 @@ public class ProductStepDefinitions { - @Autowired - private ProductController productController; - - private ResponseEntity getProductByIdResponse; - private ResponseEntity updateProductResponse; - private ResponseEntity deleteProductResponse; - private List listOfProducts; - private Product newProduct; - private Product savedProduct; - private String baseURL; - private HttpStatusCode responseStatusCode; - - public void unmarshalDataTable(DataTable dataTable) { - List> data = dataTable.asLists(); - newProduct=new Product(); - // Access the data and populate the object "Product" - for (List row : data) { - String property = row.get(0); - String value = row.get(1); - - // Set the property value in the object "Product" - switch (property) { - case "name": - newProduct.setName(value); - break; - case "description": - newProduct.setDescription(value); - break; - case "price": - double price = Double.parseDouble(value); - newProduct.setPrice(price); - break; - } - } - - } - -public Long getProductIDfromAPI(String string){ - int sizeOfInputString = string.length(); - char lastCharOfInputString=string.charAt(sizeOfInputString-1); - assertTrue((lastCharOfInputString>='0')&&(string.charAt(sizeOfInputString-1)<='9')); - Long id=(long) (lastCharOfInputString-'0'); - return id; -} - - -@Given("the base URL is {string}") -public void the_base_url_is(String string) { - // Write code here that turns the phrase above into concrete actions - baseURL=string; - System.out.println("the base URL is: "+baseURL); -} - - @When("the client sends a GET request {string} to get the list of all products") - public void the_client_sends_a_get_request_to_get_the_list_of_all_products(String string) { - listOfProducts = productController.getAllProducts(); - } - - @Then("the list of products returned should be empty") - public void the_list_of_products_returned_should_be_empty() { - assertEquals(0,listOfProducts.size()); - } - - @Given("the client provides the following product data:") -public void the_client_provides_the_following_product_data(DataTable dataTable) { - // Write code here that turns the phrase above into concrete actions - // For automatic transformation, change DataTable to one of - // E, List, List>, List>, Map or - // Map>. E,K,V must be a String, Integer, Float, - // Double, Byte, Short, Long, BigInteger or BigDecimal. - // - // For other transformations you can register a DataTableType - - unmarshalDataTable(dataTable); - -} -@When("the client sends a POST request to {string}") -public void the_client_sends_a_post_request_to(String string) { - // Write code here that turns the phrase above into concrete actions - savedProduct = productController.createProduct(newProduct); - -} -@Then("the saved product should not be null and its properties must correspond to those provided by client") -public void the_saved_product_should_not_be_null_and_its_properties_must_correspond_to_those_provided_by_client() { - // Write code here that turns the phrase above into concrete actions - assertNotNull(savedProduct); - assertEquals( newProduct.getPrice(),savedProduct.getPrice(),.001); - assertEquals(savedProduct.getName(), newProduct.getName(), "unexpected product name: "+savedProduct.getName()); - assertEquals(savedProduct.getDescription(), newProduct.getDescription(), "unexpected product name: "+savedProduct.getDescription()); -} - -@Given("there is an existing product with ID {long}") -public void there_is_an_existing_product_with_id(Long id) { - // Write code here that turns the phrase above into concrete actions - listOfProducts = productController.getAllProducts(); - boolean productPresentFlag = false; - for (Product product : listOfProducts) { - if (product.getId()==id){ - productPresentFlag=true; - break; - } - } - assertTrue(productPresentFlag); -} -@When("the client sends a GET request {string} to get a product by its id") -public void the_client_sends_a_GET_request_to_get_a_product_by_its_id(String string) { - // Write code here that turns the phrase above into concrete actions - Long id=getProductIDfromAPI(string); - getProductByIdResponse=productController.getProductById(id); - responseStatusCode= getProductByIdResponse.getStatusCode(); -} -@Then("the response status code should be {int}") -public void the_response_status_code_should_be(Integer expectedStatusCode) { - // Write code here that turns the phrase above into concrete actions - assertEquals(expectedStatusCode, responseStatusCode.value()); -} -@Then("the response should contain the product with ID {long}") -public void the_response_should_contain_the_product_with_id(Long id) { - // Write code here that turns the phrase above into concrete actions - Product product = getProductByIdResponse.getBody(); - assertEquals(id, product.getId()); - } - - -@When("the client sends a PUT request to {string}") -public void the_client_sends_a_put_request_to(String string) { - // Write code here that turns the phrase above into concrete actions - updateProductResponse= productController.updateProduct(getProductIDfromAPI(string), newProduct); - responseStatusCode=updateProductResponse.getStatusCode(); -} -@Then("the product with ID {long} should be updated with the provided details") -public void the_product_with_ID_should_be_updated_with_the_provided_details(Long id) { - // Write code here that turns the phrase above into concrete actions - Product updatedProduct = productController.getProductById(id).getBody(); - assertEquals(newProduct.getDescription(), updatedProduct.getDescription()); - assertEquals(newProduct.getName(), updatedProduct.getName()); - assertEquals(newProduct.getPrice(), updatedProduct.getPrice()); -} - -@When("the client sends a DELETE request to {string}") -public void the_client_sends_a_delete_request_to(String string) { - // Write code here that turns the phrase above into concrete actions - Long id = getProductIDfromAPI(string); - deleteProductResponse=productController.deleteProduct(id); - responseStatusCode=deleteProductResponse.getStatusCode(); -} -@Then("the product with ID {long} should no longer exist") -public void the_product_with_id_should_no_longer_exist(Long id) { - // Write code here that turns the phrase above into concrete actions - getProductByIdResponse =productController.getProductById(id); - assertEquals(HttpStatus.NOT_FOUND,getProductByIdResponse.getStatusCode()); -} - + @Autowired + private ProductController productController; + + private ResponseEntity getProductByIdResponse; + + private ResponseEntity updateProductResponse; + + private ResponseEntity deleteProductResponse; + + private List listOfProducts; + + private Product newProduct; + + private Product savedProduct; + + private String baseURL; + + private HttpStatusCode responseStatusCode; + + public void unmarshalDataTable(DataTable dataTable) { + List> data = dataTable.asLists(); + newProduct = new Product(); + // Access the data and populate the object "Product" + for (List row : data) { + String property = row.get(0); + String value = row.get(1); + + // Set the property value in the object "Product" + switch (property) { + case "name": + newProduct.setName(value); + break; + case "description": + newProduct.setDescription(value); + break; + case "price": + double price = Double.parseDouble(value); + newProduct.setPrice(price); + break; + } + } + + } + + public Long getProductIDfromAPI(String string) { + int sizeOfInputString = string.length(); + char lastCharOfInputString = string.charAt(sizeOfInputString - 1); + assertTrue((lastCharOfInputString >= '0') && (string.charAt(sizeOfInputString - 1) <= '9')); + Long id = (long) (lastCharOfInputString - '0'); + return id; + } + + @Given("the base URL is {string}") + public void the_base_url_is(String string) { + // Write code here that turns the phrase above into concrete actions + baseURL = string; + System.out.println("the base URL is: " + baseURL); + } + + @When("the client sends a GET request {string} to get the list of all products") + public void the_client_sends_a_get_request_to_get_the_list_of_all_products(String string) { + listOfProducts = productController.getAllProducts(); + } + + @Then("the list of products returned should be empty") + public void the_list_of_products_returned_should_be_empty() { + assertEquals(0, listOfProducts.size()); + } + + @Given("the client provides the following product data:") + public void the_client_provides_the_following_product_data(DataTable dataTable) { + // Write code here that turns the phrase above into concrete actions + // For automatic transformation, change DataTable to one of + // E, List, List>, List>, Map or + // Map>. E,K,V must be a String, Integer, Float, + // Double, Byte, Short, Long, BigInteger or BigDecimal. + // + // For other transformations you can register a DataTableType + + unmarshalDataTable(dataTable); + + } + + @When("the client sends a POST request to {string}") + public void the_client_sends_a_post_request_to(String string) { + // Write code here that turns the phrase above into concrete actions + savedProduct = productController.createProduct(newProduct); + + } + + @Then("the saved product should not be null and its properties must correspond to those provided by client") + public void the_saved_product_should_not_be_null_and_its_properties_must_correspond_to_those_provided_by_client() { + // Write code here that turns the phrase above into concrete actions + assertNotNull(savedProduct); + assertEquals(newProduct.getPrice(), savedProduct.getPrice(), .001); + assertEquals(savedProduct.getName(), newProduct.getName(), + "unexpected product name: " + savedProduct.getName()); + assertEquals(savedProduct.getDescription(), newProduct.getDescription(), + "unexpected product name: " + savedProduct.getDescription()); + } + + @Given("there is an existing product with ID {long}") + public void there_is_an_existing_product_with_id(Long id) { + // Write code here that turns the phrase above into concrete actions + listOfProducts = productController.getAllProducts(); + boolean productPresentFlag = false; + for (Product product : listOfProducts) { + if (product.getId() == id) { + productPresentFlag = true; + break; + } + } + assertTrue(productPresentFlag); + } + + @When("the client sends a GET request {string} to get a product by its id") + public void the_client_sends_a_GET_request_to_get_a_product_by_its_id(String string) { + // Write code here that turns the phrase above into concrete actions + Long id = getProductIDfromAPI(string); + getProductByIdResponse = productController.getProductById(id); + responseStatusCode = getProductByIdResponse.getStatusCode(); + } + + @Then("the response status code should be {int}") + public void the_response_status_code_should_be(Integer expectedStatusCode) { + // Write code here that turns the phrase above into concrete actions + assertEquals(expectedStatusCode, responseStatusCode.value()); + } + + @Then("the response should contain the product with ID {long}") + public void the_response_should_contain_the_product_with_id(Long id) { + // Write code here that turns the phrase above into concrete actions + Product product = getProductByIdResponse.getBody(); + assertEquals(id, product.getId()); + } + + @When("the client sends a PUT request to {string}") + public void the_client_sends_a_put_request_to(String string) { + // Write code here that turns the phrase above into concrete actions + updateProductResponse = productController.updateProduct(getProductIDfromAPI(string), newProduct); + responseStatusCode = updateProductResponse.getStatusCode(); + } + + @Then("the product with ID {long} should be updated with the provided details") + public void the_product_with_ID_should_be_updated_with_the_provided_details(Long id) { + // Write code here that turns the phrase above into concrete actions + Product updatedProduct = productController.getProductById(id).getBody(); + assertEquals(newProduct.getDescription(), updatedProduct.getDescription()); + assertEquals(newProduct.getName(), updatedProduct.getName()); + assertEquals(newProduct.getPrice(), updatedProduct.getPrice()); + } + + @When("the client sends a DELETE request to {string}") + public void the_client_sends_a_delete_request_to(String string) { + // Write code here that turns the phrase above into concrete actions + Long id = getProductIDfromAPI(string); + deleteProductResponse = productController.deleteProduct(id); + responseStatusCode = deleteProductResponse.getStatusCode(); + } + + @Then("the product with ID {long} should no longer exist") + public void the_product_with_id_should_no_longer_exist(Long id) { + // Write code here that turns the phrase above into concrete actions + getProductByIdResponse = productController.getProductById(id); + assertEquals(HttpStatus.NOT_FOUND, getProductByIdResponse.getStatusCode()); + } } - \ No newline at end of file diff --git a/src/test/java/com/bootexample4/products/cucumber/SpringIntegrationTests.java b/src/test/java/com/bootexample4/products/cucumber/SpringIntegrationTests.java index 8fb8814e..07a41a6b 100644 --- a/src/test/java/com/bootexample4/products/cucumber/SpringIntegrationTests.java +++ b/src/test/java/com/bootexample4/products/cucumber/SpringIntegrationTests.java @@ -7,5 +7,5 @@ @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) @CucumberContextConfiguration public class SpringIntegrationTests { - + } diff --git a/src/test/java/com/bootexample4/products/model/ProductGetDescriptionTest.java b/src/test/java/com/bootexample4/products/model/ProductGetDescriptionTest.java new file mode 100644 index 00000000..7503d010 --- /dev/null +++ b/src/test/java/com/bootexample4/products/model/ProductGetDescriptionTest.java @@ -0,0 +1,102 @@ +// ********RoostGPT******** +/* +Test generated by RoostGPT for test java-springboot using AI Type Claude AI and AI Model claude-3-opus-20240229 + +ROOST_METHOD_HASH=getDescription_791d670f82 +ROOST_METHOD_SIG_HASH=getDescription_b1844ea396 + +Scenario 1: Get Description Returns Correct Value + +Details: + TestName: getDescriptionReturnsCorrectValue() + Description: This test verifies that the getDescription method returns the correct description value when called on an instance of the class. + +Execution: + Arrange: Create an instance of the class and set its description field to a known value. + Act: Invoke the getDescription method on the instance. + Assert: Use assertEquals to compare the returned value with the expected description value. + +Validation: + The assertion verifies that the getDescription method correctly retrieves and returns the value stored in the description field of the class instance. + This test is important to ensure that the getDescription method functions as expected and provides access to the description property of the class. + +Scenario 2: Get Description Returns Null When Description Is Not Set + +Details: + TestName: getDescriptionReturnsNullWhenDescriptionNotSet() + Description: This test checks that the getDescription method returns null when the description field of the class instance has not been explicitly set. + +Execution: + Arrange: Create an instance of the class without setting its description field. + Act: Invoke the getDescription method on the instance. + Assert: Use assertNull to verify that the returned value is null. + +Validation: + The assertion confirms that the getDescription method does not throw an exception and correctly returns null when the description field has not been initialized. + This test is crucial to ensure that the getDescription method handles the case where the description is not set, preventing potential null pointer exceptions and providing a predictable behavior. + +Scenario 3: Get Description Returns Empty String When Description Is Set To Empty + +Details: + TestName: getDescriptionReturnsEmptyStringWhenDescriptionSetToEmpty() + Description: This test verifies that the getDescription method returns an empty string when the description field of the class instance is explicitly set to an empty string. + +Execution: + Arrange: Create an instance of the class and set its description field to an empty string. + Act: Invoke the getDescription method on the instance. + Assert: Use assertEquals to compare the returned value with an empty string. + +Validation: + The assertion ensures that the getDescription method correctly returns an empty string when the description field is set to an empty string, rather than returning null. + This test is important to confirm that the getDescription method handles empty string values appropriately and does not treat them as equivalent to null. + +Note: The provided test scenarios assume the existence of a class with a description field and a getDescription method. The actual implementation details of the class are not provided in the given code snippet. +*/ + +// ********RoostGPT******** +package com.bootexample4.products.model; + +import org.junit.jupiter.api.Test; +import static org.junit.jupiter.api.Assertions.*; +import jakarta.persistence.Entity; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; + +class ProductGetDescriptionTest { + + @Test + void getDescriptionReturnsCorrectValue() { + // Arrange + Product product = new Product(); + String expectedDescription = "Sample description"; + product.setDescription(expectedDescription); + // Act + String actualDescription = product.getDescription(); + // Assert + assertEquals(expectedDescription, actualDescription); + } + + @Test + void getDescriptionReturnsNullWhenDescriptionNotSet() { + // Arrange + Product product = new Product(); + // Act + String actualDescription = product.getDescription(); + // Assert + assertNull(actualDescription); + } + + @Test + void getDescriptionReturnsEmptyStringWhenDescriptionSetToEmpty() { + // Arrange + Product product = new Product(); + String emptyDescription = ""; + product.setDescription(emptyDescription); + // Act + String actualDescription = product.getDescription(); + // Assert + assertEquals(emptyDescription, actualDescription); + } + +} \ No newline at end of file diff --git a/src/test/java/com/bootexample4/products/model/ProductGetIdTest.java b/src/test/java/com/bootexample4/products/model/ProductGetIdTest.java new file mode 100644 index 00000000..80f682f8 --- /dev/null +++ b/src/test/java/com/bootexample4/products/model/ProductGetIdTest.java @@ -0,0 +1,144 @@ +// ********RoostGPT******** +/* +Test generated by RoostGPT for test java-springboot using AI Type Claude AI and AI Model claude-3-opus-20240229 + +ROOST_METHOD_HASH=getId_7023725436 +ROOST_METHOD_SIG_HASH=getId_ba349b1eff + +Here are the JUnit test scenarios for the provided getId() method: + +Scenario 1: Test getId() returns the correct id value + +Details: + TestName: getIdReturnsCorrectValue() + Description: This test verifies that the getId() method returns the correct id value when called on an entity object. +Execution: + Arrange: Create an instance of the entity class and set its id field to a known value. + Act: Invoke the getId() method on the entity object. + Assert: Use assertEquals to compare the returned id value with the expected value. +Validation: + The assertion verifies that the getId() method correctly retrieves the id value from the entity object. + This test ensures that the entity's id field is properly mapped and accessible through the getId() method. + +Scenario 2: Test getId() returns null when id is not set + +Details: + TestName: getIdReturnsNullWhenNotSet() + Description: This test checks that the getId() method returns null when the id field of the entity object is not set. +Execution: + Arrange: Create an instance of the entity class without setting its id field. + Act: Invoke the getId() method on the entity object. + Assert: Use assertNull to verify that the returned id value is null. +Validation: + The assertion confirms that the getId() method does not throw an exception and correctly returns null when the id field is not initialized. + This test ensures that the entity object can be created without an id value and that the getId() method handles this scenario gracefully. + +Scenario 3: Test getId() returns the correct id value after persisting the entity + +Details: + TestName: getIdReturnsCorrectValueAfterPersist() + Description: This test verifies that the getId() method returns the correct id value after the entity object is persisted to the database. +Execution: + Arrange: Create an instance of the entity class and persist it to the database using the EntityManager. + Act: Invoke the getId() method on the persisted entity object. + Assert: Use assertNotNull to verify that the returned id value is not null, and use assertEquals to compare it with the expected generated id value. +Validation: + The assertions ensure that the getId() method correctly retrieves the generated id value from the database after the entity is persisted. + This test validates that the entity's id field is properly populated by the persistence provider and can be accessed through the getId() method. + +Scenario 4: Test getId() returns the correct id value for multiple entity instances + +Details: + TestName: getIdReturnsCorrectValueForMultipleInstances() + Description: This test checks that the getId() method returns the correct id value for multiple instances of the entity class. +Execution: + Arrange: Create multiple instances of the entity class and set their id fields to different known values. + Act: Invoke the getId() method on each entity object. + Assert: Use assertEquals to compare the returned id values with the expected values for each entity instance. +Validation: + The assertions verify that the getId() method correctly retrieves the id value for each entity instance independently. + This test ensures that the entity's id field is properly encapsulated and that the getId() method returns the correct value for each instance. + +These test scenarios cover different aspects of the getId() method, including returning the correct id value, handling null id values, retrieving the id after persisting the entity, and testing multiple entity instances. They ensure that the getId() method behaves as expected in various scenarios and help validate the correctness of the entity's id field mapping and accessibility. +*/ + +// ********RoostGPT******** +package com.bootexample4.products.model; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.BeforeEach; +import static org.assertj.core.api.Assertions.assertThat; +import jakarta.persistence.Entity; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; + +class ProductGetIdTest { + + private Product product; + + @BeforeEach + void setUp() { + product = new Product(); + } + + @Test + void getIdReturnsCorrectValue() { + // Arrange + Long expectedId = 1L; + product.setId(expectedId); + + // Act + Long actualId = product.getId(); + + // Assert + assertThat(actualId).isEqualTo(expectedId); + } + + @Test + void getIdReturnsNullWhenNotSet() { + // Arrange + // No setup needed, id field is not set + + // Act + Long actualId = product.getId(); + + // Assert + assertThat(actualId).isNull(); + } + + @Test + void getIdReturnsCorrectValueAfterPersist() { + // Arrange + // TODO: Mock the persistence layer or use an in-memory database + // TODO: Persist the product entity to the database + // TODO: Set the expected generated id value + Long expectedGeneratedId = null; + + // Act + Long actualId = product.getId(); + + // Assert + assertThat(actualId).isNotNull(); + assertThat(actualId).isEqualTo(expectedGeneratedId); + } + + @Test + void getIdReturnsCorrectValueForMultipleInstances() { + // Arrange + Product product1 = new Product(); + product1.setId(1L); + + Product product2 = new Product(); + product2.setId(2L); + + // Act + Long actualId1 = product1.getId(); + Long actualId2 = product2.getId(); + + // Assert + assertThat(actualId1).isEqualTo(1L); + assertThat(actualId2).isEqualTo(2L); + } + +} diff --git a/src/test/java/com/bootexample4/products/model/ProductGetNameTest.java b/src/test/java/com/bootexample4/products/model/ProductGetNameTest.java new file mode 100644 index 00000000..c5c1288b --- /dev/null +++ b/src/test/java/com/bootexample4/products/model/ProductGetNameTest.java @@ -0,0 +1,124 @@ +// ********RoostGPT******** +/* +Test generated by RoostGPT for test java-springboot using AI Type Claude AI and AI Model claude-3-opus-20240229 + +ROOST_METHOD_HASH=getName_3a12ffc596 +ROOST_METHOD_SIG_HASH=getName_8400ac6fb7 + +Scenario 1: Get Name - Positive Case + +Details: + TestName: getNameReturnsCorrectValue() + Description: This test verifies that the getName() method returns the correct value of the name variable when it is set to a non-null value. +Execution: + Arrange: Create an instance of the class containing the getName() method and set the name variable to a specific value. + Act: Invoke the getName() method on the created instance. + Assert: Use assertEquals to compare the returned value from getName() with the expected name value. +Validation: + The assertion verifies that the getName() method correctly retrieves and returns the value of the name variable. + This test ensures that the basic functionality of the getName() method works as expected when the name variable is properly set. + +Scenario 2: Get Name - Null Case + +Details: + TestName: getNameReturnsNullWhenNameIsNull() + Description: This test checks the behavior of the getName() method when the name variable is set to null. +Execution: + Arrange: Create an instance of the class containing the getName() method and set the name variable to null. + Act: Invoke the getName() method on the created instance. + Assert: Use assertNull to verify that the returned value from getName() is null. +Validation: + The assertion confirms that the getName() method handles the case when the name variable is null and returns null accordingly. + This test ensures that the getName() method does not throw any exceptions or return unexpected values when the name variable is null. + +Scenario 3: Get Name - Empty String Case + +Details: + TestName: getNameReturnsEmptyStringWhenNameIsEmpty() + Description: This test verifies the behavior of the getName() method when the name variable is set to an empty string. +Execution: + Arrange: Create an instance of the class containing the getName() method and set the name variable to an empty string. + Act: Invoke the getName() method on the created instance. + Assert: Use assertEquals to compare the returned value from getName() with an empty string. +Validation: + The assertion checks that the getName() method correctly returns an empty string when the name variable is set to an empty string. + This test ensures that the getName() method handles the case of an empty string value for the name variable and returns it as expected. + +Scenario 4: Get Name - Multiple Invocations + +Details: + TestName: getNameReturnsSameValueOnMultipleInvocations() + Description: This test verifies that multiple invocations of the getName() method on the same instance return the same value consistently. +Execution: + Arrange: Create an instance of the class containing the getName() method and set the name variable to a specific value. + Act: Invoke the getName() method multiple times on the same instance. + Assert: Use assertEquals to compare the returned values from each invocation of getName() and ensure they are all equal. +Validation: + The assertion confirms that the getName() method returns the same value for multiple invocations on the same instance. + This test ensures that the getName() method is idempotent and does not modify the name variable or produce inconsistent results across multiple calls. +*/ + +// ********RoostGPT******** +package com.bootexample4.products.model; + +import org.junit.jupiter.api.Test; +import static org.junit.jupiter.api.Assertions.*; +import jakarta.persistence.Entity; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; + +class ProductGetNameTest { + + @Test + void getNameReturnsCorrectValue() { + // Arrange + Product product = new Product(); + String expectedName = "Sample Product"; + product.setName(expectedName); + // Act + String actualName = product.getName(); + // Assert + assertEquals(expectedName, actualName); + } + + @Test + void getNameReturnsNullWhenNameIsNull() { + // Arrange + Product product = new Product(); + product.setName(null); + // Act + String actualName = product.getName(); + // Assert + assertNull(actualName); + } + + @Test + void getNameReturnsEmptyStringWhenNameIsEmpty() { + // Arrange + Product product = new Product(); + String expectedName = ""; + product.setName(expectedName); + // Act + String actualName = product.getName(); + // Assert + assertEquals(expectedName, actualName); + } + + @Test + void getNameReturnsSameValueOnMultipleInvocations() { + // Arrange + Product product = new Product(); + String expectedName = "Sample Product"; + product.setName(expectedName); + // Act + String actualName1 = product.getName(); + String actualName2 = product.getName(); + String actualName3 = product.getName(); + // Assert + assertEquals(expectedName, actualName1); + assertEquals(expectedName, actualName2); + assertEquals(expectedName, actualName3); + } + +} \ No newline at end of file diff --git a/src/test/java/com/bootexample4/products/model/ProductGetPriceTest.java b/src/test/java/com/bootexample4/products/model/ProductGetPriceTest.java new file mode 100644 index 00000000..2a75c21c --- /dev/null +++ b/src/test/java/com/bootexample4/products/model/ProductGetPriceTest.java @@ -0,0 +1,125 @@ +// ********RoostGPT******** +/* +Test generated by RoostGPT for test java-springboot using AI Type Claude AI and AI Model claude-3-opus-20240229 + +ROOST_METHOD_HASH=getPrice_b54117587b +ROOST_METHOD_SIG_HASH=getPrice_d2cb73a47d + +Here are the JUnit test scenarios for the provided getPrice() method: + +Scenario 1: Get Price of a Product + +Details: + TestName: getPriceOfProduct() + Description: This test verifies that the getPrice() method returns the correct price of a product. +Execution: + Arrange: Create a new instance of the class containing the getPrice() method and set a known price value. + Act: Call the getPrice() method on the instance. + Assert: Use assertEquals() to compare the returned price with the expected price value. +Validation: + The assertion verifies that the getPrice() method accurately retrieves the price property of the object. + This test ensures that the price getter method functions correctly and returns the expected value. + +Scenario 2: Get Price of a Product with Zero Price + +Details: + TestName: getPriceOfProductWithZeroPrice() + Description: This test checks the behavior of the getPrice() method when the price of a product is set to zero. +Execution: + Arrange: Create a new instance of the class containing the getPrice() method and set the price to zero. + Act: Call the getPrice() method on the instance. + Assert: Use assertEquals() to verify that the returned price is equal to zero. +Validation: + The assertion confirms that the getPrice() method handles the case when the price is zero correctly. + This test ensures that the method does not throw any exceptions or return unexpected values for a zero price. + +Scenario 3: Get Price of a Product with Negative Price + +Details: + TestName: getPriceOfProductWithNegativePrice() + Description: This test verifies the behavior of the getPrice() method when the price of a product is set to a negative value. +Execution: + Arrange: Create a new instance of the class containing the getPrice() method and set the price to a negative value. + Act: Call the getPrice() method on the instance. + Assert: Use assertEquals() to check that the returned price matches the negative value set. +Validation: + The assertion validates that the getPrice() method correctly returns the negative price value without any modifications. + This test ensures that the method handles negative prices as expected and does not throw exceptions or return unexpected results. + +Scenario 4: Get Price of a Product with Maximum Double Value + +Details: + TestName: getPriceOfProductWithMaxDoubleValue() + Description: This test verifies the behavior of the getPrice() method when the price of a product is set to the maximum value of a double. +Execution: + Arrange: Create a new instance of the class containing the getPrice() method and set the price to Double.MAX_VALUE. + Act: Call the getPrice() method on the instance. + Assert: Use assertEquals() to verify that the returned price is equal to Double.MAX_VALUE. +Validation: + The assertion confirms that the getPrice() method correctly handles the maximum value of a double without any loss of precision. + This test ensures that the method can handle extreme values and returns the expected result. + +Note: Since the provided getPrice() method is a simple getter method without any complex logic or dependencies, the test scenarios are relatively straightforward and focus on verifying the basic functionality and edge cases. +*/ + +// ********RoostGPT******** +package com.bootexample4.products.model; + +import org.junit.jupiter.api.Test; +import static org.junit.jupiter.api.Assertions.assertEquals; +import jakarta.persistence.Entity; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; + +class ProductGetPriceTest { + + @Test + void getPriceOfProduct() { + // Arrange + Product product = new Product(); + double expectedPrice = 10.99; + product.setPrice(expectedPrice); + // Act + double actualPrice = product.getPrice(); + // Assert + assertEquals(expectedPrice, actualPrice); + } + + @Test + void getPriceOfProductWithZeroPrice() { + // Arrange + Product product = new Product(); + double expectedPrice = 0.0; + product.setPrice(expectedPrice); + // Act + double actualPrice = product.getPrice(); + // Assert + assertEquals(expectedPrice, actualPrice); + } + + @Test + void getPriceOfProductWithNegativePrice() { + // Arrange + Product product = new Product(); + double expectedPrice = -5.99; + product.setPrice(expectedPrice); + // Act + double actualPrice = product.getPrice(); + // Assert + assertEquals(expectedPrice, actualPrice); + } + + @Test + void getPriceOfProductWithMaxDoubleValue() { + // Arrange + Product product = new Product(); + double expectedPrice = Double.MAX_VALUE; + product.setPrice(expectedPrice); + // Act + double actualPrice = product.getPrice(); + // Assert + assertEquals(expectedPrice, actualPrice); + } + +} \ No newline at end of file diff --git a/src/test/java/com/bootexample4/products/model/ProductSetDescriptionTest.java b/src/test/java/com/bootexample4/products/model/ProductSetDescriptionTest.java new file mode 100644 index 00000000..2679253e --- /dev/null +++ b/src/test/java/com/bootexample4/products/model/ProductSetDescriptionTest.java @@ -0,0 +1,134 @@ +// ********RoostGPT******** +/* +Test generated by RoostGPT for test java-springboot using AI Type Claude AI and AI Model claude-3-opus-20240229 + +ROOST_METHOD_HASH=setDescription_467dbd26a0 +ROOST_METHOD_SIG_HASH=setDescription_b4ccff923c + +Here are the JUnit test scenarios for the provided setDescription method: + +Scenario 1: Valid Description + +Details: + TestName: validDescription. + Description: This test verifies that the setDescription method correctly sets the description field when a valid string is provided. +Execution: + Arrange: Create an instance of the class containing the setDescription method. + Act: Invoke the setDescription method with a valid string value. + Assert: Use assertEquals to compare the actual description field value against the expected string value. +Validation: + The assertion verifies that the description field is correctly set to the provided string value. + This test ensures that the setDescription method functions as intended for valid input. + +Scenario 2: Empty Description + +Details: + TestName: emptyDescription. + Description: This test checks that the setDescription method handles an empty string as the description value. +Execution: + Arrange: Create an instance of the class containing the setDescription method. + Act: Invoke the setDescription method with an empty string value. + Assert: Use assertEquals to verify that the description field is set to an empty string. +Validation: + The assertion confirms that the description field is correctly set to an empty string when provided. + This test ensures that the setDescription method can handle empty string input without throwing an exception or causing unexpected behavior. + +Scenario 3: Null Description + +Details: + TestName: nullDescription. + Description: This test verifies that the setDescription method handles a null value as the description. +Execution: + Arrange: Create an instance of the class containing the setDescription method. + Act: Invoke the setDescription method with a null value. + Assert: Use assertNull to check that the description field is set to null. +Validation: + The assertion verifies that the description field is correctly set to null when a null value is provided. + This test ensures that the setDescription method can handle null input without throwing an exception or causing unexpected behavior. + +Scenario 4: Long Description + +Details: + TestName: longDescription. + Description: This test checks that the setDescription method can handle a long string value as the description. +Execution: + Arrange: Create an instance of the class containing the setDescription method. + Act: Invoke the setDescription method with a long string value (e.g., 1000 characters). + Assert: Use assertEquals to verify that the description field is set to the provided long string value. +Validation: + The assertion confirms that the description field is correctly set to the long string value. + This test ensures that the setDescription method can handle long string input without truncation or causing unexpected behavior. + +Scenario 5: Special Characters in Description + +Details: + TestName: specialCharactersInDescription. + Description: This test verifies that the setDescription method can handle special characters in the description value. +Execution: + Arrange: Create an instance of the class containing the setDescription method. + Act: Invoke the setDescription method with a string value containing special characters (e.g., "!@#$%^&*()"). + Assert: Use assertEquals to check that the description field is set to the provided string value with special characters. +Validation: + The assertion confirms that the description field is correctly set to the string value containing special characters. + This test ensures that the setDescription method can handle special characters in the input without causing any issues or unexpected behavior. + +These test scenarios cover various cases, including valid input, empty string, null value, long string, and special characters, to ensure the robustness and correctness of the setDescription method. +*/ + +// ********RoostGPT******** +package com.bootexample4.products.model; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import static org.junit.jupiter.api.Assertions.*; +import jakarta.persistence.Entity; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; + +class ProductSetDescriptionTest { + + private Product product; + + @BeforeEach + void setUp() { + product = new Product(); + } + + @Test + void validDescription() { + String description = "This is a valid description"; + product.setDescription(description); + assertEquals(description, product.getDescription()); + } + + @Test + void emptyDescription() { + String description = ""; + product.setDescription(description); + assertEquals(description, product.getDescription()); + } + + @Test + void nullDescription() { + product.setDescription(null); + assertNull(product.getDescription()); + } + + @Test + void longDescription() { + String description = "This is a very long description that exceeds the typical length of a product description. " + + "It contains multiple sentences and provides detailed information about the product. " + + "The purpose of this test is to ensure that the setDescription method can handle long descriptions without any issues."; + product.setDescription(description); + assertEquals(description, product.getDescription()); + } + + @Test + void specialCharactersInDescription() { + String description = "This description contains special characters !@#$%^&*()"; + product.setDescription(description); + assertEquals(description, product.getDescription()); + } + +} \ No newline at end of file diff --git a/src/test/java/com/bootexample4/products/model/ProductSetIdTest.java b/src/test/java/com/bootexample4/products/model/ProductSetIdTest.java new file mode 100644 index 00000000..1905ea24 --- /dev/null +++ b/src/test/java/com/bootexample4/products/model/ProductSetIdTest.java @@ -0,0 +1,112 @@ +// ********RoostGPT******** +/* +Test generated by RoostGPT for test java-springboot using AI Type Claude AI and AI Model claude-3-opus-20240229 + +ROOST_METHOD_HASH=setId_b802c080bf +ROOST_METHOD_SIG_HASH=setId_04a8e16b7c + +Here are the JUnit test scenarios for the provided setId method: + +Scenario 1: Setting a Valid ID + +Details: + TestName: setValidId() + Description: This test verifies that the setId method correctly sets a valid ID value for the entity. +Execution: + Arrange: Create an instance of the entity class. + Act: Invoke the setId method with a valid Long value. + Assert: Use assertEquals to compare the entity's ID with the provided value. +Validation: + The assertion ensures that the setId method correctly assigns the provided ID value to the entity. + This test is important to validate that the entity's ID can be properly set using the setter method. + +Scenario 2: Setting a Null ID + +Details: + TestName: setNullId() + Description: This test checks the behavior of the setId method when a null value is provided as the ID. +Execution: + Arrange: Create an instance of the entity class. + Act: Invoke the setId method with a null value. + Assert: Use assertNull to verify that the entity's ID is set to null. +Validation: + The assertion confirms that the setId method allows setting the ID to null. + This test is crucial to ensure that the entity can handle cases where the ID is not provided or explicitly set to null. + +Scenario 3: Setting a Negative ID + +Details: + TestName: setNegativeId() + Description: This test verifies the behavior of the setId method when a negative value is provided as the ID. +Execution: + Arrange: Create an instance of the entity class. + Act: Invoke the setId method with a negative Long value. + Assert: Use assertEquals to compare the entity's ID with the provided negative value. +Validation: + The assertion ensures that the setId method allows setting a negative ID value. + This test is important to validate that the entity can handle cases where the ID is negative, depending on the application's requirements. + +Scenario 4: Setting a Zero ID + +Details: + TestName: setZeroId() + Description: This test checks the behavior of the setId method when a zero value is provided as the ID. +Execution: + Arrange: Create an instance of the entity class. + Act: Invoke the setId method with a Long value of zero. + Assert: Use assertEquals to compare the entity's ID with the provided zero value. +Validation: + The assertion verifies that the setId method allows setting the ID to zero. + This test is crucial to ensure that the entity can handle cases where the ID is explicitly set to zero, depending on the application's requirements. + +Note: The provided setId method does not have any specific validation or error handling. It simply assigns the provided value to the id field. Therefore, the test scenarios focus on verifying the basic functionality of setting different types of ID values. +*/ + +// ********RoostGPT******** +package com.bootexample4.products.model; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import static org.junit.jupiter.api.Assertions.*; +import jakarta.persistence.Entity; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; + +class ProductSetIdTest { + + private Product product; + + @BeforeEach + void setUp() { + product = new Product(); + } + + @Test + void setValidId() { + Long validId = 1L; + product.setId(validId); + assertEquals(validId, product.getId()); + } + + @Test + void setNullId() { + product.setId(null); + assertNull(product.getId()); + } + + @Test + void setNegativeId() { + Long negativeId = -1L; + product.setId(negativeId); + assertEquals(negativeId, product.getId()); + } + + @Test + void setZeroId() { + Long zeroId = 0L; + product.setId(zeroId); + assertEquals(zeroId, product.getId()); + } + +} \ No newline at end of file diff --git a/src/test/java/com/bootexample4/products/model/ProductSetNameTest.java b/src/test/java/com/bootexample4/products/model/ProductSetNameTest.java new file mode 100644 index 00000000..40ea6524 --- /dev/null +++ b/src/test/java/com/bootexample4/products/model/ProductSetNameTest.java @@ -0,0 +1,132 @@ +// ********RoostGPT******** +/* +Test generated by RoostGPT for test java-springboot using AI Type Claude AI and AI Model claude-3-opus-20240229 + +ROOST_METHOD_HASH=setName_6a446514c1 +ROOST_METHOD_SIG_HASH=setName_5d23a892d9 + +Here are the JUnit test scenarios for the provided setName method: + +Scenario 1: Valid Name Assignment + +Details: + TestName: validNameAssignment + Description: This test verifies that the setName method correctly assigns a valid name to the name field of the object. +Execution: + Arrange: Create an instance of the class containing the setName method. + Act: Invoke the setName method with a valid name string. + Assert: Use assertEquals to compare the assigned name with the expected name. +Validation: + The assertion ensures that the name field is properly set with the provided value. + This test is important to validate that the setName method functions as intended for valid input. + +Scenario 2: Null Name Assignment + +Details: + TestName: nullNameAssignment + Description: This test checks the behavior of the setName method when a null value is passed as the name parameter. +Execution: + Arrange: Create an instance of the class containing the setName method. + Act: Invoke the setName method with a null value. + Assert: Use assertNull to verify that the name field is set to null. +Validation: + The assertion confirms that the setName method handles null input correctly by setting the name field to null. + This test ensures that the method does not throw an exception or exhibit unexpected behavior when given a null name. + +Scenario 3: Empty Name Assignment + +Details: + TestName: emptyNameAssignment + Description: This test verifies that the setName method correctly handles an empty string as the name parameter. +Execution: + Arrange: Create an instance of the class containing the setName method. + Act: Invoke the setName method with an empty string. + Assert: Use assertEquals to compare the assigned name with an empty string. +Validation: + The assertion ensures that the name field is set to an empty string when provided. + This test validates that the setName method allows empty strings as valid input and assigns them accordingly. + +Scenario 4: Long Name Assignment + +Details: + TestName: longNameAssignment + Description: This test checks the behavior of the setName method when a very long name string is provided. +Execution: + Arrange: Create an instance of the class containing the setName method. + Act: Invoke the setName method with a name string exceeding a reasonable length (e.g., 1000 characters). + Assert: Use assertEquals to compare the assigned name with the expected long name. +Validation: + The assertion verifies that the setName method can handle and assign long name strings without truncation or errors. + This test ensures that the method does not have any limitations or issues when dealing with unusually long names. + +Scenario 5: Name Assignment with Special Characters + +Details: + TestName: specialCharactersNameAssignment + Description: This test verifies that the setName method correctly handles names containing special characters. +Execution: + Arrange: Create an instance of the class containing the setName method. + Act: Invoke the setName method with a name string that includes special characters (e.g., "John Doe!@#$%"). + Assert: Use assertEquals to compare the assigned name with the expected name containing special characters. +Validation: + The assertion ensures that the setName method can handle and assign names with special characters without any issues. + This test validates that the method does not have any restrictions or unexpected behavior when dealing with special characters in names. + +These test scenarios cover various aspects of the setName method, including valid name assignment, null and empty name handling, long name assignment, and special character support. They ensure that the method behaves as expected under different input conditions and edge cases. +*/ + +// ********RoostGPT******** +package com.bootexample4.products.model; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import static org.junit.jupiter.api.Assertions.*; +import jakarta.persistence.Entity; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; + +class ProductSetNameTest { + + private Product product; + + @BeforeEach + void setUp() { + product = new Product(); + } + + @Test + void validNameAssignment() { + String expectedName = "Valid Name"; + product.setName(expectedName); + assertEquals(expectedName, product.getName()); + } + + @Test + void nullNameAssignment() { + product.setName(null); + assertNull(product.getName()); + } + + @Test + void emptyNameAssignment() { + String expectedName = ""; + product.setName(expectedName); + assertEquals(expectedName, product.getName()); + } + + @Test + void longNameAssignment() { + String expectedName = "A".repeat(1000); + product.setName(expectedName); + assertEquals(expectedName, product.getName()); + } + + @Test + void specialCharactersNameAssignment() { + String expectedName = "John Doe!@#$%"; + product.setName(expectedName); + assertEquals(expectedName, product.getName()); + } + +} \ No newline at end of file diff --git a/src/test/java/com/bootexample4/products/model/ProductSetPriceTest.java b/src/test/java/com/bootexample4/products/model/ProductSetPriceTest.java new file mode 100644 index 00000000..2a27a821 --- /dev/null +++ b/src/test/java/com/bootexample4/products/model/ProductSetPriceTest.java @@ -0,0 +1,136 @@ +// ********RoostGPT******** +/* +Test generated by RoostGPT for test java-springboot using AI Type Claude AI and AI Model claude-3-opus-20240229 + +ROOST_METHOD_HASH=setPrice_aba0654a68 +ROOST_METHOD_SIG_HASH=setPrice_8f1e19b496 + +Here are the JUnit test scenarios for the provided setPrice method: + +Scenario 1: Setting a positive price + +Details: + TestName: setPriceWithPositiveValue + Description: This test checks if the setPrice method correctly sets a positive price value for the object. +Execution: + Arrange: Create an instance of the class containing the setPrice method. + Act: Invoke the setPrice method with a positive double value, e.g., 10.99. + Assert: Use assertEquals to verify that the price variable of the object is equal to the provided value. +Validation: + The assertion verifies that the setPrice method correctly assigns the provided positive value to the price variable. + This test ensures that the method behaves as expected when setting a valid positive price. + +Scenario 2: Setting a zero price + +Details: + TestName: setPriceWithZeroValue + Description: This test checks if the setPrice method allows setting the price to zero. +Execution: + Arrange: Create an instance of the class containing the setPrice method. + Act: Invoke the setPrice method with a value of 0.0. + Assert: Use assertEquals to verify that the price variable of the object is equal to 0.0. +Validation: + The assertion verifies that the setPrice method correctly assigns the value 0.0 to the price variable. + This test ensures that the method handles setting the price to zero correctly, depending on the business requirements. + +Scenario 3: Setting a negative price + +Details: + TestName: setPriceWithNegativeValue + Description: This test checks if the setPrice method handles setting a negative price value. +Execution: + Arrange: Create an instance of the class containing the setPrice method. + Act: Invoke the setPrice method with a negative double value, e.g., -5.99. + Assert: Use assertEquals to verify that the price variable of the object is equal to the provided negative value. +Validation: + The assertion verifies that the setPrice method correctly assigns the provided negative value to the price variable. + This test ensures that the method allows setting negative prices, which may or may not be desired depending on the business logic. If negative prices are not allowed, the test should be adjusted to expect an exception or validation error. + +Scenario 4: Setting a large price value + +Details: + TestName: setPriceWithLargeValue + Description: This test checks if the setPrice method can handle setting a large price value. +Execution: + Arrange: Create an instance of the class containing the setPrice method. + Act: Invoke the setPrice method with a large double value, e.g., 999999.99. + Assert: Use assertEquals to verify that the price variable of the object is equal to the provided large value. +Validation: + The assertion verifies that the setPrice method correctly assigns the provided large value to the price variable. + This test ensures that the method can handle large price values without any issues, such as precision loss or overflow. + +Scenario 5: Setting a price with decimal places + +Details: + TestName: setPriceWithDecimalPlaces + Description: This test checks if the setPrice method correctly handles setting a price with decimal places. +Execution: + Arrange: Create an instance of the class containing the setPrice method. + Act: Invoke the setPrice method with a double value that has decimal places, e.g., 9.99. + Assert: Use assertEquals with a delta parameter to verify that the price variable of the object is equal to the provided value within a small tolerance. +Validation: + The assertion with a delta parameter ensures that the setPrice method correctly assigns the provided value with decimal places to the price variable, allowing for small differences due to floating-point precision. + This test ensures that the method can handle prices with decimal places accurately. + +These test scenarios cover various aspects of the setPrice method, including setting positive, zero, negative, large, and decimal prices. They ensure that the method behaves as expected in different scenarios and help identify any potential issues or edge cases. +*/ + +// ********RoostGPT******** +package com.bootexample4.products.model; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.within; +import jakarta.persistence.Entity; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; + +class ProductSetPriceTest { + + private Product product; + + @BeforeEach + void setUp() { + product = new Product(); + } + + @Test + void setPriceWithPositiveValue() { + double price = 10.99; + product.setPrice(price); + assertThat(product.getPrice()).isEqualTo(price); + } + + @Test + void setPriceWithZeroValue() { + double price = 0.0; + product.setPrice(price); + assertThat(product.getPrice()).isEqualTo(price); + } + + @Test + void setPriceWithNegativeValue() { + double price = -5.99; + product.setPrice(price); + assertThat(product.getPrice()).isEqualTo(price); + } + + @Test + void setPriceWithLargeValue() { + double price = 999999.99; + product.setPrice(price); + assertThat(product.getPrice()).isEqualTo(price); + } + + @ParameterizedTest + @ValueSource(doubles = { 9.99, 0.01, 100.50 }) + void setPriceWithDecimalPlaces(double price) { + product.setPrice(price); + assertThat(product.getPrice()).isCloseTo(price, within(0.001)); + } + +} \ No newline at end of file diff --git a/target/classes/application.properties b/target/classes/application.properties new file mode 100644 index 00000000..8b137891 --- /dev/null +++ b/target/classes/application.properties @@ -0,0 +1 @@ + diff --git a/target/classes/com/bootexample4/products/ProductsApplication.class b/target/classes/com/bootexample4/products/ProductsApplication.class new file mode 100644 index 00000000..6a52de87 Binary files /dev/null and b/target/classes/com/bootexample4/products/ProductsApplication.class differ diff --git a/target/classes/com/bootexample4/products/controller/ProductController.class b/target/classes/com/bootexample4/products/controller/ProductController.class new file mode 100644 index 00000000..7f5465d9 Binary files /dev/null and b/target/classes/com/bootexample4/products/controller/ProductController.class differ diff --git a/target/classes/com/bootexample4/products/model/Product.class b/target/classes/com/bootexample4/products/model/Product.class new file mode 100644 index 00000000..0b02a5ee Binary files /dev/null and b/target/classes/com/bootexample4/products/model/Product.class differ diff --git a/target/classes/com/bootexample4/products/repository/ProductRepository.class b/target/classes/com/bootexample4/products/repository/ProductRepository.class new file mode 100644 index 00000000..359c7e3f Binary files /dev/null and b/target/classes/com/bootexample4/products/repository/ProductRepository.class differ diff --git a/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst b/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst new file mode 100644 index 00000000..3fc2fa99 --- /dev/null +++ b/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst @@ -0,0 +1,4 @@ +com/bootexample4/products/model/Product.class +com/bootexample4/products/controller/ProductController.class +com/bootexample4/products/repository/ProductRepository.class +com/bootexample4/products/ProductsApplication.class diff --git a/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst b/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst new file mode 100644 index 00000000..116af463 --- /dev/null +++ b/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst @@ -0,0 +1,4 @@ +/var/tmp/Roost/RoostGPT/java-springboot/64f204f0-1343-4582-a0d0-b2c7510a9b19/source/java-springboot/src/main/java/com/bootexample4/products/model/Product.java +/var/tmp/Roost/RoostGPT/java-springboot/64f204f0-1343-4582-a0d0-b2c7510a9b19/source/java-springboot/src/main/java/com/bootexample4/products/ProductsApplication.java +/var/tmp/Roost/RoostGPT/java-springboot/64f204f0-1343-4582-a0d0-b2c7510a9b19/source/java-springboot/src/main/java/com/bootexample4/products/controller/ProductController.java +/var/tmp/Roost/RoostGPT/java-springboot/64f204f0-1343-4582-a0d0-b2c7510a9b19/source/java-springboot/src/main/java/com/bootexample4/products/repository/ProductRepository.java diff --git a/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/createdFiles.lst b/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/createdFiles.lst new file mode 100644 index 00000000..6a637de6 --- /dev/null +++ b/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/createdFiles.lst @@ -0,0 +1,17 @@ +com/bootexample4/products/cucumber/SpringIntegrationTests.class +com/bootexample4/products/model/ProductSetDescriptionTest.class +com/bootexample4/products/model/ProductGetDescriptionTest.class +com/bootexample4/products/model/ProductGetPriceTest.class +com/bootexample4/products/model/ProductSetNameTest.class +com/bootexample4/products/cucumber/CucumberTestRunner.class +com/bootexample4/products/model/ProductGetNameTest.class +com/bootexample4/products/ProductsApplicationTests.class +com/bootexample4/products/model/ProductSetPriceTest.class +com/bootexample4/products/controller/ProductControllerCreateProductTest.class +com/bootexample4/products/cucumber/ProductStepDefinitions.class +com/bootexample4/products/TestMockServer.class +com/bootexample4/products/controller/ProductControllerUpdateProductTest.class +com/bootexample4/products/model/ProductGetIdTest.class +com/bootexample4/products/model/ProductSetIdTest.class +com/bootexample4/products/controller/ProductControllerGetAllProductsTest.class +com/bootexample4/products/controller/ProductControllerDeleteProductTest.class diff --git a/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/inputFiles.lst b/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/inputFiles.lst new file mode 100644 index 00000000..e04bc510 --- /dev/null +++ b/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/inputFiles.lst @@ -0,0 +1,18 @@ +/var/tmp/Roost/RoostGPT/java-springboot/64f204f0-1343-4582-a0d0-b2c7510a9b19/source/java-springboot/src/test/java/com/bootexample4/products/model/ProductGetIdTest.java +/var/tmp/Roost/RoostGPT/java-springboot/64f204f0-1343-4582-a0d0-b2c7510a9b19/source/java-springboot/src/test/java/com/bootexample4/products/model/ProductGetDescriptionTest.java +/var/tmp/Roost/RoostGPT/java-springboot/64f204f0-1343-4582-a0d0-b2c7510a9b19/source/java-springboot/src/test/java/com/bootexample4/products/model/ProductSetDescriptionTest.java +/var/tmp/Roost/RoostGPT/java-springboot/64f204f0-1343-4582-a0d0-b2c7510a9b19/source/java-springboot/src/test/java/com/bootexample4/products/controller/ProductControllerDeleteProductTest.java +/var/tmp/Roost/RoostGPT/java-springboot/64f204f0-1343-4582-a0d0-b2c7510a9b19/source/java-springboot/src/test/java/com/bootexample4/products/cucumber/ProductStepDefinitions.java +/var/tmp/Roost/RoostGPT/java-springboot/64f204f0-1343-4582-a0d0-b2c7510a9b19/source/java-springboot/src/test/java/com/bootexample4/products/ProductsApplicationTests.java +/var/tmp/Roost/RoostGPT/java-springboot/64f204f0-1343-4582-a0d0-b2c7510a9b19/source/java-springboot/src/test/java/com/bootexample4/products/controller/ProductControllerGetAllProductsTest.java +/var/tmp/Roost/RoostGPT/java-springboot/64f204f0-1343-4582-a0d0-b2c7510a9b19/source/java-springboot/src/test/java/com/bootexample4/products/cucumber/SpringIntegrationTests.java +/var/tmp/Roost/RoostGPT/java-springboot/64f204f0-1343-4582-a0d0-b2c7510a9b19/source/java-springboot/src/test/java/com/bootexample4/products/model/ProductGetPriceTest.java +/var/tmp/Roost/RoostGPT/java-springboot/64f204f0-1343-4582-a0d0-b2c7510a9b19/source/java-springboot/src/test/java/com/bootexample4/products/TestMockServer.java +/var/tmp/Roost/RoostGPT/java-springboot/64f204f0-1343-4582-a0d0-b2c7510a9b19/source/java-springboot/src/test/java/com/bootexample4/products/model/ProductSetPriceTest.java +/var/tmp/Roost/RoostGPT/java-springboot/64f204f0-1343-4582-a0d0-b2c7510a9b19/source/java-springboot/src/test/java/com/bootexample4/products/model/ProductSetIdTest.java +/var/tmp/Roost/RoostGPT/java-springboot/64f204f0-1343-4582-a0d0-b2c7510a9b19/source/java-springboot/src/test/java/com/bootexample4/products/model/ProductGetNameTest.java +/var/tmp/Roost/RoostGPT/java-springboot/64f204f0-1343-4582-a0d0-b2c7510a9b19/source/java-springboot/src/test/java/com/bootexample4/products/cucumber/CucumberTestRunner.java +/var/tmp/Roost/RoostGPT/java-springboot/64f204f0-1343-4582-a0d0-b2c7510a9b19/source/java-springboot/src/test/java/com/bootexample4/products/controller/ProductControllerCreateProductTest.java +/var/tmp/Roost/RoostGPT/java-springboot/64f204f0-1343-4582-a0d0-b2c7510a9b19/source/java-springboot/src/test/java/com/bootexample4/products/controller/ProductControllerUpdateProductTest.java +/var/tmp/Roost/RoostGPT/java-springboot/64f204f0-1343-4582-a0d0-b2c7510a9b19/source/java-springboot/src/test/java/com/bootexample4/products/model/ProductSetNameTest.java +/var/tmp/Roost/RoostGPT/java-springboot/64f204f0-1343-4582-a0d0-b2c7510a9b19/source/java-springboot/src/test/java/com/bootexample4/products/controller/ProductControllerGetProductByIdTest.java diff --git a/target/test-classes/com/bootexample4/products/ProductsApplicationTests.class b/target/test-classes/com/bootexample4/products/ProductsApplicationTests.class new file mode 100644 index 00000000..c5b36d0e Binary files /dev/null and b/target/test-classes/com/bootexample4/products/ProductsApplicationTests.class differ diff --git a/target/test-classes/com/bootexample4/products/TestMockServer.class b/target/test-classes/com/bootexample4/products/TestMockServer.class new file mode 100644 index 00000000..104a1f18 Binary files /dev/null and b/target/test-classes/com/bootexample4/products/TestMockServer.class differ diff --git a/target/test-classes/com/bootexample4/products/controller/ProductControllerCreateProductTest.class b/target/test-classes/com/bootexample4/products/controller/ProductControllerCreateProductTest.class new file mode 100644 index 00000000..5efd8c66 Binary files /dev/null and b/target/test-classes/com/bootexample4/products/controller/ProductControllerCreateProductTest.class differ diff --git a/target/test-classes/com/bootexample4/products/controller/ProductControllerDeleteProductTest.class b/target/test-classes/com/bootexample4/products/controller/ProductControllerDeleteProductTest.class new file mode 100644 index 00000000..6c27a546 Binary files /dev/null and b/target/test-classes/com/bootexample4/products/controller/ProductControllerDeleteProductTest.class differ diff --git a/target/test-classes/com/bootexample4/products/controller/ProductControllerGetAllProductsTest.class b/target/test-classes/com/bootexample4/products/controller/ProductControllerGetAllProductsTest.class new file mode 100644 index 00000000..74416bc0 Binary files /dev/null and b/target/test-classes/com/bootexample4/products/controller/ProductControllerGetAllProductsTest.class differ diff --git a/target/test-classes/com/bootexample4/products/controller/ProductControllerUpdateProductTest.class b/target/test-classes/com/bootexample4/products/controller/ProductControllerUpdateProductTest.class new file mode 100644 index 00000000..8eb9ef66 Binary files /dev/null and b/target/test-classes/com/bootexample4/products/controller/ProductControllerUpdateProductTest.class differ diff --git a/target/test-classes/com/bootexample4/products/cucumber/CucumberTestRunner.class b/target/test-classes/com/bootexample4/products/cucumber/CucumberTestRunner.class new file mode 100644 index 00000000..62a90b4a Binary files /dev/null and b/target/test-classes/com/bootexample4/products/cucumber/CucumberTestRunner.class differ diff --git a/target/test-classes/com/bootexample4/products/cucumber/ProductStepDefinitions.class b/target/test-classes/com/bootexample4/products/cucumber/ProductStepDefinitions.class new file mode 100644 index 00000000..4f352d00 Binary files /dev/null and b/target/test-classes/com/bootexample4/products/cucumber/ProductStepDefinitions.class differ diff --git a/target/test-classes/com/bootexample4/products/cucumber/SpringIntegrationTests.class b/target/test-classes/com/bootexample4/products/cucumber/SpringIntegrationTests.class new file mode 100644 index 00000000..273ecef2 Binary files /dev/null and b/target/test-classes/com/bootexample4/products/cucumber/SpringIntegrationTests.class differ diff --git a/target/test-classes/com/bootexample4/products/model/ProductGetDescriptionTest.class b/target/test-classes/com/bootexample4/products/model/ProductGetDescriptionTest.class new file mode 100644 index 00000000..22e6689c Binary files /dev/null and b/target/test-classes/com/bootexample4/products/model/ProductGetDescriptionTest.class differ diff --git a/target/test-classes/com/bootexample4/products/model/ProductGetIdTest.class b/target/test-classes/com/bootexample4/products/model/ProductGetIdTest.class new file mode 100644 index 00000000..e140cd28 Binary files /dev/null and b/target/test-classes/com/bootexample4/products/model/ProductGetIdTest.class differ diff --git a/target/test-classes/com/bootexample4/products/model/ProductGetNameTest.class b/target/test-classes/com/bootexample4/products/model/ProductGetNameTest.class new file mode 100644 index 00000000..21676687 Binary files /dev/null and b/target/test-classes/com/bootexample4/products/model/ProductGetNameTest.class differ diff --git a/target/test-classes/com/bootexample4/products/model/ProductGetPriceTest.class b/target/test-classes/com/bootexample4/products/model/ProductGetPriceTest.class new file mode 100644 index 00000000..2656cd20 Binary files /dev/null and b/target/test-classes/com/bootexample4/products/model/ProductGetPriceTest.class differ diff --git a/target/test-classes/com/bootexample4/products/model/ProductSetDescriptionTest.class b/target/test-classes/com/bootexample4/products/model/ProductSetDescriptionTest.class new file mode 100644 index 00000000..a5a5470c Binary files /dev/null and b/target/test-classes/com/bootexample4/products/model/ProductSetDescriptionTest.class differ diff --git a/target/test-classes/com/bootexample4/products/model/ProductSetIdTest.class b/target/test-classes/com/bootexample4/products/model/ProductSetIdTest.class new file mode 100644 index 00000000..9dd7a834 Binary files /dev/null and b/target/test-classes/com/bootexample4/products/model/ProductSetIdTest.class differ diff --git a/target/test-classes/com/bootexample4/products/model/ProductSetNameTest.class b/target/test-classes/com/bootexample4/products/model/ProductSetNameTest.class new file mode 100644 index 00000000..d63668df Binary files /dev/null and b/target/test-classes/com/bootexample4/products/model/ProductSetNameTest.class differ diff --git a/target/test-classes/com/bootexample4/products/model/ProductSetPriceTest.class b/target/test-classes/com/bootexample4/products/model/ProductSetPriceTest.class new file mode 100644 index 00000000..897dbb0b Binary files /dev/null and b/target/test-classes/com/bootexample4/products/model/ProductSetPriceTest.class differ diff --git a/target/test-classes/features/sample.feature b/target/test-classes/features/sample.feature new file mode 100644 index 00000000..61fb017b --- /dev/null +++ b/target/test-classes/features/sample.feature @@ -0,0 +1,38 @@ +Feature: Product API + As a user of the product API + I want to be able to perform CRUD operations on products + So that I can manage my products effectively + + Background: + Given the base URL is "http://localhost:8080" + + Scenario: Get all products + When the client sends a GET request "/api/products" to get the list of all products + Then the list of products returned should be empty + + Scenario: Create a new product + Given the client provides the following product data: + | name | description | price | + | Test Product | This is a test product. | 10.0 | + When the client sends a POST request to "/api/products" + Then the saved product should not be null and its properties must correspond to those provided by client + + Scenario: Get a product by ID + Given there is an existing product with ID 1 + When the client sends a GET request "/api/products/1" to get a product by its id + Then the response status code should be 200 + And the response should contain the product with ID 1 + + Scenario: Update an existing product + Given there is an existing product with ID 1 + And the client provides the following product data: + | name | description | price | + | Updated Product | This is an updated test product. | 15.0 | + When the client sends a PUT request to "/api/products/1" + Then the product with ID 1 should be updated with the provided details + + Scenario: Delete an existing product + Given there is an existing product with ID 1 + When the client sends a DELETE request to "/api/products/1" + Then the response status code should be 200 + And the product with ID 1 should no longer exist