File size: 2,783 Bytes
1c8e50c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package in.garvit.tasks.controllerTest;

import org.mockito.InjectMocks;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.crypto.password.PasswordEncoder;


import in.garvit.tasks.controller.AuthController;
import in.garvit.tasks.repository.UserRepository;
import in.garvit.tasks.service.CustomerServiceImplementation;
import in.garvit.tasks.taskSecurityConfig.JwtProvider;


class AuthControllerTest {

    @MockBean
    private UserRepository userRepository;

    @MockBean
    private PasswordEncoder passwordEncoder;

    @MockBean
    private CustomerServiceImplementation customUserDetails;

    @MockBean
    private AuthenticationManager authenticationManager;

    @MockBean
    private JwtProvider jwtProvider;

    @InjectMocks
    private AuthController authController;

	/*
	 * @Test void testCreateUserHandler() throws Exception { User user = new User();
	 * user.setEmail("test@example.com"); user.setPassword("testPassword");
	 * user.setFullName("Test User"); user.setMobile("1234567890");
	 * user.setRole("ROLE_USER");
	 * 
	 * // when(userRepository.findByEmail(any())).thenReturn(null);
	 * when(userRepository.save(any())).thenReturn(user);
	 * when(passwordEncoder.encode(any())).thenReturn("encodedPassword");
	 * when(authenticationManager.authenticate(any())).thenReturn(null);
	 * when(JwtProvider.generateToken(any())).thenReturn("testToken");
	 * 
	 * ResponseEntity<AuthResponse> responseEntity =
	 * authController.createUserHandler(user);
	 * 
	 * assertEquals(HttpStatus.OK, responseEntity.getStatusCode());
	 * assertEquals("Register Success", responseEntity.getBody().getMessage());
	 * assertEquals("testToken", responseEntity.getBody().getJwt());
	 * assertEquals(true, responseEntity.getBody().getStatus()); }
	 */

	/*
	 * @Test void testSignin() { LoginRequest loginRequest = new LoginRequest();
	 * loginRequest.setUsername("test@example.com");
	 * loginRequest.setPassword("testPassword");
	 * 
	 * UserDetails userDetails = Mockito.mock(UserDetails.class);
	 * when(customUserDetails.loadUserByUsername(any())).thenReturn(userDetails);
	 * when(passwordEncoder.matches(any(), any())).thenReturn(true);
	 * when(authenticationManager.authenticate(any())).thenReturn(null);
	 * when(JwtProvider.generateToken(any())).thenReturn("testToken");
	 * 
	 * ResponseEntity<AuthResponse> responseEntity =
	 * authController.signin(loginRequest);
	 * 
	 * assertEquals(HttpStatus.OK, responseEntity.getStatusCode());
	 * assertEquals("Login success", responseEntity.getBody().getMessage());
	 * assertEquals("testToken", responseEntity.getBody().getJwt());
	 * assertEquals(true, responseEntity.getBody().getStatus()); }
	 */
}