Search in sources :

Example 1 with ListLocationsResponse

use of com.google.api.services.appengine.v1.model.ListLocationsResponse in project google-cloud-intellij by GoogleCloudPlatform.

the class GoogleApiClientAppEngineAdminService method fetchAllAppEngineLocations.

private List<Location> fetchAllAppEngineLocations(Credential credential) throws GoogleApiException, IOException {
    try {
        ListLocationsResponse response = fetchAppEngineLocationPage(credential, null);
        List<Location> locations = new ArrayList<>(response.getLocations());
        while (response.getNextPageToken() != null) {
            response = fetchAppEngineLocationPage(credential, response.getNextPageToken());
            locations.addAll(response.getLocations());
        }
        return locations;
    } catch (GoogleJsonResponseException e) {
        throw GoogleApiException.from(e);
    }
}
Also used : GoogleJsonResponseException(com.google.api.client.googleapis.json.GoogleJsonResponseException) ListLocationsResponse(com.google.api.services.appengine.v1.model.ListLocationsResponse) ArrayList(java.util.ArrayList) Location(com.google.api.services.appengine.v1.model.Location)

Example 2 with ListLocationsResponse

use of com.google.api.services.appengine.v1.model.ListLocationsResponse in project google-cloud-intellij by GoogleCloudPlatform.

the class GoogleApiClientAppEngineAdminServiceTest method testGetAllAppEngineLocations_success.

@Test
public void testGetAllAppEngineLocations_success() throws IOException, GoogleApiException {
    String pageToken = "page-token";
    ListLocationsResponse response1 = new ListLocationsResponse();
    List<Location> locationsPage1 = Arrays.asList(createMockLocation("location-1"), createMockLocation("location-2"));
    response1.setLocations(locationsPage1);
    response1.setNextPageToken(pageToken);
    List<Location> locationsPage2 = Arrays.asList(createMockLocation("location-3"), createMockLocation("location-4"));
    ListLocationsResponse response2 = new ListLocationsResponse();
    response2.setLocations(locationsPage2);
    response2.setNextPageToken(null);
    when(appengineClientMock.getAppsLocationsListQuery().setPageToken(any())).thenReturn(appengineClientMock.getAppsLocationsListQuery());
    when(appengineClientMock.getAppsLocationsListQuery().execute()).thenReturn(response1);
    Appengine.Apps.Locations.List appsLocationsListQuery2 = mock(Appengine.Apps.Locations.List.class);
    when(appengineClientMock.getAppsLocationsListQuery().setPageToken(eq(pageToken))).thenReturn(appsLocationsListQuery2);
    when(appsLocationsListQuery2.execute()).thenReturn(response2);
    List<Location> expectedResults = new ArrayList<>(locationsPage1);
    expectedResults.addAll(locationsPage2);
    // make the call twice. the service should only be hit once per page
    assertEquals(expectedResults, service.getAllAppEngineLocations(mock(Credential.class)));
    assertEquals(expectedResults, service.getAllAppEngineLocations(mock(Credential.class)));
    verify(appengineClientMock.getAppsLocationsListQuery(), times(1)).execute();
    verify(appsLocationsListQuery2, times(1)).execute();
}
Also used : ListLocationsResponse(com.google.api.services.appengine.v1.model.ListLocationsResponse) Appengine(com.google.api.services.appengine.v1.Appengine) ArrayList(java.util.ArrayList) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Location(com.google.api.services.appengine.v1.model.Location) Test(org.junit.Test)

Aggregations

ListLocationsResponse (com.google.api.services.appengine.v1.model.ListLocationsResponse)2 Location (com.google.api.services.appengine.v1.model.Location)2 ArrayList (java.util.ArrayList)2 GoogleJsonResponseException (com.google.api.client.googleapis.json.GoogleJsonResponseException)1 Appengine (com.google.api.services.appengine.v1.Appengine)1 Test (org.junit.Test)1 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)1