aboutsummaryrefslogtreecommitdiff
path: root/ufund-api/src/test/java/com/ufund/api/ufundapi/controller/AuthControllerTest.java
diff options
context:
space:
mode:
authorGunther6070 <haydenhartman10@yahoo.com>2025-03-17 17:10:38 -0400
committerGunther6070 <haydenhartman10@yahoo.com>2025-03-17 17:10:38 -0400
commitc4316368ccd2e724de838fa6648ff390d4f417a6 (patch)
treeda20406da93c33f1fab350802cbdf5be5131560e /ufund-api/src/test/java/com/ufund/api/ufundapi/controller/AuthControllerTest.java
parentb998a4e7ca580f19ab10862de61d7458031027f2 (diff)
parented3d0e5e5f9c58c3926ea55a422212f4da1c8849 (diff)
downloadJellySolutions-c4316368ccd2e724de838fa6648ff390d4f417a6.tar.gz
JellySolutions-c4316368ccd2e724de838fa6648ff390d4f417a6.tar.bz2
JellySolutions-c4316368ccd2e724de838fa6648ff390d4f417a6.zip
Merge branch 'main' of https://github.com/RIT-SWEN-261-02/team-project-2245-swen-261-02-2b
Diffstat (limited to 'ufund-api/src/test/java/com/ufund/api/ufundapi/controller/AuthControllerTest.java')
-rw-r--r--ufund-api/src/test/java/com/ufund/api/ufundapi/controller/AuthControllerTest.java104
1 files changed, 104 insertions, 0 deletions
diff --git a/ufund-api/src/test/java/com/ufund/api/ufundapi/controller/AuthControllerTest.java b/ufund-api/src/test/java/com/ufund/api/ufundapi/controller/AuthControllerTest.java
new file mode 100644
index 0000000..3d4637d
--- /dev/null
+++ b/ufund-api/src/test/java/com/ufund/api/ufundapi/controller/AuthControllerTest.java
@@ -0,0 +1,104 @@
+package com.ufund.api.ufundapi.controller;
+
+import java.io.IOException;
+import java.util.Map;
+import static java.util.Map.entry;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import static org.mockito.ArgumentMatchers.any;
+import org.mockito.Mockito;
+import static org.mockito.Mockito.doThrow;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.ResponseEntity;
+import org.springframework.web.bind.annotation.RequestMapping;
+
+import com.ufund.api.ufundapi.service.AuthService;
+
+@RequestMapping("auth")
+public class AuthControllerTest {
+
+ private AuthController authController;
+ private AuthService mockAuthService;
+ private Map<String, String> authMap;
+
+ @BeforeEach
+ private void setupAuthController() {
+ mockAuthService = mock(AuthService.class);
+ authController = new AuthController(mockAuthService);
+
+ authMap = Map.ofEntries(
+ entry("Bob", "123")
+ );
+ }
+
+ @Test
+ public void testLogin() throws IllegalAccessException, IOException {
+ // Setup
+ String key = "123";
+
+ // Mock
+ when(mockAuthService.login(any(), any())).thenReturn(key);
+
+ // Invoke
+ ResponseEntity<String> response = authController.login(authMap);
+
+ // Analyze
+ assertEquals(HttpStatus.OK, response.getStatusCode());
+ assertEquals(key, response.getBody());
+ }
+
+ @Test
+ public void testLoginUnauthorized() throws IllegalAccessException, IOException {
+ // Mock
+ when(mockAuthService.login(any(), any())).thenThrow(IllegalAccessException.class);
+
+ // Invoke
+ ResponseEntity<String> response = authController.login(authMap);
+
+ // Analyze
+ assertEquals(HttpStatus.UNAUTHORIZED, response.getStatusCode());
+ }
+
+ @Test
+ public void testLoginIOException() throws IllegalAccessException, IOException {
+ // Mock
+ when(mockAuthService.login(any(), any())).thenThrow(IOException.class);
+
+ // Invoke
+ ResponseEntity<String> response = authController.login(authMap);
+
+ // Analyze
+ assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, response.getStatusCode());
+ }
+
+ @Test
+ public void testLogout() throws IllegalAccessException, IOException {
+ // Setup
+ String key = "123";
+
+ // Invoke
+ ResponseEntity<Object> response = authController.logout(key);
+
+ // Analyze
+ assertEquals(HttpStatus.OK, response.getStatusCode());
+ }
+
+ @Test
+ public void testLogoutIOException() throws IllegalAccessException, IOException {
+ // Setup
+ String key = "123";
+
+ // Mock
+ doThrow(new IOException()).when(mockAuthService).logout(key);
+
+ // Invoke
+ ResponseEntity<Object> response = authController.logout(key);
+
+ // Analyze
+ assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, response.getStatusCode());
+ }
+}