AuditServiceSAOTest
unknown
plain_text
2 years ago
8.1 kB
14
Indexable
//package com.kotak.collection.reporting.sao;
//
//import com.kotak.collection.reporting.configuration.AuditServiceClientConfigProperties;
//import com.kotak.collection.reporting.dto.AuditServiceUpdateCallRecordingRequest;
//import com.kotak.collection.reporting.dto.AuditServiceUpdateCallRecordingResponse;
//import lombok.extern.log4j.Log4j2;
//import org.junit.jupiter.api.Test;
//import org.junit.jupiter.api.extension.ExtendWith;
//import org.mockito.InjectMocks;
//import org.mockito.Mock;
//import org.mockito.Mockito;
//import org.mockito.junit.jupiter.MockitoExtension;
//import org.springframework.core.ParameterizedTypeReference;
//import org.springframework.http.HttpMethod;
//import org.springframework.http.HttpStatus;
//import org.springframework.http.ResponseEntity;
//import org.springframework.web.client.RestClientException;
//import org.springframework.web.client.RestTemplate;
//
//import java.util.List;
//import java.util.Optional;
//
//import static org.junit.jupiter.api.Assertions.assertEquals;
//import static org.junit.jupiter.api.Assertions.assertThrows;
//import static org.mockito.ArgumentMatchers.eq;
//import static org.mockito.Mockito.when;
//
//@Log4j2
//@ExtendWith(MockitoExtension.class)
//public class AuditServiceSAOTest {
//
// @InjectMocks
// private AuditServiceSAO auditServiceSAO;
//
// @Mock
// private RestTemplate auditServiceRestTemplate;
// @Mock
// private AuditServiceClientConfigProperties auditServiceClientConfigProperties;
//
// private static final String apiEndpoint = "http://localhost:8080/student";
// private static final String RECORDING_ID= "recordingId";
//
// @Test
// public void testGetAgencyListExecutesSuccessfulCall() {
// //Data Creation
// final List<FilterOption> filterOptions = Mockito.mock(List.class);
// final ResponseEntity<List<FilterOption>> responseEntity = new ResponseEntity<>(filterOptions, HttpStatus.OK);
// when(auditServiceClientConfigProperties.getGetAgencyListEndpoint()).thenReturn(apiEndpoint);
// when(auditServiceRestTemplate.exchange(apiEndpoint, HttpMethod.GET, null,
// new ParameterizedTypeReference<List<FilterOption>>() {})).thenReturn(responseEntity);
//
// //Testing
// final Optional<List<FilterOption>> agencyList = auditServiceSAO.getAgencyList();
//
// //Assertions
// assertEquals(agencyList, Optional.ofNullable(filterOptions));
// Mockito.verify(auditServiceRestTemplate, Mockito.times(1)).exchange(apiEndpoint,
// HttpMethod.GET, null, new ParameterizedTypeReference<List<FilterOption>>() {});
// }
//
// @Test
// public void testGetAgencyListExecutesFailureCall() {
// //Data Creation
// final List<FilterOption> filterOptions = Mockito.mock(List.class);
// final ResponseEntity<List<FilterOption>> responseEntity = new ResponseEntity<>(filterOptions, HttpStatus.NOT_FOUND);
// when(auditServiceClientConfigProperties.getGetAgencyListEndpoint()).thenReturn(apiEndpoint);
// when(auditServiceRestTemplate.exchange(apiEndpoint, HttpMethod.GET, null,
// new ParameterizedTypeReference<List<FilterOption>>() {})).thenReturn(responseEntity);
//
// //Testing
// assertThrows(AuditServiceSAO.CallAuditServiceException.class, () -> {
// auditServiceSAO.getAgencyList();
// });
//
// //Assertions
// Mockito.verify(auditServiceRestTemplate, Mockito.times(1)).exchange(apiEndpoint,
// HttpMethod.GET, null, new ParameterizedTypeReference<List<FilterOption>>() {});
// }
//
// @Test
// public void testGetAgencyListThrowsRestClientException() {
// //Data Creation
// when(auditServiceClientConfigProperties.getGetAgencyListEndpoint()).thenReturn(apiEndpoint);
// when(auditServiceRestTemplate.exchange(apiEndpoint, HttpMethod.GET, null,
// new ParameterizedTypeReference<List<FilterOption>>() {})).thenThrow(RestClientException.class);
//
// //Testing and Assertions
// assertThrows(AuditServiceSAO.CallAuditServiceException.class, () -> {
// auditServiceSAO.getAgencyList();
// });
// }
//
// @Test
// public void testUpdateCallRecordingDataExecutesSuccessfulCall() {
// //Data Creation
// final AuditServiceUpdateCallRecordingRequest auditServiceUpdateCallRecordingRequest =
// Mockito.mock(AuditServiceUpdateCallRecordingRequest.class);
// final AuditServiceUpdateCallRecordingResponse auditServiceUpdateCallRecordingResponse =
// Mockito.mock(AuditServiceUpdateCallRecordingResponse.class);
// final ResponseEntity<AuditServiceUpdateCallRecordingResponse> responseEntity =
// new ResponseEntity<>(auditServiceUpdateCallRecordingResponse, HttpStatus.OK);
// when(auditServiceClientConfigProperties.getUpdateCallRecordingEndpoint()).thenReturn(apiEndpoint);
// when(auditServiceRestTemplate.exchange(eq(apiEndpoint), eq(HttpMethod.PUT), Mockito.any(),
// eq(AuditServiceUpdateCallRecordingResponse.class), eq(RECORDING_ID))).thenReturn(responseEntity);
//
// //Testing
// final Optional<AuditServiceUpdateCallRecordingResponse> actualResponse = auditServiceSAO
// .updateCallRecordingData(auditServiceUpdateCallRecordingRequest, RECORDING_ID);
//
// //Assertions
// assertEquals(actualResponse, Optional.ofNullable(auditServiceUpdateCallRecordingResponse));
// Mockito.verify(auditServiceRestTemplate, Mockito.times(1)).exchange(eq(apiEndpoint),
// eq(HttpMethod.PUT), Mockito.any(), eq(AuditServiceUpdateCallRecordingResponse.class), eq(RECORDING_ID));
// }
//
// @Test
// public void testUpdateCallRecordingDataExecutesFailureCall() {
// //Data Creation
// final AuditServiceUpdateCallRecordingRequest auditServiceUpdateCallRecordingRequest =
// Mockito.mock(AuditServiceUpdateCallRecordingRequest.class);
// final AuditServiceUpdateCallRecordingResponse auditServiceUpdateCallRecordingResponse =
// Mockito.mock(AuditServiceUpdateCallRecordingResponse.class);
// final ResponseEntity<AuditServiceUpdateCallRecordingResponse> responseEntity =
// new ResponseEntity<>(auditServiceUpdateCallRecordingResponse, HttpStatus.NOT_FOUND);
// when(auditServiceClientConfigProperties.getUpdateCallRecordingEndpoint()).thenReturn(apiEndpoint);
// when(auditServiceRestTemplate.exchange(eq(apiEndpoint), eq(HttpMethod.PUT), Mockito.any(),
// eq(AuditServiceUpdateCallRecordingResponse.class), eq(RECORDING_ID))).thenReturn(responseEntity);
//
// //Testing
// assertThrows(AuditServiceSAO.CallAuditServiceException.class, () -> {
// auditServiceSAO.updateCallRecordingData(auditServiceUpdateCallRecordingRequest, RECORDING_ID);
// });
//
// //Assertions
// Mockito.verify(auditServiceRestTemplate, Mockito.times(1)).exchange(eq(apiEndpoint),
// eq(HttpMethod.PUT), Mockito.any(), eq(AuditServiceUpdateCallRecordingResponse.class), eq(RECORDING_ID));
// }
//
// @Test
// public void testUpdateCallRecordingDataThrowsRestClientException() {
// //Data Creation
// final AuditServiceUpdateCallRecordingRequest auditServiceUpdateCallRecordingRequest =
// Mockito.mock(AuditServiceUpdateCallRecordingRequest.class);
// when(auditServiceClientConfigProperties.getUpdateCallRecordingEndpoint()).thenReturn(apiEndpoint);
// when(auditServiceRestTemplate.exchange(eq(apiEndpoint), eq(HttpMethod.PUT), Mockito.any(),
// eq(AuditServiceUpdateCallRecordingResponse.class), eq(RECORDING_ID))).thenThrow(RestClientException.class);
//
// assertThrows(AuditServiceSAO.CallAuditServiceException.class, () -> {
// auditServiceSAO.updateCallRecordingData(auditServiceUpdateCallRecordingRequest, RECORDING_ID);
// });
// }
//}Editor is loading...
Leave a Comment