aboutsummaryrefslogtreecommitdiff
path: root/ufund-api/src/test/java/com/ufund/api/ufundapi/controller/AuthControllerTest.java
diff options
context:
space:
mode:
authorTyler Ferrari <69283684+Sowgro@users.noreply.github.com>2025-03-17 16:44:16 -0400
committerGitHub <noreply@github.com>2025-03-17 16:44:16 -0400
commited3d0e5e5f9c58c3926ea55a422212f4da1c8849 (patch)
treea33f760bb831c948ebf1844ca52d7625ca7f6fe7 /ufund-api/src/test/java/com/ufund/api/ufundapi/controller/AuthControllerTest.java
parent9baaa0590fbc38c06d530786a1de804ee9edd7db (diff)
parent0377515c685b3ced5f67ae6d2ffee22893943acb (diff)
downloadJellySolutions-ed3d0e5e5f9c58c3926ea55a422212f4da1c8849.tar.gz
JellySolutions-ed3d0e5e5f9c58c3926ea55a422212f4da1c8849.tar.bz2
JellySolutions-ed3d0e5e5f9c58c3926ea55a422212f4da1c8849.zip
Merge pull request #9 from RIT-SWEN-261-02/service-tests
service-tests merge
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());
+ }
+}