-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
P4PU fixed IamUserInfoDTO2UserInfoImplTest
- Loading branch information
1 parent
d13a5cb
commit d41c262
Showing
4 changed files
with
36 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 0 additions & 3 deletions
3
src/test/java/it/gov/pagopa/arc/dto/mapper/IamUserInfoDTO2UserInfoImplTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 28 additions & 19 deletions
47
src/test/java/it/gov/pagopa/arc/service/AuthServiceImplTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,57 @@ | ||
package it.gov.pagopa.arc.service; | ||
|
||
import it.gov.pagopa.arc.dto.IamUserInfoDTO; | ||
import it.gov.pagopa.arc.dto.mapper.IamUserInfoDTO2UserInfo; | ||
import it.gov.pagopa.arc.fakers.auth.IamUserInfoDTOFaker; | ||
import org.junit.jupiter.api.AfterEach; | ||
import it.gov.pagopa.arc.fakers.auth.UserInfoDTOFaker; | ||
import it.gov.pagopa.arc.model.generated.UserInfo; | ||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.mapstruct.factory.Mappers; | ||
import org.mockito.InjectMocks; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.mockito.Mock; | ||
import org.mockito.Mockito; | ||
import org.mockito.junit.jupiter.MockitoExtension; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.mock.web.MockHttpServletRequest; | ||
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; | ||
import org.springframework.security.core.context.SecurityContextHolder; | ||
import org.springframework.security.web.authentication.WebAuthenticationDetails; | ||
|
||
@ExtendWith(MockitoExtension.class) | ||
class AuthServiceImplTest { | ||
|
||
@InjectMocks | ||
IamUserInfoDTO2UserInfo mapper = Mappers.getMapper(IamUserInfoDTO2UserInfo.class); | ||
|
||
@Mock | ||
AuthServiceImpl authService; | ||
IamUserInfoDTO2UserInfo mapperMock; | ||
@Autowired | ||
private AuthService authService; | ||
|
||
private final IamUserInfoDTO iamUserInfoDTO = IamUserInfoDTOFaker.mockInstance(); | ||
|
||
@BeforeEach | ||
void setup(){ | ||
authService = new AuthServiceImpl(mapper); | ||
//given | ||
void setUp() { | ||
authService = new AuthServiceImpl(mapperMock); | ||
SecurityContextHolder.clearContext(); | ||
UsernamePasswordAuthenticationToken authentication = new UsernamePasswordAuthenticationToken( | ||
IamUserInfoDTOFaker.mockInstance(), null, null); | ||
iamUserInfoDTO, null, null); | ||
authentication.setDetails(new WebAuthenticationDetails(new MockHttpServletRequest())); | ||
SecurityContextHolder.getContext().setAuthentication(authentication); | ||
|
||
} | ||
|
||
@AfterEach | ||
void clearContext() { | ||
SecurityContextHolder.clearContext(); | ||
} | ||
|
||
@Test | ||
void givenValidAuthenticationSessionThenRetrieveUserInfo() { | ||
//given | ||
UserInfo userInfo = UserInfoDTOFaker.mockInstance(); | ||
Mockito.when(mapperMock.mapIamUserToUserInfo(iamUserInfoDTO)).thenReturn(userInfo); | ||
//when | ||
UserInfo user = authService.getUserLoginInfo(); | ||
//then | ||
Assertions.assertNotNull(authService.getUserLoginInfo()); | ||
Assertions.assertNotNull(user); | ||
|
||
Assertions.assertEquals(user.getUserId(),iamUserInfoDTO.getUserId()); | ||
Assertions.assertEquals(user.getName(),iamUserInfoDTO.getName()); | ||
Assertions.assertEquals(user.getFamilyName(),iamUserInfoDTO.getFamilyName()); | ||
Assertions.assertEquals(user.getEmail(),iamUserInfoDTO.getEmail()); | ||
Assertions.assertEquals(user.getFiscalCode(),iamUserInfoDTO.getFiscalCode()); | ||
} | ||
|
||
} |