Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/main/java/com/amadeus/resources/Resource.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import com.amadeus.Response;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import lombok.Getter;

/**
Expand All @@ -28,7 +30,11 @@ protected Resource() {}
*/
public static Resource[] fromArray(Response response, Class klass) {
Gson gson = new GsonBuilder().setDateFormat("yyyy-MM-dd").create();
Resource[] resources = (Resource[]) gson.fromJson(response.getData(), klass);
JsonElement responseData = response.getData();
if (responseData == null) {
responseData = new JsonArray(0);
}
Resource[] resources = (Resource[]) gson.fromJson(responseData, klass);
for (Resource resource : resources) {
resource.response = response;
resource.deSerializationClass = klass;
Expand Down
24 changes: 24 additions & 0 deletions src/test/java/com/amadeus/referenceData/locations/CitiesIT.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package com.amadeus.referencedata.locations;

import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
import static com.github.tomakehurst.wiremock.client.WireMock.equalTo;
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 com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo;
import static org.assertj.core.api.AssertionsForClassTypes.assertThatThrownBy;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotEquals;

import com.amadeus.Amadeus;
Expand Down Expand Up @@ -74,6 +77,27 @@ public void givenClientWhenCallCitySearchWithParamsThenOK()
assertNotEquals(0, result.length);
}

@Test
public void givenClientWhenCallCitySearchWithParamsThenEmpty() throws ResponseException {

// Given
String address = "/v1/reference-data/locations/cities";
wireMockServer.stubFor(get(urlPathEqualTo(address))
.withQueryParam("keyword", equalTo("SANC"))
.withQueryParam("countryCode", equalTo("AZ"))
.willReturn(aResponse().withHeader("Content-Type", "application/json")
.withStatus(200)
.withBodyFile("city_search_response_empty.json")));

Params params = Params.with("keyword", "SANC").and("countryCode", "AZ");

// When
City[] result = amadeus.referenceData.locations.cities.get(params);

// Then
assertEquals(0, result.length);
}

@Test
public void givenClientWhenCallCitySearchWithoutParamsThenOK()
throws ResponseException {
Expand Down
19 changes: 19 additions & 0 deletions src/test/resources/__files/city_search_response_empty.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"warnings": [
{
"code": 1797,
"title": "DATA NOT FOUND",
"detail": "No Cities available",
"source": {
"parameter": "keyword"
},
"status": 200
}
],
"meta": {
"count": 0,
"links": {
"self": "https://test.api.amadeus.com/v1/reference-data/locations/cities?countryCode=AZ&keyword=SANC&max=1000"
}
}
}
Loading