Skip to content

Commit

Permalink
P4ADEV-1274 coverage unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
macacia committed Oct 17, 2024
1 parent 7c12cd2 commit 80ab0f5
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ public ClientCredentialServiceImpl(ValidateClientCredentialsService validateClie

@Override
public AccessToken postToken(String clientId, String grantType, String scope, String clientSecret) {
log.info("Client {} requested authentication with grant type {} and scope {}", clientId, grantType, scope);
validateClientCredentialsService.validate(clientId, grantType, scope, clientSecret);
return new AccessToken("fakeToken", "bearer", 7);
return AccessToken.builder().accessToken("accessToken").build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package it.gov.pagopa.payhub.auth.service.a2a;

import it.gov.pagopa.payhub.model.generated.AccessToken;
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;

@ExtendWith(MockitoExtension.class)
class ClientCredentialsServiceTest {

@Mock
private ValidateClientCredentialsService validateClientCredentialsServiceMock;
private ClientCredentialService service;

@BeforeEach
void init() {
service = new ClientCredentialServiceImpl(validateClientCredentialsServiceMock);
}

@Test
void givenValidTokenWhenPostTokenThenSuccess(){
// Given
String clientId="CLIENT_ID";
String grantType="GRANT_TYPE";;
String scope="SCOPE";
String clientSecret="CLIENT_SECRET";

Mockito.doNothing().when(validateClientCredentialsServiceMock).validate(clientId, grantType, scope, clientSecret);
AccessToken expectedAccessToken = AccessToken.builder().accessToken("accessToken").build();
//When
AccessToken result = service.postToken(clientId, grantType, scope, clientSecret);
//Then
Assertions.assertEquals(expectedAccessToken, result);
}

}

0 comments on commit 80ab0f5

Please sign in to comment.