diff options
Diffstat (limited to 'ufund-api')
| -rw-r--r-- | ufund-api/src/test/java/com/ufund/api/ufundapi/controller/UserControllerTest.java | 24 | 
1 files changed, 18 insertions, 6 deletions
diff --git a/ufund-api/src/test/java/com/ufund/api/ufundapi/controller/UserControllerTest.java b/ufund-api/src/test/java/com/ufund/api/ufundapi/controller/UserControllerTest.java index 496c68c..d189836 100644 --- a/ufund-api/src/test/java/com/ufund/api/ufundapi/controller/UserControllerTest.java +++ b/ufund-api/src/test/java/com/ufund/api/ufundapi/controller/UserControllerTest.java @@ -1,6 +1,7 @@  package com.ufund.api.ufundapi.controller;  import java.io.IOException; +import java.util.HashMap;  import static org.junit.jupiter.api.Assertions.assertEquals;  import org.junit.jupiter.api.BeforeEach; @@ -13,18 +14,21 @@ import org.springframework.http.HttpStatus;  import org.springframework.http.ResponseEntity;  import com.ufund.api.ufundapi.model.User; +import com.ufund.api.ufundapi.model.UserAuth; +import com.ufund.api.ufundapi.persistence.UserAuthFIleDAO;  import com.ufund.api.ufundapi.persistence.UserFileDAO;  @Tag("Controller-tier")  public class UserControllerTest {      private UserController userController;      private UserFileDAO mockUserDAO; +    private UserAuthFIleDAO mockAuthUserDAO;      @BeforeEach      public void setupUserController() {          mockUserDAO = mock(UserFileDAO.class); -        userController = new UserController(mockUserDAO); - +        mockAuthUserDAO = mock(UserAuthFIleDAO.class); +        userController = new UserController(mockUserDAO, mockAuthUserDAO);      }      @Test @@ -32,11 +36,13 @@ public class UserControllerTest {          // Setup          String username = "Test";          User user = new User(username); +        String key = UserAuth.generate(username).getKey();          // When the same id is passed in, our mock User DAO will return the User object          when(mockUserDAO.getUser(username)).thenReturn(user); +                  // Invoke -        ResponseEntity<User> response = userController.getUser(username); +        ResponseEntity<User> response = userController.getUser(username, key);          // Analyze          assertEquals(HttpStatus.OK, response.getStatusCode()); @@ -47,12 +53,14 @@ public class UserControllerTest {      public void testGetUserNotFound() throws Exception { // createUser may throw IOException          // Setup          String username = "Test"; +        String key = UserAuth.generate(username).getKey();          // When the same id is passed in, our mock User DAO will return null, simulating          // no User found          when(mockUserDAO.getUser(username)).thenReturn(null); +                  // Invoke -        ResponseEntity<User> response = userController.getUser(username); +        ResponseEntity<User> response = userController.getUser(username, key);          // Analyze          assertEquals(HttpStatus.NOT_FOUND, response.getStatusCode()); @@ -62,11 +70,12 @@ public class UserControllerTest {      public void testGetUserHandleException() throws Exception { // createUser may throw IOException          // Setup          String username = "Test"; +        String key = UserAuth.generate(username).getKey();          // When getUser is called on the Mock User DAO, throw an IOException          doThrow(new IOException()).when(mockUserDAO).getUser(username);          // Invoke -        ResponseEntity<User> response = userController.getUser(username); +        ResponseEntity<User> response = userController.getUser(username, key);          // Analyze          assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, response.getStatusCode()); @@ -82,12 +91,15 @@ public class UserControllerTest {          // Setup          String username = "Test";          User user = new User(username); +        String key = UserAuth.generate(username).getKey();          // when createUser is called, return true simulating successful          // creation and save          when(mockUserDAO.addUser(user)).thenReturn(user); +         +          // Invoke -        ResponseEntity<User> response = userController.createUser(user); +        ResponseEntity<User> response = userController.createUser(params);          // Analyze          assertEquals(HttpStatus.CREATED, response.getStatusCode());  | 
