-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #26 from rcsim/feature/recomendacao
Feature/recomendacao
- Loading branch information
Showing
13 changed files
with
181 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
src/test/java/com/postech30/movies/controller/UserControllerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package com.postech30.movies.controller; | ||
|
||
import com.postech30.movies.entity.Video; | ||
import com.postech30.movies.service.UserService; | ||
import org.bson.types.ObjectId; | ||
import org.mockito.InjectMocks; | ||
import org.junit.jupiter.api.Test; | ||
import org.mockito.InjectMocks; | ||
import org.mockito.Mock; | ||
import org.springframework.boot.test.autoconfigure.web.reactive.WebFluxTest; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.test.web.reactive.server.WebTestClient; | ||
import reactor.core.publisher.Flux; | ||
|
||
import java.time.LocalDate; | ||
import java.util.Arrays; | ||
import java.util.Collections; | ||
|
||
import static org.mockito.Mockito.when; | ||
@SpringBootTest | ||
public class UserControllerTest { | ||
|
||
@InjectMocks | ||
private UserController userController; | ||
|
||
@Mock | ||
private UserService userService; | ||
|
||
@Test | ||
public void testGetRecommendations() { | ||
// Configurar dados de exemplo | ||
String userId = "exampleUserId"; | ||
Video video1 = new Video( | ||
"12334", | ||
"Example Title", | ||
"Example Description", | ||
"https://example.com", | ||
LocalDate.now(), | ||
1000, | ||
Arrays.asList(new ObjectId("65b30969b4f04b5b4cf30b20"), new ObjectId("65b30969b4f04b5b4cfe0b20")).toString(), | ||
Collections.singletonList(new ObjectId("65b30969b4f04b5b4cfe0ba0")), | ||
"Example Category Name", | ||
"Example Category Description" | ||
); | ||
|
||
when(userService.getRecommendedVideos(userId)).thenReturn(Flux.just(video1)); | ||
|
||
userController.getRecommendations("user1"); | ||
} | ||
} |
67 changes: 67 additions & 0 deletions
67
src/test/java/com/postech30/movies/service/Impl/UserServiceImplTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package com.postech30.movies.service.Impl; | ||
|
||
|
||
import com.postech30.movies.entity.User; | ||
import com.postech30.movies.entity.Video; | ||
import com.postech30.movies.repository.UserRepository; | ||
import com.postech30.movies.repository.VideoRepository; | ||
import com.postech30.movies.service.UserService; | ||
import org.bson.types.ObjectId; | ||
import org.junit.jupiter.api.Test; | ||
import org.mockito.InjectMocks; | ||
import org.mockito.Mock; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import reactor.core.publisher.Flux; | ||
import reactor.core.publisher.Mono; | ||
import reactor.test.StepVerifier; | ||
|
||
import java.time.LocalDate; | ||
import java.util.Arrays; | ||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
import static org.mockito.Mockito.when; | ||
|
||
@SpringBootTest | ||
public class UserServiceImplTest { | ||
|
||
@InjectMocks | ||
private UserServiceImpl userService; | ||
|
||
@Mock | ||
private UserRepository userRepository; | ||
|
||
@Mock | ||
private VideoRepository videoRepository; | ||
|
||
|
||
|
||
|
||
|
||
@Test | ||
public void testGetRecommendedVideos() { | ||
// Configurar dados de exemplo | ||
String userId = "exampleUserId"; | ||
User user = new User("1","teste","[email protected]", Arrays.asList(new ObjectId("65b30969b4f04b5b4cfe0b20"))); | ||
Video video1 = new Video( | ||
"12334", | ||
"Example Title", | ||
"Example Description", | ||
"https://example.com", | ||
LocalDate.now(), | ||
1000, | ||
Arrays.asList(new ObjectId("65b30969b4f04b5b4cf30b20"), new ObjectId("65b30969b4f04b5b4cfe0b20")).toString(), | ||
Collections.singletonList(new ObjectId("65b30969b4f04b5b4cfe0ba0")), | ||
"Example Category Name", | ||
"Example Category Description" | ||
); | ||
when(userRepository.findById(userId)).thenReturn(Mono.just(user)); | ||
when(videoRepository.findById("videoId1")).thenReturn(Mono.just(video1)); | ||
when(videoRepository.findVideosByCategory(new ObjectId("65b30969b4f04b5b4cfe0ba0"))).thenReturn(Flux.just(video1)); | ||
|
||
// Chamar o método e verificar a resposta usando StepVerifier | ||
Flux<Video> result = userService.getRecommendedVideos(userId); | ||
|
||
} | ||
|
||
} |
Binary file not shown.