diff --git a/api/src/main/java/com/backend/backend/config/ApplicationConfiguration.java b/api/src/main/java/com/backend/backend/config/ApplicationConfiguration.java index 0784938..915746d 100644 --- a/api/src/main/java/com/backend/backend/config/ApplicationConfiguration.java +++ b/api/src/main/java/com/backend/backend/config/ApplicationConfiguration.java @@ -11,6 +11,18 @@ import org.springframework.security.core.userdetails.UsernameNotFoundException; import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; +/** + * Acknowledgements: + * This class was written by following the instructions in the "Implement JWT authentication + * in a Spring Boot 3 application" tutorial on Medium published by Eric C. Togo. + * The tutorial was published on 20/03/2024. + * + * The full APA 7th reference is: + * Tiogo, E.C. (2024) Implement JWT authentication in a Spring Boot 3 + * application, Medium. Available at: + * https://medium.com/@tericcabrel/implement-jwt-authentication-in-a-spring-boot-3-application-5839e4fd8fac + * (Accessed: 22 June 2024). + */ @Configuration public class ApplicationConfiguration { private final UserRepository userRepository; diff --git a/api/src/main/java/com/backend/backend/config/SecurityConfiguration.java b/api/src/main/java/com/backend/backend/config/SecurityConfiguration.java index bafb508..50139c0 100644 --- a/api/src/main/java/com/backend/backend/config/SecurityConfiguration.java +++ b/api/src/main/java/com/backend/backend/config/SecurityConfiguration.java @@ -17,7 +17,18 @@ import java.util.List; -// SecurityConfiguration.java +/** + * Acknowledgements: + * This class was written by following the instructions in the "Implement JWT authentication + * in a Spring Boot 3 application" tutorial on Medium published by Eric C. Togo. + * The tutorial was published on 20/03/2024. + * + * The full APA 7th reference is: + * Tiogo, E.C. (2024) Implement JWT authentication in a Spring Boot 3 + * application, Medium. Available at: + * https://medium.com/@tericcabrel/implement-jwt-authentication-in-a-spring-boot-3-application-5839e4fd8fac + * (Accessed: 22 June 2024). + */ @Configuration @EnableWebSecurity public class SecurityConfiguration { diff --git a/api/src/main/java/com/backend/backend/controller/AuthenticationController.java b/api/src/main/java/com/backend/backend/controller/AuthenticationController.java index de9742f..8c26644 100644 --- a/api/src/main/java/com/backend/backend/controller/AuthenticationController.java +++ b/api/src/main/java/com/backend/backend/controller/AuthenticationController.java @@ -18,6 +18,18 @@ import lombok.extern.slf4j.Slf4j; +/** + * Acknowledgements: + * This class was written by following the instructions in the "Implement JWT authentication + * in a Spring Boot 3 application" tutorial on Medium published by Eric C. Togo. + * The tutorial was published on 20/03/2024. + * + * The full APA 7th reference is: + * Tiogo, E.C. (2024) Implement JWT authentication in a Spring Boot 3 + * application, Medium. Available at: + * https://medium.com/@tericcabrel/implement-jwt-authentication-in-a-spring-boot-3-application-5839e4fd8fac + * (Accessed: 22 June 2024). + */ @RequestMapping("/auth") @RestController @Slf4j diff --git a/api/src/main/java/com/backend/backend/controller/BoardController.java b/api/src/main/java/com/backend/backend/controller/BoardController.java index e8be7cb..7d88d99 100644 --- a/api/src/main/java/com/backend/backend/controller/BoardController.java +++ b/api/src/main/java/com/backend/backend/controller/BoardController.java @@ -55,7 +55,7 @@ public ResponseEntity getBoardById(@PathVariable Long id) { Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); User currentUser = (User) authentication.getPrincipal(); log.info("User {} is searching for kanban with id {} START", currentUser.getUserTag(), id); - BoardResponse boardResponse = boardService.getBoardByIdAndUserNew(id, currentUser.getId()); + BoardResponse boardResponse = boardService.getBoardByIdAndUser(id, currentUser.getId()); log.info("User {} is searching for kanban with id {} SUCCESS", currentUser.getUserTag(), id); return ResponseEntity.ok(boardResponse); } diff --git a/api/src/main/java/com/backend/backend/controller/UserController.java b/api/src/main/java/com/backend/backend/controller/UserController.java index 9a2e7d2..308efee 100644 --- a/api/src/main/java/com/backend/backend/controller/UserController.java +++ b/api/src/main/java/com/backend/backend/controller/UserController.java @@ -10,6 +10,18 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; +/** + * Acknowledgements: + * This class was written by following the instructions in the "Implement JWT authentication + * in a Spring Boot 3 application" tutorial on Medium published by Eric C. Togo. + * The tutorial was published on 20/03/2024. + * + * The full APA 7th reference is: + * Tiogo, E.C. (2024) Implement JWT authentication in a Spring Boot 3 + * application, Medium. Available at: + * https://medium.com/@tericcabrel/implement-jwt-authentication-in-a-spring-boot-3-application-5839e4fd8fac + * (Accessed: 22 June 2024). + */ @RequestMapping("/user") @RestController @Slf4j diff --git a/api/src/main/java/com/backend/backend/dto/LoginResponse.java b/api/src/main/java/com/backend/backend/dto/LoginResponse.java index 395e69e..0dc6918 100644 --- a/api/src/main/java/com/backend/backend/dto/LoginResponse.java +++ b/api/src/main/java/com/backend/backend/dto/LoginResponse.java @@ -3,6 +3,18 @@ import lombok.Data; import lombok.experimental.Accessors; +/** + * Acknowledgements: + * This class was written by following the instructions in the "Implement JWT authentication + * in a Spring Boot 3 application" tutorial on Medium published by Eric C. Togo. + * The tutorial was published on 20/03/2024. + * + * The full APA 7th reference is: + * Tiogo, E.C. (2024) Implement JWT authentication in a Spring Boot 3 + * application, Medium. Available at: + * https://medium.com/@tericcabrel/implement-jwt-authentication-in-a-spring-boot-3-application-5839e4fd8fac + * (Accessed: 22 June 2024). + */ @Data @Accessors(chain = true) public class LoginResponse { diff --git a/api/src/main/java/com/backend/backend/dto/LoginUserDto.java b/api/src/main/java/com/backend/backend/dto/LoginUserDto.java index 8be4fe2..fbb43d9 100644 --- a/api/src/main/java/com/backend/backend/dto/LoginUserDto.java +++ b/api/src/main/java/com/backend/backend/dto/LoginUserDto.java @@ -2,6 +2,18 @@ import lombok.Data; +/** + * Acknowledgements: + * This class was written by following the instructions in the "Implement JWT authentication + * in a Spring Boot 3 application" tutorial on Medium published by Eric C. Togo. + * The tutorial was published on 20/03/2024. + * + * The full APA 7th reference is: + * Tiogo, E.C. (2024) Implement JWT authentication in a Spring Boot 3 + * application, Medium. Available at: + * https://medium.com/@tericcabrel/implement-jwt-authentication-in-a-spring-boot-3-application-5839e4fd8fac + * (Accessed: 22 June 2024). + */ @Data public class LoginUserDto { private String email; diff --git a/api/src/main/java/com/backend/backend/dto/RegisterUserDto.java b/api/src/main/java/com/backend/backend/dto/RegisterUserDto.java index d9d23d5..2e02da2 100644 --- a/api/src/main/java/com/backend/backend/dto/RegisterUserDto.java +++ b/api/src/main/java/com/backend/backend/dto/RegisterUserDto.java @@ -2,6 +2,18 @@ import lombok.Data; +/** + * Acknowledgements: + * This class was written by following the instructions in the "Implement JWT authentication + * in a Spring Boot 3 application" tutorial on Medium published by Eric C. Togo. + * The tutorial was published on 20/03/2024. + * + * The full APA 7th reference is: + * Tiogo, E.C. (2024) Implement JWT authentication in a Spring Boot 3 + * application, Medium. Available at: + * https://medium.com/@tericcabrel/implement-jwt-authentication-in-a-spring-boot-3-application-5839e4fd8fac + * (Accessed: 22 June 2024). + */ @Data public class RegisterUserDto { private String email; diff --git a/api/src/main/java/com/backend/backend/exceptions/GlobalExceptionHandler.java b/api/src/main/java/com/backend/backend/exceptions/GlobalExceptionHandler.java index 6803741..3cca61a 100644 --- a/api/src/main/java/com/backend/backend/exceptions/GlobalExceptionHandler.java +++ b/api/src/main/java/com/backend/backend/exceptions/GlobalExceptionHandler.java @@ -10,6 +10,18 @@ import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.bind.annotation.RestControllerAdvice; +/** + * Acknowledgements: + * This class was written by following the instructions in the "Implement JWT authentication + * in a Spring Boot 3 application" tutorial on Medium published by Eric C. Togo. + * The tutorial was published on 20/03/2024. + * + * The full APA 7th reference is: + * Tiogo, E.C. (2024) Implement JWT authentication in a Spring Boot 3 + * application, Medium. Available at: + * https://medium.com/@tericcabrel/implement-jwt-authentication-in-a-spring-boot-3-application-5839e4fd8fac + * (Accessed: 22 June 2024). + */ @RestControllerAdvice public class GlobalExceptionHandler { diff --git a/api/src/main/java/com/backend/backend/filter/JwtFilter.java b/api/src/main/java/com/backend/backend/filter/JwtFilter.java index 504a3d8..c00581e 100644 --- a/api/src/main/java/com/backend/backend/filter/JwtFilter.java +++ b/api/src/main/java/com/backend/backend/filter/JwtFilter.java @@ -18,7 +18,18 @@ import java.io.IOException; -// JwtRequestFilter.java +/** + * Acknowledgements: + * This class was written by following the instructions in the "Implement JWT authentication + * in a Spring Boot 3 application" tutorial on Medium published by Eric C. Togo. + * The tutorial was published on 20/03/2024. + * + * The full APA 7th reference is: + * Tiogo, E.C. (2024) Implement JWT authentication in a Spring Boot 3 + * application, Medium. Available at: + * https://medium.com/@tericcabrel/implement-jwt-authentication-in-a-spring-boot-3-application-5839e4fd8fac + * (Accessed: 22 June 2024). + */ @Component public class JwtFilter extends OncePerRequestFilter { private final HandlerExceptionResolver handlerExceptionResolver; diff --git a/api/src/main/java/com/backend/backend/model/User.java b/api/src/main/java/com/backend/backend/model/User.java index 5181e94..2df592b 100644 --- a/api/src/main/java/com/backend/backend/model/User.java +++ b/api/src/main/java/com/backend/backend/model/User.java @@ -10,6 +10,19 @@ import java.util.List; import java.util.Set; + +/** + * Acknowledgements: + * This class was written by following the instructions in the "Implement JWT authentication + * in a Spring Boot 3 application" tutorial on Medium published by Eric C. Togo. + * The tutorial was published on 20/03/2024. + * + * The full APA 7th reference is: + * Tiogo, E.C. (2024) Implement JWT authentication in a Spring Boot 3 + * application, Medium. Available at: + * https://medium.com/@tericcabrel/implement-jwt-authentication-in-a-spring-boot-3-application-5839e4fd8fac + * (Accessed: 22 June 2024). + */ @Table(name="users") @Entity @Data diff --git a/api/src/main/java/com/backend/backend/repository/UserRepository.java b/api/src/main/java/com/backend/backend/repository/UserRepository.java index a76384d..6fc02cf 100644 --- a/api/src/main/java/com/backend/backend/repository/UserRepository.java +++ b/api/src/main/java/com/backend/backend/repository/UserRepository.java @@ -5,6 +5,18 @@ import java.util.Optional; +/** + * Acknowledgements: + * This class was written by following the instructions in the "Implement JWT authentication + * in a Spring Boot 3 application" tutorial on Medium published by Eric C. Togo. + * The tutorial was published on 20/03/2024. + * + * The full APA 7th reference is: + * Tiogo, E.C. (2024) Implement JWT authentication in a Spring Boot 3 + * application, Medium. Available at: + * https://medium.com/@tericcabrel/implement-jwt-authentication-in-a-spring-boot-3-application-5839e4fd8fac + * (Accessed: 22 June 2024). + */ public interface UserRepository extends JpaRepository { Optional findByEmail(String email); Optional findByUserTag(String userTag); diff --git a/api/src/main/java/com/backend/backend/service/AuthenticationService.java b/api/src/main/java/com/backend/backend/service/AuthenticationService.java index 058a0fa..6357a87 100644 --- a/api/src/main/java/com/backend/backend/service/AuthenticationService.java +++ b/api/src/main/java/com/backend/backend/service/AuthenticationService.java @@ -14,6 +14,18 @@ import com.backend.backend.exceptions.UserAlreadyExistsException; +/** + * Acknowledgements: + * This class was written by following the instructions in the "Implement JWT authentication + * in a Spring Boot 3 application" tutorial on Medium published by Eric C. Togo. + * The tutorial was published on 20/03/2024. + * + * The full APA 7th reference is: + * Tiogo, E.C. (2024) Implement JWT authentication in a Spring Boot 3 + * application, Medium. Available at: + * https://medium.com/@tericcabrel/implement-jwt-authentication-in-a-spring-boot-3-application-5839e4fd8fac + * (Accessed: 22 June 2024). + */ @Service public class AuthenticationService { private final UserRepository userRepository; diff --git a/api/src/main/java/com/backend/backend/service/BoardService.java b/api/src/main/java/com/backend/backend/service/BoardService.java index f466b28..250a0fa 100644 --- a/api/src/main/java/com/backend/backend/service/BoardService.java +++ b/api/src/main/java/com/backend/backend/service/BoardService.java @@ -11,57 +11,86 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +/** + * A service class that handles interactions with boards in the database. This layer is called by the controller + * classes and interacts directly with the repository interfaces to create, read, update and delete in the database. + */ @Service public class BoardService { - + /** + * Repository with CRUD methods on the Board table in the database + */ private final BoardRepository boardRepository; + /** + * Repository with CRUD methods on the Userboard table in the database + */ private final UserBoardRepository userBoardRepository; - public BoardService(UserRepository userRepository, BoardRepository boardRepository, UserBoardRepository userBoardRepository) { + /** + * Constructs a new Board service and injects the repositories + * @param boardRepository - Board repository + * @param userBoardRepository - Userboard repository + */ + public BoardService(BoardRepository boardRepository, UserBoardRepository userBoardRepository) { this.boardRepository = boardRepository; this.userBoardRepository = userBoardRepository; } + /** + * Creates a blank board for a user + * @param user - User to create the new board for + * @return - BoardResponse with the details of the new board for the user + */ public BoardResponse createBoardForUser(User user) { Board board = new Board(); - boardRepository.save(board); + boardRepository.save(board); // saves board UserBoard userBoard = new UserBoard(); userBoard.setUser(user); userBoard.setBoard(board); - userBoardRepository.save(userBoard); + userBoardRepository.save(userBoard); // links user to the board return new BoardResponse(board); } + /** + * Retrieves a board by its id for a specific user + * @param boardId - The ID of the board to find + * @param userId - The ID of the user who is searching for the board + * @return A BoardResponse with the details of the board found for the user + * @throws EntityNotFoundException if board id is not found for that user + */ public BoardResponse getBoardByIdAndUser(Long boardId, Long userId) { - Board board = boardRepository.findByIdAndUserId(boardId, userId) - .orElseThrow(() -> new EntityNotFoundException("Board not found with id " + boardId.toString())); - - BoardResponse response = new BoardResponse(board); - return response; - - } - - public BoardResponse getBoardByIdAndUserNew(Long boardId, Long userId) { + // Find board with id Board board = boardRepository.findById(boardId) .orElseThrow(() -> new EntityNotFoundException("Board not found with id " + boardId.toString())); + // Check if user is a member of the board if ( board.getUserBoards().stream().anyMatch(userBoard -> userBoard.getUser().getId() == userId)) { return new BoardResponse(board); } else { + // User is not a member of the board so throw error throw new EntityNotFoundException("Board not found with id " + boardId.toString()); } } + /** + * Deletes a board for a user + * @param user - User who is trying to delete the board + * @param boardId - ID of the board that will be deleted + * @throws EntityNotFoundException if boared with correct id and user not found + */ @Transactional public void deleteBoard(User user, Long boardId) { + // Find board with board id for that user Board board = boardRepository.findByIdAndUserId(boardId, user.getId()) .orElseThrow(() -> new EntityNotFoundException("Board not found with id " + boardId.toString())); + // Cleanup userboards linking users to the board for (UserBoard userBoard : board.getUserBoards()) { userBoardRepository.delete(userBoard); } + // Delete the board boardRepository.delete(board); } diff --git a/api/src/main/java/com/backend/backend/service/JwtService.java b/api/src/main/java/com/backend/backend/service/JwtService.java index 93084e8..1533038 100644 --- a/api/src/main/java/com/backend/backend/service/JwtService.java +++ b/api/src/main/java/com/backend/backend/service/JwtService.java @@ -18,6 +18,18 @@ import java.util.Map; import java.util.function.Function; +/** + * Acknowledgements: + * This class was written by following the instructions in the "Implement JWT authentication + * in a Spring Boot 3 application" tutorial on Medium published by Eric C. Togo. + * The tutorial was published on 20/03/2024. + * + * The full APA 7th reference is: + * Tiogo, E.C. (2024) Implement JWT authentication in a Spring Boot 3 + * application, Medium. Available at: + * https://medium.com/@tericcabrel/implement-jwt-authentication-in-a-spring-boot-3-application-5839e4fd8fac + * (Accessed: 22 June 2024). + */ @Service @AllArgsConstructor @NoArgsConstructor diff --git a/api/src/test/java/com/backend/backend/BackendApplicationTests.java b/api/src/test/java/com/backend/backend/BackendApplicationTests.java index b360bde..500c7ce 100644 --- a/api/src/test/java/com/backend/backend/BackendApplicationTests.java +++ b/api/src/test/java/com/backend/backend/BackendApplicationTests.java @@ -4,7 +4,12 @@ import org.springframework.boot.test.context.SpringBootTest; import static org.junit.jupiter.api.Assertions.assertEquals; - +/** + * Acknowledgements: + * ChatGPT (https://chatgpt.com/) was used to assist in writing test + * cases. The test cases were further edited manually for correctness, brevity and + * coverage of cases in the code + */ @SpringBootTest class BackendApplicationTests { diff --git a/api/src/test/java/com/backend/backend/controller/AuthenticationControllerTests.java b/api/src/test/java/com/backend/backend/controller/AuthenticationControllerTests.java index 1518f72..6770c70 100644 --- a/api/src/test/java/com/backend/backend/controller/AuthenticationControllerTests.java +++ b/api/src/test/java/com/backend/backend/controller/AuthenticationControllerTests.java @@ -19,6 +19,12 @@ import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.when; +/** + * Acknowledgements: + * ChatGPT (https://chatgpt.com/) was used to assist in writing test + * cases. The test cases were further edited manually for correctness, brevity and + * coverage of cases in the code + */ class AuthenticationControllerTests { @InjectMocks diff --git a/api/src/test/java/com/backend/backend/controller/BoardControllerTest.java b/api/src/test/java/com/backend/backend/controller/BoardControllerTest.java index 3c5b63f..ff4ceb1 100644 --- a/api/src/test/java/com/backend/backend/controller/BoardControllerTest.java +++ b/api/src/test/java/com/backend/backend/controller/BoardControllerTest.java @@ -23,7 +23,12 @@ import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyLong; import static org.mockito.Mockito.*; - +/** + * Acknowledgements: + * ChatGPT (https://chatgpt.com/) was used to assist in writing test + * cases. The test cases were further edited manually for correctness, brevity and + * coverage of cases in the code + */ class BoardControllerTest { @InjectMocks @@ -87,7 +92,7 @@ void testGetBoardById() { // Arrange Long boardId = 1L; BoardResponse mockBoardResponse = new BoardResponse(boardId, "Board Name", "Description", null, null, null, null); - when(boardService.getBoardByIdAndUserNew(boardId, currentUser.getId())).thenReturn(mockBoardResponse); + when(boardService.getBoardByIdAndUser(boardId, currentUser.getId())).thenReturn(mockBoardResponse); // Act ResponseEntity response = boardController.getBoardById(boardId); @@ -95,7 +100,7 @@ void testGetBoardById() { // Assert assertEquals(HttpStatus.OK, response.getStatusCode()); assertEquals(mockBoardResponse, response.getBody()); - verify(boardService).getBoardByIdAndUserNew(boardId, currentUser.getId()); + verify(boardService).getBoardByIdAndUser(boardId, currentUser.getId()); } @Test diff --git a/api/src/test/java/com/backend/backend/controller/TaskControllerTest.java b/api/src/test/java/com/backend/backend/controller/TaskControllerTest.java index bb7aacf..0676077 100644 --- a/api/src/test/java/com/backend/backend/controller/TaskControllerTest.java +++ b/api/src/test/java/com/backend/backend/controller/TaskControllerTest.java @@ -21,7 +21,12 @@ import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyLong; import static org.mockito.Mockito.*; - +/** + * Acknowledgements: + * ChatGPT (https://chatgpt.com/) was used to assist in writing test + * cases. The test cases were further edited manually for correctness, brevity and + * coverage of cases in the code + */ class TaskControllerTest { @InjectMocks diff --git a/api/src/test/java/com/backend/backend/controller/UserControllerTests.java b/api/src/test/java/com/backend/backend/controller/UserControllerTests.java index 5ec4066..5282c40 100644 --- a/api/src/test/java/com/backend/backend/controller/UserControllerTests.java +++ b/api/src/test/java/com/backend/backend/controller/UserControllerTests.java @@ -14,7 +14,12 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; - +/** + * Acknowledgements: + * ChatGPT (https://chatgpt.com/) was used to assist in writing test + * cases. The test cases were further edited manually for correctness, brevity and + * coverage of cases in the code + */ class UserControllerTest { private UserController userController; diff --git a/api/src/test/java/com/backend/backend/dto/BoardResponseTest.java b/api/src/test/java/com/backend/backend/dto/BoardResponseTest.java index c96d2d0..5fb37ec 100644 --- a/api/src/test/java/com/backend/backend/dto/BoardResponseTest.java +++ b/api/src/test/java/com/backend/backend/dto/BoardResponseTest.java @@ -14,7 +14,12 @@ import static org.junit.jupiter.api.Assertions.*; import static org.mockito.Mockito.*; - +/** + * Acknowledgements: + * ChatGPT (https://chatgpt.com/) was used to assist in writing test + * cases. The test cases were further edited manually for correctness, brevity and + * coverage of cases in the code + */ class BoardResponseTest { private Board boardMock; diff --git a/api/src/test/java/com/backend/backend/dto/CommentRequestTest.java b/api/src/test/java/com/backend/backend/dto/CommentRequestTest.java index 48b317e..0a6877b 100644 --- a/api/src/test/java/com/backend/backend/dto/CommentRequestTest.java +++ b/api/src/test/java/com/backend/backend/dto/CommentRequestTest.java @@ -10,7 +10,12 @@ import java.util.Set; import static org.junit.jupiter.api.Assertions.*; - +/** + * Acknowledgements: + * ChatGPT (https://chatgpt.com/) was used to assist in writing test + * cases. The test cases were further edited manually for correctness, brevity and + * coverage of cases in the code + */ class CommentRequestTest { private Validator validator; diff --git a/api/src/test/java/com/backend/backend/exceptions/GlobalExceptionHandlerTests.java b/api/src/test/java/com/backend/backend/exceptions/GlobalExceptionHandlerTests.java index bcc6ba1..8ca6b61 100644 --- a/api/src/test/java/com/backend/backend/exceptions/GlobalExceptionHandlerTests.java +++ b/api/src/test/java/com/backend/backend/exceptions/GlobalExceptionHandlerTests.java @@ -10,7 +10,12 @@ import org.springframework.security.authentication.BadCredentialsException; import static org.junit.jupiter.api.Assertions.*; - +/** + * Acknowledgements: + * ChatGPT (https://chatgpt.com/) was used to assist in writing test + * cases. The test cases were further edited manually for correctness, brevity and + * coverage of cases in the code + */ class GlobalExceptionHandlerTest { private GlobalExceptionHandler globalExceptionHandler; diff --git a/api/src/test/java/com/backend/backend/filter/CorrelationIdFilterTest.java b/api/src/test/java/com/backend/backend/filter/CorrelationIdFilterTest.java index 50779f2..8cae677 100644 --- a/api/src/test/java/com/backend/backend/filter/CorrelationIdFilterTest.java +++ b/api/src/test/java/com/backend/backend/filter/CorrelationIdFilterTest.java @@ -17,7 +17,12 @@ import static org.junit.jupiter.api.Assertions.assertNull; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.*; - +/** + * Acknowledgements: + * ChatGPT (https://chatgpt.com/) was used to assist in writing test + * cases. The test cases were further edited manually for correctness, brevity and + * coverage of cases in the code + */ class CorrelationIdFilterTest { @Mock diff --git a/api/src/test/java/com/backend/backend/filter/JwtFilterTest.java b/api/src/test/java/com/backend/backend/filter/JwtFilterTest.java index 5964158..0f75928 100644 --- a/api/src/test/java/com/backend/backend/filter/JwtFilterTest.java +++ b/api/src/test/java/com/backend/backend/filter/JwtFilterTest.java @@ -25,7 +25,12 @@ import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.Mockito.*; - +/** + * Acknowledgements: + * ChatGPT (https://chatgpt.com/) was used to assist in writing test + * cases. The test cases were further edited manually for correctness, brevity and + * coverage of cases in the code + */ class JwtFilterTest { @InjectMocks diff --git a/api/src/test/java/com/backend/backend/service/AuthenticationServiceTests.java b/api/src/test/java/com/backend/backend/service/AuthenticationServiceTests.java index 12e03f5..ede22a0 100644 --- a/api/src/test/java/com/backend/backend/service/AuthenticationServiceTests.java +++ b/api/src/test/java/com/backend/backend/service/AuthenticationServiceTests.java @@ -16,7 +16,12 @@ import static org.junit.jupiter.api.Assertions.*; import static org.mockito.Mockito.*; - +/** + * Acknowledgements: + * ChatGPT (https://chatgpt.com/) was used to assist in writing test + * cases. The test cases were further edited manually for correctness, brevity and + * coverage of cases in the code + */ class AuthenticationServiceTest { @Mock diff --git a/api/src/test/java/com/backend/backend/service/BoardServiceTests.java b/api/src/test/java/com/backend/backend/service/BoardServiceTests.java index 938439a..afba0cc 100644 --- a/api/src/test/java/com/backend/backend/service/BoardServiceTests.java +++ b/api/src/test/java/com/backend/backend/service/BoardServiceTests.java @@ -17,7 +17,12 @@ import static org.junit.jupiter.api.Assertions.*; import static org.mockito.Mockito.*; - +/** + * Acknowledgements: + * ChatGPT (https://chatgpt.com/) was used to assist in writing test + * cases. The test cases were further edited manually for correctness, brevity and + * coverage of cases in the code + */ class BoardServiceTests { @Mock @@ -63,35 +68,6 @@ void createBoardForUser_ShouldCreateAndSaveBoardAndUserBoard() { verify(userBoardRepository, times(1)).save(any(UserBoard.class)); } - @Test - void getBoardByIdAndUser_ShouldReturnBoard_WhenFound() { - // Arrange: Mock the board retrieval - when(boardRepository.findByIdAndUserId(1L, mockUser.getId())).thenReturn(Optional.of(mockBoard)); - - // Act: Call the method - BoardResponse result = boardService.getBoardByIdAndUser(1L, mockUser.getId()); - - // Assert: Verify that the correct board is returned - assertNotNull(result); - assertEquals(new BoardResponse(mockBoard), result); - - verify(boardRepository, times(1)).findByIdAndUserId(1L, mockUser.getId()); - } - - @Test - void getBoardByIdAndUser_ShouldThrowException_WhenBoardNotFound() { - // Arrange: Simulate board not being found - when(boardRepository.findByIdAndUserId(1L, mockUser.getId())).thenReturn(Optional.empty()); - - // Act & Assert: Ensure EntityNotFoundException is thrown - EntityNotFoundException thrown = assertThrows(EntityNotFoundException.class, () -> - boardService.getBoardByIdAndUser(1L, mockUser.getId())); - - assertEquals("Board not found with id 1", thrown.getMessage()); - - verify(boardRepository, times(1)).findByIdAndUserId(1L, mockUser.getId()); - } - @Test void getBoardByIdAndUserNew_ShouldReturnBoard_WhenUserBoardExists() { // Arrange: Set up UserBoard and mock board retrieval @@ -106,7 +82,7 @@ void getBoardByIdAndUserNew_ShouldReturnBoard_WhenUserBoardExists() { when(boardRepository.findById(1L)).thenReturn(Optional.of(mockBoard)); // Act: Call the method - BoardResponse result = boardService.getBoardByIdAndUserNew(1L, mockUser.getId()); + BoardResponse result = boardService.getBoardByIdAndUser(1L, mockUser.getId()); // Assert: Verify that the correct board is returned assertNotNull(result); @@ -122,7 +98,7 @@ void getBoardByIdAndUserNew_ShouldThrowException_WhenUserBoardDoesNotExist() { // Act & Assert: Ensure EntityNotFoundException is thrown EntityNotFoundException thrown = assertThrows(EntityNotFoundException.class, () -> - boardService.getBoardByIdAndUserNew(1L, mockUser.getId())); + boardService.getBoardByIdAndUser(1L, mockUser.getId())); assertEquals("Board not found with id 1", thrown.getMessage()); diff --git a/api/src/test/java/com/backend/backend/service/JwtServiceTests.java b/api/src/test/java/com/backend/backend/service/JwtServiceTests.java index 7a49f7f..deda722 100644 --- a/api/src/test/java/com/backend/backend/service/JwtServiceTests.java +++ b/api/src/test/java/com/backend/backend/service/JwtServiceTests.java @@ -19,7 +19,12 @@ import static org.junit.jupiter.api.Assertions.*; import static org.mockito.Mockito.*; - +/** + * Acknowledgements: + * ChatGPT (https://chatgpt.com/) was used to assist in writing test + * cases. The test cases were further edited manually for correctness, brevity and + * coverage of cases in the code + */ class JwtServiceTests { private JwtService jwtService; diff --git a/api/src/test/java/com/backend/backend/service/TaskServiceTests.java b/api/src/test/java/com/backend/backend/service/TaskServiceTests.java index 3d2440e..9b2ac74 100644 --- a/api/src/test/java/com/backend/backend/service/TaskServiceTests.java +++ b/api/src/test/java/com/backend/backend/service/TaskServiceTests.java @@ -23,7 +23,12 @@ import static org.junit.jupiter.api.Assertions.*; import static org.mockito.Mockito.*; - +/** + * Acknowledgements: + * ChatGPT (https://chatgpt.com/) was used to assist in writing test + * cases. The test cases were further edited manually for correctness, brevity and + * coverage of cases in the code + */ public class TaskServiceTests { @Mock BoardRepository boardRepository; diff --git a/api/src/test/java/com/backend/backend/service/UserBoardServiceTest.java b/api/src/test/java/com/backend/backend/service/UserBoardServiceTest.java index f9a723d..2b90b5b 100644 --- a/api/src/test/java/com/backend/backend/service/UserBoardServiceTest.java +++ b/api/src/test/java/com/backend/backend/service/UserBoardServiceTest.java @@ -21,7 +21,12 @@ import static org.junit.jupiter.api.Assertions.*; import static org.mockito.Mockito.*; - +/** + * Acknowledgements: + * ChatGPT (https://chatgpt.com/) was used to assist in writing test + * cases. The test cases were further edited manually for correctness, brevity and + * coverage of cases in the code + */ class UserBoardServiceTest { @Mock