Skip to content

Commit eb6402e

Browse files
authored
Merge pull request #167 from jabrena/feature/hotel-autocomplete
Adding Hotel Autocomplete support
2 parents d6871f6 + aa8c268 commit eb6402e

File tree

8 files changed

+741
-0
lines changed

8 files changed

+741
-0
lines changed

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,14 @@ Hotel[] hotels = amadeus.referenceData.locations.hotels.byGeocode.get(Params
431431
.with("longitude", 2.160873)
432432
.and("latitude", 41.397158));
433433

434+
// Hotel autocomplete names
435+
Hotel[] result = amadeus.referenceData.locations.hotel.get(Params
436+
.with("keyword", "PARI")
437+
.and("subType", "HOTEL_GDS")
438+
.and("countryCode", "FR")
439+
.and("lang", "EN")
440+
.and("max", "20"));
441+
434442
// Hotel Offers Search API v3
435443
// Get multiple hotel offers
436444
HotelOfferSearch[] offers = amadeus.shopping.hotelOffersSearch.get(Params

src/main/java/com/amadeus/referenceData/Locations.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import com.amadeus.exceptions.ResponseException;
77
import com.amadeus.referenceData.locations.Airports;
88
import com.amadeus.referenceData.locations.Cities;
9+
import com.amadeus.referenceData.locations.Hotel;
910
import com.amadeus.referenceData.locations.Hotels;
1011
import com.amadeus.referenceData.locations.PointOfInterest;
1112
import com.amadeus.referenceData.locations.PointsOfInterest;
@@ -67,6 +68,13 @@ public class Locations {
6768
*/
6869
public Hotels hotels;
6970

71+
/**
72+
* <p>
73+
* A namespaced client for the
74+
* <code>/v1/reference-data/locations/hotel</code> endpoints.
75+
* </p>
76+
*/
77+
public Hotel hotel;
7078
/**
7179
* <p>
7280
* A namespaced client for the
@@ -84,6 +92,7 @@ public Locations(Amadeus client) {
8492
this.airports = new Airports(client);
8593
this.pointsOfInterest = new PointsOfInterest(client);
8694
this.hotels = new Hotels(client);
95+
this.hotel = new Hotel(client);
8796
this.cities = new Cities(client);
8897
}
8998

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package com.amadeus.referenceData.locations;
2+
3+
import com.amadeus.Amadeus;
4+
import com.amadeus.Params;
5+
import com.amadeus.Response;
6+
import com.amadeus.exceptions.ResponseException;
7+
import com.amadeus.resources.Resource;
8+
9+
/**
10+
* <p>
11+
* A namespaced client for the
12+
* <code>/v1/reference-data/locations/hotel</code> endpoints.
13+
* </p>
14+
*
15+
* <p>
16+
* Access via the Amadeus client object.
17+
* </p>
18+
*
19+
* <pre>
20+
* Amadeus amadeus = Amadeus.builder("clientId", "secret").build();
21+
* amadeus.referenceData.locations.hotel;</pre>
22+
*/
23+
public class Hotel {
24+
private Amadeus client;
25+
26+
/**
27+
* Constructor.
28+
* @hide
29+
*/
30+
public Hotel(Amadeus client) {
31+
this.client = client;
32+
}
33+
34+
/**
35+
* <p>
36+
* Returns a list of relevant hotels inside a city.
37+
* </p>
38+
*
39+
* <pre>
40+
* amadeus.referenceData.locations.hotel.get(Params
41+
* .with("cityCode", "PAR"));</pre>
42+
*
43+
* @param params the parameters to send to the API
44+
* @return an API response object
45+
* @throws ResponseException when an exception occurs
46+
*/
47+
public com.amadeus.resources.Hotel[] get(Params params) throws ResponseException {
48+
Response response = client.get("/v1/reference-data/locations/hotel", params);
49+
return (com.amadeus.resources.Hotel[])
50+
Resource.fromArray(response, com.amadeus.resources.Hotel[].class);
51+
}
52+
}

src/test/java/com/amadeus/NamespaceTest.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import com.amadeus.referenceData.RecommendedLocations;
2121
import com.amadeus.referenceData.locations.Airports;
2222
import com.amadeus.referenceData.locations.Cities;
23+
import com.amadeus.referenceData.locations.Hotel;
2324
import com.amadeus.referenceData.locations.PointsOfInterest;
2425
import com.amadeus.referenceData.locations.hotels.ByCity;
2526
import com.amadeus.referenceData.locations.hotels.ByGeocode;
@@ -56,6 +57,7 @@
5657
import org.junit.jupiter.api.Test;
5758
import org.mockito.Mockito;
5859

60+
// TODO Create an isolated Unit tests per entity.
5961
public class NamespaceTest {
6062

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

536+
// Testing hotel autocomplete feature
537+
Hotel hotel = new Hotel(client);
538+
Mockito.when(client.get("/v1/reference-data/locations/hotel", params))
539+
.thenReturn(multiResponse);
540+
assertNotNull(hotel.get(params));
541+
534542
// Testing city search get
535543
Mockito.when(client.get("/v1/reference-data/locations/cities", null))
536544
.thenReturn(multiResponse);
Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
package com.amadeus.referenceData.locations;
2+
3+
import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
4+
import static com.github.tomakehurst.wiremock.client.WireMock.get;
5+
import static com.github.tomakehurst.wiremock.client.WireMock.post;
6+
import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo;
7+
import static org.assertj.core.api.BDDAssertions.then;
8+
9+
import com.amadeus.Amadeus;
10+
import com.amadeus.Params;
11+
import com.amadeus.exceptions.ResponseException;
12+
import com.amadeus.resources.Hotel;
13+
14+
import com.github.tomakehurst.wiremock.WireMockServer;
15+
import org.junit.jupiter.api.AfterEach;
16+
import org.junit.jupiter.api.BeforeEach;
17+
import org.junit.jupiter.api.Disabled;
18+
import org.junit.jupiter.api.Test;
19+
20+
public class HotelIT {
21+
22+
WireMockServer wireMockServer;
23+
24+
private Amadeus amadeus;
25+
26+
/**
27+
* In every tests, we will authenticate.
28+
*/
29+
@BeforeEach
30+
public void setup() {
31+
wireMockServer = new WireMockServer(8080);
32+
wireMockServer.start();
33+
34+
//https://developers.amadeus.com/self-service/apis-docs/guides/authorization-262
35+
String address = "/v1/security/oauth2/token"
36+
+ "?grant_type=client_credentials&client_secret=DEMO&client_id=DEMO";
37+
wireMockServer.stubFor(post(urlEqualTo(address))
38+
.willReturn(aResponse().withHeader("Content-Type", "application/json")
39+
.withStatus(200)
40+
.withBodyFile("auth_ok.json")));
41+
42+
amadeus = Amadeus
43+
.builder("DEMO", "DEMO")
44+
.setHost("localhost")
45+
.setPort(8080)
46+
.setSsl(false)
47+
.setLogLevel("debug")
48+
.build();
49+
}
50+
51+
@AfterEach
52+
public void teardown() {
53+
wireMockServer.stop();
54+
}
55+
56+
@Test
57+
public void given_client_when_call_hotel_with_mandatory_parameters_then_returns_ok()
58+
throws ResponseException {
59+
60+
//Given
61+
Params params = Params
62+
.with("keyword", "PARI")
63+
.and("subType", "HOTEL_GDS");
64+
65+
String urlParams = "?subType=HOTEL_GDS&keyword=PARI";
66+
String address = "/v1/reference-data/locations/hotel" + urlParams;
67+
wireMockServer.stubFor(get(urlEqualTo(address))
68+
.willReturn(aResponse().withHeader("Content-Type", "application/json")
69+
.withStatus(200)
70+
.withBodyFile("reference_data_hotel_default_response_ok.json")));
71+
72+
//When
73+
Hotel[] result = amadeus.referenceData.locations.hotel.get(params);
74+
75+
//Then
76+
then(result).isNotNull();
77+
then(result.length).isGreaterThan(1);
78+
}
79+
80+
@Test
81+
public void given_client_when_call_hotel_then_returns_single_hotel_response_ok()
82+
throws ResponseException {
83+
84+
//Given
85+
Params params = Params
86+
.with("keyword", "PARI")
87+
.and("subType", "HOTEL_GDS")
88+
.and("max", "1");
89+
90+
String urlParams = "?max=1&subType=HOTEL_GDS&keyword=PARI";
91+
String address = "/v1/reference-data/locations/hotel" + urlParams;
92+
wireMockServer.stubFor(get(urlEqualTo(address))
93+
.willReturn(aResponse().withHeader("Content-Type", "application/json")
94+
.withStatus(200)
95+
.withBodyFile("reference_data_hotel_single_hotel_response_ok.json")));
96+
97+
//When
98+
Hotel[] result = amadeus.referenceData.locations.hotel.get(params);
99+
100+
//Then
101+
then(result).isNotNull();
102+
then(result.length).isEqualTo(1);
103+
}
104+
105+
@Test
106+
public void given_client_when_call_hotel_then_returns_multiple_hotel_response_ok()
107+
throws ResponseException {
108+
109+
//Given
110+
Params params = Params
111+
.with("keyword", "PARI")
112+
.and("subType", "HOTEL_GDS")
113+
.and("max", "5");
114+
115+
String urlParams = "?max=5&subType=HOTEL_GDS&keyword=PARI";
116+
String address = "/v1/reference-data/locations/hotel" + urlParams;
117+
wireMockServer.stubFor(get(urlEqualTo(address))
118+
.willReturn(aResponse().withHeader("Content-Type", "application/json")
119+
.withStatus(200)
120+
.withBodyFile("reference_data_hotel_multiple_hotel_response_ok.json")));
121+
122+
//When
123+
Hotel[] result = amadeus.referenceData.locations.hotel.get(params);
124+
125+
//Then
126+
then(result).isNotNull();
127+
then(result.length).isEqualTo(5);
128+
}
129+
130+
@Test
131+
public void given_client_when_call_hotel_with_all_parameters_then_response_ok()
132+
throws ResponseException {
133+
134+
//Given
135+
Params params = Params
136+
.with("keyword", "PARI")
137+
.and("subType", "HOTEL_GDS")
138+
.and("countryCode", "FR")
139+
.and("lang", "EN")
140+
.and("max", "20");
141+
142+
String urlParams = "?max=20&countryCode=FR&subType=HOTEL_GDS&keyword=PARI&lang=EN";
143+
String address = "/v1/reference-data/locations/hotel" + urlParams;
144+
wireMockServer.stubFor(get(urlEqualTo(address))
145+
.willReturn(aResponse().withHeader("Content-Type", "application/json")
146+
.withStatus(200)
147+
.withBodyFile("reference_data_hotel_default_response_ok.json")));
148+
149+
//When
150+
Hotel[] result = amadeus.referenceData.locations.hotel.get(params);
151+
152+
//Then
153+
then(result).isNotNull();
154+
then(result.length).isGreaterThan(1);
155+
}
156+
}

0 commit comments

Comments
 (0)