Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
219 changes: 141 additions & 78 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,89 +1,152 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.0.5</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.bootexample4</groupId>
<artifactId>products</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>products</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>17</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<!-- mockserver -->
<dependency>
<groupId>org.mock-server</groupId>
<artifactId>mockserver-netty</artifactId>
<version>3.10.8</version>
</dependency>
<dependency>
<groupId>org.mock-server</groupId>
<artifactId>mockserver-client-java</artifactId>
<version>3.10.8</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>

<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<!-- Cucumber Spring Boot Starter -->
<?xml version="1.0"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.0.5</version>
<relativePath/>
<!-- lookup parent from repository -->
</parent>
<groupId>com.bootexample4</groupId>
<artifactId>products</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>products</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>17</java.version>
</properties>
<dependencies>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-spring</artifactId>
<version>7.0.0</version>
<scope>test</scope>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<!-- mockserver -->
<dependency>
<groupId>org.mock-server</groupId>
<artifactId>mockserver-netty</artifactId>
<version>3.10.8</version>
</dependency>
<dependency>
<groupId>org.mock-server</groupId>
<artifactId>mockserver-client-java</artifactId>
<version>3.10.8</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<!-- Cucumber Spring Boot Starter -->
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-spring</artifactId>
<version>7.0.0</version>
<scope>test</scope>
</dependency>
<!-- Cucumber Java -->
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-java</artifactId>
<version>7.0.0</version>
<scope>test</scope>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-java</artifactId>
<version>7.0.0</version>
<scope>test</scope>
</dependency>
<!-- Cucumber JUnit -->
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-junit</artifactId>
<version>7.0.0</version>
<scope>test</scope>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-junit</artifactId>
<version>7.0.0</version>
<scope>test</scope>
</dependency>
<!-- AssertJ -->
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>3.19.0</version>
<scope>test</scope>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>3.19.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.spring.javaformat</groupId>
<artifactId>spring-javaformat-formatter</artifactId>
<version>0.0.40</version>
<!--Dependency added by RoostGPT-->
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>4.3.1</version>
<scope>test</scope>
<!--Dependency added by RoostGPT-->
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>

</project>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.7</version>
<executions>
<execution>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>report</id>
<phase>test</phase>
<goals>
<goal>report</goal>
</goals>
<configuration>
<outputDirectory>coverageReport</outputDirectory>
</configuration>
</execution>
</executions>
<!--Plugin added by RoostGPT-->
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.2.5</version>
<!--Plugin added by RoostGPT-->
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-report-plugin</artifactId>
<version>3.2.5</version>
<configuration>
<outputDirectory>testReport</outputDirectory>
</configuration>
<!--Plugin added by RoostGPT-->
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-site-plugin</artifactId>
<version>2.1</version>
<configuration>
<outputDirectory>testReport</outputDirectory>
</configuration>
<!--Plugin added by RoostGPT-->
</plugin>
<plugin>
<groupId>io.spring.javaformat</groupId>
<artifactId>spring-javaformat-maven-plugin</artifactId>
<version>0.0.40</version>
<!--Plugin added by RoostGPT-->
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@

// ********RoostGPT********
/*
Test generated by RoostGPT for test dbrx-java using AI Type DBRX and AI Model mixtral-8x7b-instruct-v0.1
ROOST_METHOD_HASH=createProduct_60409495d0
ROOST_METHOD_SIG_HASH=createProduct_5b0158b3eb
1. Scenario 1: Test creating a new product with valid data
TestName: createNewProductWithValidData
Description: This test checks if a new product can be created with valid data.
Execution:
Arrange: Set up a valid Product object with required fields.
Act: Invoke the createProduct method with the valid Product object.
Assert: Verify that the returned Product object has the same data as the input and has a non-null id.
Validation:
This test verifies that the createProduct method is able to save a new product with valid data to the repository.
2. Scenario 2: Test creating a new product with missing required fields
TestName: createNewProductWithMissingRequiredFields
Description: This test checks if a new product cannot be created with missing required fields.
Execution:
Arrange: Set up a Product object with missing required fields.
Act: Invoke the createProduct method with the incomplete Product object.
Assert: Verify that an exception is thrown indicating which fields are missing.
Validation:
This test verifies that the createProduct method correctly throws an exception when a product with missing required fields is passed.
3. Scenario 3: Test creating a new product with invalid data
TestName: createNewProductWithInvalidData
Description: This test checks if a new product cannot be created with invalid data.
Execution:
Arrange: Set up a Product object with invalid data (e.g. negative price).
Act: Invoke the createProduct method with the invalid Product object.
Assert: Verify that an exception is thrown indicating which fields have invalid data.
Validation:
This test verifies that the createProduct method correctly throws an exception when a product with invalid data is passed.
4. Scenario 4: Test creating a new product with null request body
TestName: createNewProductWithNullBody
Description: This test checks if a new product cannot be created with null request body.
Execution:
Arrange: Set up a null request body.
Act: Invoke the createProduct method with the null request body.
Assert: Verify that an exception is thrown indicating that the request body is null.
Validation:
This test verifies that the createProduct method correctly throws an exception when a null request body is passed.
5. Scenario 5: Test creating a new product that exceeds the maximum allowed fields limit
TestName: createNewProductWithTooManyFields
Description: This test checks if a new product cannot be created when it exceeds the maximum allowed fields limit.
Execution:
Arrange: Set up a Product object with more fields than the maximum allowed.
Act: Invoke the createProduct method with the Product object.
Assert: Verify that an exception is thrown indicating that the Product object has too many fields.
Validation:
This test verifies that the createProduct method correctly throws an exception when a Product object with too many fields is passed.
*/
// ********RoostGPT********
package com.bootexample4.products.controller;

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 java.util.Optional;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.when;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import com.bootexample4.products.model.Product;
import com.bootexample4.products.repository.ProductRepository;
import org.junit.jupiter.api.*;

@Tag("com.bootexample4.products.controller")
@Tag("com.bootexample4.products.controller.createProduct")
@com.bootexample4.products.ProductsApplicationTests
public class ProductControllerCreateProductTest {

@Mock
private ProductRepository productRepository;

@InjectMocks
private ProductController productController;

@BeforeEach
public void init() {
MockitoAnnotations.openMocks(this);
}

@Test
public void createNewProductWithValidData() {
Product product = new Product("TestProduct", 10.0);
when(productRepository.save(any(Product.class))).thenReturn(product);
Product createdProduct = productController.createProduct(product);
assertEquals(product, createdProduct);
}

@Test
public void createNewProductWithMissingRequiredFields() {
Product product = new Product();
assertThrows(RuntimeException.class, () -> productController.createProduct(product));
}

@Test
public void createNewProductWithInvalidData() {
Product product = new Product("TestProduct", -10.0);
assertThrows(RuntimeException.class, () -> productController.createProduct(product));
}

@Test
public void createNewProductWithNullBody() {
assertThrows(RuntimeException.class, () -> productController.createProduct(null));
}

@Test
public void createNewProductWithTooManyFields() {
Product product = new Product("TestProduct", 10.0);
product.setId(1L); // Add id field to exceed the maximum allowed fields limit
assertThrows(RuntimeException.class, () -> productController.createProduct(product));
}

}
Loading