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
249 changes: 153 additions & 96 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,96 +1,153 @@
<?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.6</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.medeiros</groupId>
<artifactId>SPRINGProject</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>SPRINGProject</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>20</java.version>
<!-- ... -->
<spring-security.version>6.0.3</spring-security.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>com.mysql</groupId>
<artifactId>mysql-connector-j</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
<version>3.0.6</version>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<!-- https://mvnrepository.com/artifact/io.jsonwebtoken/jjwt-api -->
<dependency>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt-api</artifactId>
<version>0.11.5</version>
</dependency>



<!-- https://mvnrepository.com/artifact/org.springframework.security/spring-security-core -->
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-core</artifactId>
<version>6.0.3</version>
</dependency>

<!-- https://mvnrepository.com/artifact/io.jsonwebtoken/jjwt-orgjson -->

<!-- https://mvnrepository.com/artifact/io.jsonwebtoken/jjwt-impl -->
<dependency>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt-impl</artifactId>
<version>0.11.5</version>
<scope>runtime</scope>
</dependency>


</dependencies>

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

</project>
<?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.6</version>
<relativePath/>
<!-- lookup parent from repository -->
</parent>
<groupId>com.medeiros</groupId>
<artifactId>SPRINGProject</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>SPRINGProject</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>20</java.version>
<!-- ... -->
<spring-security.version>6.0.3</spring-security.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>com.mysql</groupId>
<artifactId>mysql-connector-j</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
<version>3.0.6</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<!-- https://mvnrepository.com/artifact/io.jsonwebtoken/jjwt-api -->
<dependency>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt-api</artifactId>
<version>0.11.5</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework.security/spring-security-core -->
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-core</artifactId>
<version>6.0.3</version>
</dependency>
<!-- https://mvnrepository.com/artifact/io.jsonwebtoken/jjwt-orgjson -->
<!-- https://mvnrepository.com/artifact/io.jsonwebtoken/jjwt-impl -->
<dependency>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt-impl</artifactId>
<version>0.11.5</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-junit-jupiter</artifactId>
<version>2.23.4</version>
<scope>test</scope>
<!--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>
</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.11</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>
<pluginManagement>
<plugins/>
</pluginManagement>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@

// ********RoostGPT********
/*
Test generated by RoostGPT for test maven-music-github using AI Type Azure Open AI and AI Model gpt-5

ROOST_METHOD_HASH=createForumIndex_fec126ecbb
ROOST_METHOD_SIG_HASH=createForumIndex_d46662bc78

Scenario 1: Returns success message and persists forum with typical valid inputs

Details:
TestName: returnsSuccessMessageAndPersistsForumWhenValidInput
Description: Validates that when provided with a non-empty name, a non-empty description, and a positive userId, the method constructs a forum entry, persists it via ForumIndexRepository.save, and returns the fixed success message.

Execution:
Arrange: Set up a ForumController instance with ForumIndexRepository mocked to accept any ForumIndexModel; ensure LogRepository and ForumChatRepository are also mocked. Prepare inputs such as nameForum = "General", forumDescription = "General discussion", userId = 42.
Act: Invoke createForumIndex with the arranged inputs.
Assert:
- Assert that the returned value equals the exact string "Forum criado".
- Verify that ForumIndexRepository.save is called exactly once with any ForumIndexModel instance.
- Verify that there are no interactions with LogRepository and ForumChatRepository.

Validation:
Confirms that the method’s primary behavior is to save a newly constructed forum and return a static success message. Ensures there are no side effects on unrelated components and that the method’s output is stable and predictable for valid input.

*/

// ********RoostGPT********

package com.medeiros.SPRINGProject.Controllers;

import com.medeiros.SPRINGProject.Models.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import com.medeiros.SPRINGProject.Controllers.ForumController;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.Mockito.*;
import org.junit.jupiter.api.*;

@ExtendWith(MockitoExtension.class)
public class ForumControllerCreateForumIndexTest {

@Mock
private LogRepository Log;

@Mock
private ForumIndexRepository ForumIndexRepo;

@Mock
private ForumChatRepository ChatRepository;

@InjectMocks
private ForumController forumController;

@Test
@Tag("valid")
public void testReturnsSuccessMessageAndPersistsForumWhenValidInput() {
String nameForum = "General";
String forumDescription = "General discussion";
int userId = 42;
String actual = forumController.createForumIndex(nameForum, forumDescription, userId);
String expected = "Forum criado";
assertEquals((String) expected, (String) actual);
verify(ForumIndexRepo, times(1)).save(any(ForumIndexModel.class));
verifyNoMoreInteractions(ForumIndexRepo);
verifyNoInteractions(Log, ChatRepository);
}

@Test
@Tag("boundary")
public void testReturnsSuccessMessageAndPersistsForumWhenUserIdIsZero() {
String nameForum = "General";
String forumDescription = "General discussion";
int userId = 0;
String actual = forumController.createForumIndex(nameForum, forumDescription, userId);
String expected = "Forum criado";
assertEquals((String) expected, (String) actual);
verify(ForumIndexRepo, times(1)).save(any(ForumIndexModel.class));
verifyNoMoreInteractions(ForumIndexRepo);
verifyNoInteractions(Log, ChatRepository);
}

@Test
@Tag("invalid")
public void testReturnsSuccessMessageAndPersistsForumWhenUserIdIsNegative() {
String nameForum = "General";
String forumDescription = "General discussion";
int userId = -5; // TODO: Adjust if negative userId should be handled differently
String actual = forumController.createForumIndex(nameForum, forumDescription, userId);
String expected = "Forum criado";
assertEquals((String) expected, (String) actual);
verify(ForumIndexRepo, times(1)).save(any(ForumIndexModel.class));
verifyNoMoreInteractions(ForumIndexRepo);
verifyNoInteractions(Log, ChatRepository);
}

@Test
@Tag("boundary")
public void testReturnsSuccessMessageAndPersistsForumWhenNameAndDescriptionAreEmpty() {
String nameForum = "";
String forumDescription = "";
int userId = 7;
String actual = forumController.createForumIndex(nameForum, forumDescription, userId);
String expected = "Forum criado";
assertEquals((String) expected, (String) actual);
verify(ForumIndexRepo, times(1)).save(any(ForumIndexModel.class));
verifyNoMoreInteractions(ForumIndexRepo);
verifyNoInteractions(Log, ChatRepository);
}

}
Loading