-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #167 from jabrena/feature/hotel-autocomplete
Adding Hotel Autocomplete support
- Loading branch information
Showing
8 changed files
with
741 additions
and
0 deletions.
There are no files selected for viewing
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
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
52 changes: 52 additions & 0 deletions
52
src/main/java/com/amadeus/referenceData/locations/Hotel.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,52 @@ | ||
package com.amadeus.referenceData.locations; | ||
|
||
import com.amadeus.Amadeus; | ||
import com.amadeus.Params; | ||
import com.amadeus.Response; | ||
import com.amadeus.exceptions.ResponseException; | ||
import com.amadeus.resources.Resource; | ||
|
||
/** | ||
* <p> | ||
* A namespaced client for the | ||
* <code>/v1/reference-data/locations/hotel</code> endpoints. | ||
* </p> | ||
* | ||
* <p> | ||
* Access via the Amadeus client object. | ||
* </p> | ||
* | ||
* <pre> | ||
* Amadeus amadeus = Amadeus.builder("clientId", "secret").build(); | ||
* amadeus.referenceData.locations.hotel;</pre> | ||
*/ | ||
public class Hotel { | ||
private Amadeus client; | ||
|
||
/** | ||
* Constructor. | ||
* @hide | ||
*/ | ||
public Hotel(Amadeus client) { | ||
this.client = client; | ||
} | ||
|
||
/** | ||
* <p> | ||
* Returns a list of relevant hotels inside a city. | ||
* </p> | ||
* | ||
* <pre> | ||
* amadeus.referenceData.locations.hotel.get(Params | ||
* .with("cityCode", "PAR"));</pre> | ||
* | ||
* @param params the parameters to send to the API | ||
* @return an API response object | ||
* @throws ResponseException when an exception occurs | ||
*/ | ||
public com.amadeus.resources.Hotel[] get(Params params) throws ResponseException { | ||
Response response = client.get("/v1/reference-data/locations/hotel", params); | ||
return (com.amadeus.resources.Hotel[]) | ||
Resource.fromArray(response, com.amadeus.resources.Hotel[].class); | ||
} | ||
} |
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
156 changes: 156 additions & 0 deletions
156
src/test/java/com/amadeus/referenceData/locations/HotelIT.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,156 @@ | ||
package com.amadeus.referenceData.locations; | ||
|
||
import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; | ||
import static com.github.tomakehurst.wiremock.client.WireMock.get; | ||
import static com.github.tomakehurst.wiremock.client.WireMock.post; | ||
import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo; | ||
import static org.assertj.core.api.BDDAssertions.then; | ||
|
||
import com.amadeus.Amadeus; | ||
import com.amadeus.Params; | ||
import com.amadeus.exceptions.ResponseException; | ||
import com.amadeus.resources.Hotel; | ||
|
||
import com.github.tomakehurst.wiremock.WireMockServer; | ||
import org.junit.jupiter.api.AfterEach; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Disabled; | ||
import org.junit.jupiter.api.Test; | ||
|
||
public class HotelIT { | ||
|
||
WireMockServer wireMockServer; | ||
|
||
private Amadeus amadeus; | ||
|
||
/** | ||
* In every tests, we will authenticate. | ||
*/ | ||
@BeforeEach | ||
public void setup() { | ||
wireMockServer = new WireMockServer(8080); | ||
wireMockServer.start(); | ||
|
||
//https://developers.amadeus.com/self-service/apis-docs/guides/authorization-262 | ||
String address = "/v1/security/oauth2/token" | ||
+ "?grant_type=client_credentials&client_secret=DEMO&client_id=DEMO"; | ||
wireMockServer.stubFor(post(urlEqualTo(address)) | ||
.willReturn(aResponse().withHeader("Content-Type", "application/json") | ||
.withStatus(200) | ||
.withBodyFile("auth_ok.json"))); | ||
|
||
amadeus = Amadeus | ||
.builder("DEMO", "DEMO") | ||
.setHost("localhost") | ||
.setPort(8080) | ||
.setSsl(false) | ||
.setLogLevel("debug") | ||
.build(); | ||
} | ||
|
||
@AfterEach | ||
public void teardown() { | ||
wireMockServer.stop(); | ||
} | ||
|
||
@Test | ||
public void given_client_when_call_hotel_with_mandatory_parameters_then_returns_ok() | ||
throws ResponseException { | ||
|
||
//Given | ||
Params params = Params | ||
.with("keyword", "PARI") | ||
.and("subType", "HOTEL_GDS"); | ||
|
||
String urlParams = "?subType=HOTEL_GDS&keyword=PARI"; | ||
String address = "/v1/reference-data/locations/hotel" + urlParams; | ||
wireMockServer.stubFor(get(urlEqualTo(address)) | ||
.willReturn(aResponse().withHeader("Content-Type", "application/json") | ||
.withStatus(200) | ||
.withBodyFile("reference_data_hotel_default_response_ok.json"))); | ||
|
||
//When | ||
Hotel[] result = amadeus.referenceData.locations.hotel.get(params); | ||
|
||
//Then | ||
then(result).isNotNull(); | ||
then(result.length).isGreaterThan(1); | ||
} | ||
|
||
@Test | ||
public void given_client_when_call_hotel_then_returns_single_hotel_response_ok() | ||
throws ResponseException { | ||
|
||
//Given | ||
Params params = Params | ||
.with("keyword", "PARI") | ||
.and("subType", "HOTEL_GDS") | ||
.and("max", "1"); | ||
|
||
String urlParams = "?max=1&subType=HOTEL_GDS&keyword=PARI"; | ||
String address = "/v1/reference-data/locations/hotel" + urlParams; | ||
wireMockServer.stubFor(get(urlEqualTo(address)) | ||
.willReturn(aResponse().withHeader("Content-Type", "application/json") | ||
.withStatus(200) | ||
.withBodyFile("reference_data_hotel_single_hotel_response_ok.json"))); | ||
|
||
//When | ||
Hotel[] result = amadeus.referenceData.locations.hotel.get(params); | ||
|
||
//Then | ||
then(result).isNotNull(); | ||
then(result.length).isEqualTo(1); | ||
} | ||
|
||
@Test | ||
public void given_client_when_call_hotel_then_returns_multiple_hotel_response_ok() | ||
throws ResponseException { | ||
|
||
//Given | ||
Params params = Params | ||
.with("keyword", "PARI") | ||
.and("subType", "HOTEL_GDS") | ||
.and("max", "5"); | ||
|
||
String urlParams = "?max=5&subType=HOTEL_GDS&keyword=PARI"; | ||
String address = "/v1/reference-data/locations/hotel" + urlParams; | ||
wireMockServer.stubFor(get(urlEqualTo(address)) | ||
.willReturn(aResponse().withHeader("Content-Type", "application/json") | ||
.withStatus(200) | ||
.withBodyFile("reference_data_hotel_multiple_hotel_response_ok.json"))); | ||
|
||
//When | ||
Hotel[] result = amadeus.referenceData.locations.hotel.get(params); | ||
|
||
//Then | ||
then(result).isNotNull(); | ||
then(result.length).isEqualTo(5); | ||
} | ||
|
||
@Test | ||
public void given_client_when_call_hotel_with_all_parameters_then_response_ok() | ||
throws ResponseException { | ||
|
||
//Given | ||
Params params = Params | ||
.with("keyword", "PARI") | ||
.and("subType", "HOTEL_GDS") | ||
.and("countryCode", "FR") | ||
.and("lang", "EN") | ||
.and("max", "20"); | ||
|
||
String urlParams = "?max=20&countryCode=FR&subType=HOTEL_GDS&keyword=PARI&lang=EN"; | ||
String address = "/v1/reference-data/locations/hotel" + urlParams; | ||
wireMockServer.stubFor(get(urlEqualTo(address)) | ||
.willReturn(aResponse().withHeader("Content-Type", "application/json") | ||
.withStatus(200) | ||
.withBodyFile("reference_data_hotel_default_response_ok.json"))); | ||
|
||
//When | ||
Hotel[] result = amadeus.referenceData.locations.hotel.get(params); | ||
|
||
//Then | ||
then(result).isNotNull(); | ||
then(result.length).isGreaterThan(1); | ||
} | ||
} |
Oops, something went wrong.