-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CIV-8154 flight delay controller (#4726)
* 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
1 parent
89e739b
commit f237674
Showing
3 changed files
with
131 additions
and
0 deletions.
There are no files selected for viewing
39 changes: 39 additions & 0 deletions
39
...grationTest/java/uk/gov/hmcts/reform/civil/controllers/airlines/FlightControllerTest.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,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()); | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
src/main/java/uk/gov/hmcts/reform/civil/controllers/airlines/FlightController.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,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); | ||
} | ||
|
||
} |
53 changes: 53 additions & 0 deletions
53
src/test/java/uk/gov/hmcts/reform/civil/controllers/FlightControllerTest.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,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()); | ||
} | ||
} |