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
239 changes: 143 additions & 96 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,96 +1,143 @@
<?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>
<dependency>
<groupId>io.spring.javaformat</groupId>
<artifactId>spring-javaformat-formatter</artifactId>
<version>0.0.40</version>
<!--Dependency added by RoostGPT-->
</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>
<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>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
//This test file is marked invalid as it contains compilation errors. Change the extension to of this file to .java, to manually edit its contents


// ********RoostGPT********
/*
Test generated by RoostGPT for test oct21-java using AI Type Azure Open AI and AI Model gpt-4o

ROOST_METHOD_HASH=CommentMusicById_73ccb95717
ROOST_METHOD_SIG_HASH=CommentMusicById_70a5563f90


Scenario 1: Successful update of the number of comments for valid music ID

Details:
TestName: updateCommentsSuccessForValidId
Description: Validate that the number of comments for a given valid music ID is incremented by 1 and properly saved in the repository.

Execution:
Arrange:
- Mock `musicRepo.findById(id)` to return a valid `MusicModel` instance with current comments set to 5.
- Ensure `Log.save()` operation is stubbed to accept and process a `LogModel` instance.

Act:
- Call the method `CommentMusicById(1)` with a valid ID (1).

Assert:
- Verify that the `MusicModel` instance has `numberOfComments` incremented to 6.
- Confirm that `musicRepo.save()` is called once with the updated `MusicModel`.
- Ensure that `Log.save()` captures a log entry with relevant data.

Validation:
- Confirms the correct execution of the functionality for a valid music ID.
- Ensures the "Música Alterada!" message is returned upon successful update.

*/

// ********RoostGPT********
package com.medeiros.SPRINGProject.Controllers;import static org.mockito.Mockito.*;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import com.medeiros.SPRINGProject.Models.LogModel;
import com.medeiros.SPRINGProject.Models.MusicModel;
import com.medeiros.SPRINGProject.algorithm.algorithmBlender;
import com.medeiros.SPRINGProject.Controllers.AppController;
import org.springframework.web.bind.annotation.*;
import java.util.Map;
import org.junit.jupiter.api.*;
import com.medeiros.SPRINGProject.Models.*;
import org.springframework.beans.factory.annotation.Autowired;

public class AppControllerCommentMusicByIdTest {
@Mock
private MusicModel musicModelMock;

@Mock
private MusicRepository musicRepo;

@Mock
private LogRepository logMock;
@Mock
private LogModel logModelMock;

@InjectMocks
private AppController appController;
public void setUp() {
MockitoAnnotations.openMocks(this);
}
@Test
@Tag("valid")
public void updateCommentsSuccessForValidId() {
// Arrange
int mockMusicId = 1; // Valid music ID
int existingComments = 5; // Placeholder value
int expectedComments = existingComments + 1;
// Mock dependencies setup
MusicModel mockMusic = mock(MusicModel.class);
when(musicRepo.findById(mockMusicId)).thenReturn(mockMusic);
when(mockMusic.getNumberOfComents()).thenReturn(existingComments);
doNothing().when(musicRepo).save(mockMusic);

// Mock the setting of comments directly
when(mockMusic.setNumberOfComents(expectedComments)).thenReturn(mockMusic);

LogModel stubLogModel = mock(LogModel.class);
when(logMock.save(any(LogModel.class))).thenReturn(null);
// Act
String result = appController.CommentMusicById(mockMusicId);
// Assert
assertEquals("Música Alterada!", result);
assertEquals(expectedComments, mockMusic.getNumberOfComents());
verify(musicRepo, times(1)).save(mockMusic);
verify(logMock, times(1)).save(any(LogModel.class));
}
@Test
@Tag("invalid")
public void updateCommentsFailsForNonExistentId() {
// Arrange
int mockMusicId = 9999; // Non-existent ID
when(musicRepo.findById(mockMusicId)).thenReturn(null);
// Act
String result = appController.CommentMusicById(mockMusicId);
// Assert
assertEquals("Música Não Encontrada!", result);
verify(musicRepo, never()).save(any(MusicModel.class));
verify(logMock, never()).save(any(LogModel.class));
}
}
Loading