Skip to content

Commit

Permalink
Merge pull request #13 from CallFire/develop
Browse files Browse the repository at this point in the history
disabled serialization of empty arrays
  • Loading branch information
vladimir-mhl committed Oct 2, 2015
2 parents 8e4c3a9 + bcf5bf5 commit c0d5983
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 18 deletions.
1 change: 1 addition & 0 deletions src/main/java/com/callfire/api/client/JsonConverter.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public class JsonConverter {
public JsonConverter() {
mapper = new ObjectMapper();
mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
mapper.disable(SerializationFeature.WRITE_EMPTY_JSON_ARRAYS);
mapper.enable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
}
Expand Down
11 changes: 6 additions & 5 deletions src/test/java/com/callfire/api/client/api/account/MeApiTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -101,16 +101,17 @@ public void testVerifyCallerId() throws Exception {

@Test
public void testCreateApiCredentials() throws Exception {
String expectedJson = getJsonPayload(BASE_PATH + "/account/meApi/response/createApiCredentials.json");
ArgumentCaptor<HttpUriRequest> captor = mockHttpResponse(mockHttpClient, mockHttpResponse, expectedJson);
String responseJson = getJsonPayload(BASE_PATH + "/account/meApi/response/createApiCredentials.json");
String requestJson = getJsonPayload(BASE_PATH + "/account/meApi/request/createApiCredentials.json");
ArgumentCaptor<HttpUriRequest> captor = mockHttpResponse(mockHttpClient, mockHttpResponse, responseJson);

ApiCredentials credentials = new ApiCredentials("test_name");
ApiCredentials credentials = new ApiCredentials("api_20_account");
ApiCredentials apiCredentials = client.meApi().createApiCredentials(credentials);
assertThat(jsonConverter.serialize(apiCredentials), equalToIgnoringWhiteSpace(expectedJson));
assertThat(jsonConverter.serialize(apiCredentials), equalToIgnoringWhiteSpace(responseJson));

HttpUriRequest arg = captor.getValue();
assertEquals(HttpPost.METHOD_NAME, arg.getMethod());
assertEquals(jsonConverter.serialize(credentials), extractHttpEntity(arg));
assertThat(extractHttpEntity(arg), equalToIgnoringWhiteSpace(requestJson));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,44 +37,44 @@ public void setUp() throws Exception {

@Test
public void testOrderKeywords() throws Exception {
String expectedJson = getJsonPayload("/responses/account/ordersApi/orderKeywords.json");
ArgumentCaptor<HttpUriRequest> captor = mockHttpResponse(mockHttpClient, mockHttpResponse, expectedJson);
String requestJson = getJsonPayload(BASE_PATH + "/account/ordersApi/request/orderKeywords.json");
String responseJson = getJsonPayload(BASE_PATH + "/account/ordersApi/response/orderKeywords.json");
ArgumentCaptor<HttpUriRequest> captor = mockHttpResponse(mockHttpClient, mockHttpResponse, responseJson);

KeywordPurchaseRequest request = KeywordPurchaseRequest.create()
.keywords(asList("KW1", "KW2"))
.build();

ResourceId id = client.ordersApi().orderKeywords(request);
assertThat(jsonConverter.serialize(id), equalToIgnoringWhiteSpace(expectedJson));
assertThat(jsonConverter.serialize(id), equalToIgnoringWhiteSpace(responseJson));

HttpUriRequest arg = captor.getValue();
assertEquals(HttpPost.METHOD_NAME, arg.getMethod());
assertEquals(jsonConverter.serialize(request), extractHttpEntity(arg));
assertThat(extractHttpEntity(arg), equalToIgnoringWhiteSpace(requestJson));
}

@Test
public void testOrderNumbers() throws Exception {
String expectedJson = getJsonPayload("/responses/account/ordersApi/orderNumbers.json");
ArgumentCaptor<HttpUriRequest> captor = mockHttpResponse(mockHttpClient, mockHttpResponse, expectedJson);
String requestJson = getJsonPayload(BASE_PATH + "/account/ordersApi/request/orderNumbers.json");
String responseJson = getJsonPayload(BASE_PATH + "/account/ordersApi/response/orderNumbers.json");
ArgumentCaptor<HttpUriRequest> captor = mockHttpResponse(mockHttpClient, mockHttpResponse, responseJson);

NumberPurchaseRequest request = NumberPurchaseRequest.create()
.city("City")
.numbers(asList("1234567890", "1234567888"))
.zipcode("1234")
.state("LA")
.localCount(2)
.zipcode("90401")
.build();

ResourceId id = client.ordersApi().orderNumbers(request);
assertThat(jsonConverter.serialize(id), equalToIgnoringWhiteSpace(expectedJson));
assertThat(jsonConverter.serialize(id), equalToIgnoringWhiteSpace(responseJson));

HttpUriRequest arg = captor.getValue();
assertEquals(HttpPost.METHOD_NAME, arg.getMethod());
assertEquals(jsonConverter.serialize(request), extractHttpEntity(arg));
assertThat(jsonConverter.serialize(request), equalToIgnoringWhiteSpace(requestJson));
}

@Test
public void testGetOrder() throws Exception {
String expectedJson = getJsonPayload("/responses/account/ordersApi/getOrder.json");
String expectedJson = getJsonPayload(BASE_PATH + "/account/ordersApi/response/getOrder.json");
ArgumentCaptor<HttpUriRequest> captor = mockHttpResponse(mockHttpClient, mockHttpResponse, expectedJson);

NumberOrder numberOrder = client.ordersApi().getOrder(1L);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"keywords": [
"KW1",
"KW2"
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"localCount": 2,
"zipcode": "90401"
}

0 comments on commit c0d5983

Please sign in to comment.