Search in sources :

Example 6 with AppProfile

use of com.google.cloud.bigtable.admin.v2.models.AppProfile in project java-bigtable by googleapis.

the class BaseBigtableInstanceAdminClientTest method listAppProfilesTest2.

@Test
public void listAppProfilesTest2() throws Exception {
    AppProfile responsesElement = AppProfile.newBuilder().build();
    ListAppProfilesResponse expectedResponse = ListAppProfilesResponse.newBuilder().setNextPageToken("").addAllAppProfiles(Arrays.asList(responsesElement)).build();
    mockBigtableInstanceAdmin.addResponse(expectedResponse);
    String parent = "parent-995424086";
    ListAppProfilesPagedResponse pagedListResponse = client.listAppProfiles(parent);
    List<AppProfile> resources = Lists.newArrayList(pagedListResponse.iterateAll());
    Assert.assertEquals(1, resources.size());
    Assert.assertEquals(expectedResponse.getAppProfilesList().get(0), resources.get(0));
    List<AbstractMessage> actualRequests = mockBigtableInstanceAdmin.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    ListAppProfilesRequest actualRequest = ((ListAppProfilesRequest) actualRequests.get(0));
    Assert.assertEquals(parent, actualRequest.getParent());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : AbstractMessage(com.google.protobuf.AbstractMessage) ListAppProfilesPagedResponse(com.google.cloud.bigtable.admin.v2.BaseBigtableInstanceAdminClient.ListAppProfilesPagedResponse) AppProfile(com.google.bigtable.admin.v2.AppProfile) ListAppProfilesRequest(com.google.bigtable.admin.v2.ListAppProfilesRequest) ByteString(com.google.protobuf.ByteString) ListAppProfilesResponse(com.google.bigtable.admin.v2.ListAppProfilesResponse) Test(org.junit.Test)

Example 7 with AppProfile

use of com.google.cloud.bigtable.admin.v2.models.AppProfile in project java-bigtable by googleapis.

the class BaseBigtableInstanceAdminClientTest method listAppProfilesTest.

@Test
public void listAppProfilesTest() throws Exception {
    AppProfile responsesElement = AppProfile.newBuilder().build();
    ListAppProfilesResponse expectedResponse = ListAppProfilesResponse.newBuilder().setNextPageToken("").addAllAppProfiles(Arrays.asList(responsesElement)).build();
    mockBigtableInstanceAdmin.addResponse(expectedResponse);
    InstanceName parent = InstanceName.of("[PROJECT]", "[INSTANCE]");
    ListAppProfilesPagedResponse pagedListResponse = client.listAppProfiles(parent);
    List<AppProfile> resources = Lists.newArrayList(pagedListResponse.iterateAll());
    Assert.assertEquals(1, resources.size());
    Assert.assertEquals(expectedResponse.getAppProfilesList().get(0), resources.get(0));
    List<AbstractMessage> actualRequests = mockBigtableInstanceAdmin.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    ListAppProfilesRequest actualRequest = ((ListAppProfilesRequest) actualRequests.get(0));
    Assert.assertEquals(parent.toString(), actualRequest.getParent());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : InstanceName(com.google.bigtable.admin.v2.InstanceName) AbstractMessage(com.google.protobuf.AbstractMessage) ListAppProfilesPagedResponse(com.google.cloud.bigtable.admin.v2.BaseBigtableInstanceAdminClient.ListAppProfilesPagedResponse) AppProfile(com.google.bigtable.admin.v2.AppProfile) ListAppProfilesRequest(com.google.bigtable.admin.v2.ListAppProfilesRequest) ListAppProfilesResponse(com.google.bigtable.admin.v2.ListAppProfilesResponse) Test(org.junit.Test)

Example 8 with AppProfile

use of com.google.cloud.bigtable.admin.v2.models.AppProfile in project java-bigtable by googleapis.

the class BigtableInstanceAdminClientTest method testListAppProfiles.

@Test
public void testListAppProfiles() {
    // Setup
    Mockito.when(mockStub.listAppProfilesPagedCallable()).thenReturn(mockListAppProfilesCallable);
    com.google.bigtable.admin.v2.ListAppProfilesRequest expectedRequest = com.google.bigtable.admin.v2.ListAppProfilesRequest.newBuilder().setParent(NameUtil.formatInstanceName(PROJECT_ID, INSTANCE_ID)).build();
    // 3 AppProfiles spread across 2 pages
    List<com.google.bigtable.admin.v2.AppProfile> expectedProtos = Lists.newArrayList();
    for (int i = 0; i < 3; i++) {
        expectedProtos.add(com.google.bigtable.admin.v2.AppProfile.newBuilder().setName(APP_PROFILE_NAME + i).setDescription("profile" + i).setMultiClusterRoutingUseAny(com.google.bigtable.admin.v2.AppProfile.MultiClusterRoutingUseAny.getDefaultInstance()).build());
    }
    // 2 on the first page
    ListAppProfilesPage page0 = Mockito.mock(ListAppProfilesPage.class);
    Mockito.when(page0.getValues()).thenReturn(expectedProtos.subList(0, 2));
    Mockito.when(page0.hasNextPage()).thenReturn(true);
    // 1 on the last page
    ListAppProfilesPage page1 = Mockito.mock(ListAppProfilesPage.class);
    Mockito.when(page1.getValues()).thenReturn(expectedProtos.subList(2, 3));
    // Link page0 to page1
    Mockito.when(page0.getNextPageAsync()).thenReturn(ApiFutures.immediateFuture(page1));
    // Link page to the response
    ListAppProfilesPagedResponse response0 = Mockito.mock(ListAppProfilesPagedResponse.class);
    Mockito.when(response0.getPage()).thenReturn(page0);
    Mockito.when(mockListAppProfilesCallable.futureCall(expectedRequest)).thenReturn(ApiFutures.immediateFuture(response0));
    // Execute
    List<AppProfile> actualResults = adminClient.listAppProfiles(INSTANCE_ID);
    // Verify
    List<AppProfile> expectedResults = Lists.newArrayList();
    for (com.google.bigtable.admin.v2.AppProfile expectedProto : expectedProtos) {
        expectedResults.add(AppProfile.fromProto(expectedProto));
    }
    assertThat(actualResults).containsExactlyElementsIn(expectedResults);
}
Also used : AppProfile(com.google.cloud.bigtable.admin.v2.models.AppProfile) ListAppProfilesPage(com.google.cloud.bigtable.admin.v2.BaseBigtableInstanceAdminClient.ListAppProfilesPage) ListAppProfilesPagedResponse(com.google.cloud.bigtable.admin.v2.BaseBigtableInstanceAdminClient.ListAppProfilesPagedResponse) Test(org.junit.Test)

Example 9 with AppProfile

use of com.google.cloud.bigtable.admin.v2.models.AppProfile in project java-bigtable by googleapis.

the class BigtableInstanceAdminClientTest method testUpdateAppProfile.

@Test
public void testUpdateAppProfile() {
    // Setup
    Mockito.when(mockStub.updateAppProfileOperationCallable()).thenReturn(mockUpdateAppProfileCallable);
    com.google.bigtable.admin.v2.UpdateAppProfileRequest expectedRequest = com.google.bigtable.admin.v2.UpdateAppProfileRequest.newBuilder().setAppProfile(com.google.bigtable.admin.v2.AppProfile.newBuilder().setName(APP_PROFILE_NAME).setDescription("updated description")).setUpdateMask(FieldMask.newBuilder().addPaths("description")).build();
    com.google.bigtable.admin.v2.AppProfile expectedResponse = com.google.bigtable.admin.v2.AppProfile.newBuilder().setName(APP_PROFILE_NAME).setDescription("updated description").setMultiClusterRoutingUseAny(com.google.bigtable.admin.v2.AppProfile.MultiClusterRoutingUseAny.getDefaultInstance()).build();
    mockOperationResult(mockUpdateAppProfileCallable, expectedRequest, expectedResponse);
    // Execute
    AppProfile actualResult = adminClient.updateAppProfile(UpdateAppProfileRequest.of(INSTANCE_ID, APP_PROFILE_ID).setDescription("updated description"));
    // Verify
    assertThat(actualResult).isEqualTo(AppProfile.fromProto(expectedResponse));
}
Also used : AppProfile(com.google.cloud.bigtable.admin.v2.models.AppProfile) Test(org.junit.Test)

Example 10 with AppProfile

use of com.google.cloud.bigtable.admin.v2.models.AppProfile in project java-bigtable by googleapis.

the class BigtableInstanceAdminClientTest method testGetAppProfile.

@Test
public void testGetAppProfile() {
    // Setup
    Mockito.when(mockStub.getAppProfileCallable()).thenReturn(mockGetAppProfileCallable);
    com.google.bigtable.admin.v2.GetAppProfileRequest expectedRequest = com.google.bigtable.admin.v2.GetAppProfileRequest.newBuilder().setName(APP_PROFILE_NAME).build();
    com.google.bigtable.admin.v2.AppProfile expectedResponse = com.google.bigtable.admin.v2.AppProfile.newBuilder().setName(APP_PROFILE_NAME).setDescription("my description").setMultiClusterRoutingUseAny(com.google.bigtable.admin.v2.AppProfile.MultiClusterRoutingUseAny.getDefaultInstance()).build();
    Mockito.when(mockGetAppProfileCallable.futureCall(expectedRequest)).thenReturn(ApiFutures.immediateFuture(expectedResponse));
    // Execute
    AppProfile actualResult = adminClient.getAppProfile(INSTANCE_ID, APP_PROFILE_ID);
    // Verify
    assertThat(actualResult).isEqualTo(AppProfile.fromProto(expectedResponse));
}
Also used : AppProfile(com.google.cloud.bigtable.admin.v2.models.AppProfile) Test(org.junit.Test)

Aggregations

AppProfile (com.google.cloud.bigtable.admin.v2.models.AppProfile)11 Test (org.junit.Test)11 ListAppProfilesPagedResponse (com.google.cloud.bigtable.admin.v2.BaseBigtableInstanceAdminClient.ListAppProfilesPagedResponse)4 ListAppProfilesRequest (com.google.bigtable.admin.v2.ListAppProfilesRequest)3 AppProfile (com.google.bigtable.admin.v2.AppProfile)2 ListAppProfilesResponse (com.google.bigtable.admin.v2.ListAppProfilesResponse)2 ListAppProfilesPage (com.google.cloud.bigtable.admin.v2.BaseBigtableInstanceAdminClient.ListAppProfilesPage)2 AbstractMessage (com.google.protobuf.AbstractMessage)2 ApiFuture (com.google.api.core.ApiFuture)1 GetAppProfileRequest (com.google.bigtable.admin.v2.GetAppProfileRequest)1 InstanceName (com.google.bigtable.admin.v2.InstanceName)1 CreateAppProfileRequest (com.google.cloud.bigtable.admin.v2.models.CreateAppProfileRequest)1 ImmutableList (com.google.common.collect.ImmutableList)1 ByteString (com.google.protobuf.ByteString)1 List (java.util.List)1