-
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.
- Loading branch information
Showing
9 changed files
with
107 additions
and
113 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
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
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
36 changes: 0 additions & 36 deletions
36
.../java/it/gov/pagopa/payhub/auth/service/AuthorizeClientCredentialsRequestServiceTest.java
This file was deleted.
Oops, something went wrong.
89 changes: 89 additions & 0 deletions
89
...a/it/gov/pagopa/payhub/auth/service/a2a/AuthorizeClientCredentialsRequestServiceTest.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 |
---|---|---|
@@ -0,0 +1,89 @@ | ||
package it.gov.pagopa.payhub.auth.service.a2a; | ||
|
||
import it.gov.pagopa.payhub.auth.exception.custom.ClientUnauthorizedException; | ||
import it.gov.pagopa.payhub.auth.mapper.ClientMapper; | ||
import it.gov.pagopa.payhub.auth.model.Client; | ||
import it.gov.pagopa.payhub.model.generated.ClientDTO; | ||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.mockito.Mock; | ||
import org.mockito.Mockito; | ||
import org.mockito.junit.jupiter.MockitoExtension; | ||
|
||
import java.util.Optional; | ||
import java.util.UUID; | ||
|
||
@ExtendWith(MockitoExtension.class) | ||
class AuthorizeClientCredentialsRequestServiceTest { | ||
|
||
@Mock | ||
private ClientService clientServiceMock; | ||
@Mock | ||
private ClientMapper clientMapperMock; | ||
private AuthorizeClientCredentialsRequestService service; | ||
|
||
@BeforeEach | ||
void init() { | ||
service = new AuthorizeClientCredentialsRequestService(clientServiceMock, clientMapperMock); | ||
} | ||
|
||
@Test | ||
void givenRightCredentialsWhenVerifyCredentialsThenOk() { | ||
// Given | ||
String organizationIpaCode = "IPA_TEST_2"; | ||
String clientName = "SERVICE_001"; | ||
String clientId = organizationIpaCode + clientName; | ||
String clientSecretMock = UUID.randomUUID().toString(); | ||
|
||
Client mockClient = new Client(); | ||
ClientDTO expectedClientDTO = ClientDTO.builder() | ||
.clientId(clientId) | ||
.clientName(clientName) | ||
.organizationIpaCode(organizationIpaCode) | ||
.clientSecret(clientSecretMock) | ||
.build(); | ||
|
||
Mockito.when(clientServiceMock.getClientByClientId(clientId)).thenReturn(Optional.of(mockClient)); | ||
Mockito.when(clientMapperMock.mapToDTO(mockClient)).thenReturn(expectedClientDTO); | ||
// When | ||
ClientDTO actualClientDTO = service.authorizeCredentials(clientId, clientSecretMock); | ||
// Then | ||
Assertions.assertEquals(expectedClientDTO, actualClientDTO); | ||
} | ||
|
||
@Test | ||
void givenUnexpectedClientIdCredentialsWhenVerifyCredentialsThenClientUnauthorizedException() { | ||
// Given | ||
String clientId = "UNEXPECTED_CLIENT_ID"; | ||
String clientSecretMock = UUID.randomUUID().toString(); | ||
|
||
Mockito.when(clientServiceMock.getClientByClientId(clientId)).thenThrow(new ClientUnauthorizedException("error")); | ||
// When, Then | ||
Assertions.assertThrows(ClientUnauthorizedException.class, () -> service.authorizeCredentials(clientId, clientSecretMock)); | ||
} | ||
|
||
@Test | ||
void givenUnexpectedClientSecretCredentialsWhenVerifyCredentialsThenClientUnauthorizedException() { | ||
// Given | ||
String organizationIpaCode = "IPA_TEST_2"; | ||
String clientName = "SERVICE_001"; | ||
String clientId = organizationIpaCode + clientName; | ||
String clientSecret = UUID.randomUUID().toString(); | ||
|
||
Client mockClient = new Client(); | ||
ClientDTO expectedClientDTO = ClientDTO.builder() | ||
.clientId(clientId) | ||
.clientName(clientName) | ||
.organizationIpaCode(organizationIpaCode) | ||
.clientSecret(UUID.randomUUID().toString()) | ||
.build(); | ||
|
||
Mockito.when(clientServiceMock.getClientByClientId(clientId)).thenReturn(Optional.of(mockClient)); | ||
Mockito.when(clientMapperMock.mapToDTO(mockClient)).thenReturn(expectedClientDTO); | ||
|
||
// When, Then | ||
Assertions.assertThrows(ClientUnauthorizedException.class, () -> service.authorizeCredentials(clientId, clientSecret)); | ||
} | ||
} |
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
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