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
233 changes: 155 additions & 78 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,89 +1,166 @@
<?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>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<version>5.2.0</version>
<!--Dependency added by RoostGPT-->
</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>2.28.2</version>
<scope>test</scope>
<!--Dependency added by RoostGPT-->
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.1</version>
<scope>test</scope>
<!--Dependency added by RoostGPT-->
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-junit-jupiter</artifactId>
<version>2.28.2</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>io.spring.javaformat</groupId>
<artifactId>spring-javaformat-maven-plugin</artifactId>
<version>0.0.40</version>
<!--Plugin added by RoostGPT-->
</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-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>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
// ********RoostGPT********
/*
Test generated by RoostGPT for test java-sample-test using AI Type Azure Open AI and AI Model roostgpt-4-32k

ROOST_METHOD_HASH=createProduct_16b670a647
ROOST_METHOD_SIG_HASH=createProduct_36b748883e

"""
Scenario 1: Successful Product Creation Test

Details:
TestName: testCreateProductSuccess.
Description: This test is meant to check if a new product is successfully created and stored in the repository.
Execution:
Arrange: Mock the productRepository.save() method to return a product when called.
Act: Invoke the createProduct method with a valid product object.
Assert: Use JUnit assertions to compare the returned product object against the product object used for invocation.
Validation:
The assertion verifies that the returned product from the repository is the same as the one provided for creation. This validates that the createProduct method correctly saves the product in the repository.

Scenario 2: Product Creation with Null Product Object Test

Details:
TestName: testCreateProductNullProduct.
Description: This test is meant to check the behavior of the createProduct method when a null product object is provided.
Execution:
Arrange: Mock the productRepository.save() method to throw IllegalArgumentException when null is passed.
Act: Invoke the createProduct method with a null product object.
Assert: Use JUnit assertions to expect IllegalArgumentException.
Validation:
The assertion verifies that the productRepository.save method does not accept null values. This ensures that invalid products (null in this case) are not saved in the repository.

Scenario 3: Product Creation with Invalid Product Data Test

Details:
TestName: testCreateProductInvalidProductData.
Description: This test is meant to check the behavior of the createProduct method when a product object with invalid data is provided.
Execution:
Arrange: Mock the productRepository.save() method to throw a DataIntegrityViolationException when data integrity violation arises.
Act: Invoke the createProduct method with a product object containing invalid values for its fields.
Assert: Use JUnit assertions to expect DataIntegrityViolationException.
Validation:
The assertion verifies that when invalid data is present in a product, createProduct method doesn't allow the storage of this product in the repository.

Scenario 4: Repository Behavior During Exception Test

Details:
TestName: testCreateProductRepositoryException.
Description: This is meant to check how the createProduct method would handle an unexpected situation where the repository itself throws a general exception.
Execution:
Arrange: Mock the productRepository.save() method to throw a RuntimeException.
Act: Invoke the createProduct method with a valid product object.
Assert: Use JUnit assertions to expect a RuntimeException.
Validation:
The assertion verifies that whenever a repository-related exception occurs while saving the product, it is properly propagated by the createProduct method. The test's significance lies in observing how the method interacts with external dependencies during exceptions.
"""
*/

// ********RoostGPT********
package com.bootexample4.products.controller;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import com.bootexample4.products.controller.ProductController;
import com.bootexample4.products.model.Product;
import com.bootexample4.products.repository.ProductRepository;

import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static org.mockito.ArgumentMatchers.any;

@RunWith(MockitoJUnitRunner.class)
public class ProductControllerCreateProductTest {

@Mock
private ProductRepository productRepository;

private ProductController productController;

@Before
public void setup() {
productController = new ProductController();
}

@Test
public void testCreateProductSuccess() {
Product product = new Product();
product.setName("Product1");
product.setDescription("Description1");
product.setPrice(100.0);

when(productRepository.save(any(Product.class))).thenReturn(product);

Product result = productController.createProduct(product);
assertEquals(product, result);
verify(productRepository).save(product);
}

@Test(expected = IllegalArgumentException.class)
public void testCreateProductNullProduct() {
when(productRepository.save(null)).thenThrow(new IllegalArgumentException());
productController.createProduct(null);
}

@Test(expected = RuntimeException.class)
public void testCreateProductRepositoryException() {
Product product = new Product();
product.setName("Product2");
product.setDescription("Description2");
product.setPrice(200.0);

when(productRepository.save(any(Product.class))).thenThrow(new RuntimeException());

productController.createProduct(product);
}

}
Loading