package com.amplywealth.auth.service; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.mockito.Mockito.any; import static org.mockito.Mockito.doNothing; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import com.amplywealth.auth.data.payload.request.ServiceTokenRequest; import com.amplywealth.auth.data.payload.request.ServiceTokenVerificationRequest; import com.amplywealth.auth.exception.ServiceException; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit.jupiter.SpringExtension; import org.springframework.web.client.RestClientException; import org.springframework.web.client.RestTemplate; @ContextConfiguration(classes = {S2SAuthService.class}) @ExtendWith(SpringExtension.class) class S2SAuthServiceTest { @MockBean private RestTemplate restTemplate; @Autowired private S2SAuthService s2SAuthService; /** * Method under test: {@link S2SAuthService#getAccessToken(ServiceTokenRequest)} */ @Test void testGetAccessToken() throws RestClientException { when(restTemplate.postForEntity((String) any(), (Object) any(), (Class) any(), (Object[]) any())) .thenReturn(new ResponseEntity<>(HttpStatus.CONTINUE)); ServiceTokenRequest serviceTokenRequest = new ServiceTokenRequest(); serviceTokenRequest.setClientId("42"); serviceTokenRequest.setClientSecret("Client Secret"); serviceTokenRequest.setScopes("Scopes"); assertThrows(ServiceException.class, () -> s2SAuthService.getAccessToken(serviceTokenRequest)); verify(restTemplate).postForEntity((String) any(), (Object) any(), (Class) any(), (Object[]) any()); } /** * Method under test: {@link S2SAuthService#getAccessToken(ServiceTokenRequest)} */ @Test void testGetAccessToken2() throws RestClientException { when(restTemplate.postForEntity((String) any(), (Object) any(), (Class) any(), (Object[]) any())) .thenReturn(null); ServiceTokenRequest serviceTokenRequest = new ServiceTokenRequest(); serviceTokenRequest.setClientId("42"); serviceTokenRequest.setClientSecret("Client Secret"); serviceTokenRequest.setScopes("Scopes"); assertThrows(ServiceException.class, () -> s2SAuthService.getAccessToken(serviceTokenRequest)); verify(restTemplate).postForEntity((String) any(), (Object) any(), (Class) any(), (Object[]) any()); }