Search in sources :

Example 1 with ListTenantsRequest

use of com.google.cloud.talent.v4.ListTenantsRequest in project java-talent by googleapis.

the class TenantServiceClientTest method listTenantsTest2.

@Test
public void listTenantsTest2() throws Exception {
    Tenant responsesElement = Tenant.newBuilder().build();
    ListTenantsResponse expectedResponse = ListTenantsResponse.newBuilder().setNextPageToken("").addAllTenants(Arrays.asList(responsesElement)).build();
    mockTenantService.addResponse(expectedResponse);
    String parent = "parent-995424086";
    ListTenantsPagedResponse pagedListResponse = client.listTenants(parent);
    List<Tenant> resources = Lists.newArrayList(pagedListResponse.iterateAll());
    Assert.assertEquals(1, resources.size());
    Assert.assertEquals(expectedResponse.getTenantsList().get(0), resources.get(0));
    List<AbstractMessage> actualRequests = mockTenantService.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    ListTenantsRequest actualRequest = ((ListTenantsRequest) actualRequests.get(0));
    Assert.assertEquals(parent, actualRequest.getParent());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : AbstractMessage(com.google.protobuf.AbstractMessage) ListTenantsPagedResponse(com.google.cloud.talent.v4.TenantServiceClient.ListTenantsPagedResponse) Test(org.junit.Test)

Example 2 with ListTenantsRequest

use of com.google.cloud.talent.v4.ListTenantsRequest in project java-docs-samples by GoogleCloudPlatform.

the class JobSearchListTenants method listTenants.

// List Tenants.
public static void listTenants(String projectId) throws IOException {
    // the "close" method on the client to safely clean up any remaining background resources.
    try (TenantServiceClient tenantServiceClient = TenantServiceClient.create()) {
        ProjectName parent = ProjectName.of(projectId);
        ListTenantsRequest request = ListTenantsRequest.newBuilder().setParent(parent.toString()).build();
        for (Tenant responseItem : tenantServiceClient.listTenants(request).iterateAll()) {
            System.out.format("Tenant Name: %s%n", responseItem.getName());
            System.out.format("External ID: %s%n", responseItem.getExternalId());
        }
    }
}
Also used : TenantServiceClient(com.google.cloud.talent.v4beta1.TenantServiceClient) Tenant(com.google.cloud.talent.v4beta1.Tenant) ProjectName(com.google.cloud.talent.v4beta1.ProjectName) ListTenantsRequest(com.google.cloud.talent.v4beta1.ListTenantsRequest)

Example 3 with ListTenantsRequest

use of com.google.cloud.talent.v4.ListTenantsRequest in project java-talent by googleapis.

the class JobSearchListTenants method sampleListTenants.

/**
 * List Tenants
 */
public static void sampleListTenants(String projectId) {
    try (TenantServiceClient tenantServiceClient = TenantServiceClient.create()) {
        ProjectName parent = ProjectName.of(projectId);
        ListTenantsRequest request = ListTenantsRequest.newBuilder().setParent(parent.toString()).build();
        for (Tenant responseItem : tenantServiceClient.listTenants(request).iterateAll()) {
            System.out.printf("Tenant Name: %s\n", responseItem.getName());
            System.out.printf("External ID: %s\n", responseItem.getExternalId());
        }
    } catch (Exception exception) {
        System.err.println("Failed to create the client due to: " + exception);
    }
}
Also used : TenantServiceClient(com.google.cloud.talent.v4beta1.TenantServiceClient) Tenant(com.google.cloud.talent.v4beta1.Tenant) ProjectName(com.google.cloud.talent.v4beta1.ProjectName) ListTenantsRequest(com.google.cloud.talent.v4beta1.ListTenantsRequest)

Example 4 with ListTenantsRequest

use of com.google.cloud.talent.v4.ListTenantsRequest in project java-talent by googleapis.

the class TenantServiceClientTest method listTenantsTest.

@Test
public void listTenantsTest() throws Exception {
    Tenant responsesElement = Tenant.newBuilder().build();
    ListTenantsResponse expectedResponse = ListTenantsResponse.newBuilder().setNextPageToken("").addAllTenants(Arrays.asList(responsesElement)).build();
    mockTenantService.addResponse(expectedResponse);
    ProjectName parent = ProjectName.of("[PROJECT]");
    ListTenantsPagedResponse pagedListResponse = client.listTenants(parent);
    List<Tenant> resources = Lists.newArrayList(pagedListResponse.iterateAll());
    Assert.assertEquals(1, resources.size());
    Assert.assertEquals(expectedResponse.getTenantsList().get(0), resources.get(0));
    List<AbstractMessage> actualRequests = mockTenantService.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    ListTenantsRequest actualRequest = ((ListTenantsRequest) actualRequests.get(0));
    Assert.assertEquals(parent.toString(), actualRequest.getParent());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : AbstractMessage(com.google.protobuf.AbstractMessage) ListTenantsPagedResponse(com.google.cloud.talent.v4.TenantServiceClient.ListTenantsPagedResponse) Test(org.junit.Test)

Example 5 with ListTenantsRequest

use of com.google.cloud.talent.v4.ListTenantsRequest in project java-talent by googleapis.

the class ITSystemTest method listTenantsTest.

@Test
public void listTenantsTest() {
    ListTenantsRequest request = ListTenantsRequest.newBuilder().setParent(PROJECT_NAME.toString()).build();
    for (Tenant actual : tenantServiceClient.listTenants(request).iterateAll()) {
        if (tenant.getName().equals(actual.getName())) {
            assertEquals(tenant.getExternalId(), actual.getExternalId());
            assertEquals(tenant.getName(), actual.getName());
        }
    }
}
Also used : Tenant(com.google.cloud.talent.v4beta1.Tenant) ListTenantsRequest(com.google.cloud.talent.v4beta1.ListTenantsRequest) Test(org.junit.Test)

Aggregations

ListTenantsRequest (com.google.cloud.talent.v4beta1.ListTenantsRequest)3 Tenant (com.google.cloud.talent.v4beta1.Tenant)3 Test (org.junit.Test)3 ListTenantsPagedResponse (com.google.cloud.talent.v4.TenantServiceClient.ListTenantsPagedResponse)2 ProjectName (com.google.cloud.talent.v4beta1.ProjectName)2 TenantServiceClient (com.google.cloud.talent.v4beta1.TenantServiceClient)2 AbstractMessage (com.google.protobuf.AbstractMessage)2 ListTenantsRequest (com.google.cloud.talent.v4.ListTenantsRequest)1 ProjectName (com.google.cloud.talent.v4.ProjectName)1 Tenant (com.google.cloud.talent.v4.Tenant)1 TenantServiceClient (com.google.cloud.talent.v4.TenantServiceClient)1