Skip to content

Commit

Permalink
Merge pull request #167 from jabrena/feature/hotel-autocomplete
Browse files Browse the repository at this point in the history
Adding Hotel Autocomplete support
  • Loading branch information
tsolakoua authored Jul 7, 2022
2 parents d6871f6 + aa8c268 commit eb6402e
Show file tree
Hide file tree
Showing 8 changed files with 741 additions and 0 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,14 @@ Hotel[] hotels = amadeus.referenceData.locations.hotels.byGeocode.get(Params
.with("longitude", 2.160873)
.and("latitude", 41.397158));

// Hotel autocomplete names
Hotel[] result = amadeus.referenceData.locations.hotel.get(Params
.with("keyword", "PARI")
.and("subType", "HOTEL_GDS")
.and("countryCode", "FR")
.and("lang", "EN")
.and("max", "20"));

// Hotel Offers Search API v3
// Get multiple hotel offers
HotelOfferSearch[] offers = amadeus.shopping.hotelOffersSearch.get(Params
Expand Down
9 changes: 9 additions & 0 deletions src/main/java/com/amadeus/referenceData/Locations.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.amadeus.exceptions.ResponseException;
import com.amadeus.referenceData.locations.Airports;
import com.amadeus.referenceData.locations.Cities;
import com.amadeus.referenceData.locations.Hotel;
import com.amadeus.referenceData.locations.Hotels;
import com.amadeus.referenceData.locations.PointOfInterest;
import com.amadeus.referenceData.locations.PointsOfInterest;
Expand Down Expand Up @@ -67,6 +68,13 @@ public class Locations {
*/
public Hotels hotels;

/**
* <p>
* A namespaced client for the
* <code>/v1/reference-data/locations/hotel</code> endpoints.
* </p>
*/
public Hotel hotel;
/**
* <p>
* A namespaced client for the
Expand All @@ -84,6 +92,7 @@ public Locations(Amadeus client) {
this.airports = new Airports(client);
this.pointsOfInterest = new PointsOfInterest(client);
this.hotels = new Hotels(client);
this.hotel = new Hotel(client);
this.cities = new Cities(client);
}

Expand Down
52 changes: 52 additions & 0 deletions src/main/java/com/amadeus/referenceData/locations/Hotel.java
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);
}
}
8 changes: 8 additions & 0 deletions src/test/java/com/amadeus/NamespaceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.amadeus.referenceData.RecommendedLocations;
import com.amadeus.referenceData.locations.Airports;
import com.amadeus.referenceData.locations.Cities;
import com.amadeus.referenceData.locations.Hotel;
import com.amadeus.referenceData.locations.PointsOfInterest;
import com.amadeus.referenceData.locations.hotels.ByCity;
import com.amadeus.referenceData.locations.hotels.ByGeocode;
Expand Down Expand Up @@ -56,6 +57,7 @@
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;

// TODO Create an isolated Unit tests per entity.
public class NamespaceTest {

private Amadeus client;
Expand Down Expand Up @@ -531,6 +533,12 @@ public void testGetMethods() throws ResponseException {
assertNotNull(hotelsByGeocode.get(params));
assertEquals(hotelsByGeocode.get().length, 2);

// Testing hotel autocomplete feature
Hotel hotel = new Hotel(client);
Mockito.when(client.get("/v1/reference-data/locations/hotel", params))
.thenReturn(multiResponse);
assertNotNull(hotel.get(params));

// Testing city search get
Mockito.when(client.get("/v1/reference-data/locations/cities", null))
.thenReturn(multiResponse);
Expand Down
156 changes: 156 additions & 0 deletions src/test/java/com/amadeus/referenceData/locations/HotelIT.java
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);
}
}
Loading

0 comments on commit eb6402e

Please sign in to comment.