Skip to content

Commit

Permalink
CIV-8154 flight delay controller (#4726)
Browse files Browse the repository at this point in the history
* CIV-8154 flight delay controller

* CIV-8154 flight controller test

* CIV-8154 fix conflict

* CIV-8154 delete imports

* CIV-8154 controller fix

* CIV-8154 delete import

* CIV-8154 Updated FlightController for mapping

* CIV-8154 Updated FlightController for mapping

* CIV-8154 Added unit test for flight controller

---------

Co-authored-by: Manish Garg <[email protected]>
Co-authored-by: Raja Mani <[email protected]>
Co-authored-by: jarekPierchala <[email protected]>
Co-authored-by: sankhajuria <[email protected]>
  • Loading branch information
5 people authored May 29, 2024
1 parent 89e739b commit f237674
Show file tree
Hide file tree
Showing 3 changed files with 131 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package uk.gov.hmcts.reform.civil.controllers.airlines;

import lombok.SneakyThrows;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.mock.mockito.MockBean;
import uk.gov.hmcts.reform.civil.controllers.BaseIntegrationTest;
import uk.gov.hmcts.reform.civil.model.AirlineEpimsId;
import uk.gov.hmcts.reform.civil.service.AirlineEpimsDataLoader;

import java.util.ArrayList;
import java.util.List;

import static org.mockito.Mockito.when;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

public class FlightControllerTest extends BaseIntegrationTest {

@MockBean
private AirlineEpimsDataLoader airlineEpimsDataLoader;

@Test
@SneakyThrows
void shouldReturnAirlineList() {
List<AirlineEpimsId> airlineEpimsIDList = new ArrayList<>();

AirlineEpimsId airlineEpimsID = AirlineEpimsId.builder()
.airline("test")
.epimsID("123")
.build();
airlineEpimsIDList.add(airlineEpimsID);

when(airlineEpimsDataLoader.getAirlineEpimsIDList()).thenReturn(airlineEpimsIDList);

doGet(BEARER_TOKEN, "/airlines")
.andExpect(content().json(toJson(airlineEpimsIDList)))
.andExpect(status().isOk());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package uk.gov.hmcts.reform.civil.controllers.airlines;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import uk.gov.hmcts.reform.civil.model.AirlineEpimsId;
import uk.gov.hmcts.reform.civil.service.AirlineEpimsDataLoader;

import java.util.ArrayList;
import java.util.List;

@Slf4j
@RestController
@AllArgsConstructor
public class FlightController {

private final AirlineEpimsDataLoader airlineEpimsDataLoader;

@GetMapping(path = {"/airlines"}, produces = MediaType.APPLICATION_JSON_VALUE)
@Operation(summary = "Get airlines")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "OK"),
@ApiResponse(responseCode = "401", description = "Not Authorized"),
@ApiResponse(responseCode = "400", description = "Bad Request")})
public ResponseEntity<List<AirlineEpimsId>> getAirlines() {
log.info("Get airlines");
List<AirlineEpimsId> airlineEpimsIDList = new ArrayList<>(airlineEpimsDataLoader.getAirlineEpimsIDList());

return new ResponseEntity<>(airlineEpimsIDList, HttpStatus.OK);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package uk.gov.hmcts.reform.civil.controllers;

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.junit.jupiter.MockitoExtension;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import uk.gov.hmcts.reform.civil.controllers.airlines.FlightController;
import uk.gov.hmcts.reform.civil.model.AirlineEpimsId;
import uk.gov.hmcts.reform.civil.service.AirlineEpimsDataLoader;

import java.util.ArrayList;
import java.util.List;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.mockito.Mockito.when;

@ExtendWith(MockitoExtension.class)
class FlightControllerTest {

@Mock
private AirlineEpimsDataLoader airlineEpimsDataLoader;
FlightController flightController;

@BeforeEach
public void setUp() {
flightController = new FlightController(airlineEpimsDataLoader);
}

@Test
void shouldReturnAirlines() {
// Given
List<AirlineEpimsId> airlineEpimsIDs = new ArrayList<>();
AirlineEpimsId airlineEpimsID = AirlineEpimsId.builder()
.airline("test")
.epimsID("123")
.build();
airlineEpimsIDs.add(airlineEpimsID);
when(airlineEpimsDataLoader.getAirlineEpimsIDList()).thenReturn(airlineEpimsIDs);

// When
ResponseEntity<List<AirlineEpimsId>> response = flightController.getAirlines();

// Then
assertNotNull(response.getBody());
List<AirlineEpimsId> responseAirlines = response.getBody();
assertEquals(airlineEpimsID, responseAirlines.get(0));
assertEquals(HttpStatus.OK, response.getStatusCode());
}
}

0 comments on commit f237674

Please sign in to comment.