Skip to content

Commit

Permalink
Added getAllApplications
Browse files Browse the repository at this point in the history
  • Loading branch information
SMadani committed Jul 18, 2023
1 parent 8d86385 commit 112fc80
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 7 deletions.
18 changes: 15 additions & 3 deletions src/main/java/com/vonage/client/application/ApplicationClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import com.vonage.client.*;
import com.vonage.client.auth.TokenAuthMethod;
import com.vonage.client.common.HttpMethod;
import java.util.List;
import java.util.function.Function;

/**
Expand Down Expand Up @@ -113,23 +114,34 @@ public void deleteApplication(String id) throws VonageResponseParseException, Vo
}

/**
* List the first 1000 available applications.
* Lists the first 1000 available applications.
*
* @return The list of available applications.
*
* @since 7.7.0
*/
public List<Application> listAllApplications() {
return listApplications(ListApplicationRequest.builder().pageSize(1000).build()).getApplications();
}

/**
* Lists the first page of available applications.
*
* @return The ApplicationList HAL response.
*
* @throws VonageResponseParseException if the response from the API could not be parsed.
* @throws VonageClientException if there was a problem with the Vonage request.
*/
public ApplicationList listApplications() throws VonageResponseParseException, VonageClientException {
return listApplications(ListApplicationRequest.builder().pageSize(1000).build());
return listApplications(ListApplicationRequest.builder().build());
}

/**
* List the available applications.
*
* @param listApplicationRequest The page and number of applications per page to list.
*
* @return The list of available applications.
* @return The ApplicationList HAL response.
*
* @throws VonageResponseParseException if the response from the API could not be parsed.
* @throws VonageClientException if there was a problem with the Vonage request.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ public void testListApplicationWithOneResult() throws Exception {

@Test
public void testListApplicationWithMultipleResults() throws Exception {
stubResponse("{\n" +
String json = "{\n" +
" \"page_size\": 10,\n" +
" \"page\": 1,\n" +
" \"total_items\": 12,\n" +
Expand Down Expand Up @@ -385,10 +385,9 @@ public void testListApplicationWithMultipleResults() throws Exception {
" }\n" +
" ]\n" +
" }\n" +
"}"
);
"}";

ApplicationList response = client.listApplications();
ApplicationList response = stubResponseAndGet(json, client::listApplications);

assertEquals((Object) 10, response.getPageSize());
assertEquals((Object) 1, response.getPage());
Expand All @@ -401,6 +400,20 @@ public void testListApplicationWithMultipleResults() throws Exception {

assertEquals("My Application", applications.get(0).getName());
assertEquals("My Second Application", applications.get(1).getName());

applications = stubResponseAndGet(json, client::listAllApplications);
assertEquals(2, applications.size());
}

@Test
public void testListApplicationWithNoResults() throws Exception {
String json = "{\"page\":1,\"_embedded\":{\"applications\":[]}}";
ApplicationList hal = stubResponseAndGet(json, () ->
client.listApplications(ListApplicationRequest.builder().page(1).build())
);
assertEquals(0, hal.getApplications().size());
assertEquals(1, hal.getPage().intValue());
assertEquals(0, stubResponseAndGet(json, client::listAllApplications).size());
}

static abstract class ApplicationEndpointTestSpec<T, R> extends DynamicEndpointTestSpec<T, R> {
Expand Down

0 comments on commit 112fc80

Please sign in to comment.